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 57KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
  2. <html> <head>
  3. <title>AspectJ 1.1 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. 2003 Contributors.
  18. All rights reserved.
  19. </small></div>
  20. <h1>AspectJ 1.1 Readme</h1>
  21. <p> This is the initial 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>
  25. This document describes the differences between
  26. AspectJ versions 1.1 and 1.0.6.
  27. Users new to AspectJ need only read
  28. the <a href="progguide/index.html">AspectJ Programming Guide</a>
  29. since it describes the 1.1 language.
  30. Users familiar with AspectJ 1.0 may find this document
  31. a quicker way to learn what changed in the language
  32. and tools, and should use it as a guide for porting
  33. programs from 1.0 to 1.1.
  34. </p>
  35. <p>This document first summarizes changes from the 1.0 release in
  36. </p>
  37. <ul>
  38. <li><a href="#language">the language</a>,</li>
  39. <li><a href="#compiler">the compiler</a>,</li>
  40. <li><a href="#tools">the support tools</a>,</li>
  41. <li><a href="#runtime">the runtime</a>,</li>
  42. <li><a href="#devenv">the development environment support</a>,</li>
  43. <li><a href="#sources">the sources</a>, and</li>
  44. <li><a href="#distribution">the distribution</a>,</li>
  45. </ul>
  46. <p> then <a href="#details">details</a> some of the language
  47. and compiler changes,
  48. and finally points readers to the bug database for any
  49. <a href="#knownLimitations">known limitations</a>.
  50. </p>
  51. <!-- ============================== -->
  52. <hr>
  53. <h2><a name="language">The Language</a></h2>
  54. <p> AspectJ 1.1 is a slightly different language than AspectJ 1.0.
  55. In all but a few cases, programs written in AspectJ 1.0 should
  56. compile correctly in AspectJ 1.1. In many cases, there are
  57. new or preferred forms in AspectJ 1.1. However, some AspectJ 1.0
  58. features have changed in 1.1, so some 1.0 programs
  59. will not compile or will run differently in 1.1.
  60. The corresponding features are marked below as compile-time
  61. or run-time incompatible (<em>CTI</em> or <em>RTI</em>, respectively).
  62. When the language change involves a move in the static shadow effective
  63. at run-time but also apparent at compile-time (e.g., in declare
  64. error or warning statements), it is marked <em>CRTI</em>.
  65. Programs using run-time incompatible forms should be verified that
  66. they are behaving as expected in 1.1.
  67. </p>
  68. <p>
  69. Most changes to the language are additions to expressibility
  70. requested by our users:
  71. </p>
  72. <ul>
  73. <li><a href="#THROWS_PATTERN">Matching based on throws</a>: You can
  74. now make finer discriminations between methods based on declared
  75. exceptions. </li>
  76. <li><a href="#NEW_PCDS">New kinded pointcut designators</a>: Now
  77. every kind of join point has a corresponding kinded pointcut
  78. designator. </li>
  79. </ul>
  80. <p> Some are have different behavior in edge cases but offer
  81. improved power and clarity: </p>
  82. <ul>
  83. <li><a href="#ASPECT_PRECEDENCE">New aspect precedence form</a>:
  84. AspectJ 1.1 has a new declare form, <code>declare
  85. precedence</code>, that replaces the "dominates"
  86. clause on aspects. (<em>CTI</em>) </li>
  87. <li>The order of <a href="#SUPER_IFACE_INITS">initialization join
  88. points for super-interfaces</a> has been clarified. (<em>RTI</em>) </li>
  89. </ul>
  90. <p> But in order to support weaving into bytecode effectively,
  91. several incompatible changes had to be made to the language: </p>
  92. <ul>
  93. <li>A class's default constructor may
  94. <a href="#DEFAULT_CONSTRUCTOR_CONFLICT">conflict</a> with an
  95. inter-type constructor. (<em>CTI</em>) </li>
  96. <li><a href="#NO_CALLEE_SIDE_CALL">No callee-side call join
  97. points</a>: The AspectJ 1.1 compiler does not expose call join
  98. points unless it is given the calling code. (<em>CRTI</em>) </li>
  99. <li><a href="#SINGLE_INTERCLASS_TARGET">One target for intertype
  100. declarations</a>. (<em>CTI</em>) </li>
  101. <li><a href="#UNAVAILABLE_JOIN_POINTS">No initializer execution join
  102. points</a>. (<em>RTI</em>)</li>
  103. <li><a href="#AFTER_HANDLER">No after or around advice on handler
  104. join points</a>. (<em>CTI</em>) </li>
  105. <li><a href="#CONSTRUCTOR_EXECUTION_IS_BIGGER">Initializers run
  106. inside constructor execution join points</a>. (<em>RTI</em>)</li>
  107. <li><a href="#INTER_TYPE_FIELD_INITIALIZERS">inter-type field
  108. initializers</a> run before class-local field initializers. (<em>RTI</em>) </li>
  109. <li><a href="#WITHIN_MEMBER_TYPES">Small limitations of the within
  110. pointcut.</a> (<em>CRTI</em>)</li>
  111. <li><a href="#WITHIN_CODE">Small limitations of the withincode
  112. pointcut.</a> (<em>CRTI</em>)</li>
  113. <li><a href="#INSTANCEOF_ON_WILD">Can't do instanceof matching on
  114. type patterns with wildcards</a>. (<em>CTI</em>) </li>
  115. <li><a href="#NO_SOURCE_COLUMN">SourceLocation.getColumn() is
  116. deprecated and will always return 0</a>. (<em>RTI</em>) </li>
  117. <li>The interaction between aspect instantiation and advice has been
  118. <a href="#ASPECT_INSTANTIATION_AND_ADVICE">clarified</a>. (<em>RTI</em>) </li>
  119. <li><a href="#STRINGBUFFER">The String + operator is now correctly advised</a>.
  120. (<em>CRTI</em>) </li>
  121. </ul>
  122. <p><a name="NEW_LIMITATIONS">There</a> are a couple of language
  123. limitations for things that are rarely used that make the
  124. implementation simpler, so we have restricted the language accordingly.
  125. </p>
  126. <ul>
  127. <li><a href="#VOID_FIELD_SET">Field set join points now have a
  128. <code>void</code> return type.</a> This will require
  129. porting of code that uses the <code>set</code> PCD in conjunction
  130. with after-returning or around advice. (<em>CTI</em>) <p></p></li>
  131. <li>'declare soft: TYPE: POINTCUT;' - AspectJ 1.1 only
  132. accepts TYPE rather than a TYPE_PATTERN.
  133. This limitation makes declare soft
  134. much easier to implement efficiently. (<em>CTI</em>) <p></p></li>
  135. <li>Inter-type field declarations only allow a single field per
  136. line, i.e. this is now illegal 'int C.field1, D.field2;' This must
  137. instead be, 'int C.field1; int D.field2;' (<em>CTI</em>) <p></p></li>
  138. <li>We did not implement the handling of more than one
  139. <code>..</code> wildcard in args PCD's (rarely encountered in the
  140. wild) because we didn't have the time. This might be available
  141. in later releases if there is significant outcry. (<em>CTI</em>) </li>
  142. </ul>
  143. <p>We did not implement the long-awaited <a href="#PER_TYPE">new
  144. pertype aspect specifier</a> in this release, but it may well
  145. be in a future release.</p>
  146. <!-- ============================== -->
  147. <hr>
  148. <h2><a name="compiler">The Compiler</a></h2>
  149. <p> The compiler for AspectJ 1.1 is different than the compiler for
  150. AspectJ 1.0. While this document describes the differences in the
  151. compiler, it's worthwhile noting that much effort has been made to
  152. make sure that the interface to ajc 1.1 is, as much as possible, the
  153. same as the interface to ajc 1.0. There are two important changes
  154. under the hood, however. </p>
  155. <p> First, the 1.1 compiler is implemented on top of the
  156. open-source Eclipse compiler. This has two benefits: It allows us
  157. to concentrate on the AspectJ extensions to Java and let the Eclipse
  158. team worry about making sure the Java edge cases work, and it allows
  159. us to piggyback on Eclipse's already mature incremental compilation
  160. facilities. </p>
  161. <p> Second, ajc now cleanly delineates compilation of source code
  162. from assembly (or "weaving") of bytecode. The compiler still
  163. accepts source code, but internally it transforms it into bytecode
  164. format before weaving. </p>
  165. <p> This new architecture, and other changes to the compiler, allows
  166. us to implement some features that were defined in the AspectJ 1.0
  167. language but not implementable in the 1.1 compiler. It also makes
  168. some new features available: </p>
  169. <ul>
  170. <li><a href="#SOURCEROOT">The -sourceroots option</a>
  171. takes one or more directories, and indicates that all the source
  172. files in those directories should be passed to the compiler. </li>
  173. <li><a href="#BYTECODE_WEAVING">The -injars option</a>
  174. takes one or more jar files, and indicates that all the classfiles
  175. in the jar files should be woven into. </li>
  176. <li><a href="#BINARY_ASPECTS">The -aspectpath option</a>
  177. takes one or more jar files, and weaves any aspects in .class form
  178. into the sources.</li>
  179. <li><a href="#OUTJAR">The -outjar option</a> indicates
  180. that the result classfiles of compiling and weaving should be placed
  181. in the specified jar file. </li>
  182. <li><a href="#XLINT">The -Xlint option</a> allows control over
  183. warnings.</li>
  184. <li><a href="#OTHER_X_OPTIONS">Various -X options</a> changed.</li>
  185. <li><a href="#INCREMENTAL">The -incremental option</a> tells the
  186. AspectJ 1.1 compiler to recompile only as necessary. </li>
  187. </ul>
  188. <p> Some other features we wanted to support for 1.1, but did not make
  189. it into this release: </p>
  190. <ul>
  191. <li><a href="#ERROR_MESSAGES">Error messages will sometimes be scary</a></li>
  192. <li><a href="#MESSAGE_CONTEXT">Source code context is not shown
  193. for errors and warnings detected during bytecode weaving</a></li>
  194. </ul>
  195. <p> But some features of the 1.0 compiler are not supported in the
  196. 1.1 compiler: </p>
  197. <ul>
  198. <li><a href="#NO_SOURCE">The source-related options</a> -preprocess,
  199. -usejavac, -nocomment and -workingdir</li>
  200. <li><a href="#NO_STRICT_LENIENT">The -strict and -lenient options</a>
  201. </li>
  202. <li><a href="#NO_PORTING">The -porting option</a></li>
  203. <li><a href="#13_REQUIRED">J2SE 1.2 is not supported;
  204. J2SE 1.3 or later is required.</a></li>
  205. </ul>
  206. <p> A short description of the options ajc accepts is available with
  207. "<code>ajc -help</code>".
  208. Longer descriptions are available in the
  209. <a href="devguide/ajc-ref.html">Development Environment Guide
  210. section on ajc</a>. </p>
  211. <p> </p>
  212. <p> Some changes to the implementation are almost entirely
  213. internal:
  214. </p>
  215. <ul>
  216. <li>The behavior of the compiler in
  217. <a href="#TARGET_TYPES_MADE_PUBLIC">lifting the visibility</a> of
  218. the target types of some declares and pointcuts to public has been
  219. clarified. </li>
  220. </ul>
  221. <p> Also, it is worth noting that because AspectJ now works on bytecode,
  222. it is somewhat sensitive to how different compilers generate
  223. bytecode, especially when compiling with and without <a
  224. href="#ONE_FOUR_METHOD_SIGNATURES">the -1.4 flag</a>. </p>
  225. <!-- ============================== -->
  226. <hr>
  227. <h2><a name="tools">Support Tools</a></h2>
  228. <p>This release includes an Ant task for old-style 1.0 build
  229. scripts, a new task for all the new compiler options, and a
  230. CompilerAdapter to support running <code>ajc</code> with the Javac
  231. task by setting the <code>build.compiler</code> property.
  232. The new task can automatically copy input resources to output
  233. and work in incremental mode using a "tag" file.
  234. </p>
  235. <p>This release does not include <code>ajdoc</code>, the
  236. documentation tool for AspectJ sources.
  237. Ajdoc is deeply dependent on the
  238. abstract syntax tree classes from the old compiler, so it needs a
  239. bottom-up rewrite. We think it best to use this opportunity to
  240. implement more general API's for publishing and rendering static
  241. structure. Because those API's are last to settle in the new
  242. architecture, and because the compiler itself is a higher priority,
  243. we are delaying work on ajdoc until after the 1.1 release.</p>
  244. <p>AspectJ 1.1 will not include <tt>ajdb</tt>, the AspectJ
  245. stand-alone debugger. It is no longer necessary for two reasons.
  246. First, the -XnoInline flag will tell the compiler to generate
  247. code without inlining that should work correctly with any Java
  248. debugger. For code generated with inlining enabled, more
  249. third-party debuggers are starting to work according to JSR 45,
  250. "Debugging support for other languages," which is supported by
  251. AspectJ 1.0. We aim to support JSR-45 in AspectJ 1.1, but
  252. support will not be in the initial release. Consider using
  253. the -XnoInline flag until support is available.</p>
  254. <!-- ============================== -->
  255. <hr>
  256. <h2><a name="runtime">The Runtime Library</a></h2>
  257. <p>This release has minor additions to the runtime library classes.
  258. As with any release, you should compile and run with the runtime
  259. library that came with your compiler, and you may run with
  260. a later version of the library without recompiling your code.</p>
  261. <p> In one instance, however, runtime classes behave differently this release.
  262. Because the AspectJ 1.1 compiler does its weaving through
  263. bytecode, column numbers of source locations are not available.
  264. Therefore, <code>thisJoinPoint.getSourceLocation().getColumn()</code>
  265. is deprecated and will always return 0. </p>
  266. <!-- ============================== -->
  267. <hr>
  268. <h2><a name="devenv">The AJDE Tools</a></h2>
  269. <p> The AspectJ Browser supports incremental compilation and running
  270. programs. AJDE for JBuilder, AJDE for NetBeans, and AJDE for Emacs
  271. are now independent SourceForge projects (to keep their licenses).
  272. They use the batch-build mode of the new compiler.
  273. </p>
  274. <!-- ============================== -->
  275. <hr>
  276. <h2><a name="sources">The Sources and the Licenses</a></h2>
  277. <p>The AspectJ tools sources are available under the
  278. <a href="https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt">Eclipse Public License v 2.0</a>
  279. in the Git repository at
  280. <a href="http://eclipse.org/aspectj">http://eclipse.org/aspectj</a>.
  281. For more information, see the FAQ entry on
  282. <a href="faq.html#q:buildingsource">building sources</a>.
  283. </p>
  284. <!-- ============================== -->
  285. <hr>
  286. <h2><a name="distribution">The AspectJ distribution</a></h2>
  287. <p> AspectJ 1.0 had many distributions - for the tools,
  288. the documentation, each IDE support package,
  289. their respective sources, and the Ant tasks -
  290. because they came under different licenses.
  291. All of AspectJ 1.1 is licensed under the CPL 1.0,
  292. so the tools, Ant tasks, and documentation are all
  293. in one distribution available from
  294. <a href="http://eclipse.org/aspectj">
  295. http://eclipse.org/aspectj</a>.
  296. To retain their MPL 1.1 license,
  297. Ajde for
  298. <a href="http://aspectj4emacs.sourceforge.net/">Emacs</a>,
  299. <a href="http://aspectj4netbean.sourceforge.net/">NetBeans</a> and
  300. <a href="http://aspectj4jbuildr.sourceforge.net/">JBuilder</a>
  301. are now independent SourceForge projects. </p>
  302. </p>
  303. <!-- ============================== -->
  304. <hr>
  305. <hr>
  306. <h2><a name="details">Details</a> of some language and compiler changes</h2>
  307. <h3><a name="ASPECT_INSTANTIATION_AND_ADVICE">Aspect Instantiation
  308. and Advice</a></h3>
  309. <p> In AspectJ 1.0.6, we made an effort to hide some complications
  310. with Aspect instantiation from the user. In particular, the
  311. following code compiled and ran:
  312. </p>
  313. <PRE>
  314. public class Client
  315. {
  316. public static void main(String[] args) {
  317. Client c = new Client();
  318. }
  319. }
  320. aspect Watchcall {
  321. pointcut myConstructor(): execution(new(..));
  322. before(): myConstructor() {
  323. System.err.println("Entering Constructor");
  324. }
  325. }
  326. </PRE>
  327. <p> But there's a conceptual problem with this code: The before
  328. advice should run before the execution of all constructors in the
  329. system. It must run in the context of an instance of the
  330. Watchcall aspect. The only way to get such an instance is to have
  331. Watchcall's default constructor execute. But before that
  332. executes, we need to run the before advice...</p>
  333. <p> AspectJ 1.0.6 hid this circularity through the ad-hoc
  334. mechanism of preventing an aspect's advice from matching join
  335. points that were within the aspect's definition, and occurred
  336. before the aspect was initialized. But even in AspectJ 1.0.6,
  337. this circularity could be exposed:
  338. </p>
  339. <PRE>
  340. public class Client
  341. {
  342. public static int foo() { return 3; }
  343. public static void main(String[] args) {
  344. Client c = new Client();
  345. }
  346. }
  347. aspect Watchcall {
  348. int i = Client.foo();
  349. pointcut myConstructor():
  350. execution(new(..)) || execution(int foo());
  351. before(): myConstructor() {
  352. System.err.println("Entering Constructor");
  353. }
  354. }
  355. </PRE>
  356. <p>This program would throw a NullPointerException when run, since
  357. Client.foo() was called before the Watchcall instance could be
  358. instantiated. </p>
  359. <p> In AspectJ 1.1, we have decided that half-hiding the problem
  360. just leads to trouble, and so we are no longer silently hiding
  361. some join points before aspect initialization. However, we have
  362. provided a better exception than a NullPointerException for this
  363. case. In AspectJ 1.1, both of the above programs will throw
  364. org.aspectj.lang.NoAspectBoundException.
  365. </p>
  366. <h3><a name="THROWS_PATTERN">Matching based on throws</a></h3>
  367. <p> Type patterns may now be used to pick out methods and
  368. constructors based on their throws clauses. This allows the
  369. following two kinds of extremely wildcarded pointcuts: </p>
  370. <pre> pointcut throwsMathlike():
  371. // each call to a method with a throws clause containing at least
  372. // one exception with "Math" in its name.
  373. call(* *(..) throws *..*Math*);
  374. pointcut doesNotThrowMathlike():
  375. // each call to a method with a throws clause containing no
  376. // exceptions with "Math" in its name.
  377. call(* *(..) throws !*..*Math*);
  378. </pre>
  379. <p> The longwinded rules are that a method or constructor pattern
  380. can have a "throws clause pattern". Throws clause patterns look
  381. like: </p>
  382. <pre> ThrowsClausePattern:
  383. ThrowsClausePatternItem ("," ThrowsClausePatternItem)*
  384. ThrowsClausePatternItem:
  385. ["!"] TypeNamePattern
  386. </pre>
  387. <p> A ThrowsClausePattern matches the ThrowsClause of any code
  388. member signature. To match, each ThrowsClausePatternItem must
  389. match the throws clause of the member in question. If any item
  390. doesn't match, then the whole pattern doesn't match. This rule is
  391. unchanged from AspectJ 1.0. </p>
  392. <p> If a ThrowsClausePatternItem begins with "!", then it matches
  393. a particular throws clause if and only if <em>none</em> of the
  394. types named in the throws clause is matched by the
  395. TypeNamePattern. </p>
  396. <p> If a ThrowsClausePatternItem does not begin with "!", then it
  397. matches a throws clause if and only if <em>any</em> of the types
  398. named in the throws clause is matched by the TypeNamePattern.</p>
  399. <p> These rules are completely backwards compatible with
  400. AspectJ 1.0. The rule for "!" matching has one potentially
  401. surprising property, in that the two PCD's shown below will have
  402. different matching rules. </p>
  403. <pre> [1] call(* *(..) throws !IOException)
  404. [2] call(* *(..) throws (!IOException))
  405. void m() throws RuntimeException, IOException {}
  406. </pre>
  407. <p> [1] will NOT match the method m(), because method m's throws
  408. clause declares that it throws IOException. [2] WILL match the
  409. method m(), because method m's throws clause declares the it
  410. throws some exception which does not match IOException,
  411. i.e. RuntimeException. </p>
  412. <h3><a name="NEW_PCDS">New kinded pointcut designators</a></h3>
  413. <p> AspectJ 1.0 does not provide kinded pointcut designators for
  414. two (rarely used) join points: preinitialization (the code that
  415. runs before a super constructor call is made) and advice
  416. execution. AspectJ 1.1 does not change the meaning of the join
  417. points, but provides two new pointcut designators to pick out
  418. these join points, thus making join points and pointcut
  419. designators more parallel. </p>
  420. <p> <code>adviceexectuion()</code> will pick out advice execution
  421. join points. You will usually want to use <code>adviceexecution()
  422. && within(Aspect)</code> to restrict it to only those pieces of
  423. advice defined in a particular aspect. <br>
  424. <code>preinitialization(<var>ConstructorPattern</var>)</code> will
  425. pick out pre-initialization join points where the initialization
  426. process is entered through
  427. <code><var>ConstructorPattern</var></code>. </p>
  428. <h3><a name="PER_TYPE">New pertype aspect specifier</a> (not in 1.1)</h3>
  429. <p>We strongly considered adding a pertype aspect kind to 1.1.
  430. This is somewhat motivated by the new
  431. <a href="#SINGLE_INTERCLASS_TARGET">restrictions on inter-type
  432. declarations<a>. This is also motivated by many previous request
  433. to support a common logging idiom. Here's what pertype would look
  434. like:</p>
  435. <pre> /** One instance of this aspect will be created for each class,
  436. * interface or aspect in the com.bigboxco packages.
  437. */
  438. aspect Logger pertype(com.bigboxco..*) {
  439. /* This field holds a logger for the class. */
  440. Log log;
  441. /* This advice will run for every public execution defined by
  442. * a type for which a Logger aspect has been created, i.e.
  443. * any type in com.bigboxco..*
  444. */
  445. before(): execution(public * *(..)) {
  446. log.enterMethod(thisJoinPoint.getSignature().getName());
  447. }
  448. /* We can use a special constructor to initialize the log field */
  449. public Logger(Class myType) {
  450. this.log = new Log(myType);
  451. }
  452. }
  453. /** External code could use aspectOf to get at the log, i.e. */
  454. Log l = Logger.aspectOf(com.bigboxco.Foo.class).log;
  455. </pre>
  456. <p>The one open question that we see is how this should interact
  457. with inner types. If a pertype aspect is created for an outer
  458. type should advice in that aspect run for join points in inner
  459. types? That is the behavior of the most common uses of this
  460. idiom. </p>
  461. <p> In any case, this feature will not be in AspectJ 1.1.
  462. </p>
  463. <h3><a name="SINGLE_INTERCLASS_TARGET">One target for intertype
  464. declarations</a></h3>
  465. <p> Intertype declarations (once called "introductions") in
  466. AspectJ 1.1 can only have one target type. So the following code
  467. intended to declare that there is a void doStuff() method on all
  468. subtypes of Target is not legal AspectJ 1.1 code.
  469. </p>
  470. <pre> aspect A {
  471. public void Target+.doStuff() { ... }
  472. }
  473. </pre>
  474. <p> The functionality of "multi-intertype declarations" can be
  475. recovered by using a helper interface.
  476. </p>
  477. <pre> aspect A {
  478. private interface MyTarget {}
  479. declare parents: Target+ implements MyTarget;
  480. public void MyTarget.doStuff() { ... }
  481. }
  482. </pre>
  483. <p> We believe this is better style in AspectJ 1.0 as well, as it
  484. makes clear the static type of "this" inside the method body.
  485. </p>
  486. <p> The one piece of functionality that can not be easily
  487. recovered is the ability to add static fields to many classes. We
  488. believe that the <a href="#PER_TYPE">pertype proposal</a> provides
  489. this functionality in a much more usable form.</p>
  490. <h3><a name="UNAVAILABLE_JOIN_POINTS">No initializer execution join
  491. points</a></h3>
  492. <p> AspectJ 1.1 does not consider initializer execution a
  493. principled join point. The collection of initializer code (the
  494. code that sets fields with initializers and the code in non-static
  495. initializer blocks) is something that makes sense only in Java
  496. source code, not in Java bytecode. </p>
  497. <h3><a name="AFTER_HANDLER"></a>No after or around advice on handler
  498. join points</h3>
  499. <p> The end of an exception handler is underdetermined in bytecode,
  500. so ajc will not implement after or around advice on handler join
  501. points, instead signaling a compile-time error.</p>
  502. <h3><a name="CONSTRUCTOR_EXECUTION_IS_BIGGER">Initializers run
  503. inside constructor execution join points</a></h3>
  504. <p> The code generated by the initializers in Java source code now
  505. runs inside of constructor execution join points. This changes
  506. how before advice runs on constructor execution join points.
  507. Consider: </p>
  508. <pre> class C {
  509. C() { }
  510. String id = "identifier"; // this assignment
  511. // has to happen sometime
  512. }
  513. aspect A {
  514. before(C c) this(c) && execution(C.new()) {
  515. System.out.println(c.id.length());
  516. }
  517. }
  518. </pre>
  519. <p> In AspectJ 1.0, this will print "10", since id is assigned its
  520. initial value prior to the before advice's execution. However, in
  521. AspectJ 1.1, this will throw a NullPointerExcception, since "id"
  522. does not have a value prior to the before advice's execution.
  523. </p>
  524. <p> Note that the various flavors of after returning advice are
  525. unchanged in this respect in AspectJ 1.1. Also note that this
  526. only matters for the execution of constructors that call a
  527. super-constructor. Execution of constructors that call a
  528. this-constructor are the same in AspectJ 1.1 as in AspectJ 1.0.
  529. </p>
  530. <p> We believe this difference should be minimal to real programs,
  531. since programmers using before advice on constructor execution
  532. must always assume incomplete object initialization, since the
  533. constructor has not yet run. </p>
  534. <h3><a name="INTER_TYPE_FIELD_INITIALIZERS">Inter-type field initializers</a></h3>
  535. <p> The initializer, if any, of an inter-type field definition runs
  536. before the class-local initializers of its target class. </p>
  537. <p> In AspectJ 1.0.6, such an initializer would run after the
  538. initializers of a class but before the execution of any of its
  539. constructor bodies. As already discussed in the sections about
  540. <a href="#UNAVAILABLE_JOIN_POINTS">initializer execution join
  541. points</a> and <a href="#CONSTRUCTOR_EXECUTION_IS_BIGGER">constructor
  542. execution</a>, the point in code between the initializers of a class
  543. and its constructor body is not principled in bytecode. So we had a
  544. choice of running the initializer of an inter-type field definition at
  545. the beginning of initialization (i.e., before initializers from
  546. the target class) or at the end (i.e., just before its called
  547. constructor exits). We chose the former, having this pattern in mind:
  548. </p>
  549. <PRE>
  550. int C.methodCount = 0;
  551. before(C c): this(c) &amp;&amp; execution(* *(..)) { c.methodCount++; }
  552. </PRE>
  553. <p> We felt there would be too much surprise if a constructor called a
  554. method (thus incrementing the method count) and then the field was
  555. reset to zero after the constructor was done.
  556. </p>
  557. <h3><a name="WITHIN_MEMBER_TYPES">Small limitations of the within
  558. pointcut</a></h3>
  559. <p>Because of the guarantees made (and not made) by the Java
  560. classfile format, there are cases where AspectJ 1.1 cannot
  561. guarantee that the within pointcut designator will pick out all
  562. code that was originally within the source code of a certain
  563. type.
  564. </p>
  565. <p> The non-guarantee applies to code inside of anonymous and
  566. local types inside member types. While the within pointcut
  567. designator behaves exactly as it did in AspectJ 1.0 when given a
  568. package-level type (like C, below), if given a member-type (like
  569. C.InsideC, below), it is not guaranteed to capture code in
  570. contained local and anonymous types. For example: </p>
  571. <pre> class C {
  572. Thread t;
  573. class InsideC {
  574. void setupOuterThread() {
  575. t = new Thread(
  576. new Runnable() {
  577. public void run() {
  578. // join points with code here
  579. // might not be captured by
  580. // within(C.InsideC), but are
  581. // captured by within(C)
  582. System.out.println("hi");
  583. }
  584. });
  585. }
  586. }
  587. }
  588. </pre>
  589. <p> We believe the non-guarantee is small, and we haven't verified
  590. that it is a problem in practice. </p>
  591. <h3><a name="WITHIN_CODE">Small limitations of the withincode
  592. pointcut</a></h3>
  593. <p>The withincode pointcut has similar issues to those described
  594. above for within.
  595. </p>
  596. <h3><a name="INSTANCEOF_ON_WILD">Can't do instanceof matching on
  597. type patterns with wildcard</a></h3>
  598. <p>The pointcut designators this, target and args specify a
  599. dynamic test on their argument. These tests can not be performed
  600. on type patterns with wildcards in them. The following code that
  601. compiled under 1.0 will be an error in AspectJ-1.1:</p>
  602. <pre> pointcut oneOfMine(): this(com.bigboxco..*);
  603. </pre>
  604. <p>The only way to implement this kind of matching in a modular
  605. way would be to use the reflection API at runtime on the Class of
  606. the object. This would have a very high performance cost and
  607. possible security issues. There are two good work-arounds. If
  608. you control the source or bytecode to the type you want to match
  609. then you can use declare parents, i.e.:</p>
  610. <pre> private interface OneOfMine {}
  611. declare parents: com.bigboxco..* implements OneOfMine;
  612. pointcut oneOfMine(): this(OneOfMine);
  613. </pre>
  614. <p>If you want the more dynamic matching and are willing to pay
  615. for the performance, then you should use the Java reflection API
  616. combined with if. That would look something like:</p>
  617. <pre> pointcut oneOfMine(): this(Object) &&
  618. if(classMatches("com.bigboxco..*",
  619. thisJoinPoint.getTarget().getClass()));
  620. static boolean classMatches(String pattern, Class _class) {
  621. if (patternMatches(pattern, _class.getName())) return true;
  622. ...
  623. }
  624. </pre>
  625. <p>Note: wildcard type matching still works in all other PCD's that
  626. match based on static types. So, you can use
  627. 'within(com.bigboxco..*+)' to match any code lexically within one
  628. of your classes or a subtype thereof. This is often a good
  629. choice.</p>
  630. </p>
  631. <h3><a name="NO_SOURCE_COLUMN">SourceLocation.getColumn()</a></h3>
  632. <p>The Java .class file format contains information about the
  633. source file and line numbers of its contents; however, it has no
  634. information about source columns. As a result, we can not
  635. effectively support the access of column information in the
  636. reflection API. So, any calls to
  637. thisJoinPoint.getSourceLocation().getColumn() will be marked as
  638. deprecated by the compiler, and will always return 0.</p>
  639. <h3><a name="ASPECT_PRECEDENCE">Aspect precedence</a></h3>
  640. <p> AspectJ 1.1 has a new declare form:
  641. </p>
  642. <pre> declare precedence ":" TypePatternList ";"
  643. </pre>
  644. <p> This is used to declare advice ordering constraints on join
  645. points. For example, the constraints that (1) aspects that have
  646. Security as part of their name should dominate all other aspects, and
  647. (2) the Logging aspect (and any aspect that extends it) should
  648. dominate all non-security aspects, can be expressed by: </p>
  649. <pre> declare precedence: *..*Security*, Logging+, *;
  650. </pre>
  651. <p> In the TypePatternList, the wildcard * means "any type not matched
  652. by another type in the declare precedence". </p>
  653. <h4>Various cycles</h4>
  654. <p> It is an error for any aspect to be matched by more than one
  655. TypePattern in a single declare precedence, so: </p>
  656. <pre> declare precedence: A, B, A ; // error
  657. </pre>
  658. <p> However, multiple declare precedence forms may legally have this
  659. kind of circularity. For example, each of these declare precedence is
  660. perfectly legal:
  661. </p>
  662. <pre> declare precedence: B, A;
  663. declare precedence: A, B;
  664. </pre>
  665. <p> And a system in which both constraints are active may also be
  666. legal, so long as advice from A and B don't share a join point. So
  667. this is an idiom that can be used to enforce that A and B are strongly
  668. independent. </p>
  669. <h4>Applies to concrete aspects</h4>
  670. <p> Consider the following library aspects:
  671. </p>
  672. <pre> abstract aspect Logging {
  673. abstract pointcut logged();
  674. before(): logged() {
  675. System.err.println("thisJoinPoint: " + thisJoinPoint);
  676. }
  677. }
  678. aspect MyProfiling {
  679. abstract pointcut profiled();
  680. Object around(): profiled() {
  681. long beforeTime = System.currentTimeMillis();
  682. try {
  683. return proceed();
  684. } finally {
  685. long afterTime = System.currentTimeMillis();
  686. addToProfile(thisJoinPointStaticPart,
  687. afterTime - beforeTime);
  688. }
  689. }
  690. abstract void addToProfile(
  691. org.aspectj.JoinPoint.StaticPart jp,
  692. long elapsed);
  693. }
  694. </pre>
  695. <p> In order to use either aspect, they must be extended with
  696. concrete aspects, say, MyLogging and MyProfiling. In AspectJ
  697. 1.0, it was not possible to express that Logging's advice (when
  698. concerned with the concrete aspect MyLogging) dominated
  699. Profiling's advice (when concerned with the concrete aspect
  700. MyProfiling) without adding a dominates clause to Logging
  701. itself. In AspectJ 1.1, we can express that constraint with a
  702. simple: </p>
  703. <pre> declare precedence: MyLogging, MyProfiling;
  704. </pre>
  705. <h4>Changing order of advice for sub-aspects</h4>
  706. <p> By default, advice in a sub-aspect has more precedence than
  707. advice in a super-aspect. One use of the AspectJ 1.0 dominates
  708. form was to change this precedence:
  709. </p>
  710. <pre> abstract aspect SuperA dominates SubA {
  711. pointcut foo(): ... ;
  712. before(): foo() {
  713. // in AspectJ 1.0, runs before the advice in SubA
  714. // because of the dominates clause
  715. }
  716. }
  717. aspect SubA extends SuperA {
  718. before(): foo() {
  719. // in AspectJ 1.0, runs after the advice in SuperA
  720. // because of the dominates clause
  721. }
  722. }
  723. </pre>
  724. <p> This no longer works in AspectJ 1.1, since declare precedence only
  725. matters for concrete aspects. Thus, if you want to regain this kind
  726. of precedence change, you will need to refactor your aspects.
  727. </p>
  728. <h3><a name="SOURCEROOT">The -sourceroots option</a></h3>
  729. <p> The AspectJ 1.1 compiler now accepts a -sourceroots option used to
  730. pass all .java files in particular directories to the compiler. It
  731. takes either a single directory name, or a list of directory names
  732. separated with the CLASSPATH separator character (":" for various
  733. Unices, ";" for various Windows). </p>
  734. <p> So, if you have your project separated into a gui module and a
  735. base module, each of which is stored in a directory tree, you might
  736. use one of
  737. </p>
  738. <pre> ajc -sourceroots /myProject/gui:/myProject/base
  739. ajc -sourceroots d:\myProject\gui;d:\myProject\base
  740. </pre>
  741. <p> This option may be used in conjunction with lst files, listing
  742. .java files on the command line, and the -injars option.
  743. </p>
  744. <h3><a name="BYTECODE_WEAVING">The -injars option</a></h3>
  745. <p> The AspectJ 1.1 compiler now accepts an -injars option used to
  746. pass all .class files in a particular jar file to the compiler. It
  747. takes either a single directory name, or a list of directory names
  748. separated with the CLASSPATH separator character (":" for various
  749. Unices, ";" for various Windows). </p>
  750. <p> So, if MyTracing.java defines a trace aspect that you want to
  751. apply to all the classes in myBase.jar and myGui.jar, you would use
  752. one of: </p>
  753. <pre> ajc -injars /bin/myBase.jar:/bin/myGui.jar MyTracing.java
  754. ajc -injars d:\bin\myBase.jar;d:\bin\myGui.jar MyTracing.java
  755. </pre>
  756. <p> The class files in the input jars must not have had advice woven
  757. into them, since AspectJ enforces the requirement that advice is woven
  758. into a particular classfile only once. So if the classfiles in the
  759. jar file are to be created with the ajc compiler (as opposed to a pure
  760. Java compiler), they should not be compiled with any non-abstract
  761. aspects. </p>
  762. <p> This option may be used in conjunction with lst files, listing
  763. .java files on the command line, and the -sourceroots option.
  764. </p>
  765. <h3><a name="OUTJAR">The -outjar option</a></h3>
  766. <p> The -outjar option takes the name of a jar file into which the
  767. results of the compilation should be put. For example:
  768. <pre> ajc -injars myBase.jar MyTracing.java -outjar myTracedBase.jar
  769. </pre>
  770. <p> No meta information is placed in the output jar file. </p>
  771. <h3><a name="INCREMENTAL">Incremental compilation</a></h3>
  772. <p> The AspectJ 1.1 compiler now supports incremental compilation.
  773. When ajc is called with the -incremental option, it must also be
  774. passed a -sourceroots option specifying a directory to incrementally
  775. compile. Once the initial compile is done, ajc waits for console
  776. input. Every time it reads a new line (i.e., every time the user
  777. hits return) ajc recompiles those input files that need recompiling.
  778. </p>
  779. <h4>Limitations</h4>
  780. <p> This new functionality is still only lightly tested. </p>
  781. <h3><a name="XNOWEAVE">-XnoWeave, a compiler option to suppress
  782. weaving</a></h3>
  783. <p> The -XnoWeave option suppresses weaving, and generates
  784. classfiles and that can be passed to ajc again (through the
  785. -injars option) to generate final, woven classfiles. </p>
  786. <p> This option was originally envisioned to be the primary way to
  787. generate binary aspects that could be linked with other code, and
  788. so it was previously (in AspectJ 1.1beta1) named
  789. <code>-noweave</code>. We feel that using the
  790. <code><a href="#BINARY_ASPECTS">-aspectpath</a></code> option is a
  791. much better option. There may still be use cases for unwoven
  792. classfiles, but we've moved the flag to experimental status.
  793. </p>
  794. <h3><a name="BINARY_ASPECTS">-aspectpath, working with aspects in .class/.jar
  795. form</a> </h3>
  796. <p> When aspects are compiled into classfiles, they include all
  797. information necessary for the ajc compiler to weave their advice
  798. and deal with their inter-type declarations. In order for these
  799. aspects to have an effect on a compilation process, they must be
  800. passed to the compiler on the -aspectpath. Every .jar file on
  801. this path will be searched for aspects and any aspects that are
  802. found will be enabled during the compilation. The binary forms of
  803. this aspects will be untouched. </p>
  804. <h3><a name="NO_CALLEE_SIDE_CALL">Callee-side call join
  805. points</a></h3>
  806. <p> The 1.0 implementation of AspectJ, when given:
  807. </p>
  808. <pre> class MyRunnable implements Runnable {
  809. public void run() { ... }
  810. }
  811. aspect A {
  812. call(): (void run()) && target(MyRunnable) {
  813. // do something here
  814. }
  815. }
  816. </pre>
  817. <p> would cause A's advice to execute even when, say, java.lang.Thread
  818. called run() on a MyRunnable instance.
  819. </p>
  820. <p> With the new compiler, two things have happened in regard to
  821. callee-side calls:
  822. </p>
  823. <ol>
  824. <li>because the programmer has access to more code (i.e.,
  825. bytecode, not just source code), callee-side calls are much
  826. less important to have.</li>
  827. <li>because compilation is more modular, allowing and
  828. encouraging separate compilation, callee-side calls are much
  829. more difficult to implement</li>
  830. </ol>
  831. <p> With these two points in mind, advice in an aspect will not be
  832. applied to call join points whose call site is completely
  833. unavailable to the aspect. </p>
  834. <ol>
  835. <li>One reason (though not the only reason) we worked so hard in
  836. the <em>implementation</em> of 1.0.6 to expose call join
  837. points, even if we only had access to the callee's code, was
  838. that otherwise users couldn't get access to call join points
  839. where the call was made from bytecode. This is no longer the
  840. case. In short, the implementation controls much more code (or
  841. has the capability to) than ever before.</li>
  842. <li>The implementation model for the AspectJ 1.1 compiler is to
  843. separate the compilation of aspects/advice from their
  844. weaving/linking. A property of the model is that the
  845. compilation requires no access to "target" code, only the
  846. weaving/linking does, and weaving/linking is inherently
  847. per-class local: No action at weaving/linking time depends on
  848. the coordinated mangling of multiple classfiles. Rather, all
  849. weaving is done on a per classfile basis. This is an essential
  850. property for the current separate compilation model. <br>
  851. However, allowing implementation of call advice on either
  852. side requires simultaneous knowledge of both sides. If we first
  853. have access to a call, we can't decide to simply put the advice
  854. on the call site, since later we may decide to implement on the
  855. callee.</li>
  856. </ol>
  857. <p>This implementation decision is completely in the letter and
  858. the spirit of the AspectJ language. From the semantics guide
  859. describing code the implementation controls:</p>
  860. <blockquote>
  861. But AspectJ implementations are permitted to deviate from this
  862. in a well-defined way -- they are permitted to advise only
  863. accesses in <em>code the implementation
  864. controls</em>. Each implementation is free within certain
  865. bounds to provide its own definition of what it means to control
  866. code.
  867. </blockquote>
  868. <p>And about a particular decision about the 1.0.6
  869. implementation:</p>
  870. <blockquote>
  871. Different join points have different requirements. Method call
  872. join points can be advised only if ajc controls
  873. <em>either</em> the code for the caller or the code
  874. for the receiver, and some call pointcut designators may
  875. require caller context (what the static type of the receiver
  876. is, for example) to pick out join points.
  877. </blockquote>
  878. <p> The 1.1 implementation makes a different design decision:
  879. Method call join points can be advised only if ajc (in compiler or
  880. linker form) controls the code for the caller. </p>
  881. <p>What does 1.1 gain from this?</p>
  882. <ul>
  883. <li>a clear (and implemented) separate compilation model (see
  884. point 2, above)</li>
  885. <li>a less confusing interaction between call join points and
  886. the thisJoinPoint reflective object: We still get bug reports
  887. about source information sometimes existing and sometimes not
  888. existing at call join points.</li>
  889. </ul>
  890. <p> What does 1.1 lose from this?</p>
  891. <ul>
  892. <li>The ability to capture all calls to Runnable.run() from
  893. anywhere to code ajc has access too, even from Thread, even if
  894. you don't compile java.lang with ajc.</li>
  895. <li>The ability to, without access to the caller, capture entry to
  896. a particular method, but not super calls.</li>
  897. <li>A code-size-improvement performance optimization.</li>
  898. </ul>
  899. <p> What are the possibilities for the future?</p>
  900. <ul>
  901. <li>AspectJ 1.1.1 could expand its capture of call join points,
  902. possibly at the expense of separate compilation clarity,
  903. possibly not. </li>
  904. <li>AspectJ 1.1.1 could re-introduce reception join points from
  905. AspectJ 0.7 (what callee-side call join points actually are):
  906. though they would never ever be taught in a tutorial or
  907. entry-level description of the model, they may have specialized
  908. uses.</li>
  909. </ul>
  910. <p> How will this affect developers?</p>
  911. <ul>
  912. <li>When using the call PCD but only supplying the callee
  913. code, supply the calling code or use the execution PCD instead.
  914. </li>
  915. </ul>
  916. <h3><a name="OTHER_X_OPTIONS">Various -X options</a></h3>
  917. <p> The AspectJ 1.0 compiler supported a number of options that
  918. started with X, for "experimental". Some of them will not be
  919. supported in 1.1, either because the "experiment" succeeded (in
  920. which case it's part of the normal functionality) or failed.
  921. Others will be supported as is (or nearly so) in 1.1:
  922. </p>
  923. <ul>
  924. <li>-XOcodeSize: This is no longer necessary because inlining
  925. of around advice is on by default. We support its inverse,
  926. <a href="#XNOINLINE"><code>-XnoInline</code></a>.
  927. </li>
  928. <li><a href="#XNOWEAVE">-XnoWeave, a compiler option to suppress
  929. weaving</a></li>
  930. <li>-XtargetNearSource: Not supported in this release. </li>
  931. <li>-XserializableAspects: Supported. </li>
  932. <li>-XaddSafePrefix: This option will not be supported in 1.1 at
  933. all because we're now always using (what we believe to be) safe
  934. prefixes. </li>
  935. <li>-Xlint: Still supported, with <a href="#XLINT">various
  936. options</a>. </li>
  937. </ul>
  938. <h3><a name="ERROR_MESSAGES">Some confusing error messages</a></h3>
  939. <p>Building on the eclipse compiler has given us access to a very
  940. sophisticated problem reporting system as well as highly optimized
  941. error messages for pure Java code. Often this leads to noticeably
  942. better error messages than from ajc-1.0.6. However, when we don't
  943. handle errors correctly this can sometimes lead to cascading error
  944. messages where a single small syntax error will produce dozens of
  945. other messages. Please report any very confusing error messages as
  946. bugs.</p>
  947. <h3><a name="MESSAGE_CONTEXT">Source code context is not shown
  948. for errors and warnings detected during bytecode weaving</a></h3>
  949. <p>For compiler errors and warnings detected during bytecode weaving,
  950. source code context will not be displayed. In particular, for declare
  951. error and declare warning statements, the compiler now only emits the
  952. file and line. We are investigating ways to overcome this in cases
  953. where the source code is available; in cases where source code is
  954. not available, we might specify the signature of the offending code.
  955. For more information, see bug 31724.</p>
  956. <h3><a name="XLINT">The -Xlint option</a></h3>
  957. <p><code>-Xlint:ignore,error,warning</code> will set the level for
  958. all Xlint warnings. <code>-Xlint</code>, alone, is an
  959. abbreviation for <code>-Xlint:warning</code>.</p>
  960. <p>The <code>-Xlintfile:lint.properties</code> allows fine-grained
  961. control. In tools.jar, see
  962. <code>org/aspectj/weaver/XlintDefault.properties</code> for the
  963. default behavior and a template to copy. </p>
  964. <p> More <code>-Xlint</code> warnings are supported now, and
  965. we may add disabled warnings in subsequent bug-fix releases of 1.1.
  966. Because the configurability allows users to turn off
  967. warnings, we will be able to warn about more potentially
  968. dangerous situations, such as the potentially unsafe casts used by
  969. very polymorphic uses of proceed in around advice. </p>
  970. <h3><a name="NO_SOURCE">Source-specific options</a></h3>
  971. <p> Because AspectJ 1.1 does not generate source code after
  972. weaving, the source-code-specific options -preprocess, -usejavac,
  973. -nocomment and -workingdir options are meaningless and so not
  974. supported. </p>
  975. <h3><a name="NO_STRICT_LENIENT">The -strict and -lenient
  976. options</a></h3>
  977. <p> Because AspectJ 1.1 uses the Eclipse compiler, which has its
  978. own mechanism for changing strictness, we no longer support the
  979. -strict and -lenient options. </p>
  980. <h3><a name="NO_PORTING">The -porting option</a></h3>
  981. <p> AspectJ 1.1 does not have a -porting option.</p>
  982. <h3><a name="13_REQUIRED">J2SE 1.3 required</a></h3>
  983. <p>Because we build on Eclipse, the compiler will no longer run
  984. under J2SE 1.2. You must run the compiler (and all tools based on
  985. the compiler) using J2SE 1.3 or later. The code generated by the
  986. compiler can still run on Java 1.1 or later VM's if compiled against
  987. the correct runtime libraries.</p>
  988. <h3><a name="DEFAULT_CONSTRUCTOR_CONFLICT">Default
  989. constructors</a></h3>
  990. <p> AspectJ 1.1 does not allow the inter-type definition of a
  991. zero-argument constructor on a class with a visible default
  992. constructor. So this is no longer allowed: </p>
  993. <PRE>
  994. class C {}
  995. aspect A {
  996. C.new() {} // was allowed in 1.0.6
  997. // is a "multiple definitions" conflict in 1.1
  998. }
  999. </PRE>
  1000. <p> In the Java Programming Language, a class defined without a
  1001. constructor actually has a "default" constructor that takes no
  1002. arguments and just calls <code>super()</code>. </p>
  1003. <p> This default constructor is a member of the class like any other
  1004. member, and can be referenced by other classes, and has code generated
  1005. for it in classfiles. Therefore, it was an oversight that AspectJ
  1006. 1.0.6 allowed such an "overriding" inter-type constructor definition.
  1007. </p>
  1008. <h3><a name="SUPER_IFACE_INITS">Initialization join points for
  1009. super-interfaces</a></h3>
  1010. <p> In AspectJ, interfaces may have non-static members due to
  1011. inter-type declarations. Because of this, the semantics of AspectJ
  1012. defines the order that initializer code for interfaces is run.
  1013. </p>
  1014. <p> In the semantics document for AspectJ 1.0.6, the following
  1015. promises were made about the order of this initialization:
  1016. </p>
  1017. <ol>
  1018. <li>a supertype is initialized before a subtype</li>
  1019. <li>initialized code runs only once</li>
  1020. <li>initializers for supertypes run in left-to-right order</li>
  1021. </ol>
  1022. <p> The first two properties are important and are preserved in
  1023. AspectJ 1.1, but the third property is and was ludicrous, and was
  1024. never properly implemented (and never could be) in AspectJ 1.0.6.
  1025. Consider: </p>
  1026. <PRE>
  1027. interface Top0 {}
  1028. interface Top1 {}
  1029. interface I extends Top0, Top1 {}
  1030. interface J extends Top1, Top0 {}
  1031. class C implements I, J {}
  1032. // I says Top0's inits must run before Top1's
  1033. // J says Top1's inits must run before Top0's
  1034. aspect A {
  1035. int Top0.i = foo("I'm in Top0");
  1036. int Top1.i = foo("I'm in Top1");
  1037. static int foo(String s) {
  1038. System.out.println(s);
  1039. return 37;
  1040. }
  1041. }
  1042. </PRE>
  1043. <p> This was simply a bug in the AspectJ specification. The correct
  1044. third rule is:
  1045. </p>
  1046. <blockquote>the initializers for a type's superclass are run before the
  1047. initializers for its superinterfaces.
  1048. </blockquote>
  1049. <h3><a name="VOID_FIELD_SET">Field Set Join Points</a></h3>
  1050. <p> In AspectJ 1.0.6, the join point for setting a field F had, as a
  1051. return type, F's type. This was "java compatible" because
  1052. field assignment in java, such as "Foo.i = 37", is in fact an
  1053. expression, and does in fact return a value, the value that the
  1054. field is assigned to.
  1055. </p>
  1056. <p> This was never "java programmer compatible", however, largely
  1057. because programmers have absorbed the good style of rarely using an
  1058. assignment statement in a value context. Programmers typically expect
  1059. "Foo.i = 37" not to return a value, but to simply assign a value. </p>
  1060. <p> Thus, programmers typically wanted to write something like:
  1061. </p>
  1062. <PRE>
  1063. void around(): set(int Foo.i) {
  1064. if (theSetIsAllowed()) {
  1065. proceed();
  1066. }
  1067. }
  1068. </PRE>
  1069. <p> And were confused by it being a compile-time error. They weren't
  1070. confused for long, and soon adapted to writing:
  1071. </p>
  1072. <PRE>
  1073. int around(): set(int Foo.i) {
  1074. if (theSetIsAllowed()) {
  1075. return proceed();
  1076. } else {
  1077. return Foo.i;
  1078. }
  1079. }
  1080. </PRE>
  1081. <p> But there was definitely a short disconnect. </p>
  1082. <p> On top of that, we were never shown a convincing use-case for
  1083. returning an interesting value from a set join point. When we
  1084. revisited this issue, in fact, we realized we had a long-standing bug
  1085. in 1.0.6 dealing with the return value of pre-increment expressions
  1086. (such as ++Foo.i) that nobody had found because nobody cares about the
  1087. return value of such join points.
  1088. </p>
  1089. <p> So, because it's easier to implement, and because we believe that
  1090. this is the last possibility to make the semantics more useful, we
  1091. have made set join points have a void return type in 1.1. </p>
  1092. <h3><a name="XNOINLINE">The -XnoInline Option</a></h3>
  1093. <p> The <code>-XnoInline</code>
  1094. option to indicate that no inlining of any kind should be done. This
  1095. is purely a compiler pragma: No program semantics (apart from stack
  1096. traces) will be changed by the presence or absence of this option.
  1097. </p>
  1098. <h3><a name="TARGET_TYPES_MADE_PUBLIC">Target types made
  1099. public</a></h3>
  1100. <p> Even in 1.0.6, the AspectJ compiler has occasionally needed to
  1101. convert the visibility of a package-level class to a public one. This
  1102. was previously done in an ad-hoc basis that took whole-program
  1103. analysis into account. With the incremental compilation model of
  1104. AspectJ 1.1, we can now specify the occasions when the compiler makes
  1105. these visibility changes.
  1106. </p>
  1107. <p> In particular, the types used in the <code>this</code>,
  1108. <code>target</code>, and <code>args</code> pointcuts are made public,
  1109. as are the super-types from <code>declare parents</code> and the
  1110. exception type from <code>declare soft</code>.
  1111. </p>
  1112. <p> We believe the visibility changes could be avoided in the future
  1113. with various implementation tricks if they become a serious
  1114. concern, but did not encounter them as such a concern when they were
  1115. done in the 1.0.6 implementation. </p>
  1116. <h3><a name="STRINGBUFFER">String + now advised</a></h3>
  1117. <p> In Java, the + operator sometimes results in StringBuffer objects
  1118. being created, appended to, and used to generate a new String. Thus,
  1119. </p>
  1120. <PRE>
  1121. class Foo {
  1122. String makeEmphatic(String s) {
  1123. return s + "!";
  1124. }
  1125. }
  1126. </PRE>
  1127. <p> is approximately the same at runtime as
  1128. </p>
  1129. <PRE>
  1130. class Foo {
  1131. String makeEmphatic(String s) {
  1132. return new StringBuffer(s).append("!").toString();
  1133. }
  1134. }
  1135. </PRE>
  1136. <p> In the design process of AspectJ 1.0.6 we didn't expose those
  1137. StringBuffer methods and constructors as join points (though we did
  1138. discuss it), but in 1.1 we do. </p>
  1139. <p> This change is likely to affect highly wildcarded aspects, and can
  1140. do so in surprising ways. In particular:
  1141. </p>
  1142. <PRE>
  1143. class A {
  1144. before(int i): call(* *(int)) &amp;&amp; args(i) {
  1145. System.err.println("entering with " + i);
  1146. }
  1147. }
  1148. </PRE>
  1149. <p> may result in a stack overflow error, since the argument to
  1150. println is really </p>
  1151. <PRE>
  1152. new StringBuffer("entering with ").append(i).toString()
  1153. </PRE>
  1154. <p> which has a call to StringBuffer.append(int). In such cases, it's
  1155. worth restricting your pointcut, with something like one of:
  1156. </p>
  1157. <PRE>
  1158. call(* *(int)) &amp;&amp; args(i) &amp;&amp; !within(A)
  1159. call(* *(int)) &amp;&amp; args(i) &amp;&amp; !target(StringBuffer)
  1160. </PRE>
  1161. <h3><a name="ONE_FOUR_METHOD_SIGNATURES">The -1.4 flag and method signatures</a></h3>
  1162. <p> Consider the following aspect
  1163. </p>
  1164. <PRE>
  1165. public aspect SwingCalls {
  1166. pointcut callingAnySwing(): call(* javax.swing..*+.*(..));
  1167. before(): callingAnySwing() {
  1168. System.out.println("Calling any Swing");
  1169. }
  1170. }
  1171. </PRE>
  1172. <p> And then consider the two statements
  1173. </p>
  1174. <PRE>
  1175. JFrame frame = new JFrame();
  1176. frame.setTitle("Title");
  1177. </PRE>
  1178. <p> According to the Java Language Specification version 2, the call
  1179. to <code>frame.setTitle("Title")</code> should always produce the
  1180. bytecode for a call to <code>javax.swing.JFrame.setTitle</code>.
  1181. However, older compilers (and eclipse when run without the
  1182. <code>-1.4</code> flag) will generate the bytecode for a call to
  1183. <code>java.awt.Frame.setTitle</code> instead since this method is not
  1184. overriden by JFrame. The AspectJ weaver depends on the correctly
  1185. generated bytecode in order to match patterns like the one you show
  1186. correctly. </p>
  1187. <p> This is a good example of why the pattern <code>call(* *(..)) &&
  1188. target(JFrame)</code> is the recommended style. In general, OO
  1189. programmers don't want to care about the static type of an object at a
  1190. call site, but only want to know the dynamic instanceof behavior which
  1191. is what the target matching will handle. </p>
  1192. <h2><a name="knownLimitations">Known limitations</a></h2>
  1193. <p>The AspectJ 1.1.0 release contains a small number of known limitations
  1194. relative to the AspectJ 1.1 language.
  1195. For the most up-to-date information about known limitations in an
  1196. AspectJ 1.1 release, see the bug database at
  1197. <a href="http://bugs.eclipse.org/bugs">http://bugs.eclipse.org/bugs</a>,
  1198. especially the open bugs for the
  1199. <a href="http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&component=Compiler&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED">
  1200. compiler</a>,
  1201. <a href="http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&component=IDE&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED">
  1202. IDE support</a>,
  1203. <a href="http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&component=Doc&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED">
  1204. documentation</a>, and
  1205. <a href="http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&component=Ant&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED">
  1206. Ant tasks</a>.
  1207. Developers should know about bugs marked with the "info" keyword
  1208. because those bugs reflect failures to implement the 1.1 language perfectly.
  1209. These might be fixed during the 1.1 release cycle; find them using the query
  1210. <a href="http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&keywords=info">
  1211. http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&keywords=info</a>
  1212. For ajc's 1.1 implementation limitations, see
  1213. <a href="progguide/implementation.html">
  1214. Programming Guide Appendix: "Implementation Notes"</a>.
  1215. </p>
  1216. </body> </html>