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.

semantics.xml 95KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709
  1. <appendix id="semantics" xreflabel="Semantics">
  2. <title>Language Semantics</title>
  3. <sect1 id="semantics-intro">
  4. <title>Introduction</title>
  5. <para>
  6. AspectJ extends Java by overlaying a concept of join points onto the
  7. existing Java semantics and adding a few new program elements to Java:
  8. </para>
  9. <para>
  10. A join point is a well-defined point in the execution of a
  11. program. These include method and constructor calls, field accesses and
  12. others described below.
  13. </para>
  14. <para>
  15. A pointcut picks out join points, and exposes some of the values in the
  16. execution context of those join points. There are several primitive
  17. pointcut designators, and others can be named and defined by the
  18. <literal>pointcut</literal> declaration.
  19. </para>
  20. <para>
  21. A piece of advice is code that executes at each join point in a
  22. pointcut. Advice has access to the values exposed by the
  23. pointcut. Advice is defined by <literal>before</literal>,
  24. <literal>after</literal>, and <literal>around</literal> declarations.
  25. </para>
  26. <para>
  27. Inter-type declarations form AspectJ's static crosscutting features,
  28. that is, is code that may change the type structure of a program, by
  29. adding to or extending interfaces and classes with new fields,
  30. constructors, or methods. Some inter-type declarations are defined
  31. through an extension of usual method, field, and constructor
  32. declarations, and other declarations are made with a new
  33. <literal>declare</literal> keyword.
  34. </para>
  35. <para>
  36. An aspect is a crosscutting type that encapsulates pointcuts, advice,
  37. and static crosscutting features. By type, we mean Java's notion: a
  38. modular unit of code, with a well-defined interface, about which it is
  39. possible to do reasoning at compile time. Aspects are defined by the
  40. <literal>aspect</literal> declaration.
  41. </para>
  42. </sect1>
  43. <!-- ============================== -->
  44. <sect1 id="semantics-joinPoints">
  45. <title>Join Points</title>
  46. <para>
  47. While aspects define types that crosscut, the AspectJ system does not
  48. allow completely arbitrary crosscutting. Rather, aspects define types
  49. that cut across principled points in a program's execution. These
  50. principled points are called join points.
  51. </para>
  52. <para>
  53. A join point is a well-defined point in the execution of a
  54. program. The join points defined by AspectJ are:
  55. </para>
  56. <variablelist>
  57. <varlistentry>
  58. <term>Method call</term>
  59. <listitem>
  60. When a method is called, not including super calls of
  61. non-static methods.
  62. </listitem>
  63. </varlistentry>
  64. <varlistentry>
  65. <term>Method execution</term>
  66. <listitem>
  67. When the body of code for an actual method executes.
  68. </listitem>
  69. </varlistentry>
  70. <varlistentry>
  71. <term>Constructor call</term>
  72. <listitem>
  73. When an object is built and that object's initial constructor is
  74. called (i.e., not for "super" or "this" constructor calls). The
  75. object being constructed is returned at a constructor call join
  76. point, so its return type is considered to be the type of the
  77. object, and the object itself may be accessed with <literal>after
  78. returning</literal> advice.
  79. </listitem>
  80. </varlistentry>
  81. <varlistentry>
  82. <term>Constructor execution</term>
  83. <listitem>
  84. When the body of code for an actual constructor executes, after
  85. its this or super constructor call. The object being constructed
  86. is the currently executing object, and so may be accessed with
  87. the <literal>this</literal> pointcut. The constructor execution
  88. join point for a constructor that calls a super constructor also
  89. includes any non-static initializers of enclosing class. No
  90. value is returned from a constructor execution join point, so its
  91. return type is considered to be void.
  92. </listitem>
  93. </varlistentry>
  94. <varlistentry>
  95. <term>Static initializer execution</term>
  96. <listitem>
  97. When the static initializer for a class executes. No value is
  98. returned from a static initializer execution join point, so its
  99. return type is considered to be void.
  100. </listitem>
  101. </varlistentry>
  102. <varlistentry>
  103. <term>Object pre-initialization</term>
  104. <listitem>
  105. Before the object initialization code for a particular class runs.
  106. This encompasses the time between the start of its first called
  107. constructor and the start of its parent's constructor. Thus, the
  108. execution of these join points encompass the join points of the
  109. evaluation of the arguments of <literal>this()</literal> and
  110. <literal>super()</literal> constructor calls. No value is
  111. returned from an object pre-initialization join point, so its
  112. return type is considered to be void.
  113. </listitem>
  114. </varlistentry>
  115. <varlistentry>
  116. <term>Object initialization</term>
  117. <listitem>
  118. When the object initialization code for a particular class runs.
  119. This encompasses the time between the return of its parent's
  120. constructor and the return of its first called constructor. It
  121. includes all the dynamic initializers and constructors used to
  122. create the object. The object being constructed is the currently
  123. executing object, and so may be accessed with the
  124. <literal>this</literal> pointcut. No value is returned from a
  125. constructor execution join point, so its return type is
  126. considered to be void.
  127. </listitem>
  128. </varlistentry>
  129. <varlistentry>
  130. <term>Field reference</term>
  131. <listitem>
  132. When a non-constant field is referenced. [Note that references
  133. to constant fields (static final fields bound to a constant
  134. string object or primitive value) are not join points, since Java
  135. requires them to be inlined.]
  136. </listitem>
  137. </varlistentry>
  138. <varlistentry>
  139. <term>Field set</term>
  140. <listitem>
  141. When a field is assigned to.
  142. Field set join points are considered to have one argument,
  143. the value the field is being set to.
  144. No value is returned from a field set join point, so
  145. its return type is considered to be void.
  146. [Note that the initializations of constant fields (static
  147. final fields where the initializer is a constant string object or
  148. primitive value) are not join points, since Java requires their
  149. references to be inlined.]
  150. </listitem>
  151. </varlistentry>
  152. <varlistentry>
  153. <term>Handler execution</term>
  154. <listitem>
  155. When an exception handler executes.
  156. Handler execution join points are considered to have one argument,
  157. the exception being handled.
  158. No value is returned from a field set join point, so
  159. its return type is considered to be void.
  160. </listitem>
  161. </varlistentry>
  162. <varlistentry>
  163. <term>Advice execution</term>
  164. <listitem>
  165. When the body of code for a piece of advice executes.
  166. </listitem>
  167. </varlistentry>
  168. </variablelist>
  169. </sect1>
  170. <!-- ============================== -->
  171. <sect1 id="semantics-pointcuts">
  172. <title>Pointcuts</title>
  173. <para>
  174. A pointcut is a program element that picks out join points and
  175. exposes data from the execution context of those join points.
  176. Pointcuts are used primarily by advice. They can be composed with
  177. boolean operators to build up other pointcuts. The primitive
  178. pointcuts and combinators provided by the language are:
  179. </para>
  180. <variablelist>
  181. <varlistentry>
  182. <term><literal>call(<replaceable>MethodPattern</replaceable>)</literal></term>
  183. <listitem>
  184. Picks out each method call join point whose signature matches
  185. <replaceable>MethodPattern</replaceable>.
  186. </listitem>
  187. </varlistentry>
  188. <varlistentry>
  189. <term><literal>execution(<replaceable>MethodPattern</replaceable>)</literal></term>
  190. <listitem>
  191. Picks out each method execution join point whose signature matches
  192. <replaceable>MethodPattern</replaceable>.
  193. </listitem>
  194. </varlistentry>
  195. <varlistentry>
  196. <term><literal>get(<replaceable>FieldPattern</replaceable>)</literal></term>
  197. <listitem>
  198. Picks out each field reference join point whose signature matches
  199. <replaceable>FieldPattern</replaceable>.
  200. [Note that references to constant fields (static final
  201. fields bound to a constant string object or primitive value) are not
  202. join points, since Java requires them to be inlined.]
  203. </listitem>
  204. </varlistentry>
  205. <varlistentry>
  206. <term><literal>set(<replaceable>FieldPattern</replaceable>)</literal></term>
  207. <listitem>
  208. Picks out each field set join point whose signature matches
  209. <replaceable>FieldPattern</replaceable>.
  210. [Note that the initializations of constant fields (static
  211. final fields where the initializer is a constant string object or
  212. primitive value) are not join points, since Java requires their
  213. references to be inlined.]
  214. </listitem>
  215. </varlistentry>
  216. <varlistentry>
  217. <term><literal>call(<replaceable>ConstructorPattern</replaceable>)</literal></term>
  218. <listitem>
  219. Picks out each constructor call join point whose signature matches
  220. <replaceable>ConstructorPattern</replaceable>.
  221. </listitem>
  222. </varlistentry>
  223. <varlistentry>
  224. <term><literal>execution(<replaceable>ConstructorPattern</replaceable>)</literal></term>
  225. <listitem>
  226. Picks out each constructor execution join point whose signature matches
  227. <replaceable>ConstructorPattern</replaceable>.
  228. </listitem>
  229. </varlistentry>
  230. <varlistentry>
  231. <term><literal>initialization(<replaceable>ConstructorPattern</replaceable>)</literal></term>
  232. <listitem>
  233. Picks out each object initialization join point whose signature matches
  234. <replaceable>ConstructorPattern</replaceable>.
  235. </listitem>
  236. </varlistentry>
  237. <varlistentry>
  238. <term><literal>preinitialization(<replaceable>ConstructorPattern</replaceable>)</literal></term>
  239. <listitem>
  240. Picks out each object pre-initialization join point whose signature matches
  241. <replaceable>ConstructorPattern</replaceable>.
  242. </listitem>
  243. </varlistentry>
  244. <varlistentry>
  245. <term><literal>staticinitialization(<replaceable>TypePattern</replaceable>)</literal></term>
  246. <listitem>
  247. Picks out each static initializer execution join point whose signature matches
  248. <replaceable>TypePattern</replaceable>.
  249. </listitem>
  250. </varlistentry>
  251. <varlistentry>
  252. <term><literal>handler(<replaceable>TypePattern</replaceable>)</literal></term>
  253. <listitem>
  254. Picks out each exception handler join point whose signature matches
  255. <replaceable>TypePattern</replaceable>.
  256. </listitem>
  257. </varlistentry>
  258. <varlistentry>
  259. <term><literal>adviceexecution()</literal></term>
  260. <listitem>
  261. Picks out all advice execution join points.
  262. </listitem>
  263. </varlistentry>
  264. <varlistentry>
  265. <term><literal>within(<replaceable>TypePattern</replaceable>)</literal></term>
  266. <listitem>
  267. Picks out each join point where the executing code is defined
  268. in a type matched by <replaceable>TypePattern</replaceable>.
  269. </listitem>
  270. </varlistentry>
  271. <varlistentry>
  272. <term><literal>withincode(<replaceable>MethodPattern</replaceable>)</literal></term>
  273. <listitem>
  274. Picks out each join point where the executing code is defined in
  275. a method whose signature matches
  276. <replaceable>MethodPattern</replaceable>.
  277. </listitem>
  278. </varlistentry>
  279. <varlistentry>
  280. <term><literal>withincode(<replaceable>ConstructorPattern</replaceable>)</literal></term>
  281. <listitem>
  282. Picks out each join point where the executing code is defined
  283. in a constructor whose signature matches
  284. <replaceable>ConstructorPattern</replaceable>.
  285. </listitem>
  286. </varlistentry>
  287. <varlistentry>
  288. <term><literal>cflow(<replaceable>Pointcut</replaceable>)</literal></term>
  289. <listitem>
  290. Picks out each join point in the control flow of any join point
  291. <replaceable>P</replaceable> picked out by
  292. <replaceable>Pointcut</replaceable>, including
  293. <replaceable>P</replaceable> itself.
  294. </listitem>
  295. </varlistentry>
  296. <varlistentry>
  297. <term><literal>cflowbelow(<replaceable>Pointcut</replaceable>)</literal></term>
  298. <listitem>
  299. Picks out each join point in the control flow of any join point
  300. <replaceable>P</replaceable> picked out by
  301. <replaceable>Pointcut</replaceable>, but not
  302. <replaceable>P</replaceable> itself.
  303. </listitem>
  304. </varlistentry>
  305. <varlistentry>
  306. <term><literal>this(<replaceable>Type</replaceable> or <replaceable>Id</replaceable>)</literal></term>
  307. <listitem>
  308. Picks out each join point where the currently executing object
  309. (the object bound to <literal>this</literal>) is an instance of
  310. <replaceable>Type</replaceable>, or of the type of
  311. <replaceable>Id</replaceable> (which must be bound in the enclosing
  312. advice or pointcut definition).
  313. Will not match any join points from static contexts.
  314. </listitem>
  315. </varlistentry>
  316. <varlistentry>
  317. <term><literal>target(<replaceable>Type</replaceable> or <replaceable>Id</replaceable>)</literal></term>
  318. <listitem>
  319. Picks out each join point where the target object (the object
  320. on which a call or field operation is applied to) is an instance of
  321. <replaceable>Type</replaceable>, or of the type of
  322. <replaceable>Id</replaceable> (which must be bound in the enclosing
  323. advice or pointcut definition).
  324. Will not match any calls, gets, or sets of static members.
  325. </listitem>
  326. </varlistentry>
  327. <varlistentry>
  328. <term><literal>args(<replaceable>Type</replaceable> or <replaceable>Id</replaceable>, ...)</literal></term>
  329. <listitem>
  330. Picks out each join point where the arguments are instances of
  331. a type of the appropriate type pattern or identifier.
  332. </listitem>
  333. </varlistentry>
  334. <varlistentry>
  335. <term><literal><replaceable>PointcutId</replaceable>(<replaceable>TypePattern</replaceable> or <replaceable>Id</replaceable>, ...)</literal></term>
  336. <listitem>
  337. Picks out each join point that is picked out by the
  338. user-defined pointcut designator named by
  339. <replaceable>PointcutId</replaceable>.
  340. </listitem>
  341. </varlistentry>
  342. <varlistentry>
  343. <term><literal>if(<replaceable>BooleanExpression</replaceable>)</literal></term>
  344. <listitem>
  345. Picks out each join point where the boolean expression
  346. evaluates to <literal>true</literal>. The boolean expression used
  347. can only access static members, variables exposed by teh enclosing
  348. pointcut or advice, and <literal>thisJoinPoint</literal> forms. In
  349. particular, it cannot call non-static methods on the aspect.
  350. </listitem>
  351. </varlistentry>
  352. <varlistentry>
  353. <term><literal>! <replaceable>Pointcut</replaceable></literal></term>
  354. <listitem>
  355. Picks out each join point that is not picked out by
  356. <replaceable>Pointcut</replaceable>.
  357. </listitem>
  358. </varlistentry>
  359. <varlistentry>
  360. <term><literal><replaceable>Pointcut0</replaceable> <![CDATA[&&]]> <replaceable>Pointcut1</replaceable></literal></term>
  361. <listitem>
  362. Picks out each join points that is picked out by both
  363. <replaceable>Pointcut0</replaceable> and
  364. <replaceable>Pointcut1</replaceable>.
  365. </listitem>
  366. </varlistentry>
  367. <varlistentry>
  368. <term><literal><replaceable>Pointcut0</replaceable> || <replaceable>Pointcut1</replaceable></literal></term>
  369. <listitem>
  370. Picks out each join point that is picked out by either
  371. pointcuts. <replaceable>Pointcut0</replaceable> or
  372. <replaceable>Pointcut1</replaceable>.
  373. </listitem>
  374. </varlistentry>
  375. <varlistentry>
  376. <term><literal>( <replaceable>Pointcut</replaceable> )</literal></term>
  377. <listitem>
  378. Picks out each join points picked out by
  379. <replaceable>Pointcut</replaceable>.
  380. </listitem>
  381. </varlistentry>
  382. </variablelist>
  383. <sect2>
  384. <title>Pointcut definition</title>
  385. <para>
  386. Pointcuts are defined and named by the programmer with the
  387. <literal>pointcut</literal> declaration.
  388. </para>
  389. <programlisting>
  390. pointcut publicIntCall(int i):
  391. call(public * *(int)) <![CDATA[&&]]> args(i);
  392. </programlisting>
  393. <para>
  394. A named pointcut may be defined in either a class or aspect, and is
  395. treated as a member of the class or aspect where it is found. As a
  396. member, it may have an access modifier such as
  397. <literal>public</literal> or <literal>private</literal>.
  398. </para>
  399. <programlisting>
  400. class C {
  401. pointcut publicCall(int i):
  402. call(public * *(int)) <![CDATA[&&]]> args(i);
  403. }
  404. class D {
  405. pointcut myPublicCall(int i):
  406. C.publicCall(i) <![CDATA[&&]]> within(SomeType);
  407. }
  408. </programlisting>
  409. <para>
  410. Pointcuts that are not final may be declared abstract, and defined
  411. without a body. Abstract pointcuts may only be declared within
  412. abstract aspects.
  413. </para>
  414. <programlisting>
  415. abstract aspect A {
  416. abstract pointcut publicCall(int i);
  417. }
  418. </programlisting>
  419. <para>
  420. In such a case, an extending aspect may override the abstract
  421. pointcut.
  422. </para>
  423. <programlisting>
  424. aspect B extends A {
  425. pointcut publicCall(int i): call(public Foo.m(int)) <![CDATA[&&]]> args(i);
  426. }
  427. </programlisting>
  428. <para>
  429. For completeness, a pointcut with a declaration may be declared
  430. <literal>final</literal>.
  431. </para>
  432. <para>
  433. Though named pointcut declarations appear somewhat like method
  434. declarations, and can be overridden in subaspects, they cannot be
  435. overloaded. It is an error for two pointcuts to be named with the
  436. same name in the same class or aspect declaration.
  437. </para>
  438. <para>
  439. The scope of a named pointcut is the enclosing class declaration.
  440. This is different than the scope of other members; the scope of
  441. other members is the enclosing class <emphasis>body</emphasis>.
  442. This means that the following code is legal:
  443. </para>
  444. <programlisting>
  445. aspect B percflow(publicCall()) {
  446. pointcut publicCall(): call(public Foo.m(int));
  447. }
  448. </programlisting>
  449. </sect2>
  450. <sect2>
  451. <title>Context exposure</title>
  452. <para>
  453. Pointcuts have an interface; they expose some parts of the
  454. execution context of the join points they pick out. For example,
  455. the PublicIntCall above exposes the first argument from the
  456. receptions of all public unary integer methods. This context is
  457. exposed by providing typed formal parameters to named pointcuts and
  458. advice, like the formal parameters of a Java method. These formal
  459. parameters are bound by name matching.
  460. </para>
  461. <para>
  462. On the right-hand side of advice or pointcut declarations, in
  463. certain pointcut designators, a Java identifier is allowed in place
  464. of a type or collection of types. The pointcut designators that
  465. allow this are <literal>this</literal>, <literal>target</literal>,
  466. and <literal>args</literal>. In all such cases, using an
  467. identifier rather than a type does two things. First, it selects
  468. join points as based on the type of the formal parameter. So the
  469. pointcut
  470. </para>
  471. <programlisting>
  472. pointcut intArg(int i): args(i);
  473. </programlisting>
  474. <para>
  475. picks out join points where an <literal>int</literal> is being
  476. passed as an argument. Second, though, it makes the value of that
  477. argument available to the enclosing advice or pointcut.
  478. </para>
  479. <para>
  480. Values can be exposed from named pointcuts as well, so
  481. </para>
  482. <programlisting>
  483. pointcut publicCall(int x): call(public *.*(int)) <![CDATA[&&]]> intArg(x);
  484. pointcut intArg(int i): args(i);
  485. </programlisting>
  486. <para>
  487. is a legal way to pick out all calls to public methods accepting an
  488. int argument, and exposing that argument.
  489. </para>
  490. <para>
  491. There is one special case for this kind of exposure. Exposing an
  492. argument of type Object will also match primitive typed arguments,
  493. and expose a "boxed" version of the primitive. So,
  494. </para>
  495. <programlisting>
  496. pointcut publicCall(): call(public *.*(..)) <![CDATA[&&]]> args(Object);
  497. </programlisting>
  498. <para>
  499. will pick out all unary methods that take, as their only argument,
  500. subtypes of Object (i.e., not primitive types like
  501. <literal>int</literal>), but
  502. </para>
  503. <programlisting>
  504. pointcut publicCall(Object o): call(public *.*(..)) <![CDATA[&&]]> args(o);
  505. </programlisting>
  506. <para>
  507. will pick out all unary methods that take any argument: And if the
  508. argument was an <literal>int</literal>, then the value passed to
  509. advice will be of type <literal>java.lang.Integer</literal>.
  510. </para>
  511. </sect2>
  512. <sect2>
  513. <title>Primitive pointcuts</title>
  514. <sect3>
  515. <title>Method-related pointcuts</title>
  516. <para>AspectJ provides two primitive pointcut designators designed to
  517. capture method call and execution join points. </para>
  518. <itemizedlist>
  519. <listitem><literal>call(<replaceable>MethodPattern</replaceable>)</literal></listitem>
  520. <listitem><literal>execution(<replaceable>MethodPattern</replaceable>)</literal></listitem>
  521. </itemizedlist>
  522. </sect3>
  523. <sect3>
  524. <title>Field-related pointcuts</title>
  525. <para>
  526. AspectJ provides two primitive pointcut designators designed to
  527. capture field reference and set join points:
  528. </para>
  529. <itemizedlist>
  530. <listitem><literal>get(<replaceable>FieldPattern</replaceable>)</literal></listitem>
  531. <listitem><literal>set(<replaceable>FieldPattern</replaceable>)</literal></listitem>
  532. </itemizedlist>
  533. <para>
  534. All set join points are treated as having one argument, the value the
  535. field is being set to, so at a set join point, that value can be
  536. accessed with an <literal>args</literal> pointcut. So an aspect
  537. guarding an integer variable x declared in type T might be written as
  538. </para>
  539. <programlisting><![CDATA[
  540. aspect GuardedX {
  541. static final int MAX_CHANGE = 100;
  542. before(int newval): set(int T.x) && args(newval) {
  543. if (Math.abs(newval - T.x) > MAX_CHANGE)
  544. throw new RuntimeException();
  545. }
  546. }
  547. ]]></programlisting>
  548. </sect3>
  549. <sect3>
  550. <title>Object creation-related pointcuts</title>
  551. <para>
  552. AspectJ provides primitive pointcut designators designed to
  553. capture the initializer execution join points of objects.
  554. </para>
  555. <itemizedlist>
  556. <listitem><literal>call(<replaceable>ConstructorPattern</replaceable>)</literal></listitem>
  557. <listitem><literal>execution(<replaceable>ConstructorPattern</replaceable>)</literal></listitem>
  558. <listitem><literal>initialization(<replaceable>ConstructorPattern</replaceable>)</literal></listitem>
  559. <listitem><literal>preinitialization(<replaceable>ConstructorPattern</replaceable>)</literal></listitem>
  560. </itemizedlist>
  561. </sect3>
  562. <sect3>
  563. <title>Class initialization-related pointcuts</title>
  564. <para>
  565. AspectJ provides one primitive pointcut designator to pick out
  566. static initializer execution join points.
  567. </para>
  568. <itemizedlist>
  569. <listitem><literal>staticinitialization(<replaceable>TypePattern</replaceable>)</literal></listitem>
  570. </itemizedlist>
  571. </sect3>
  572. <sect3>
  573. <title>Exception handler execution-related pointcuts</title>
  574. <para>
  575. AspectJ provides one primitive pointcut designator to capture
  576. execution of exception handlers:
  577. </para>
  578. <itemizedlist>
  579. <listitem><literal>handler(<replaceable>TypePattern</replaceable>)</literal></listitem>
  580. </itemizedlist>
  581. <para>
  582. All handler join points are treated as having one argument, the value
  583. of the exception being handled. That value can be accessed with an
  584. <literal>args</literal> pointcut. So an aspect used to put
  585. <literal>FooException</literal> objects into some normal form before
  586. they are handled could be written as
  587. </para>
  588. <programlisting>
  589. aspect NormalizeFooException {
  590. before(FooException e): handler(FooException) <![CDATA[&&]]> args(e) {
  591. e.normalize();
  592. }
  593. }
  594. </programlisting>
  595. </sect3>
  596. <sect3>
  597. <title>Advice execution-related pointcuts</title>
  598. <para>
  599. AspectJ provides one primitive pointcut designator to capture
  600. execution of advice
  601. </para>
  602. <itemizedlist>
  603. <listitem><literal>adviceexecution()</literal></listitem>
  604. </itemizedlist>
  605. <para>
  606. This can be used, for example, to filter out any join point in the
  607. control flow of advice from a particular aspect.
  608. </para>
  609. <programlisting>
  610. aspect TraceStuff {
  611. pointcut myAdvice(): adviceexecution() <![CDATA[&&]]> within(TraceStuff);
  612. before(): call(* *(..)) <![CDATA[&&]]> !cflow(myAdvice) {
  613. // do something
  614. }
  615. }
  616. </programlisting>
  617. </sect3>
  618. <sect3>
  619. <title>State-based pointcuts</title>
  620. <para>
  621. Many concerns cut across the dynamic times when an object of a
  622. particular type is executing, being operated on, or being passed
  623. around. AspectJ provides primitive pointcuts that capture join
  624. points at these times. These pointcuts use the dynamic types of
  625. their objects to pick out join points. They may also be used to
  626. expose the objects used for discrimination.
  627. </para>
  628. <itemizedlist>
  629. <listitem><literal>this(<replaceable>Type</replaceable> or <replaceable>Id</replaceable>)</literal></listitem>
  630. <listitem><literal>target(<replaceable>Type</replaceable> or <replaceable>Id</replaceable>)</literal></listitem>
  631. </itemizedlist>
  632. <para>
  633. The <literal>this</literal> pointcut picks out each join point where
  634. the currently executing object (the object bound to
  635. <literal>this</literal>) is an instance of a particular type. The
  636. <literal>target</literal> pointcut picks out each join point where
  637. the target object (the object on which a method is called or a field
  638. is accessed) is an instance of a particular type. Note that
  639. <literal>target</literal> should be understood to be the object the
  640. current join point is transfering control to. This means that the
  641. target object is the same as the current object at a method execution
  642. join point, for example, but may be different at a method call join
  643. point.
  644. </para>
  645. <itemizedlist>
  646. <listitem><literal>args(<replaceable>Type</replaceable> or <replaceable>Id</replaceable> or "..", ...)</literal></listitem>
  647. </itemizedlist>
  648. <para>
  649. The args pointcut picks out each join point where the arguments are
  650. instances of some types. Each element in the comma-separated list is
  651. one of four things. If it is a type name, then the argument in that
  652. position must be an instance of that type. If it is an identifier,
  653. then that identifier must be bound in the enclosing advice or
  654. pointcut declaration, and so the argument in that position must be an
  655. instance of the type of the identifier (or of any type if the
  656. identifier is typed to Object). If it is the "*" wildcard, then any
  657. argument will match, and if it is the special wildcard "..", then any
  658. number of arguments will match, just like in signature patterns. So the
  659. pointcut
  660. </para>
  661. <programlisting>
  662. args(int, .., String)
  663. </programlisting>
  664. <para>
  665. will pick out all join points where the first argument is an
  666. <literal>int</literal> and the last is a <literal>String</literal>.
  667. </para>
  668. </sect3>
  669. <sect3>
  670. <title>Control flow-based pointcuts</title>
  671. <para>
  672. Some concerns cut across the control flow of the program. The
  673. <literal>cflow</literal> and <literal>cflowbelow</literal> primitive
  674. pointcut designators capture join points based on control flow.
  675. </para>
  676. <itemizedlist>
  677. <listitem><literal>cflow(<replaceable>Pointcut</replaceable>)</literal></listitem>
  678. <listitem><literal>cflowbelow(<replaceable>Pointcut</replaceable>)</literal></listitem>
  679. </itemizedlist>
  680. <para>
  681. The <literal>cflow</literal> pointcut picks out all join points that
  682. occur between entry and exit of each join point
  683. <replaceable>P</replaceable> picked out by
  684. <replaceable>Pointcut</replaceable>, including
  685. <replaceable>P</replaceable> itself. Hence, it picks out the join
  686. points <emphasis>in</emphasis> the control flow of the join points
  687. picked out by <replaceable>Pointcut</replaceable>.
  688. </para>
  689. <para>
  690. The <literal>cflowbelow</literal> pointcut picks out all join points
  691. that occur between entry and exit of each join point
  692. <replaceable>P</replaceable> picked out by
  693. <replaceable>Pointcut</replaceable>, but not including
  694. <replaceable>P</replaceable> itself. Hence, it picks out the join
  695. points <emphasis>below</emphasis> the control flow of the join points
  696. picked out by <replaceable>Pointcut</replaceable>.
  697. </para>
  698. </sect3>
  699. <sect3>
  700. <title>Program text-based pointcuts</title>
  701. <para>
  702. While many concerns cut across the runtime structure of the program,
  703. some must deal with the lexical structure. AspectJ allows aspects to
  704. pick out join points based on where their associated code is defined.
  705. </para>
  706. <itemizedlist>
  707. <listitem><literal>within(<replaceable>TypePattern</replaceable>)</literal></listitem>
  708. <listitem><literal>withincode(<replaceable>MethodPattern</replaceable>)</literal></listitem>
  709. <listitem><literal>withincode(<replaceable>ConstructorPattern</replaceable>)</literal></listitem>
  710. </itemizedlist>
  711. <para>
  712. The <literal>within</literal> pointcut picks out each join point
  713. where the code executing is defined in the declaration of one of the
  714. types in <replaceable>TypePattern</replaceable>. This includes the
  715. class initialization, object initialization, and method and
  716. constructor execution join points for the type, as well as any join
  717. points associated with the statements and expressions of the type.
  718. It also includes any join points that are associated with code in a
  719. type's nested types, and that type's default constructor, if there is
  720. one.
  721. </para>
  722. <para>
  723. The <literal>withincode</literal> pointcuts picks out each join point
  724. where the code executing is defined in the declaration of a
  725. particular method or constructor. This includes the method or
  726. constructor execution join point as well as any join points
  727. associated with the statements and expressions of the method or
  728. constructor. It also includes any join points that are associated
  729. with code in a method or constructor's local or anonymous types.
  730. </para>
  731. </sect3>
  732. <sect3>
  733. <title>Expression-based pointcuts</title>
  734. <itemizedlist>
  735. <listitem><literal>if(<replaceable>BooleanExpression</replaceable>)</literal></listitem>
  736. </itemizedlist>
  737. <para>
  738. The if pointcut picks out join points based on a dynamic property.
  739. It's syntax takes an expression, which must evaluate to a boolean
  740. true or false. Within this expression, the
  741. <literal>thisJoinPoint</literal> object is available. So one
  742. (extremely inefficient) way of picking out all call join points would
  743. be to use the pointcut
  744. </para>
  745. <programlisting>
  746. if(thisJoinPoint.getKind().equals("call"))
  747. </programlisting>
  748. </sect3>
  749. </sect2>
  750. <sect2>
  751. <title>Signatures</title>
  752. <para>
  753. One very important property of a join point is its signature, which is
  754. used by many of AspectJ's pointcut designators to select particular
  755. join points.
  756. </para>
  757. <sect3>
  758. <title>Methods</title>
  759. <para>
  760. Join points associated with methods typically have method signatures,
  761. consisting of a method name, parameter types, return type, the types of
  762. the declared (checked) exceptions, and some type that the method could
  763. be called on (below called the "qualifying type").
  764. </para>
  765. <para>
  766. At a method call join point, the signature is a method signature whose
  767. qualifying type is the static type used to <emphasis>access</emphasis>
  768. the method. This means that the signature for the join point created
  769. from the call <literal>((Integer)i).toString()</literal> is different
  770. than that for the call <literal>((Object)i).toString()</literal>, even
  771. if <literal>i</literal> is the same variable.
  772. </para>
  773. <para>
  774. At a method execution join point, the signature a method signature
  775. whose qualifying type is the declaring type of the method.
  776. </para>
  777. </sect3>
  778. <sect3>
  779. <title>Fields</title>
  780. <para>
  781. Join points associated with fields typically have field signatures,
  782. consisting of a field name and a field type. A field reference join
  783. point has such a signature, and no parameters. A field set join point
  784. has such a signature, but has a has a single parameter whose type is
  785. the same as the field type.
  786. </para>
  787. </sect3>
  788. <sect3>
  789. <title>Constructors</title>
  790. <para>
  791. Join points associated with constructors typically have constructor
  792. signatures, consisting of a parameter types, the types of the declared
  793. (checked) exceptions, and the declaring type.
  794. </para>
  795. <para>
  796. At a constructor call join point, the signature is the constructor
  797. signature of the called constructor. At a constructor execution join
  798. point, the signature is the constructor signature of the currently
  799. executing constructor.
  800. </para>
  801. <para>
  802. At object initialization and pre-initialization join points, the
  803. signature is the constructor signature for the constructor that started
  804. this initialization: the first constructor entered during this type's
  805. initialization of this object.
  806. </para>
  807. </sect3>
  808. <sect3>
  809. <title>Others</title>
  810. <para>
  811. At a handler execution join point, the signature is composed of the
  812. exception type that the handler handles.
  813. </para>
  814. <para>
  815. At an advice execution join point, the signature is composed of the
  816. aspect type, the parameter types of the advice, the return type (void
  817. for all but around advice) and the types of the declared (checked)
  818. exceptions.
  819. </para>
  820. </sect3>
  821. </sect2>
  822. <!-- ============================== -->
  823. <sect2>
  824. <title>Matching</title>
  825. <para>
  826. The <literal>withincode</literal>, <literal>call</literal>,
  827. <literal>execution</literal>, <literal>get</literal>, and
  828. <literal>set</literal> primitive pointcut designators all use signature
  829. patterns to determine the join points they describe. A signature
  830. pattern is an abstract description of one or more join-point
  831. signatures. Signature patterns are intended to match very closely the
  832. same kind of things one would write when defining individual methods
  833. and constructors.
  834. </para>
  835. <para>
  836. Method definitions in Java include method names, method parameters,
  837. return types, modifiers like static or private, and throws clauses,
  838. while constructor definitions omit the return type and replace the
  839. method name with the class name. The start of a particular method
  840. definition, in class <literal>Test</literal>, for example, might be
  841. </para>
  842. <programlisting>
  843. class C {
  844. public final void foo() throws ArrayOutOfBoundsException { ... }
  845. }
  846. </programlisting>
  847. <para>
  848. In AspectJ, method signature patterns have all these, but most elements
  849. can be replaced by wildcards. So
  850. </para>
  851. <programlisting>
  852. call(public final void C.foo() throws ArrayOutOfBoundsException)
  853. </programlisting>
  854. <para>
  855. picks out call join points to that method, and the pointcut
  856. </para>
  857. <programlisting>
  858. call(public final void *.*() throws ArrayOutOfBoundsException)
  859. </programlisting>
  860. <para>
  861. picks out all call join points to methods, regardless of their name
  862. name or which class they are defined on, so long as they take no
  863. arguments, return no value, are both <literal>public</literal> and
  864. <literal>final</literal>, and are declared to throw
  865. <literal>ArrayOutOfBounds</literal> exceptions.
  866. </para>
  867. <para>
  868. The defining type name, if not present, defaults to *, so another way
  869. of writing that pointcut would be
  870. </para>
  871. <programlisting>
  872. call(public final void *() throws ArrayOutOfBoundsException)
  873. </programlisting>
  874. <para>
  875. Formal parameter lists can use the wildcard <literal>..</literal> to
  876. indicate zero or more arguments, so
  877. </para>
  878. <programlisting>
  879. execution(void m(..))
  880. </programlisting>
  881. <para>
  882. picks out execution join points for void methods named
  883. <literal>m</literal>, of any number of arguments, while
  884. </para>
  885. <programlisting>
  886. execution(void m(.., int))
  887. </programlisting>
  888. <para>
  889. picks out execution join points for void methods named
  890. <literal>m</literal> whose last parameter is of type
  891. <literal>int</literal>.
  892. </para>
  893. <para>
  894. The modifiers also form part of the signature pattern. If an AspectJ
  895. signature pattern should match methods without a particular modifier,
  896. such as all non-public methods, the appropriate modifier should be
  897. negated with the <literal>!</literal> operator. So,
  898. </para>
  899. <programlisting>
  900. withincode(!public void foo())
  901. </programlisting>
  902. <para>
  903. picks out all join points associated with code in null non-public
  904. void methods named <literal>foo</literal>, while
  905. </para>
  906. <programlisting>
  907. withincode(void foo())
  908. </programlisting>
  909. <para>
  910. picks out all join points associated with code in null void methods
  911. named <literal>foo</literal>, regardless of access modifier.
  912. </para>
  913. <para>
  914. Method names may contain the * wildcard, indicating any number of
  915. characters in the method name. So
  916. </para>
  917. <programlisting>
  918. call(int *())
  919. </programlisting>
  920. <para>
  921. picks out all call join points to <literal>int</literal> methods
  922. regardless of name, but
  923. </para>
  924. <programlisting>
  925. call(int get*())
  926. </programlisting>
  927. <para>
  928. picks out all call join points to <literal>int</literal> methods
  929. where the method name starts with the characters "get".
  930. </para>
  931. <para>
  932. AspectJ uses the <literal>new</literal> keyword for constructor
  933. signature patterns rather than using a particular class name. So the
  934. execution join points of private null constructor of a class C
  935. defined to throw an ArithmeticException can be picked out with
  936. </para>
  937. <programlisting>
  938. execution(private C.new() throws ArithmeticException)
  939. </programlisting>
  940. <sect3>
  941. <title>Matching based on the throws clause</title>
  942. <para>
  943. Type patterns may be used to pick out methods and constructors
  944. based on their throws clauses. This allows the following two
  945. kinds of extremely wildcarded pointcuts:
  946. </para>
  947. <programlisting>
  948. pointcut throwsMathlike():
  949. // each call to a method with a throws clause containing at least
  950. // one exception exception with "Math" in its name.
  951. call(* *(..) throws *..*Math*);
  952. pointcut doesNotThrowMathlike():
  953. // each call to a method with a throws clause containing no
  954. // exceptions with "Math" in its name.
  955. call(* *(..) throws !*..*Math*);
  956. </programlisting>
  957. <para>
  958. A <replaceable>ThrowsClausePattern</replaceable> is a comma-separated list of
  959. <replaceable>ThrowsClausePatternItem</replaceable>s, where
  960. <variablelist>
  961. <varlistentry>
  962. <term><replaceable>ThrowsClausePatternItem</replaceable> :</term>
  963. <listitem>
  964. <literal>[ ! ]
  965. <replaceable>TypeNamePattern</replaceable></literal>
  966. </listitem>
  967. </varlistentry>
  968. </variablelist>
  969. </para>
  970. <para>
  971. A <replaceable>ThrowsClausePattern</replaceable> matches the
  972. throws clause of any code member signature. To match, each
  973. <literal>ThrowsClausePatternItem</literal> must
  974. match the throws clause of the member in question. If any item
  975. doesn't match, then the whole pattern doesn't match.
  976. </para>
  977. <para>
  978. If a ThrowsClausePatternItem begins with "!", then it matches a
  979. particular throws clause if and only if <emphasis>none</emphasis>
  980. of the types named in the throws clause is matched by the
  981. <literal>TypeNamePattern</literal>.
  982. </para>
  983. <para>
  984. If a <replaceable>ThrowsClausePatternItem</replaceable> does not
  985. begin with "!", then it matches a throws clause if and only if
  986. <emphasis>any</emphasis> of the types named in the throws clause
  987. is matched by the <emphasis>TypeNamePattern</emphasis>.
  988. </para>
  989. <para>
  990. The rule for "!" matching has one potentially surprising
  991. property, in that these two pointcuts
  992. <itemizedlist>
  993. <listitem> call(* *(..) throws !IOException) </listitem>
  994. <listitem> call(* *(..) throws (!IOException)) </listitem>
  995. </itemizedlist>
  996. will match differently on calls to
  997. <blockquote>
  998. <literal>
  999. void m() throws RuntimeException, IOException {}
  1000. </literal>
  1001. </blockquote>
  1002. </para>
  1003. <para>
  1004. [1] will NOT match the method m(), because method m's throws
  1005. clause declares that it throws IOException. [2] WILL match the
  1006. method m(), because method m's throws clause declares the it
  1007. throws some exception which does not match IOException,
  1008. i.e. RuntimeException.
  1009. </para>
  1010. </sect3>
  1011. </sect2>
  1012. <sect2>
  1013. <title>Type patterns</title>
  1014. <para>
  1015. Type patterns are a way to pick out collections of types and use them
  1016. in places where you would otherwise use only one type. The rules for
  1017. using type patterns are simple.
  1018. </para>
  1019. <sect3>
  1020. <title>Type name patterns</title>
  1021. <para>
  1022. First, all type names are also type patterns. So
  1023. <literal>Object</literal>, <literal>java.util.HashMap</literal>,
  1024. <literal>Map.Entry</literal>, <literal>int</literal> are all type
  1025. patterns.
  1026. </para>
  1027. <para>
  1028. There is a special type name, *, which is also a type pattern. * picks out all
  1029. types, including primitive types. So
  1030. </para>
  1031. <programlisting>
  1032. call(void foo(*))
  1033. </programlisting>
  1034. <para>
  1035. picks out all call join points to void methods named foo, taking one
  1036. argument of any type.
  1037. </para>
  1038. <para>
  1039. Type names that contain the two wildcards "*" and
  1040. "<literal>..</literal>" are also type patterns. The * wildcard matches
  1041. zero or more characters characters except for ".", so it can be used
  1042. when types have a certain naming convention. So
  1043. </para>
  1044. <programlisting>
  1045. handler(java.util.*Map)
  1046. </programlisting>
  1047. <para>
  1048. picks out the types java.util.Map and java.util.java.util.HashMap,
  1049. among others, and
  1050. </para>
  1051. <programlisting>
  1052. handler(java.util.*)
  1053. </programlisting>
  1054. <para>
  1055. picks out all types that start with "<literal>java.util.</literal>" and
  1056. don't have any more "."s, that is, the types in the
  1057. <literal>java.util</literal> package, but not inner types
  1058. (such as java.util.Map.Entry).
  1059. </para>
  1060. <para>
  1061. The "<literal>..</literal>" wildcard matches any sequence of
  1062. characters that start and end with a ".", so it can be used
  1063. to pick out all types in any subpackage, or all inner types. So
  1064. </para>
  1065. <programlisting>
  1066. within(com.xerox..*)
  1067. </programlisting>
  1068. <para>
  1069. picks out all join points where the code is in any type
  1070. definition of a type whose name begins with "<literal>com.xerox.</literal>".
  1071. </para>
  1072. </sect3>
  1073. <sect3>
  1074. <title>Subtype patterns</title>
  1075. <para>
  1076. It is possible to pick out all subtypes of a type (or a collection of
  1077. types) with the "+" wildcard. The "+" wildcard follows immediately a
  1078. type name pattern. So, while
  1079. </para>
  1080. <programlisting>
  1081. call(Foo.new())
  1082. </programlisting>
  1083. <para>
  1084. picks out all constructor call join points where an instance of exactly
  1085. type Foo is constructed,
  1086. </para>
  1087. <programlisting>
  1088. call(Foo+.new())
  1089. </programlisting>
  1090. <para>
  1091. picks out all constructor call join points where an instance of any
  1092. subtype of Foo (including Foo itself) is constructed, and the unlikely
  1093. </para>
  1094. <programlisting>
  1095. call(*Handler+.new())
  1096. </programlisting>
  1097. <para>
  1098. picks out all constructor call join points where an instance of any
  1099. subtype of any type whose name ends in "Handler" is constructed.
  1100. </para>
  1101. </sect3>
  1102. <sect3>
  1103. <title>Array type patterns</title>
  1104. <para>
  1105. A type name pattern or subtype pattern can be followed by one or more
  1106. sets of square brackets to make array type patterns. So
  1107. <literal>Object[]</literal> is an array type pattern, and so is
  1108. <literal>com.xerox..*[][]</literal>, and so is
  1109. <literal>Object+[]</literal>.
  1110. </para>
  1111. </sect3>
  1112. <sect3>
  1113. <title>Type patterns</title>
  1114. <para>
  1115. Type patterns are built up out of type name patterns, subtype patterns,
  1116. and array type patterns, and constructed with boolean operators
  1117. <literal><![CDATA[&&]]></literal>, <literal>||</literal>, and
  1118. <literal>!</literal>. So
  1119. </para>
  1120. <programlisting>
  1121. staticinitialization(Foo || Bar)
  1122. </programlisting>
  1123. <para>
  1124. picks out the static initializer execution join points of either Foo or Bar,
  1125. and
  1126. </para>
  1127. <programlisting>
  1128. call((Foo+ <![CDATA[&&]]> ! Foo).new(..))
  1129. </programlisting>
  1130. <para>
  1131. picks out the constructor call join points when a subtype of Foo, but
  1132. not Foo itself, is constructed.
  1133. </para>
  1134. </sect3>
  1135. </sect2>
  1136. </sect1>
  1137. <!-- ============================== -->
  1138. <sect1 id="semantics-advice">
  1139. <title>Advice</title>
  1140. <para>
  1141. Each piece of advice is of the form
  1142. <blockquote>
  1143. <literal>[ strictfp ] <replaceable>AdviceSpec</replaceable> [
  1144. throws <replaceable>TypeList</replaceable> ] :
  1145. <replaceable>Pointcut</replaceable> {
  1146. <replaceable>Body</replaceable> } </literal>
  1147. </blockquote>
  1148. where <replaceable>AdviceSpec</replaceable> is one of
  1149. </para>
  1150. <itemizedlist>
  1151. <listitem>
  1152. <literal>before( <replaceable>Formals</replaceable> ) </literal>
  1153. </listitem>
  1154. <listitem>
  1155. <literal>after( <replaceable>Formals</replaceable> ) returning
  1156. [ ( <replaceable>Formal</replaceable> ) ] </literal>
  1157. </listitem>
  1158. <listitem>
  1159. <literal>after( <replaceable>Formals</replaceable> ) throwing [
  1160. ( <replaceable>Formal</replaceable> ) ] </literal>
  1161. </listitem>
  1162. <listitem>
  1163. <literal>after( <replaceable>Formals</replaceable> ) </literal>
  1164. </listitem>
  1165. <listitem>
  1166. <literal><replaceable>Type</replaceable>
  1167. around( <replaceable>Formals</replaceable> )</literal>
  1168. </listitem>
  1169. </itemizedlist>
  1170. <para>
  1171. Advice defines crosscutting behavior. It is defined in terms of
  1172. pointcuts. The code of a piece of advice runs at every join point
  1173. picked out by its pointcut. Exactly how the code runs depends on the
  1174. kind of advice.
  1175. </para>
  1176. <para>
  1177. AspectJ supports three kinds of advice. The kind of advice determines how
  1178. it interacts with the join points it is defined over. Thus AspectJ
  1179. divides advice into that which runs before its join points, that which
  1180. runs after its join points, and that which runs in place of (or "around")
  1181. its join points.
  1182. </para>
  1183. <para>
  1184. While before advice is relatively unproblematic, there can be three
  1185. interpretations of after advice: After the execution of a join point
  1186. completes normally, after it throws an exception, or after it does either
  1187. one. AspectJ allows after advice for any of these situations.
  1188. </para>
  1189. <programlisting>
  1190. aspect A {
  1191. pointcut publicCall(): call(public Object *(..));
  1192. after() returning (Object o): publicCall() {
  1193. System.out.println("Returned normally with " + o);
  1194. }
  1195. after() throwing (Exception e): publicCall() {
  1196. System.out.println("Threw an exception: " + e);
  1197. }
  1198. after(): publicCall(){
  1199. System.out.println("Returned or threw an Exception");
  1200. }
  1201. }
  1202. </programlisting>
  1203. <para>
  1204. After returning advice may not care about its returned object, in which
  1205. case it may be written
  1206. </para>
  1207. <programlisting>
  1208. after() returning: call(public Object *(..)) {
  1209. System.out.println("Returned normally");
  1210. }
  1211. </programlisting>
  1212. <para>
  1213. It is an error to try to put after returning advice on a join point that
  1214. does not return the correct type. For example,
  1215. </para>
  1216. <programlisting>
  1217. after() returning (byte b): call(int String.length()) {
  1218. // this is an error
  1219. }
  1220. </programlisting>
  1221. <para>
  1222. is not allowed. But if no return value is exposed, or the exposed return
  1223. value is typed to <literal>Object</literal>, then it may be applied to
  1224. any join point. If the exposed value is typed to
  1225. <literal>Object</literal>, then the actual return value is converted to
  1226. an object type for the body of the advice: <literal>int</literal> values
  1227. are represented as <literal>java.lang.Integer</literal> objects, etc, and
  1228. no value (from void methods, for example) is represented as
  1229. <literal>null</literal>.
  1230. </para>
  1231. <para>
  1232. Around advice runs in place of the join point it operates over, rather
  1233. than before or after it. Because around is allowed to return a value, it
  1234. must be declared with a return type, like a method. A piece of around
  1235. advice may be declared <literal>void</literal>, in which case it is not
  1236. allowed to return a value, and instead whatever value the join point
  1237. returned will be returned by the around advice (unless the around advice
  1238. throws an exception of its own).
  1239. </para>
  1240. <para>
  1241. Thus, a simple use of around advice is to make a particular method
  1242. constant:
  1243. </para>
  1244. <programlisting>
  1245. aspect A {
  1246. int around(): call(int C.foo()) {
  1247. return 3;
  1248. }
  1249. }
  1250. </programlisting>
  1251. <para>
  1252. Within the body of around advice, though, the computation of the original
  1253. join point can be executed with the special syntax
  1254. </para>
  1255. <programlisting>
  1256. proceed( ... )
  1257. </programlisting>
  1258. <para>
  1259. The proceed form takes as arguments the context exposed by the around's
  1260. pointcut, and returns whatever the around is declared to return. So the
  1261. following around advice will double the second argument to
  1262. <literal>foo</literal> whenever it is called, and then halve its result:
  1263. </para>
  1264. <programlisting>
  1265. aspect A {
  1266. int around(int i): call(int C.foo(Object, int)) <![CDATA[&&]]> args(i) {
  1267. int newi = proceed(i*2)
  1268. return newi/2;
  1269. }
  1270. }
  1271. </programlisting>
  1272. <para>
  1273. If the return value of around advice is typed to
  1274. <literal>Object</literal>, then the result of proceed is converted to an
  1275. object representation, even if it is originally a primitive value. And
  1276. when the advice returns an Object value, that value is converted back to
  1277. whatever representation it was originally. So another way to write the
  1278. doubling and halving advice is:
  1279. </para>
  1280. <programlisting>
  1281. aspect A {
  1282. Object around(int i): call(int C.foo(Object, int)) <![CDATA[&&]]> args(i) {
  1283. Integer newi = (Integer) proceed(i*2)
  1284. return new Integer(newi.intValue() / 2);
  1285. }
  1286. }
  1287. </programlisting>
  1288. <para>
  1289. In all kinds of advice, the parameters of the advice behave exactly like
  1290. method parameters. In particular, assigning to any parameter affects
  1291. only the value of the parameter, not the value that it came from. This
  1292. means that
  1293. </para>
  1294. <programlisting>
  1295. aspect A {
  1296. after() returning (int i): call(int C.foo()) {
  1297. i = i * 2;
  1298. }
  1299. }
  1300. </programlisting>
  1301. <para>
  1302. will <emphasis>not</emphasis> double the returned value of the advice.
  1303. Rather, it will double the local parameter. Changing the values of
  1304. parameters or return values of join points can be done by using around
  1305. advice.
  1306. </para>
  1307. <sect2>
  1308. <title>Advice modifiers</title>
  1309. <para>
  1310. The <literal>strictfp</literal> modifier is the only modifier allowed
  1311. on advice, and it has the effect of making all floating-point
  1312. expressions within the advice be FP-strict.
  1313. </para>
  1314. </sect2>
  1315. <sect2>
  1316. <title>Advice and checked exceptions</title>
  1317. <para>
  1318. An advice declaration must include a <literal>throws</literal> clause
  1319. listing the checked exceptions the body may throw. This list of
  1320. checked exceptions must be compatible with each target join point
  1321. of the advice, or an error is signalled by the compiler.
  1322. </para>
  1323. <para>
  1324. For example, in the following declarations:
  1325. </para>
  1326. <programlisting>
  1327. import java.io.FileNotFoundException;
  1328. class C {
  1329. int i;
  1330. int getI() { return i; }
  1331. }
  1332. aspect A {
  1333. before(): get(int C.i) {
  1334. throw new FileNotFoundException();
  1335. }
  1336. before() throws FileNotFoundException: get(int C.i) {
  1337. throw new FileNotFoundException();
  1338. }
  1339. }
  1340. </programlisting>
  1341. <para>
  1342. both pieces of advice are illegal. The first because the body throws
  1343. an undeclared checked exception, and the second because field get join
  1344. points cannot throw <literal>FileNotFoundException</literal>s.
  1345. </para>
  1346. <para> The exceptions that each kind of join point in AspectJ may throw are:
  1347. </para>
  1348. <variablelist>
  1349. <varlistentry>
  1350. <term>method call and execution</term>
  1351. <listitem>
  1352. the checked exceptions declared by the target method's
  1353. <literal>throws</literal> clause.
  1354. </listitem>
  1355. </varlistentry>
  1356. <varlistentry>
  1357. <term>constructor call and execution</term>
  1358. <listitem>
  1359. the checked exceptions declared by the target constructor's
  1360. <literal>throws</literal> clause.
  1361. </listitem>
  1362. </varlistentry>
  1363. <varlistentry>
  1364. <term>field get and set</term>
  1365. <listitem>
  1366. no checked exceptions can be thrown from these join points.
  1367. </listitem>
  1368. </varlistentry>
  1369. <varlistentry>
  1370. <term>exception handler execution</term>
  1371. <listitem>
  1372. the exceptions that can be thrown by the target exception handler.
  1373. </listitem>
  1374. </varlistentry>
  1375. <varlistentry>
  1376. <term>static initializer execution</term>
  1377. <listitem>
  1378. no checked exceptions can be thrown from these join points.
  1379. </listitem>
  1380. </varlistentry>
  1381. <varlistentry>
  1382. <term>pre-initialization and initialization</term>
  1383. <listitem>
  1384. any exception that is in the throws clause of
  1385. <emphasis>all</emphasis> constructors of the initialized class.
  1386. </listitem>
  1387. </varlistentry>
  1388. <varlistentry>
  1389. <term>advice execution</term>
  1390. <listitem>
  1391. any exception that is in the throws clause of the advice.
  1392. </listitem>
  1393. </varlistentry>
  1394. </variablelist>
  1395. </sect2>
  1396. <sect2>
  1397. <title>Advice precedence</title>
  1398. <para>
  1399. Multiple pieces of advice may apply to the same join point. In such
  1400. cases, the resolution order of the advice is based on advice
  1401. precedence.
  1402. </para>
  1403. <sect3>
  1404. <title>Determining precedence</title>
  1405. <para>There are a number of rules that determine whether a particular
  1406. piece of advice has precedence over another when they advise the same
  1407. join point. </para>
  1408. <para>If the two pieces of advice are defined in different aspects,
  1409. then there are three cases: </para>
  1410. <itemizedlist>
  1411. <listitem>If aspect A is matched earlier than aspect B in some
  1412. <literal>declare precedence</literal> form, then all advice in
  1413. concrete aspect A has precedence over all advice in concrete aspect B
  1414. when they are on the same join point. </listitem>
  1415. <listitem>
  1416. Otherwise, if aspect A is a subaspect of aspect B, then all advice
  1417. defined in A has precedence over all advice defined in
  1418. B. So, unless otherwise specified with
  1419. <literal>declare precedence</literal>, advice in a subaspect
  1420. has precedence over advice in a superaspect.
  1421. </listitem>
  1422. <listitem>
  1423. Otherwise, if two pieces of advice are defined in two different
  1424. aspects, it is undefined which one has precedence.
  1425. </listitem>
  1426. </itemizedlist>
  1427. <para>If the two pieces of advice are defined in the same aspect, then
  1428. there are two cases: </para>
  1429. <itemizedlist>
  1430. <listitem>If either are <literal>after</literal> advice, then the one that
  1431. appears later in the aspect has precedence over the one that appears
  1432. earlier. </listitem>
  1433. <listitem>Otherwise, then the one that appears earlier in the aspect
  1434. has precedence over the one that appears later.
  1435. </listitem>
  1436. </itemizedlist>
  1437. <para>These rules can lead to circularity, such as</para>
  1438. <programlisting>
  1439. aspect A {
  1440. before(): execution(void main(String[] args)) {}
  1441. after(): execution(void main(String[] args)) {}
  1442. before(): execution(void main(String[] args)) {}
  1443. }
  1444. </programlisting>
  1445. <para>such circularities will result in errors signalled by the compiler. </para>
  1446. </sect3>
  1447. <sect3>
  1448. <title>Effects of precedence</title>
  1449. <para>At a particular join point, advice is ordered by precedence.</para>
  1450. <para>A piece of <literal>around</literal> advice controls whether
  1451. advice of lower precedence will run by calling
  1452. <literal>proceed</literal>. The call to <literal>proceed</literal>
  1453. will run the advice with next precedence, or the computation under the
  1454. join point if there is no further advice. </para>
  1455. <para>A piece of <literal>before</literal> advice can prevent advice of
  1456. lower precedence from running by throwing an exception. If it returns
  1457. normally, however, then the advice of the next precedence, or the
  1458. computation under the join pint if there is no further advice, will run.
  1459. </para>
  1460. <para>Running <literal>after returning</literal> advice will run the
  1461. advice of next precedence, or the computation under the join point if
  1462. there is no further advice. Then, if that computation returned
  1463. normally, the body of the advice will run. </para>
  1464. <para>Running <literal>after throwing</literal> advice will run the
  1465. advice of next precedence, or the computation under the join
  1466. point if there is no further advice. Then, if that computation threw
  1467. an exception of an appropriate type, the body of the advice will
  1468. run. </para>
  1469. <para>Running <literal>after</literal> advice will run the advice of
  1470. next precedence, or the computation under the join point if
  1471. there is no further advice. Then the body of the advice will
  1472. run. </para>
  1473. </sect3>
  1474. </sect2>
  1475. <sect2>
  1476. <title>Reflective access to the join point</title>
  1477. <para>
  1478. Three special variables are visible within bodies of advice:
  1479. <literal>thisJoinPoint</literal>,
  1480. <literal>thisJoinPointStaticPart</literal>, and
  1481. <literal>thisEnclosingJoinPointStaticPart</literal>. Each is bound to
  1482. an object that encapsulates some of the context of the advice's current
  1483. or enclosing join point. These variables exist because some pointcuts
  1484. may pick out very large collections of join points. For example, the
  1485. pointcut
  1486. </para>
  1487. <programlisting>
  1488. pointcut publicCall(): call(public * *(..));
  1489. </programlisting>
  1490. <para>
  1491. picks out calls to many methods. Yet the body of advice over this
  1492. pointcut may wish to have access to the method name or parameters of a
  1493. particular join point.
  1494. </para>
  1495. <para>
  1496. <literal>thisJoinPoint</literal> is bound to a complete join point
  1497. object.
  1498. </para>
  1499. <para>
  1500. <literal>thisJoinPointStaticPart</literal> is bound to a part of the
  1501. join point object that includes less information, but for which no
  1502. memory allocation is required on each execution of the advice. It is
  1503. equivalent to <literal>thisJoinPoint.getStaticPart()</literal>.
  1504. </para>
  1505. <para>
  1506. <literal>thisEnclosingJoinPointStaticPart</literal> is bound to the
  1507. static part of the join point enclosing the current join point. Only
  1508. the static part of this enclosing join point is available through this
  1509. mechanism.
  1510. </para>
  1511. <para>
  1512. Standard Java reflection uses objects from the
  1513. <literal>java.lang.reflect</literal> hierarchy to build up its
  1514. reflective objects. Similarly, AspectJ join point objects have types
  1515. in a type hierarchy. The type of objects bound to
  1516. <literal>thisJoinPoint</literal> is
  1517. <literal>org.aspectj.lang.JoinPoint</literal>, while
  1518. <literal>thisStaticJoinPoint</literal> is bound to objects of interface
  1519. type <literal>org.aspectj.lang.JoinPoint.StaticPart</literal>.
  1520. </para>
  1521. </sect2>
  1522. </sect1>
  1523. <sect1 id="semantics-declare">
  1524. <title>Static crosscutting</title>
  1525. <para>
  1526. Advice declarations change the behavior of classes they crosscut, but do
  1527. not change their static type structure. For crosscutting concerns that do
  1528. operate over the static structure of type hierarchies, AspectJ provides
  1529. inter-type member declarations and other <literal>declare</literal> forms.
  1530. </para>
  1531. <sect2>
  1532. <title>Inter-type member declarations</title>
  1533. <para>
  1534. AspectJ allows the declaration of members by aspects that are
  1535. associated with other types.
  1536. </para>
  1537. <para>
  1538. An inter-type method declaration looks like
  1539. </para>
  1540. <itemizedlist>
  1541. <listitem><literal>
  1542. [ <replaceable>Modifiers</replaceable> ]
  1543. <replaceable>Type</replaceable> <replaceable>OnType</replaceable>
  1544. .
  1545. <replaceable>Id</replaceable>(<replaceable>Formals</replaceable>)
  1546. [ <replaceable>ThrowsClause</replaceable> ]
  1547. { <replaceable>Body</replaceable> }</literal></listitem>
  1548. <listitem><literal>abstract
  1549. [ <replaceable>Modifiers</replaceable> ]
  1550. <replaceable>Type</replaceable> <replaceable>OnType</replaceable>
  1551. . <replaceable>Id</replaceable>(<replaceable>Formals</replaceable>)
  1552. [ <replaceable>ThrowsClause</replaceable> ]
  1553. ;
  1554. </literal></listitem>
  1555. </itemizedlist>
  1556. <para>
  1557. The effect of such a declaration is to make <replaceable>OnType</replaceable>
  1558. support the new method. Even if <replaceable>OnType</replaceable> is
  1559. an interface. Even if the method is neither public nor abstract. So the
  1560. following is legal AspectJ code:
  1561. </para>
  1562. <programlisting>
  1563. interface Iface {}
  1564. aspect A {
  1565. private void Iface.m() {
  1566. System.err.println("I'm a private method on an interface");
  1567. }
  1568. void worksOnI(Iface iface) {
  1569. // calling a private method on an interface
  1570. iface.m();
  1571. }
  1572. }
  1573. </programlisting>
  1574. <para>
  1575. An inter-type constructor declaration looks like
  1576. </para>
  1577. <itemizedlist>
  1578. <listitem><literal>
  1579. [ <replaceable>Modifiers</replaceable> ]
  1580. <replaceable>OnType</replaceable> . new (
  1581. <replaceable>Formals</replaceable> )
  1582. [ <replaceable>ThrowsClause</replaceable> ]
  1583. { <replaceable>Body</replaceable> }</literal></listitem>
  1584. </itemizedlist>
  1585. <para>
  1586. The effect of such a declaration is to make
  1587. <replaceable>OnType</replaceable> support the new constructor. It is
  1588. an error for <replaceable>OnType</replaceable> to be an interface.
  1589. </para>
  1590. <para>
  1591. Note that in the Java language, classes that define no constructors
  1592. have an implicit no-argument constructor that just calls
  1593. <literal>super()</literal>. This means that attempting to declare
  1594. a no-argument inter-type constructor on such a class may result in
  1595. a conflict, even though it <emphasis>looks</emphasis> like no
  1596. constructor is defined.
  1597. </para>
  1598. <para>
  1599. An inter-type field declaration looks like one of
  1600. </para>
  1601. <itemizedlist>
  1602. <listitem><literal>
  1603. [ <replaceable>Modifiers</replaceable> ]
  1604. <replaceable>Type</replaceable>
  1605. <replaceable>OnType</replaceable> . <replaceable>Id</replaceable>
  1606. = <replaceable>Expression</replaceable>;</literal></listitem>
  1607. <listitem><literal>
  1608. [ <replaceable>Modifiers</replaceable> ]
  1609. <replaceable>Type</replaceable>
  1610. <replaceable>OnType</replaceable> . <replaceable>Id</replaceable>;</literal></listitem>
  1611. </itemizedlist>
  1612. <para>
  1613. The effect of such a declaration is to make
  1614. <replaceable>OnType</replaceable> support the new field. Even if
  1615. <replaceable>OnType</replaceable> is an interface. Even if the field is
  1616. neither public, nor static, nor final.
  1617. </para>
  1618. <para>
  1619. The initializer, if any, of an inter-type field definition runs
  1620. before the class-local initializers defined in its target class.
  1621. </para>
  1622. </sect2>
  1623. <para>
  1624. Any occurrence of the identifier <literal>this</literal> in the body of
  1625. an inter-type constructor or method declaration, or in the initializer
  1626. of an inter-type field declaration, refers to the
  1627. <replaceable>OnType</replaceable> object rather than to the aspect
  1628. type; it is an error to access <literal>this</literal> in such a
  1629. position from a <literal>static</literal> inter-type member
  1630. declaration.
  1631. </para>
  1632. <sect2>
  1633. <title>Access modifiers</title>
  1634. <para>
  1635. Inter-type member declarations may be public or private, or have
  1636. default (package-protected) visibility. AspectJ does not provide
  1637. protected inter-type members.
  1638. </para>
  1639. <para>
  1640. The access modifier applies in relation to the aspect, not in relation
  1641. to the target type. So a private inter-type member is visible only from
  1642. code that is defined within the declaring aspect. A default-visibility
  1643. inter-type member is visible only from code that is defined within the
  1644. declaring aspect's package.
  1645. </para>
  1646. <para>
  1647. Note that a declaring a private inter-type method (which AspectJ
  1648. supports) is very different from inserting a private method declaration
  1649. into another class. The former allows access only from the declaring
  1650. aspect, while the latter would allow access only from the target type.
  1651. Java serialization, for example, uses the presense of a private method
  1652. <literal>void writeObject(ObjectOutputStream)</literal> for the
  1653. implementation of <literal>java.io.Serializable</literal>. A private
  1654. inter-type declaration of that method would not fulfill this
  1655. requirement, since it would be private to the aspect, not private to
  1656. the target type.
  1657. </para>
  1658. </sect2>
  1659. <sect2>
  1660. <title>Conflicts</title>
  1661. <para>
  1662. Inter-type declarations raise the possibility of conflicts among
  1663. locally declared members and inter-type members. For example, assuming
  1664. <literal>otherPackage</literal> is not the package containing the
  1665. aspect <classname>A</classname>, the code
  1666. </para>
  1667. <programlisting>
  1668. aspect A {
  1669. private Registry otherPackage.*.r;
  1670. public void otherPackage.*.register(Registry r) {
  1671. r.register(this);
  1672. this.r = r;
  1673. }
  1674. }
  1675. </programlisting>
  1676. <para>
  1677. declares that every type in <literal>otherPackage</literal> has a field
  1678. <literal>r</literal>. This field, however, is only accessible from the
  1679. code inside of aspect <literal>A</literal>. The aspect also declares
  1680. that every type in <literal>otherPackage</literal> has a method
  1681. "<literal>register</literal>", but makes this method accessible from
  1682. everywhere.
  1683. </para>
  1684. <para>
  1685. If any type in <literal>otherPackage</literal> already defines a
  1686. private or package-protected field "<literal>r</literal>", there is no
  1687. conflict: The aspect cannot see such a field, and no code in
  1688. <literal>otherPackage</literal> can see the inter-type
  1689. "<literal>r</literal>".
  1690. </para>
  1691. <para>
  1692. If any type in <literal>otherPackage</literal> defines a public field
  1693. "<literal>r</literal>", there is a conflict: The expression
  1694. </para>
  1695. <programlisting>
  1696. this.r = r
  1697. </programlisting>
  1698. <para>
  1699. is an error, since it is ambiguous whether the private inter-type
  1700. "<literal>r</literal>" or the public locally-defined
  1701. "<literal>r</literal>" should be used.
  1702. </para>
  1703. <para>
  1704. If any type in <literal>otherPackage</literal> defines any method
  1705. "<literal>register(Registry)</literal>" there is a conflict, since it
  1706. would be ambiguous to any code that could see such a defined method
  1707. which "<literal>register(Registry)</literal>" method was applicable.
  1708. </para>
  1709. <para>
  1710. Conflicts are resolved as much as possible as per Java's conflict
  1711. resolution rules:
  1712. </para>
  1713. <itemizedlist>
  1714. <listitem>A subclass can inherit multiple <emphasis>fields</emphasis> from its superclasses,
  1715. all with the same name and type. However, it is an error to have an ambiguous
  1716. <emphasis>reference</emphasis> to a field.</listitem>
  1717. <listitem>A subclass can only inherit multiple
  1718. <emphasis>methods</emphasis> with the same name and argument types from
  1719. its superclasses if only zero or one of them is concrete (i.e., all but
  1720. one is abstract, or all are abstract).
  1721. </listitem>
  1722. </itemizedlist>
  1723. <para>
  1724. Given a potential conflict between inter-type member declarations in
  1725. different aspects, if one aspect has precedence over the other its
  1726. declaration will take effect without any conflict notice from compiler.
  1727. This is true both when the precedence is declared explicitly with
  1728. <literal>declare precedence</literal> as well as when when sub-aspects
  1729. implicitly have precedence over their super-aspect.
  1730. </para>
  1731. </sect2>
  1732. <sect2>
  1733. <title>Extension and Implementation</title>
  1734. <para>
  1735. An aspect may change the inheritance hierarchy of a system by changing
  1736. the superclass of a type or adding a superinterface onto a type, with
  1737. the <literal>declare parents</literal> form.
  1738. </para>
  1739. <itemizedlist>
  1740. <listitem><literal>declare parents: <replaceable>TypePattern</replaceable> extends <replaceable>Type</replaceable>;</literal></listitem>
  1741. <listitem><literal>declare parents: <replaceable>TypePattern</replaceable> implements <replaceable>TypeList</replaceable>;</literal></listitem>
  1742. </itemizedlist>
  1743. <para>
  1744. For example, if an aspect wished to make a particular class runnable,
  1745. it might define appropriate inter-type <literal>void
  1746. run()</literal> method, but it should also declare that the class
  1747. fulfills the <literal>Runnable</literal> interface. In order to
  1748. implement the methods in the <literal>Runnable</literal> interface, the
  1749. inter-type <literal>run()</literal> method must be public:
  1750. </para>
  1751. <programlisting>
  1752. aspect A {
  1753. declare parents: SomeClass implements Runnable;
  1754. public void SomeClass.run() { ... }
  1755. }
  1756. </programlisting>
  1757. </sect2>
  1758. <sect2>
  1759. <title>Interfaces with members</title>
  1760. <para>
  1761. Through the use of inter-type members, interfaces may now carry
  1762. (non-public-static-final) fields and (non-public-abstract) methods that
  1763. classes can inherit. Conflicts may occur from ambiguously inheriting
  1764. members from a superclass and multiple superinterfaces.
  1765. </para>
  1766. <para>
  1767. Because interfaces may carry non-static initializers, each interface
  1768. behaves as if it has a zero-argument constructor containing its
  1769. initializers. The order of super-interface instantiation is
  1770. observable. We fix this order with the following properties: A
  1771. supertype is initialized before a subtype, initialized code runs only
  1772. once, and the initializers for a type's superclass are run before the
  1773. initializers for its superinterfaces. Consider the following hierarchy
  1774. where {<literal>Object</literal>, <literal>C</literal>,
  1775. <literal>D</literal>, <literal>E</literal>} are classes,
  1776. {<literal>M</literal>, <literal>N</literal>, <literal>O</literal>,
  1777. <literal>P</literal>, <literal>Q</literal>} are interfaces.
  1778. </para>
  1779. <programlisting>
  1780. Object M O
  1781. \ / \ /
  1782. C N Q
  1783. \ / /
  1784. D P
  1785. \ /
  1786. E
  1787. </programlisting>
  1788. <para>
  1789. when a new <literal>E</literal> is instantiated, the initializers run in this order:
  1790. </para>
  1791. <programlisting>
  1792. Object M C O N D Q P E
  1793. </programlisting>
  1794. </sect2>
  1795. <!-- ============================== -->
  1796. <sect2>
  1797. <title>Warnings and Errors</title>
  1798. <para>An aspect may specify that a particular join point should never be
  1799. reached. </para>
  1800. <itemizedlist>
  1801. <listitem><literal>declare error: <replaceable>Pointcut</replaceable>: <replaceable>String</replaceable>;</literal></listitem>
  1802. <listitem><literal>declare warning: <replaceable>Pointcut</replaceable>: <replaceable>String</replaceable>;</literal></listitem>
  1803. </itemizedlist>
  1804. <para>If the compiler determines that a join point in
  1805. <replaceable>Pointcut</replaceable> could possibly be reached, then it
  1806. will signal either an error or warning, as declared, using the
  1807. <replaceable>String</replaceable> for its message. </para>
  1808. </sect2>
  1809. <sect2>
  1810. <title>Softened exceptions</title>
  1811. <para>An aspect may specify that a particular kind of exception, if
  1812. thrown at a join point, should bypass Java's usual static exception
  1813. checking system and instead be thrown as a
  1814. <literal>org.aspectj.lang.SoftException</literal>, which is subtype of
  1815. <literal>RuntimeException</literal> and thus does not need to be
  1816. declared. </para>
  1817. <itemizedlist>
  1818. <listitem><literal>declare soft: <replaceable>Type</replaceable>: <replaceable>Pointcut</replaceable>;</literal></listitem>
  1819. </itemizedlist>
  1820. <para>For example, the aspect</para>
  1821. <programlisting>
  1822. aspect A {
  1823. declare soft: Exception: execution(void main(String[] args));
  1824. }
  1825. </programlisting>
  1826. <para>Would, at the execution join point, catch any
  1827. <literal>Exception</literal> and rethrow a
  1828. <literal>org.aspectj.lang.SoftException</literal> containing
  1829. original exception. </para>
  1830. <para>This is similar to what the following advice would do</para>
  1831. <programlisting>
  1832. aspect A {
  1833. void around() execution(void main(String[] args)) {
  1834. try { proceed(); }
  1835. catch (Exception e) {
  1836. throw new org.aspectj.lang.SoftException(e);
  1837. }
  1838. }
  1839. }
  1840. </programlisting>
  1841. <para>except, in addition to wrapping the exception, it also affects
  1842. Java's static exception checking mechanism. </para>
  1843. </sect2>
  1844. <sect2>
  1845. <title>Advice Precedence</title>
  1846. <para>
  1847. An aspect may declare a precedence relationship between concrete
  1848. aspects with the <literal>declare precedence</literal> form:
  1849. </para>
  1850. <itemizedlist>
  1851. <listitem><literal>declare precedence :
  1852. <replaceable>TypePatternList</replaceable> ; </literal></listitem>
  1853. </itemizedlist>
  1854. <para>This signifies that if any join point has advice from two
  1855. concrete aspects matched by some pattern in
  1856. <replaceable>TypePatternList</replaceable>, then the precedence of
  1857. the advice will be the order of in the list. </para>
  1858. <para>In <replaceable>TypePatternList</replaceable>, the wildcard "*" can
  1859. appear at most once, and it means "any type not matched by any other
  1860. pattern in the list". </para>
  1861. <para>For example, the constraints that (1) aspects that have
  1862. Security as part of their name should have precedence over all other
  1863. aspects, and (2) the Logging aspect (and any aspect that extends it)
  1864. should have precedence over all non-security aspects, can be
  1865. expressed by:</para>
  1866. <programlisting>
  1867. declare precedence: *..*Security*, Logging+, *;
  1868. </programlisting>
  1869. <para>
  1870. For another example, the CountEntry aspect might want to count the
  1871. entry to methods in the current package accepting a Type object as
  1872. its first argument. However, it should count all entries, even
  1873. those that the aspect DisallowNulls causes to throw exceptions.
  1874. This can be accomplished by stating that CountEntry has precedence
  1875. over DisallowNulls. This declaration could be in either aspect, or
  1876. in another, ordering aspect:
  1877. </para>
  1878. <programlisting>
  1879. aspect Ordering {
  1880. declare precedence: CountEntry, DisallowNulls;
  1881. }
  1882. aspect DisallowNulls {
  1883. pointcut allTypeMethods(Type obj): call(* *(..)) <![CDATA[&&]]> args(obj, ..);
  1884. before(Type obj): allTypeMethods(obj) {
  1885. if (obj == null) throw new RuntimeException();
  1886. }
  1887. }
  1888. aspect CountEntry {
  1889. pointcut allTypeMethods(Type obj): call(* *(..)) <![CDATA[&&]]> args(obj, ..);
  1890. static int count = 0;
  1891. before(): allTypeMethods(Type) {
  1892. count++;
  1893. }
  1894. }
  1895. </programlisting>
  1896. <sect3>
  1897. <title>Various cycles</title>
  1898. <para>
  1899. It is an error for any aspect to be matched by more than one
  1900. TypePattern in a single decare precedence, so:
  1901. </para>
  1902. <programlisting>
  1903. declare precedence: A, B, A ; // error
  1904. </programlisting>
  1905. <para>
  1906. However, multiple declare precedence forms may legally have this
  1907. kind of circularity. For example, each of these declare
  1908. precedence is perfectly legal:
  1909. </para>
  1910. <programlisting>
  1911. declare precedence: B, A;
  1912. declare precedence: A, B;
  1913. </programlisting>
  1914. <para>
  1915. And a system in which both constraints are active may also be
  1916. legal, so long as advice from A and B don't share a join
  1917. point. So this is an idiom that can be used to enforce that A and
  1918. B are strongly independent.
  1919. </para>
  1920. </sect3>
  1921. <sect3>
  1922. <title>Applies to concrete aspects</title>
  1923. <para>
  1924. Consider the following library aspects:
  1925. </para>
  1926. <programlisting>
  1927. abstract aspect Logging {
  1928. abstract pointcut logged();
  1929. before(): logged() {
  1930. System.err.println("thisJoinPoint: " + thisJoinPoint);
  1931. }
  1932. }
  1933. aspect aspect MyProfiling {
  1934. abstract pointcut profiled();
  1935. Object around(): profiled() {
  1936. long beforeTime = System.currentTimeMillis();
  1937. try {
  1938. return proceed();
  1939. } finally {
  1940. long afterTime = System.currentTimeMillis();
  1941. addToProfile(thisJoinPointStaticPart,
  1942. afterTime - beforeTime);
  1943. }
  1944. }
  1945. abstract void addToProfile(
  1946. org.aspectj.JoinPoint.StaticPart jp,
  1947. long elapsed);
  1948. }
  1949. </programlisting>
  1950. <para>
  1951. In order to use either aspect, they must be extended with
  1952. concrete aspects, say, MyLogging and MyProfiling. Because advice
  1953. only applies from concrete aspects, the declare precedence form
  1954. only matters when declaring precedence with concrete aspects. So
  1955. </para>
  1956. <programlisting>
  1957. declare precedence: Logging, Profiling;
  1958. </programlisting>
  1959. <para>
  1960. has no effect, but both
  1961. </para>
  1962. <programlisting>
  1963. declare precedence: MyLogging, MyProfiling;
  1964. declare precedence: Logging+, Profiling+;
  1965. </programlisting>
  1966. <para>
  1967. are meaningful.
  1968. </para>
  1969. </sect3>
  1970. </sect2>
  1971. <sect2>
  1972. <title>Statically determinable pointcuts</title>
  1973. <para>Pointcuts that appear inside of <literal>declare</literal> forms
  1974. have certain restrictions. Like other pointcuts, these pick out join
  1975. points, but they do so in a way that is statically determinable. </para>
  1976. <para>Consequently, such pointcuts may not include, directly or
  1977. indirectly (through user-defined pointcut declarations) pointcuts that
  1978. discriminate based on dynamic (runtime) context. Therefore, such
  1979. pointcuts may not be defined in terms of</para>
  1980. <itemizedlist>
  1981. <listitem>cflow</listitem>
  1982. <listitem>cflowbelow</listitem>
  1983. <listitem>this</listitem>
  1984. <listitem>target</listitem>
  1985. <listitem>args</listitem>
  1986. <listitem>if</listitem>
  1987. </itemizedlist>
  1988. <para> all of which can discriminate on runtime information. </para>
  1989. </sect2>
  1990. </sect1>
  1991. <sect1 id="semantics-aspects">
  1992. <title>Aspects</title>
  1993. <para>
  1994. An aspect is a crosscutting type defined by the <literal>aspect</literal>
  1995. declaration. The <literal>aspect</literal> declaration is similar to the
  1996. <literal>class</literal> declaration in that it defines a type and an
  1997. implementation for that type. It differs in that the type and
  1998. implementation can cut across other types (including those defined by
  1999. other aspect declarations), and that it may not be directly instantiated
  2000. with a new expression, with cloning, or with serialization. Aspects may
  2001. have one constructor definition, but if so it must be of a constructor
  2002. taking no arguments and throwing no checked exceptions.
  2003. </para>
  2004. <para>
  2005. Aspects may be defined either at the package level, or as a static nested
  2006. aspect -- that is, a static member of a class, interface, or aspect. If it
  2007. is not at the package level, the aspect <emphasis>must</emphasis> be
  2008. defined with the static keyword. Local and anonymous aspects are not
  2009. allowed.
  2010. </para>
  2011. <sect2>
  2012. <title>Aspect Extension</title>
  2013. <para>
  2014. To support abstraction and composition of crosscutting concerns,
  2015. aspects can be extended in much the same way that classes can. Aspect
  2016. extension adds some new rules, though.
  2017. </para>
  2018. <sect3>
  2019. <title>Aspects may extend classes and implement interfaces</title>
  2020. <para>
  2021. An aspect, abstract or concrete, may extend a class and may implement
  2022. a set of interfaces. Extending a class does not provide the ability
  2023. to instantiate the aspect with a new expression: The aspect may still
  2024. only define a null constructor.
  2025. </para>
  2026. </sect3>
  2027. <sect3>
  2028. <title>Classes may not extend aspects</title>
  2029. <para>
  2030. It is an error for a class to extend or implement an aspect.
  2031. </para>
  2032. </sect3>
  2033. <sect3>
  2034. <title>Aspects extending aspects
  2035. </title>
  2036. <para>
  2037. Aspects may extend other aspects, in which case not only are fields
  2038. and methods inherited but so are pointcuts. However, aspects may only
  2039. extend abstract aspects. It is an error for a concrete aspect to
  2040. extend another concrete aspect.
  2041. </para>
  2042. </sect3>
  2043. </sect2>
  2044. <sect2>
  2045. <title>Aspect instantiation</title>
  2046. <para>
  2047. Unlike class expressions, aspects are not instantiated with
  2048. <literal>new</literal> expressions. Rather, aspect instances are
  2049. automatically created to cut across programs.
  2050. </para>
  2051. <para>
  2052. Because advice only runs in the context of an aspect instance, aspect
  2053. instantiation indirectly controls when advice runs.
  2054. </para>
  2055. <para>
  2056. The criteria used to determine how an aspect is instantiated
  2057. is inherited from its parent aspect. If the aspect has no parent
  2058. aspect, then by default the aspect is a singleton aspect.
  2059. </para>
  2060. <sect3>
  2061. <title>Singleton Aspects</title>
  2062. <itemizedlist>
  2063. <listitem><literal>aspect <replaceable>Id</replaceable> { ... }</literal></listitem>
  2064. <listitem><literal>aspect <replaceable>Id</replaceable> issingleton { ... }</literal></listitem>
  2065. </itemizedlist>
  2066. <para>
  2067. By default (or by using the modifier <literal>issingleton</literal>)
  2068. an aspect has exactly one instance that cuts across the entire
  2069. program. That instance is available at any time during program
  2070. execution with the static method <literal>aspectOf()</literal>
  2071. defined on the aspect
  2072. -- so, in the above examples, <literal>A.aspectOf()</literal> will
  2073. return A's instance. This aspect instance is created as the aspect's
  2074. classfile is loaded.
  2075. </para>
  2076. <para>
  2077. Because the an instance of the aspect exists at all join points in
  2078. the running of a program (once its class is loaded), its advice will
  2079. have a chance to run at all such join points.
  2080. </para>
  2081. <para>
  2082. (In actuality, one instance of the aspect A is made for each version
  2083. of the aspect A, so there will be one instantiation for each time A
  2084. is loaded by a different classloader.)
  2085. </para>
  2086. </sect3>
  2087. <sect3>
  2088. <title>Per-object aspects</title>
  2089. <itemizedlist>
  2090. <listitem><literal>aspect <replaceable>Id</replaceable> perthis(<replaceable>Pointcut</replaceable>) { ... }</literal></listitem>
  2091. <listitem><literal>aspect <replaceable>Id</replaceable> pertarget(<replaceable>Pointcut</replaceable>) { ... }</literal></listitem>
  2092. </itemizedlist>
  2093. <para>
  2094. If an aspect A is defined
  2095. <literal>perthis(<replaceable>Pointcut</replaceable>)</literal>, then
  2096. one object of type A is created for every object that is the
  2097. executing object (i.e., "this") at any of the join points picked out
  2098. by <replaceable>Pointcut</replaceable>.
  2099. The advice defined in A may then run at any join point where the
  2100. currently executing object has been associated with an instance of
  2101. A.
  2102. </para>
  2103. <para> Similarly, if an aspect A is defined
  2104. <literal>pertarget(<replaceable>Pointcut</replaceable>)</literal>,
  2105. then one object of type A is created for every object that is the
  2106. target object of the join points picked out by
  2107. <replaceable>Pointcut</replaceable>.
  2108. The advice defined in A may then run at any join point where the
  2109. target object has been associated with an instance of
  2110. A.
  2111. </para>
  2112. <para>
  2113. In either case, the static method call
  2114. <literal>A.aspectOf(Object)</literal> can be used to get the aspect
  2115. instance (of type A) registered with the object. Each aspect
  2116. instance is created as early as possible, but not before reaching a
  2117. join point picked out by <replaceable>Pointcut</replaceable> where
  2118. there is no associated aspect of type A.
  2119. </para>
  2120. <para> Both <literal>perthis</literal> and <literal>pertarget</literal>
  2121. aspects may be affected by code the AspectJ compiler controls, as
  2122. discussed in the <xref linkend="limitations"/> appendix. </para>
  2123. </sect3>
  2124. <sect3>
  2125. <title>Per-control-flow aspects</title>
  2126. <itemizedlist>
  2127. <listitem><literal>aspect <replaceable>Id</replaceable> percflow(<replaceable>Pointcut</replaceable>) { ... }</literal></listitem>
  2128. <listitem><literal>aspect <replaceable>Id</replaceable> percflowbelow(<replaceable>Pointcut</replaceable>) { ... }</literal></listitem>
  2129. </itemizedlist>
  2130. <para>
  2131. If an aspect A is defined
  2132. <literal>percflow(<replaceable>Pointcut</replaceable>)</literal> or
  2133. <literal>percflowbelow(<replaceable>Pointcut</replaceable>)</literal>,
  2134. then one object of type A is created for each flow of control of the
  2135. join points picked out by <replaceable>Pointcut</replaceable>, either
  2136. as the flow of control is entered, or below the flow of control,
  2137. respectively. The advice defined in A may run at any join point in
  2138. or under that control flow. During each such flow of control, the
  2139. static method <literal>A.aspectOf()</literal> will return an object
  2140. of type
  2141. A. An instance of the aspect is created upon entry into each such
  2142. control flow.
  2143. </para>
  2144. </sect3>
  2145. <sect3>
  2146. <title>Aspect instantiation and advice</title>
  2147. <para>
  2148. All advice runs in the context of an aspect instance,
  2149. but it is possible to write a piece of advice with a pointcut
  2150. that picks out a join point that must occur before asopect
  2151. instantiation. For example:
  2152. </para>
  2153. <programlisting>
  2154. public class Client
  2155. {
  2156. public static void main(String[] args) {
  2157. Client c = new Client();
  2158. }
  2159. }
  2160. aspect Watchcall {
  2161. pointcut myConstructor(): execution(new(..));
  2162. before(): myConstructor() {
  2163. System.err.println("Entering Constructor");
  2164. }
  2165. }
  2166. </programlisting>
  2167. <para>
  2168. The before advice should run before the execution of all
  2169. constructors in the system. It must run in the context of an
  2170. instance of the Watchcall aspect. The only way to get such an
  2171. instance is to have Watchcall's default constructor execute. But
  2172. before that executes, we need to run the before advice...
  2173. </para>
  2174. <para>
  2175. There is no general way to detect these kinds of circularities at
  2176. compile time. If advice runs before its aspect is instantiated,
  2177. AspectJ will throw a <ulink
  2178. url="../api/org/aspectj/lang/NoAspectBoundException.html">
  2179. <literal>org.aspectj.lang.NoAspectBoundException</literal></ulink>.
  2180. </para>
  2181. </sect3>
  2182. </sect2>
  2183. <sect2>
  2184. <title>Aspect privilege</title>
  2185. <itemizedlist>
  2186. <listitem><literal>privileged aspect <replaceable>Id</replaceable> { ... }</literal></listitem>
  2187. </itemizedlist>
  2188. <para>
  2189. Code written in aspects is subject to the same access control rules as
  2190. Java code when referring to members of classes or aspects. So, for
  2191. example, code written in an aspect may not refer to members with
  2192. default (package-protected) visibility unless the aspect is defined in
  2193. the same package.
  2194. </para>
  2195. <para>
  2196. While these restrictions are suitable for many aspects, there may be
  2197. some aspects in which advice or inter-type members needs to access private
  2198. or protected resources of other types. To allow this, aspects may be
  2199. declared <literal>privileged</literal>. Code in priviliged aspects has
  2200. access to all members, even private ones.
  2201. </para>
  2202. <programlisting>
  2203. class C {
  2204. private int i = 0;
  2205. void incI(int x) { i = i+x; }
  2206. }
  2207. privileged aspect A {
  2208. static final int MAX = 1000;
  2209. before(int x, C c): call(void C.incI(int)) <![CDATA[&&]]> target(c) <![CDATA[&&]]> args(x) {
  2210. if (c.i+x &gt; MAX) throw new RuntimeException();
  2211. }
  2212. }
  2213. </programlisting>
  2214. <para>
  2215. In this case, if A had not been declared privileged, the field reference
  2216. c.i would have resulted in an error signaled by the compiler.
  2217. </para>
  2218. <para>
  2219. If a privileged aspect can access multiple versions of a particular
  2220. member, then those that it could see if it were not privileged take
  2221. precedence. For example, in the code
  2222. </para>
  2223. <programlisting>
  2224. class C {
  2225. private int i = 0;
  2226. void foo() { }
  2227. }
  2228. privileged aspect A {
  2229. private int C.i = 999;
  2230. before(C c): call(void C.foo()) target(c) {
  2231. System.out.println(c.i);
  2232. }
  2233. }
  2234. </programlisting>
  2235. <para>
  2236. A's private inter-type field C.i, initially bound to 999, will be
  2237. referenced in the body of the advice in preference to C's privately
  2238. declared field, since the A would have access to its own inter-type
  2239. fields even if it were not privileged.
  2240. </para>
  2241. <para>
  2242. Note that a privileged aspect can access private inter-type
  2243. declarations made by other aspects, since they are simply
  2244. considered private members of that other aspect.
  2245. </para>
  2246. </sect2>
  2247. </sect1>
  2248. </appendix>