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-1.1.adoc 49KB

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