You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README-11.html 45KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
  2. <html> <head>
  3. <title>AspectJ 1.1beta2 -- Readme</title>
  4. <style type="text/css">
  5. <!--
  6. P { margin-left: 20px; }
  7. PRE { margin-left: 20px; }
  8. LI { margin-left: 20px; }
  9. H4 { margin-left: 20px; }
  10. H3 { margin-left: 10px; }
  11. -->
  12. </style>
  13. </head>
  14. <body>
  15. <div align="right"><small>
  16. &copy; Copyright 2002 Palo Alto Research Center, Incorporated.
  17. All rights reserved.
  18. </small></div>
  19. <h1>AspectJ Readme</h1>
  20. <p align="right"><i>Version 1.1beta2</i></p>
  21. <p> This is an early-access release of AspectJ 1.1. It includes a small
  22. number of new language features as well as major improvements to the
  23. functionality of the tools. </p>
  24. <p> This document is intended to completely describe the 1.1 language
  25. and tools in relation to AspectJ 1.0.6. With that in mind, many
  26. features are documented sketchily with the flag "not working in
  27. 1.1beta2", but we believe it to include some description of all the
  28. features of 1.1 that are different from those in 1.0.6.
  29. </p>
  30. <p>The information in this document will be folded into the main line
  31. of <a href="http://dev.eclipse.org/aspectj/documentation.html">AspectJ
  32. documentation</a> but has not yet. All descriptions here should be
  33. read as changes to the AspectJ documentation. </p>
  34. <p> The main body of this document describes the differences between
  35. the 1.1beta2 release and the 1.0.6 release. For those following our
  36. release schedule closely, however, these are the changes since the
  37. 1.1beta1 release: </p>
  38. <ul>
  39. <li>The documentation, core tools and ant tasks are now part of a
  40. single downloadable distribution. </li>
  41. <li>More 1.0 features have been implemented: inter-type constructor
  42. definitions, instance initialization and pre-initialization join
  43. points, exception handler join points, advice execution join
  44. points, and the -XserializableAspects experimental option. </li>
  45. <li><a href="#VOID_FIELD_SET">Field set join points now have a
  46. <code>void</code> return type.</a></li> XXX
  47. <li>Users now have more control over the <a href="#XLINT">-Xlint</a>
  48. option. </li>
  49. <li>AspectJ 1.1 will not pick out
  50. <a href="#NO_CALLEE_SIDE_CALL">callee-side call join
  51. points</a>. </li>
  52. <li>The <code>-noweave</code> option is now the
  53. <code><a href="#XNOWEAVE">-XnoWeave</a></code> option.</li>
  54. <li>A new option, <code><a href="#XNOINLINE"></a>-XnoInline</code>,
  55. is now supported to control some compiler behavior.</li>
  56. <li>A class's default constructor may
  57. <a href="#DEFAULT_CONSTRUCTOR_CONFLICT">conflict</a> with an
  58. inter-type constructor. </li>
  59. <li>Some of the treatment of
  60. <a href="#SUPER_IFACE_INITS">initialization join points for
  61. super-interfaces</a> have been clarified. </li>
  62. <li>The <a href="#PER_TYPE">new pertype aspect specifier</a> has
  63. been taken off the table for 1.1rc, though it may well be in a
  64. future release. </li>
  65. </ul>
  66. <p> This document begins with short descriptions of changes from the
  67. 1.0 release.
  68. </p>
  69. <ul>
  70. <li><a href="#language">the language</a>,</li>
  71. <li><a href="#compiler">the compiler</a>,</li>
  72. <li><a href="#tools">the support tools</a>,</li>
  73. <li><a href="#runtime">the runtime</a>,</li>
  74. <li><a href="#devenv">the development environment support</a>, and</li>
  75. <li><a href="#sources">the sources</a>,</li>
  76. </ul>
  77. <p> followed by <a href="#details">details</a> of many of the changes.
  78. </p>
  79. <!-- ============================== -->
  80. <hr>
  81. <h2><a name="language">The Language</a></h2>
  82. <p> AspectJ 1.1 is a slightly different language than AspectJ 1.0.
  83. In all but a few cases, programs written in AspectJ 1.0 should
  84. compile correctly in AspectJ 1.1. In many cases, there are
  85. new or preferred forms in AspectJ 1.1. However, some AspectJ 1.0
  86. features are not yet implemented in 1.1, so many 1.0 programs
  87. will not compile in this release.
  88. </p>
  89. <p>
  90. Most changes to the language are additions to expressibility
  91. requested by our users:
  92. </p>
  93. <ul>
  94. <li><a href="#THROWS_PATTERN">Matching based on throws</a>: You can
  95. now make finer discriminations between methods based on declared
  96. exceptions. </li>
  97. <li><a href="#NEW_PCDS">New kinded pointcut designators</a>: Now
  98. every kind of pointcut has a corresponding kinded pointcut
  99. designator. </li>
  100. </ul>
  101. <p> Some are have different behavior in edge cases but offer
  102. improved power and clarity: </p>
  103. <ul>
  104. <li><a href="#ASPECT_PRECEDENCE">New aspect precedence form</a>:
  105. AspectJ 1.1 has a new declare form, declare dominates, that is
  106. intended to replace the "dominates" clause on aspects. </li>
  107. </ul>
  108. <p> But in order to support weaving into bytecode effectively,
  109. several incompatible changes had to be made to the language: </p>
  110. <ul>
  111. <li>A class's default constructor may
  112. <a href="#DEFAULT_CONSTRUCTOR_CONFLICT">conflict</a> with an
  113. inter-type constructor. </li>
  114. <li><a href="#NO_CALLEE_SIDE_CALL">No callee-side call join
  115. points</a>: The AspectJ 1.1 compiler does not expose call join
  116. points unless it is given the calling code. </li>
  117. <li><a href="#SINGLE_INTERCLASS_TARGET">One target for intertype
  118. declarations</a></li>
  119. <li><a href="#UNAVAILABLE_JOIN_POINTS">No initializer execution join
  120. points</a></li>
  121. <li><a href="#CONSTRUCTOR_EXECUTION_IS_BIGGER">Initializers run
  122. inside constructor execution join points</a></li>
  123. <li><a href="#WITHIN_MEMBER_TYPES">Small limitations of the within
  124. pointcut</a></li>
  125. <li><a href="#WITHIN_CODE">Small limitations of the withincode
  126. pointcut</a></li>
  127. <li><a href="#INSTANCEOF_ON_WILD">Can't do instanceof matching on
  128. type patterns with wildcards</a></li>
  129. <li><a href="#NO_SOURCE_COLUMN">SourceLocation.getColumn() is
  130. deprecated and will always return 0</a></li>
  131. </ul>
  132. <p><a name="NEW_LIMITATIONS">There</a> are a couple of language
  133. limitations for things that are rarely used that make the
  134. implementation simpler. If no one speaks up in defense of these,
  135. they will probably become official simplifications of the language.
  136. If defenders speak up, then they will be listed as limitations of
  137. the current compiler implementation. </p>
  138. <ul>
  139. <li>'declare soft: TYPE: POINTCUT;' In 1.0 a TYPE_PATTERN was
  140. allowed rather than a TYPE. This limitation makes declare soft
  141. much easier to implement efficiently.</li>
  142. <li>Inter-type field declarations only allow a single field per
  143. line, i.e. this is now illegal 'int C.field1, D.field2;' This must
  144. instead be, 'int C.field1; int D.field2;'</li>
  145. </ul>
  146. <p>Finally, we did not implement the handling of multiple
  147. <code>..</code> wildcards in args PCDs (rarely encountered in the
  148. wild) because we didn't have the time. It should be available in
  149. 1.1rc1.</p>
  150. <!-- ============================== -->
  151. <hr>
  152. <h2><a name="compiler">The Compiler</a></h2>
  153. <p> The compiler for AspectJ 1.1 is different than the compiler for
  154. AspectJ 1.0. While this document describes the differences in the
  155. compiler, it's worthwhile noting that much effort has been made to
  156. make sure that the interface to ajc 1.1 is, as much as possible, the
  157. same as the interface to ajc 1.0. There are two important changes
  158. under the hood, however. </p>
  159. <p> First, The 1.1 compiler is implemented on top of IBM's
  160. open-source Eclipse compiler. This has two benefits: It allows us
  161. to concentrate on the AspectJ extensions to Java and let the Eclipse
  162. team worry about making sure the Java edge cases work, and it allows
  163. us to piggyback on Eclipse's already mature incremental compilation
  164. facilities. </p>
  165. <p> Second, ajc now cleanly deliniates compilation of source code
  166. from assembly (or "weaving") of bytecode. The compiler still
  167. accepts source code, but internally it transforms it into bytecode
  168. format before weaving. </p>
  169. <p> This new architecture, and other changes to the compiler, allows
  170. us to implement some features that were defined in the AspectJ 1.0
  171. language but not implementable in the 1.1 compiler (after returning
  172. advice on handler join points will probably be one of those
  173. features, when handler join points are finished). It also makes
  174. some new features available: </p>
  175. <ul>
  176. <li><a href="#SOURCEROOT">The -sourceroots option</a>: This option
  177. takes one or more directories, and indicates that all the source
  178. files in those directories should be passed to the compiler. </li>
  179. <li><a href="#BYTECODE_WEAVING">The -injars option</a>: This option
  180. takes one or more jar files, and indicates that all the classfiles
  181. in the jar files should be woven into. </li>
  182. <li><a href="#XNOWEAVE">-XnoWeave, a compiler option to suppress
  183. weaving</a></li>
  184. <li><a href="#BINARY_ASPECTS">-aspectpath, working with aspects in
  185. .class/.jar form</a></li>
  186. <li><a href="#OUTJAR">The -outjar option</a>: This option indicates
  187. that the result classfiles of compiling and weaving should be placed
  188. in the specified jar file. </li>
  189. <li><a href="#XLINT">The -Xlint option allows control over
  190. warnings.</a></li>
  191. <li><a href="#OTHER_X_OPTIONS">Various -X options</a> changed.</li>
  192. <li><a href="#INCREMENTAL">Incremental compilation</a>: The AspectJ
  193. 1.1 compiler supports incremental compilation. </li>
  194. </ul>
  195. <p> Some other features we plan to support for 1.1, but did not make
  196. it into this beta release: </p>
  197. <ul>
  198. <li><a href="#NO_AROUND_OPTIMIZATION">Inlining around advice</a>:
  199. The optimization of around advice is not turned on in the beta,
  200. and so will result in slower generated code than that generated by
  201. ajc 1.0.</li>
  202. <li><a href="#EXCEPTION_CHECKING">Exception checking is not
  203. handled completely during weaving</a></li>
  204. <li><a href="#ERROR_MESSAGES">Error messages will sometimes be scary</a></li>
  205. <li>Only one <code>..</code> wildcard is supported in the args
  206. PCD. </li>
  207. </ul>
  208. <p> But some features of the 1.0 compiler are not supported in the
  209. 1.1 compiler: </p>
  210. <ul>
  211. <li><a href="#NO_SOURCE">Source-specific options</a>: The -source,
  212. -usejavac, -nocomment and -workingdir options are no longer
  213. supported</li>
  214. <li><a href="#NO_STRICT_LENIENT">The -strict and -lenient options</a>
  215. </li>
  216. <li><a href="#NO_PORTING">The -porting option</a></li>
  217. <li><a href="#13_REQUIRED">J2SE 1.2 is not supported;
  218. J2SE 1.3 or later is required;.</a></li>
  219. </ul>
  220. <p> A short description of the options ajc accepts is available with
  221. "ajc -help". </p>
  222. <p> </p>
  223. <!-- ============================== -->
  224. <hr>
  225. <h2><a name="tools">Support Tools</a></h2>
  226. <p>This release includes two new experimental Ant variants,
  227. a CompilerAdapter to support running <tt>ajc</tt> with the Javac task
  228. by setting the build.compiler property and a task that supports
  229. incremental mode by watching a file.
  230. </p>
  231. <p>This release does not include <tt>ajdoc</tt>, the documentation tool for
  232. AspectJ sources, and its 1.1 release will trail the others' by weeks.
  233. <tt>Ajdoc</tt> is deeply dependent on the abstract syntax tree
  234. classes from the old compiler, so it needs a bottom-up rewrite.
  235. We think it best to use this opportunity to implement more general
  236. API's for publishing and rendering static structure. Because those API's
  237. are last to settle in the new architecture, and because the compiler itself
  238. is a higher priority, we are delaying work on <tt>ajdoc</tt> until
  239. after the 1.1 release.</p>
  240. <p>AspectJ 1.1 will not include <tt>ajdb</tt>, the AspectJ stand-alone debugger.
  241. It is no longer necessary because more third-party debuggers are starting
  242. to work according to JSR 45, "Debugging support for other languages",
  243. which we plan to support in AspectJ 1.1. </p>
  244. <!-- ============================== -->
  245. <hr>
  246. <h2><a name="runtime">The Runtime Library</a></h2>
  247. <p>This release has minor additions to the runtime library classes.
  248. As with any release, you should compile and run with the runtime
  249. library that came with your compiler, and you may run with
  250. a later version of the library without recompiling your code.</p>
  251. <p> In one instance, however, they behave differently this release.
  252. Because the AspectJ 1.1 compiler does its weaving through
  253. bytecode, column numbers of source locations are not available.
  254. Therefore, <code>thisJoinPoint.getSourceLocation().getColumn()</code>
  255. is deprecated and will always return 0. </p>
  256. <!-- ============================== -->
  257. <hr>
  258. <h2><a name="devenv">The AJDE Tools</a></h2>
  259. <p> AJDE for JBuilder, AJDE for Netbeans, and AJDE for Emacs and the
  260. AJBrowser have not changed much. They use the batch-build mode of
  261. the new compiler. The beta compiler does not yet produce
  262. crosscutting structure (for anything but method executions) so there are no inline
  263. annotations in JBuilder or Emacs support and you only see a
  264. declaration tree in the structure views. Incremental building and
  265. bytecode weaving are not available in the AJDE tools in the beta
  266. release, but will be in a future release.</p>
  267. <p> Of note for the beta is that NetBeans 3.4 is supported, and there is now
  268. better integration for the compiler messages output window.</p>
  269. <!-- ============================== -->
  270. <hr>
  271. <h2><a name="sources">The Sources and the Licences</a></h2>
  272. <p> The AspectJ tools sources are available under the
  273. <a href="http://eclipse.org/legal/cpl-v10.html">Common Public
  274. Licence</a> in the CVS repository
  275. at <a href="http://eclipse.org">http://eclipse.org</a>.
  276. </p>
  277. <p> More information about the sources can be found in their
  278. respective README files. </p>
  279. <!-- ============================== -->
  280. <hr>
  281. <hr>
  282. <h2><a name="details">Details</a></h2>
  283. <h3><a name="THROWS_PATTERN">Matching based on throws</a></h3>
  284. <p> Type patterns may now be used to pick out methods and
  285. constructors based on their throws clauses. This allows the
  286. following two kinds of extremely wildcarded pointcuts: </p>
  287. <pre> pointcut throwsMathlike():
  288. // each call to a method with a throws clause containing at least
  289. // one exception exception with "Math" in its name.
  290. call(* *(..) throws *..*Math*);
  291. pointcut doesNotThrowMathlike():
  292. // each call to a method with a throws clause containing no
  293. // exceptions with "Math" in its name.
  294. call(* *(..) throws !*..*Math*);
  295. </pre>
  296. <p> The longwinded rules are that a method or constructor pattern
  297. can have a "throws clause pattern". Throws clause patterns look
  298. like: </p>
  299. <pre> ThrowsClausePattern:
  300. ThrowsClausePatternItem ("," ThrowsClausePatternItem)*
  301. ThrowsClausePatternItem:
  302. ["!"] TypeNamePattern
  303. </pre>
  304. <p> A ThrowsClausePattern matches the ThrowsClause of any code
  305. member signature. To match, each ThrowsClausePatternItem must
  306. match the throws clause of the member in question. If any item
  307. doesn't match, then the whole pattern doesn't match. This rule is
  308. unchanged from AspectJ 1.0. </p>
  309. <p> If a ThrowsClausePatternItem begins with "!", then it matches
  310. a particular throws clause if and only if <em>none</em> of the
  311. types named in the throws clause is matched by the
  312. TypeNamePattern. </p>
  313. <p> If a ThrowsClausePatternItem does not begin with "!", then it
  314. matches a throws clause if and only if <em>any</em> of the types
  315. named in the throws clause is matched by the TypeNamePattern.</p>
  316. <p> These rules are completely backwards compatible with
  317. AspectJ 1.0. The rule for "!" matching has one potentially
  318. surprising property, in that the two PCDs shown below will have
  319. different matching rules. </p>
  320. <pre> [1] call(* *(..) throws !IOException)
  321. [2] call(* *(..) throws (!IOException))
  322. void m() throws RuntimeException, IOException {}
  323. </pre>
  324. <p> [1] will NOT match the method m(), because method m's throws
  325. clause declares that it throws IOException. [2] WILL match the
  326. method m(), because method m's throws clause declares the it
  327. throws some exception which does not match IOException,
  328. i.e. RuntimeException. </p>
  329. <h3><a name="NEW_PCDS">New kinded pointcut designators</a></h3>
  330. <p> AspectJ 1.0 does not provide kinded pointcut designators for
  331. two (rarely used) join points: preinitialization (the code that
  332. runs before a super constructor call is made) and advice
  333. execution. AspectJ 1.1 does not change the meaning of the join
  334. points, but provides two new pointcut designators to pick out
  335. these join points, thus making join points and pointcut
  336. designators more parallel. </p>
  337. <p> <code>adviceexectuion()</code> will pick out advice execution
  338. join points. You will usually want to use <code>adviceexecution()
  339. && within(Aspect)</code> to restrict it to only those pieces of
  340. advice defined in a particular aspect. <br>
  341. <code>preinitialization(<var>ConstructorPattern</var>)</code> will
  342. pick out pre-initialization join points where the initializaiton
  343. process is entered through <var>ConstructorPattern</var>. </p>
  344. <h3><a name="PER_TYPE">New pertype aspect specifier</a></h3>
  345. <p>We strongly considered adding a pertype aspect kind to 1.1.
  346. This is somewhat motivated by the new
  347. <a href="#SINGLE_INTERCLASS_TARGET">restrictions on inter-type
  348. declarations<a>. This is also motivated by many previous request
  349. to support a common logging idiom. Here's what pertype would look
  350. like:</p>
  351. <pre> /** One instance of this aspect will be created for each class,
  352. * interface or aspect in the com.bigboxco packages.
  353. */
  354. aspect Logger pertype(com.bigboxco..*) {
  355. /* This field holds a logger for the class. */
  356. Log log;
  357. /* This advice will run for every public execution defined by
  358. * a type for which a Logger aspect has been created, i.e.
  359. * any type in com.bigboxco..*
  360. */
  361. before(): execution(public * *(..)) {
  362. log.enterMethod(thisJoinPoint.getSignature().getName());
  363. }
  364. /* We can use a special constructor to initialize the log field */
  365. public Logger(Class myType) {
  366. this.log = new Log(myType);
  367. }
  368. }
  369. /** External code could use aspectOf to get at the log, i.e. */
  370. Log l = Logger.aspectOf(com.bigboxco.Foo.class).log;
  371. </pre>
  372. <p>The one open question that we see is how this should interact
  373. with inner types. If a pertype aspect is created for an outer
  374. type should advice in that aspect run for join points in inner
  375. types? That is the behavior of the most common uses of this
  376. idiom. </p>
  377. <p> In any case, this feature will not be in AspectJ 1.1.
  378. </p>
  379. <h3><a name="SINGLE_INTERCLASS_TARGET">One target for intertype
  380. declarations</a></h3>
  381. <p> Intertype declarations (once called "introductions") in
  382. AspectJ 1.1 can only have one target type. So the following code
  383. intended to declare that there is a void doStuff() method on all
  384. subtypes of Target is not legal AspectJ 1.1 code.
  385. </p>
  386. <pre> aspect A {
  387. public void Target+.doStuff() { ... }
  388. }
  389. </pre>
  390. <p> The functionality of "multi-intertype declarations" can be
  391. recovered by using a helper interface.
  392. </p>
  393. <pre> aspect A {
  394. private interface MyTarget {}
  395. declare parents: Target+ implements MyTarget;
  396. public void MyTarget.doStuff() { ... }
  397. }
  398. </pre>
  399. <p> We believe this is better style in AspectJ 1.0 as well, as it
  400. makes clear the static type of "this" inside the method body.
  401. </p>
  402. <p> The one piece of functionality that can not be easily
  403. recovered is the ability to add static fields to many classes. We
  404. believe that the <a href="#PER_TYPE">pertype proposal</a> provides
  405. this functionality in a much more usable form.</p>
  406. <h3><a name="UNAVAILABLE_JOIN_POINTS">No initializer execution join
  407. points</a></h3>
  408. <p> AspectJ 1.1 does not consider initializer execution as a
  409. principled join point. The collection of initializer code (the
  410. code that sets fields with initializers and the code in non-static
  411. initializer blocks) is something that makes sense only in Java
  412. source code, not in Java bytecode. </p>
  413. <h3><a name="CONSTRUCTOR_EXECUTION_IS_BIGGER">Initializers run
  414. inside constructor execution join points</a></h3>
  415. <p> The code generated by the initializers in Java source code now
  416. runs inside of constructor execution join points. This changes
  417. how before advice runs on constructor execution join points.
  418. Consider: </p>
  419. <pre> class C {
  420. C() { }
  421. String id = "identifier"; // this assignment
  422. // has to happen sometime
  423. }
  424. aspect A {
  425. before(C c) this(c) && execution(C.new()) {
  426. System.out.println(c.id.length());
  427. }
  428. }
  429. </pre>
  430. <p> In AspectJ 1.0, this will print "10", since id is assigned its
  431. initial value prior to the before advice's execution. However, in
  432. AspectJ 1.1, this will throw a NullPointerExcception, since "id"
  433. does not have a value prior to the before advice's execution.
  434. </p>
  435. <p> Note that the various flavors of after returning advice are
  436. unchanged in this respect in AspectJ 1.1. Also note that this
  437. only matters for the execution of constructors that call a
  438. super-constructor. Execution of constructors that call a
  439. this-constructor are the same in AspectJ 1.1 as in AspectJ 1.0.
  440. </p>
  441. <p> We believe this difference should be minimal to real programs,
  442. since programmers using before advice on constructor execution
  443. must always assume incomplete object initialization, since the
  444. constructor has not yet run. </p>
  445. <h3><a name="WITHIN_MEMBER_TYPES">Small limitations of the within
  446. pointcut</a></h3>
  447. <p> Becuase of the guarantees made (and not made) by the Java
  448. classfile format, there are cases where AspectJ 1.1 cannot
  449. guarantee that the within pointcut designator will pick out all
  450. code that was originally within the source code of a certain
  451. type.
  452. </p>
  453. <p> The non-guarantee applies to code inside of anonymous and
  454. local types inside member types. While the within pointcut
  455. designator behaves exactly as it did in AspectJ 1.0 when given a
  456. package-level type (like C, below), if given a member-type (like
  457. C.InsideC, below), it is not guaranteed to capture code in
  458. contained local and anonymous types. For example: </p>
  459. <pre> class C {
  460. Thread t;
  461. class InsideC {
  462. void setupOuterThread() {
  463. t = new Thread(
  464. new Runnable() {
  465. public void run() {
  466. // join points with code here
  467. // might not be captured by
  468. // within(C.InsideC), but are
  469. // captured by within(C)
  470. System.out.println("hi");
  471. }
  472. });
  473. }
  474. }
  475. }
  476. </pre>
  477. <p> We believe the non-guarantee is small, and we haven't verified
  478. that it is a problem in practice. </p>
  479. <h3><a name="WITHIN_CODE">Small limitations of the withincode
  480. pointcut</a></h3>
  481. <p>The withincode pointcut has similar issues to those described
  482. above for within.
  483. </p>
  484. <h3><a name="INSTANCEOF_ON_WILD">Can't do instanceof matching on
  485. type patterns with wildcard</a></h3>
  486. <p>The pointcut designators this, target and args specify a
  487. dynamic test on their argument. These tests can not be performed
  488. on type patterns with wildcards in them. The following code that
  489. compiled under 1.0 will be an error in AspectJ-1.1:</p>
  490. <pre> pointcut oneOfMine(): this(com.bigboxco..*);
  491. </pre>
  492. <p>The only way to implement this kind of matching in a modular
  493. way would be to use the reflection API at runtime on the Class of
  494. the object. This would have a very high performance cost and
  495. possible security issues. There are two good work-arounds. If
  496. you control the source or bytecode to the type you want to match
  497. then you can use declare parents, i.e.:</p>
  498. <pre> private interface OneOfMine {}
  499. declare parents: com.bigboxco..* implements OneOfMine;
  500. pointcut oneOfMine(): this(OneOfMine);
  501. </pre>
  502. <p>If you want the more dynamic matching and are willing to pay
  503. for the performance, then you should use the Java reflection API
  504. combinded with if. That would look something like:</p>
  505. <pre> pointcut oneOfMine(): this(Object) &&
  506. if(classMatches("com.bigboxco..*",
  507. thisJoinPoint.getTarget().getClass()));
  508. static boolean classMatches(String pattern, Class _class) {
  509. if (patternMatches(pattern, _class.getName())) return true;
  510. ...
  511. }
  512. </pre>
  513. <p>Note: wildcard type matching still works in all other pcds that
  514. match based on static types. So, you can use
  515. 'within(com.bigboxco..*+)' to match any code lexically within one
  516. of your classes or a subtype thereof. This is often a good
  517. choice.</p>
  518. </p>
  519. <h3><a name="NO_SOURCE_COLUMN">SourceLocation.getColumn()</a></h3>
  520. <p>The Java .class file format contains information about the
  521. source file and line numbers of its contents; however, it has not
  522. information about source columns. As a result, we can not
  523. effectively support the accesss of column information in the
  524. reflection API. So, any calls to
  525. thisJoinPoint.getSourceLocation().getColumn() will be marked as
  526. deprecated by the compiler, and will always return 0.</p>
  527. <h3><a name="ASPECT_PRECEDENCE">Aspect precedence</a></h3>
  528. <p> AspectJ 1.1 has a new declare form:
  529. </p>
  530. <pre> declare dominates ":" TypePatternList ";"
  531. </pre>
  532. <p> This is used to declare advice ordering constraints on join
  533. points. For example, the constraints that (1) aspects that have
  534. Security as part of their name should dominate all other aspects, and
  535. (2) the Logging aspect (and any aspect that extends it) should
  536. dominate all non-security aspects, can be expressed by: </p>
  537. <pre> declare dominates: *..*Security*, Logging+, *;
  538. </pre>
  539. <p> In the TypePatternList, the wildcard * means "any type not matched
  540. by another type in the declare dominates". </p>
  541. <h4>Various cycles</h4>
  542. <p> It is an error for any aspect to be matched by more than one
  543. TypePattern in a single decare dominates, so: </p>
  544. <pre> declare dominates: A, B, A ; // error
  545. </pre>
  546. <p> However, multiple declare dominates forms may legally have this
  547. kind of circularity. For example, each of these declare dominates is
  548. perfectly legal:
  549. </p>
  550. <pre> declare dominates: B, A;
  551. declare dominates: A, B;
  552. </pre>
  553. <p> And a system in which both constraints are active may also be
  554. legal, so long as advice from A and B don't share a join point. So
  555. this is an idiom that can be used to enforce that A and B are strongly
  556. independent. </p>
  557. <h4>Applies to concrete aspects</h4>
  558. <p> Consider the following library aspects:
  559. </p>
  560. <pre> abstract aspect Logging {
  561. abstract pointcut logged();
  562. before(): logged() {
  563. System.err.println("thisJoinPoint: " + thisJoinPoint);
  564. }
  565. }
  566. aspect aspect MyProfiling {
  567. abstract pointcut profiled();
  568. Object around(): profiled() {
  569. long beforeTime = System.currentTimeMillis();
  570. try {
  571. return proceed();
  572. } finally {
  573. long afterTime = System.currentTimeMillis();
  574. addToProfile(thisJoinPointStaticPart,
  575. afterTime - beforeTime);
  576. }
  577. }
  578. abstract void addToProfile(
  579. org.aspectj.JoinPoint.StaticPart jp,
  580. long elapsed);
  581. }
  582. </pre>
  583. <p> In order to use either aspect, they must be extended with
  584. concrete aspects, say, MyLogging and MyProfiling. In AspectJ
  585. 1.0, it was not possible to express that Logging's advice (when
  586. concerned with the concrete aspect MyLogging) dominated
  587. Profiling's advice (when concerned with the concrete aspect
  588. MyProfiling) without adding a dominates clause to Logging
  589. itself. In AspectJ 1.1, we can express that constraint with a
  590. simple: </p>
  591. <pre> declare dominates: MyLogging, MyProfiling;
  592. </pre>
  593. <h4>Changing order of advice for sub-aspects</h4>
  594. <p> By default, advice in a sub-aspect has more precedence than
  595. advice in a super-aspect. One use of the AspectJ 1.0 dominates
  596. form was to change this precedence:
  597. </p>
  598. <pre> abstract aspect SuperA dominates SubA {
  599. pointcut foo(): ... ;
  600. before(): foo() {
  601. // in AspectJ 1.0, runs before the advice in SubA
  602. // because of the dominates clause
  603. }
  604. }
  605. aspect SubA extends SuperA {
  606. before(): foo() {
  607. // in AspectJ 1.0, runs after the advice in SuperA
  608. // because of the dominates clause
  609. }
  610. }
  611. </pre>
  612. <p> This no longer works in AspectJ 1.1, since declare dominates only
  613. matters for concrete aspects. Thus, if you want to regain this kind
  614. of precedence change, you will need to refactor your aspects.
  615. </p>
  616. <h3><a name="SOURCEROOT">The -sourceroots option</a></h3>
  617. <p> The AspectJ 1.1 compiler now accepts a -sourceroots option used to
  618. pass all .java files in particular directories to the compiler. It
  619. takes either a single directory name, or a list of directory names
  620. separated with the CLASSPATH separator character (":" for various
  621. Unices, ";" for various Windows). </p>
  622. <p> So, if you have your project separated into a gui module and a
  623. base module, each of which is stored in a directory tree, you might
  624. use one of
  625. </p>
  626. <pre> ajc -sourceroots /myProject/gui:/myProject/base
  627. ajc -sourceroots d:\myProject\gui;d:\myProject\base
  628. </pre>
  629. <p> This option may be used in conjunction with lst files, listing
  630. .java files on the command line, and the -injars option.
  631. </p>
  632. <p> <strong>ALPHA:</strong> In the beta release of the compiler,
  633. only one directory can be passed to the -sourceroots option.
  634. </p>
  635. <h3><a name="BYTECODE_WEAVING">The -injars option</a></h3>
  636. <p> The AspectJ 1.1 compiler now accepts an -injars option used to
  637. pass all .class files in a particular jar file to the compiler. It
  638. takes either a single directory name, or a list of directory names
  639. separated with the CLASSPATH separator character (":" for various
  640. Unices, ";" for various Windows). </p>
  641. <p> So, if MyTracing.java defines a trace aspect that you want to
  642. apply to all the classes in myBase.jar and myGui.jar, you would use
  643. one of: </p>
  644. <pre> ajc -injars /bin/myBase.jar:/bin/myGui.jar MyTracing.java
  645. ajc -injars d:\bin\myBase.jar;d:\bin\myGui.jar MyTracing.java
  646. </pre>
  647. <p> The class files in the input jars must not have had advice woven
  648. into them, since AspectJ enforces the requirement that advice is woven
  649. into a particular classfile only once. So if the classfiles in the
  650. jar file are to be created with the ajc compiler (as opposed to a pure
  651. Java compiler), they should not be compiled with any non-abstract
  652. aspects. </p>
  653. <p> This option may be used in conjunction with lst files, listing
  654. .java files on the command line, and the -sourceroots option.
  655. </p>
  656. <h3><a name="OUTJAR">The -outjar option</a></h3>
  657. <p> The -outjar option takes the name of a jar file into which the
  658. results of the compilation should be put. For example:
  659. <pre> ajc -injars myBase.jar MyTracing.java -outjar myTracedBase.jar
  660. </pre>
  661. <p> No meta information is placed in the output jar file </p>
  662. <h3><a name="INCREMENTAL">Incremental compilation</a></h3>
  663. <p> The AspectJ 1.1 compiler now supports incremental compilation.
  664. For the final release, this will work from the various IDE plugins we
  665. ship, but for the Alpha release, it is only supported on the
  666. command-line compiler.
  667. </p>
  668. <p> When ajc is called with the -incremental option, it must also be
  669. passed a -sourceroots option specifying a directory to incrementally
  670. compile. Once the initial compile is done, ajc waits for console
  671. input. Every time it reads a new line, (i.e., every time the user
  672. hits return) ajc recompiles those input files that need recompiling.
  673. </p>
  674. <h4>Limitations for 1.1beta2</h4>
  675. <p> some changes to classes should force re-weaving, but are not
  676. noticed</p>
  677. <p> inter-type declarations, declare parents are not tracked
  678. correctly</p>
  679. <h3><a name="XNOWEAVE">-XnoWeave, a compiler option to suppress
  680. weaving</a></h3>
  681. <p> The -XnoWeave option suppresses weaving, and generates
  682. classfiles and that can be passed to ajc again (through the
  683. -injars option) to generate final, woven classfiles. </p>
  684. <p> This option was originally envisioned to be the primary way to
  685. generate binary aspects that could be linked with other code, and
  686. so it was previously (in AspectJ 1.1beta1) named
  687. <code>-noweave</code>. We feel that using the
  688. <code><a href="#BINARY_ASPECTS">-aspectpath</a></code> option is a
  689. much better option. There may still be use cases for unwoven
  690. classfiles, but we've moved the flag to experimental status.
  691. </p>
  692. <h3><a name="BINARY_ASPECTS">-aspectpath, working with aspects in .class/.jar
  693. form</a> </h3>
  694. <p> When aspects are compiled into classfiles, they include all
  695. information necessary for the ajc compiler to weave their advice
  696. and deal with their inter-type declarations. In order for these
  697. aspects to have an effect on a compilation process, they must be
  698. passed to the compiler on the -aspectpath. Every .jar file on
  699. this path will be searched for aspects and any aspects that are
  700. found will be enabled during the compilation. The binary forms of
  701. this aspects will be untouched. </p>
  702. <h3><a name="NO_AROUND_OPTIMIZATION">Inlining around advice</a></h3>
  703. <p> In the beta release of the compiler, around advice was
  704. implemented in the safest way for all uses of around advice. However,
  705. many (if not most) case of around advice do not involve, for example,
  706. inner classes capturing proceed, and can (and will) be implemented in
  707. more efficient styles. </p>
  708. <h3><a name="NO_CALLEE_SIDE_CALL">Callee-side call join
  709. points</a></h3>
  710. <p> The 1.0 implementation of AspectJ, when given:
  711. </p>
  712. <pre> class MyRunnable implements Runnable {
  713. public void run() { ... }
  714. }
  715. aspect A {
  716. call(): (void run()) && target(MyRunnable) {
  717. // do something here
  718. }
  719. }
  720. </pre>
  721. <p> would cause A's advice to execute even when, say, java.lang.Thread
  722. called run() on a MyRunnable instance.
  723. </p>
  724. <p> With the new compiler, two things have happened in regard to
  725. callee-side calls:
  726. </p>
  727. <ol>
  728. <li>because the programmer has access to more code (i.e.,
  729. bytecode, not just source code), callee-side calls are much
  730. less important to have.</li>
  731. <li>because compilation is more modular, allowing and
  732. encouraging separate compilation, callee-side calls are much
  733. more difficult to implement</li>
  734. </ol>
  735. <p> With these two points in mind, advice in an aspect will not be
  736. applied to call join points whose call site is completely
  737. unavailable to the aspect. </p>
  738. <ol>
  739. <li>One reason (though not the only reason) we worked so hard in
  740. the <em>implementation</em> of 1.0.6 to expose call join
  741. points, even if we only had access to the callee's code, was
  742. that otherwise users couldn't get access to call join points
  743. where the call was made from bytecode. This is no longer the
  744. case. In short, the implementation controls much more code (or
  745. has the capability to) than ever before.</li>
  746. <li>The implementation model for the AspectJ 1.1 compiler is to
  747. separate the compilation of aspects/advice from their
  748. weaving/linking. A property of the model is that the
  749. compilation requires no access to "target" code, only the
  750. weaving/linking does, and weaving/linking is inherently
  751. per-class local: No action at weaving/linking time depends on
  752. the coordinated mangling of multiple classfiles. Rather, all
  753. weaving is done on a per classfile basis. This is an essential
  754. property for the current separate compilation model. <br>
  755. However, allowing implementation of call advice on either
  756. side requires simultaneous knowlege of both sides. If we first
  757. have access to a call, we can't decide to simply put the advice
  758. on the call site, since later we may decide to implement on the
  759. callee.</li>
  760. </ol>
  761. <p>This implementation decision is completely in the letter and
  762. the spirit of the AspectJ language. From the semantics guide
  763. describing code the implementation controls:</p>
  764. <blockquote>
  765. But AspectJ implementations are permitted to deviate from this
  766. in a well-defined way -- they are permitted to advise only
  767. accesses in <em>code the implementation
  768. controls</em>. Each implementation is free within certain
  769. bounds to provide its own definition of what it means to control
  770. code.
  771. </blockquote>
  772. <p>And about a particular decision about the 1.0.6
  773. implementation:</p>
  774. <blockquote>
  775. Different join points have different requirements. Method call
  776. join points can be advised only if ajc controls
  777. <em>either</em> the code for the caller or the code
  778. for the receiver, and some call pointcut designators may
  779. require caller context (what the static type of the receiver
  780. is, for example) to pick out join points.
  781. </blockquote>
  782. <p> The 1.1 implementation makes a different design decision:
  783. Method call join points can be advised only if ajc (in compiler or
  784. linker form) controls the code for the caller. </p>
  785. <p>What does 1.1 gain from this?</p>
  786. <ul>
  787. <li>a clear (and implemented) separate compilation model (see
  788. point 2, above)</li>
  789. <li>a less confusing interaction between call join points and
  790. the thisJoinPoint reflective object: We still get bug reports
  791. about source information sometimes existing and sometimes not
  792. existing at call join points.</li>
  793. </ul>
  794. <p> What does 1.1 lose from this?</p>
  795. <ul>
  796. <li>The ability to capture all calls to Runnable.run() from
  797. anywhere to code ajc has access too, even from Thread, even if
  798. you don't compile java.lang with ajc.</li>
  799. <li>The ability to, without access to the caller, capture entry to
  800. a particular method, but not super calls.</li>
  801. <li>A code-size-improvement performance optimization.</li>
  802. </ul>
  803. <p> What are the possibilities for the future?</p>
  804. <ul>
  805. <li>AspectJ 1.1.1 could expand its capture of call join points,
  806. possibly at the expense of separate compilation clarity,
  807. possibly not. </li>
  808. <li>AspectJ 1.1.1 could re-introduce reception join points from
  809. AspectJ 0.7 (what callee-side call join points actually are):
  810. though they would never ever be taught in a tutorial or
  811. entry-level description of the model, they may have specialized
  812. uses.</li>
  813. </ul>
  814. <h3><a name="OTHER_X_OPTIONS">Various -X options</a></h3>
  815. <p> The AspectJ 1.0 compiler supported a number of options that
  816. started with X, for "experimantal". Some of them will not be
  817. supported in 1.1, either because the "experiment" succeeded (in
  818. which case it's part of the normal functionality) or failed.
  819. Others will be supported as is (or nearly so) in 1.1:
  820. </p>
  821. <ul>
  822. <li>-XOcodeSize: Not supported in 1.1beta2, since we're not
  823. doing <em>any</em> <a href="#NO_AROUND_OPTIMIZATION">inlining of
  824. around advice</a> in beta. This may or may not be supported in
  825. 1.1 final: bytecode weaving gives us more leeway in inlining
  826. anyway, so this may be the default. </li> XXX replaced with noInline
  827. <li>-XtargetNearSource: Not suppoted in 1.1beta2, may not be
  828. supported in 1.1 final. </li>
  829. <li>-XserializableAspects: Supported. </li>
  830. <li>-XaddSafePrefix: This option will not be supported in 1.1 at
  831. all because we're now always using (what we believe to be) safe
  832. prefixes. </li>
  833. <li>-Xlint: Still supported, with <a href="#XLINT">various
  834. options</a>. </li>
  835. </ul>
  836. <h3><a name="ERROR_MESSAGES">Many confusing error messages in
  837. 1.1beta2</a></h3>
  838. <p>Building on the eclipse compiler has given us access to a very
  839. sophisticated problem reporting system as well as highly optimized
  840. error messages for pure Java code. Often this leads to noticably
  841. better error messages than from ajc-1.0.6. However, when we don't
  842. handle errors correctly this can sometimes lead to cascading error
  843. messages where a single small syntax error will produce dozens of
  844. other messages.</p>
  845. <p>Many error condition in beta2 are signalled by exception. You
  846. shouldn't be surprised to see RuntimeException("unimplemented")
  847. produced from perfectly reasonable programs that use features we
  848. just haven't implemented yet.</p>
  849. <h3><a name="EXCEPTION_CHECKING">No exception checking during
  850. weaving in 1.1beta2</a></h3>
  851. <p>Advice that has an explicit throws clause needs to have that
  852. throws clause checked during weaving for each join point that is
  853. matched. This checking is not implemented in 1.1beta2 which can
  854. lead to checked exceptions being thrown from places they are not
  855. allowed by the Java language.</p>
  856. <pre> before() throws IOException : execution (void m()) {
  857. InputStream s = new FileInputStream("m.out");
  858. ...
  859. }
  860. ...
  861. public void m() { ... }
  862. </pre>
  863. <p>This code should result in a link-time weaving error that the
  864. throws clause in the advice is incompatible with the checked
  865. exceptions which can be legally thrown from the matched join
  866. point. In beta2 this will just silently weave in the advice and
  867. it will be possible for an IOException to be thrown from m().</p>
  868. <h3><a name="XLINT">The -Xlint option</a></h3>
  869. <p><code>-Xlint:ignore,error,warning</code> will set the level for
  870. all Xlint warnings. <code>-Xlint</code>, alone, is an
  871. abbreviation for <code>-Xlint:warning</code>.</p>
  872. <p>The <code>-Xlintfile:lint.properties</code> allows fine-grained
  873. control. In tools.jar, see
  874. <code>org/aspectj/weaver/XlintDefault.properties</code> for the
  875. default behavior and a template to copy. </p>
  876. <p> Though more <code>-Xlint</code> warnings are supported in
  877. 1.1beta2 than previously, we expect even more to be supported in
  878. 1.1final. Because the configurability allows users to turn off
  879. warnings, we will also be able to warn about more potentially
  880. dangerous situations, such as the potentially unsafe casts used by
  881. very polymorphic uses of proceed in around advice. </p>
  882. <h3><a name="NO_SOURCE">Source-specific options</a></h3>
  883. <p> Because AspectJ 1.1beta2 does not generate source code after
  884. weaving, the source-code-specific options -source, -usejavac,
  885. -nocomment and -workingdir options are meaningless and so not
  886. supported. </p>
  887. <h3><a name="NO_STRICT_LENIENT">The -strict and -lenient
  888. options</a></h3>
  889. <p> Because AspectJ 1.1 uses the Eclipse compiler, which has its
  890. own mechanism for changing strictness, we no longer support the
  891. -strict and -lenient options. </p>
  892. <h3><a name="NO_PORTING">The -porting option</a></h3>
  893. <p> AspectJ 1.1 does not have a -porting option. We believe that
  894. many useful porting information will be presented by the -Xlint
  895. option when it is enabled. </p>
  896. <h3><a name="13_REQUIRED">J2SE 1.3 required</a></h3>
  897. <p>Because we build on Eclipse, the compiler will no longer run under J2SE 1.2.
  898. You must run the compiler (and all tools based on the compiler)
  899. using J2SE 1.3 or later. </p>
  900. <h3><a name="DEFAULT_CONSTRUCTOR_CONFLICT">Default
  901. Constructors</a></h3>
  902. XXX
  903. <pre>
  904. inter-type constructors and default constructors conflict now
  905. </pre>
  906. <h3><a name="SUPER_IFACE_INITS">Initialization join points for
  907. super-interfaces</a></h3>
  908. XXX
  909. <pre>
  910. We promised to run super inits in L-R order. This was, of course, totally ludricous. We couldn't do it then and we can't do it now.
  911. It is undefined what order they go in, apart from the other promises made in that section (interfaces with members)
  912. int C.methodCount = 0;
  913. before(C c): this(c) &amp;&amp; execution(* *(..)) { c.methodCount++; }
  914. --
  915. this would have bizarre behavior if we didn't run initializers before constructors
  916. </pre>
  917. <h3><a name="VOID_FIELD_SET">Field Set Join Points</a></h3>
  918. XXX
  919. <p> Are now void
  920. </p>
  921. <h3><a name="XNOINLINE">The -XnoInline Option</a></h3>
  922. XXX
  923. <p> Link to other X flags, in particular XblahBlah
  924. </p>
  925. </body> </html>