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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
  3. "../../lib/docbook/docbook-dtd/docbookx.dtd">
  4. <?xml-stylesheet type="text/css"
  5. href="../../style.css"?>
  6. <!-- `copy-to-register' (C-x r s) then `insert-register' (C-x r i).
  7. <qandaentry>
  8. <question id="q:XX" xreflabel="Q:XX">
  9. <para></para>
  10. </question>
  11. <answer>
  12. <para></para>
  13. </answer>
  14. </qandaentry>
  15. -->
  16. <article class="faq">
  17. <title>Frequently Asked Questions about AspectJ</title>
  18. <para>Copyright (c) 1997-2001 Xerox Corporation,
  19. 2002 Palo Alto Research Center, Incorporated. All rights reserved.
  20. </para>
  21. <!-- todo Update me! -->
  22. <para>Last updated January 8, 2003.
  23. </para>
  24. <para>
  25. For a list of recently-updated FAQ entries, see <xref linkend="q:faqchanges"/>
  26. AspectJ 1.1 is currently in development, and
  27. some answers may change after it is released;
  28. for more information, see the README
  29. included with the AspectJ 1.1 distribution.
  30. </para>
  31. <qandaset defaultlabel="number">
  32. <qandadiv id="overview" xreflabel="Overview">
  33. <title>Overview</title>
  34. <qandaentry>
  35. <question id="q:whatisaj" xreflabel="Q:What is AspectJ?">
  36. <para>What is AspectJ?</para>
  37. </question>
  38. <answer>
  39. <para>
  40. AspectJ(tm) is a simple and practical extension to the
  41. Java(tm) programming
  42. language that adds to Java aspect-oriented programming (AOP)
  43. capabilities. AOP allows developers to reap the benefits of
  44. modularity for concerns that cut across the natural units of
  45. modularity. In object-oriented programs like Java, the natural unit
  46. of modularity is the class. In AspectJ, aspects modularize concerns that
  47. affect more than one class.
  48. </para>
  49. <para> AspectJ includes a compiler (<literal>ajc</literal>), a
  50. debugger (<literal>ajdb</literal>), a documentation generator
  51. (<literal>ajdoc</literal>), a program structure browser
  52. (<literal>ajbrowser</literal>), and integration
  53. with Eclipse, Sun-ONE/Netbeans, GNU Emacs/XEmacs, JBuilder, and Ant.
  54. </para>
  55. <para>You compile your program using the AspectJ compiler (perhaps using
  56. the supported development environments) and then run it, supplying
  57. a small (&lt; 100K) runtime library.
  58. </para>
  59. </answer>
  60. </qandaentry>
  61. <qandaentry>
  62. <question id="q:benefits"
  63. xreflabel="Q:What are the benefits of using AspectJ?">
  64. <para>What are the benefits of using AspectJ?</para>
  65. </question>
  66. <answer>
  67. <para>AspectJ can be used to improve the modularity of software
  68. systems.
  69. </para>
  70. <para> Using ordinary Java, it can be difficult to modularize design
  71. concerns such as
  72. </para>
  73. <itemizedlist>
  74. <listitem><para>system-wide error-handling</para></listitem>
  75. <listitem><para>contract enforcement</para></listitem>
  76. <listitem><para>distribution concerns</para></listitem>
  77. <listitem><para>feature variations</para></listitem>
  78. <listitem><para>context-sensitive behavior</para></listitem>
  79. <listitem><para>persistence</para></listitem>
  80. <listitem><para>testing</para></listitem>
  81. </itemizedlist>
  82. <para>The code for these concerns tends to be spread out across the
  83. system. Because these concerns won't stay inside of any one module
  84. boundary, we say that they <emphasis>crosscut</emphasis> the
  85. system's modularity.
  86. </para>
  87. <para>AspectJ adds constructs to Java that enable the modular
  88. implementation of crosscutting concerns. This ability is
  89. particularly valuable because crosscutting concerns tend to be both
  90. complex and poorly localized, making them hard to deal with.
  91. </para>
  92. <!--
  93. <para>Initial studies have shown code size reductions of up to 40%
  94. and programmer productivity gains of 20%-40%. These studies were in
  95. an earlier version of the language and only for small sample sizes.
  96. So while the results are encouraging, they aren't conclusive. We
  97. intend to run a new set of studies once the current phase of
  98. language development stabilizes.</para>
  99. -->
  100. </answer>
  101. </qandaentry>
  102. <qandaentry>
  103. <question id="q:compability"
  104. xreflabel="Q:Can AspectJ work with any Java program?">
  105. <para>Can AspectJ work with any Java program?</para>
  106. </question>
  107. <answer>
  108. <para>AspectJ has been designed as a <emphasis>compatible</emphasis>
  109. extension to Java. By compatible, we mean
  110. </para>
  111. <informaltable frame="none">
  112. <tgroup cols="2">
  113. <tbody>
  114. <row>
  115. <entry align="right">
  116. <emphasis>upward compatible</emphasis>
  117. </entry>
  118. <entry>All legal Java programs are legal AspectJ
  119. programs.
  120. </entry>
  121. </row>
  122. <row>
  123. <entry align="right">
  124. <emphasis>platform
  125. compatible
  126. </emphasis>
  127. </entry>
  128. <entry>All legal AspectJ programs run on standard Java
  129. virtual machines.
  130. </entry>
  131. </row>
  132. <row>
  133. <entry align="right">
  134. <emphasis>tool
  135. compatible
  136. </emphasis>
  137. </entry>
  138. <entry>Existing tools can be extended to work with
  139. AspectJ.
  140. </entry>
  141. </row>
  142. <row>
  143. <entry align="right">
  144. <emphasis>programmer compatible</emphasis>
  145. </entry>
  146. <entry>Programming in AspectJ feels natural to Java
  147. programmers.
  148. </entry>
  149. </row>
  150. </tbody>
  151. </tgroup>
  152. </informaltable>
  153. <para>The AspectJ tools run on any Java 2 Platform compatible
  154. platform. The AspectJ compiler produces classes that run
  155. on any Java 1.1 (or later) compatible platform.
  156. </para>
  157. </answer>
  158. </qandaentry>
  159. <qandaentry>
  160. <question id="q:license" xreflabel="Q:How is AspectJ licensed?">
  161. <para>How is AspectJ licensed?</para>
  162. </question>
  163. <answer>
  164. <para>AspectJ 1.1 source code and documentation is available under the
  165. <ulink url="http://eclipse.org/legal/cpl-v10.html">Common Public License 1.0</ulink>.
  166. </para>
  167. <para>The AspectJ 1.0 tools are open-source software available under the
  168. <ulink url="http://www.opensource.org/licenses/mozilla1.1">Mozilla Public License 1.1</ulink>.
  169. That documentation is available under a separate license
  170. that precludes for-profit or commercial
  171. redistribution.
  172. </para>
  173. <para>Most users only want to use AspectJ to build programs they distribute.
  174. There are no restrictions here. When you distribute your program, be sure to
  175. include all the runtime classes from the aspectjrt.jar for that version of AspectJ.
  176. When distributing only the runtime classes, you need not provide any notice that
  177. the program was compiled with AspectJ or includes binaries from the AspectJ project,
  178. except as necessary to preserve the warranty disclaimers in our license.
  179. </para>
  180. <para>
  181. </para>
  182. </answer>
  183. </qandaentry>
  184. <qandaentry>
  185. <question id="q:project" xreflabel="Q:What is the AspectJ Project?">
  186. <para>What is the AspectJ Project?</para>
  187. </question>
  188. <answer>
  189. <para>AspectJ is based on over ten years of research at
  190. <ulink url="http://www.parc.xerox.com">
  191. Xerox Palo Alto Research Center
  192. </ulink>
  193. as funded by Xerox, a U.S. Government grant (NISTATP), and a
  194. DARPA contract.
  195. </para>
  196. <para>It has evolved through open-source releases
  197. to a strong user community and now operates as an
  198. open source project at
  199. <ulink url="http://eclipse.org/aspectj">
  200. http://eclipse.org/aspectj</ulink>
  201. The AspectJ team works closely with the community
  202. to ensure AspectJ continues to evolve as an effective
  203. aspect-oriented programming language and tool set.
  204. </para>
  205. <para>
  206. The latest release is 1.0.6 <!-- XXX todo Update me! -->
  207. which can be downloaded from the 1.0 AspectJ
  208. <ulink url="http://aspectj.org/dl.html">download</ulink> page.
  209. The current release train is 1.1, <!-- XXX todo Update me! -->
  210. which can be downloaded from the
  211. <ulink url="http://eclipse.org/aspectj">AspectJ home page</ulink>.
  212. This development is focused on supporting applications,
  213. improving performance of the 1.1 compiler,
  214. enhancing integration with IDE's,
  215. and building the next generations of the language.
  216. </para>
  217. </answer>
  218. </qandaentry>
  219. </qandadiv>
  220. <qandadiv id="quickstart" xreflabel="Quick Start">
  221. <title>Quick Start</title>
  222. <qandaentry>
  223. <question id="q:requirements"
  224. xreflabel="Q:What Java versions does AspectJ require and support?">
  225. <para>
  226. What Java versions does AspectJ require and support?
  227. </para>
  228. </question>
  229. <answer>
  230. <para>
  231. The AspectJ compiler produces programs for any released version of the
  232. Java platform (jdk1.1 and later). When running, your program classes must
  233. be able to reach classes in the
  234. small (&lt; 100K) runtime library (aspectjrt.jar) from the distribution.
  235. The tools themselves require Java 2 (jdk 1.2) or later to run,
  236. but the compiler can be set up to target any 1.1-compliant
  237. version of the Java platform.
  238. </para>
  239. </answer>
  240. </qandaentry>
  241. <qandaentry>
  242. <question id="q:install"
  243. xreflabel="Q:How do I download and install AspectJ?">
  244. <para>How do I download and install AspectJ?</para>
  245. </question>
  246. <answer>
  247. <para>From AspectJ's
  248. <ulink url="http://elipse.org/aspectj">web page
  249. </ulink>, download the AspectJ distribution.
  250. The <literal>jar</literal> file is installed by executing
  251. </para>
  252. <programlisting>
  253. java -jar <emphasis>jar file name</emphasis>
  254. </programlisting>
  255. <para>Do <emphasis role="bold">not</emphasis> try to extract the
  256. <literal>jar</literal> file contents and then attempt to execute
  257. <literal>java org.aspectj.tools.Main</literal>. (A
  258. <classname>NoClassDefFoundError</classname> exception will be
  259. thrown.) The AspectJ distribution is not designed to be installed
  260. this way. Use the <literal>java -jar</literal> form shown above.
  261. </para>
  262. <para>To uninstall, remove the files the installer wrote in your
  263. file system. In most cases, you can delete the top-level install
  264. directory (and all contained files), after you remove any
  265. new or updated files you want to keep. On Windows, no
  266. registry settings were added or changed, so nothing needs to be
  267. undone. Do not install over prior versions, which might have
  268. different files. Delete the prior version first.
  269. </para>
  270. </answer>
  271. </qandaentry>
  272. <qandaentry>
  273. <question id="q:startUsingAJ"
  274. xreflabel="Q: How should I start using AspectJ?">
  275. <para>How should I start using AspectJ?</para>
  276. </question>
  277. <answer>
  278. <para>Many users adopt AspectJ incrementally, first using it
  279. to understand and validate their systems (relying on it only in
  280. development) and then using it to implement crosscutting concerns
  281. in production systems. AspectJ has been designed to make each
  282. step discrete and beneficial.
  283. </para>
  284. <para>
  285. In order of increasing reliance, you may use AspectJ:
  286. </para>
  287. <itemizedlist>
  288. <listitem>
  289. <para>
  290. <emphasis role="bold"> In the development
  291. process
  292. </emphasis> Use AspectJ to trace or log
  293. interesting information. You can do this by adding
  294. simple AspectJ code that performs logging or tracing.
  295. This kind of addition may be removed ("unplugged") for
  296. the final build since it does not implement a design
  297. requirement; the functionality of the system is unaffected by
  298. the aspect.
  299. </para>
  300. </listitem>
  301. <listitem>
  302. <para>
  303. <emphasis role="bold">As an ancillary part of your
  304. system
  305. </emphasis> Use AspectJ to more completely and
  306. accurately test the system.
  307. Add sophisticated code that can check contracts,
  308. provide debugging support, or implement test strategies.
  309. Like pure development aspects, this code may also be
  310. unplugged from production builds. However, the same code
  311. can often be helpful in diagnosing failures in deployed
  312. production systems, so you may design the functionality
  313. to be deployed but disabled, and enable it when debugging.
  314. </para>
  315. </listitem>
  316. <listitem>
  317. <para>
  318. <emphasis role="bold">As an essential part of your
  319. system
  320. </emphasis> Use AspectJ to modularize
  321. crosscutting concerns in your system by design.
  322. This uses AspectJ to implement logic integral to a system
  323. and is delivered in production builds.
  324. </para>
  325. </listitem>
  326. </itemizedlist>
  327. <para>This adoption sequence works well in practice and has been
  328. followed by many projects.
  329. </para>
  330. </answer>
  331. </qandaentry>
  332. <qandaentry>
  333. <question id="q:integrateWithDevTools"
  334. xreflabel="Q: How well does AspectJ integrate with existing Java development tools?">
  335. <para>How does AspectJ integrate with existing Java development
  336. tools?
  337. </para>
  338. </question>
  339. <answer>
  340. <para>AspectJ products are designed to make it easy to integrate
  341. AspectJ into an existing development process.
  342. Each release includes
  343. Ant tasks for building programs,
  344. the AspectJ Development Environment (AJDE) for writing
  345. aspects inside popular IDE's, and
  346. command-line tools for compiling and documenting Java and AspectJ code.
  347. </para>
  348. <!-- ok to order for style, not priority? -->
  349. <para>AspectJ provides replacements for standard Java tools:
  350. <itemizedlist>
  351. <listitem>
  352. <para><literal>ajc</literal>, the AspectJ compiler,
  353. runs on any Java 2 compatible platform, and produces classes
  354. that run on any Java 1.1 (or later) compatible platform.
  355. </para>
  356. </listitem>
  357. <listitem>
  358. <para><literal>ajdoc</literal> produces API documentation like
  359. javadoc, with additional crosscutting links. For example,
  360. it shows advice affecting
  361. a particular method or all code affected by a given aspect.
  362. At present, <literal>ajdoc</literal> is only supported in AspectJ 1.0.
  363. </para>
  364. </listitem>
  365. <!-- restore ajdb, ajdoc -->
  366. </itemizedlist>
  367. </para>
  368. <para>For debugging, AspectJ supports JSR-45, which provides a mechanism for
  369. debugging .class files that have multiple source files.
  370. Debugger clients and VM's are beginning to support this;
  371. see Sun's J2SE 1.4.1 VM and jdb debugger
  372. and recent versions of JBuilder.
  373. </para>
  374. <para>The AspectJ Development Environment (AJDE)
  375. enables programmers to view and navigate the crosscutting structures
  376. in their programs, integrated with existing support in
  377. popular Java IDE's for viewing and navigating object-oriented
  378. structures. For many programmers this provides a deeper understanding
  379. of how aspects work to modularize their concerns and permits them
  380. to incrementally extend their development practices without
  381. having to abandon their existing tools.
  382. </para>
  383. <para>
  384. AJDE is a set of API's providing the basis for the following
  385. development tool integrations:
  386. </para>
  387. <itemizedlist>
  388. <listitem>
  389. <para>Eclipse (version 2.0)
  390. in the Eclipse AspectJ Development Tools project
  391. <ulink url="http://eclipse.org/ajdt">
  392. http://eclipse.org/ajdt
  393. </ulink>
  394. </para>
  395. </listitem>
  396. <listitem>
  397. <para>Emacs (GNU version 20.3)
  398. and XEmacs (version 21.1 on Unix and 21.4 on Windows),
  399. in the SourceForge AspectJ for Emacs project
  400. <ulink url="http://aspectj4emacs.sourceforge.net">
  401. http://aspectj4emacs.sourceforge.net
  402. </ulink>
  403. </para>
  404. </listitem>
  405. <listitem>
  406. <para>JBuilder (versions 4 through 7) from Borland
  407. in the SourceForge AspectJ for JBuilder project
  408. <ulink url="http://aspectj4jbuildr.sourceforge.net">
  409. http://aspectj4jbuildr.sourceforge.net
  410. </ulink>
  411. </para>
  412. </listitem>
  413. <listitem>
  414. <para>Netbeans up to 3.4
  415. (and Sun Microsystems' Forte for Java (versions 2 and 3), Sun/One)
  416. in the SourceForge AspectJ for NetBeans project
  417. <ulink url="http://aspectj4netbean.sourceforge.net">
  418. http://aspectj4netbean.sourceforge.net
  419. </ulink>
  420. </para>
  421. </listitem>
  422. </itemizedlist>
  423. <para>
  424. The common functionality of AJDE is also available in
  425. the stand-alone source code browser <literal>ajbrowser</literal>,
  426. included in the tools distribution.
  427. </para>
  428. <para>Finally, as mentioned above,
  429. AspectJ also supports building with Ant by providing
  430. task interfaces to the ajc and ajdoc tools.
  431. </para>
  432. </answer>
  433. </qandaentry>
  434. </qandadiv>
  435. <qandadiv id="typicalprograms" xreflabel="Typical AspectJ programs">
  436. <title>Typical AspectJ programs</title>
  437. <qandaentry>
  438. <question id="q:aspectsoptional"
  439. xreflabel="Q:Are aspects always optional or non-functional parts of a program?">
  440. <para>Are aspects always optional or non-functional parts of
  441. a program?
  442. </para>
  443. </question>
  444. <answer>
  445. <para>No. Although AspectJ can be used in a way that allows AspectJ
  446. code to be removed for the final build, aspect-oriented code is not
  447. <emphasis>always</emphasis> optional or non-functional. Consider
  448. what AOP really does: it makes the modules in a program correspond
  449. to modules in the design. In any given design, some modules are
  450. optional, and some are not.
  451. </para>
  452. <para>The examples directory included in the AspectJ distribution
  453. contains some examples of the use aspects that are not optional.
  454. Without aspects,
  455. </para>
  456. <informaltable frame="none">
  457. <tgroup cols="2">
  458. <tbody>
  459. <row>
  460. <entry align="right">
  461. <emphasis role="strong">bean</emphasis>
  462. </entry>
  463. <entry>Point objects would not be JavaBeans.</entry>
  464. </row>
  465. <row>
  466. <entry align="right">
  467. <emphasis role="strong">introduction</emphasis>
  468. </entry>
  469. <entry>Point objects would not be cloneable, comparable or
  470. serializable.
  471. </entry>
  472. </row>
  473. <row>
  474. <entry align="right">
  475. <emphasis role="strong">spacewar</emphasis>
  476. </entry>
  477. <entry>Nothing would be displayed.</entry>
  478. </row>
  479. <row>
  480. <entry align="right">
  481. <emphasis role="strong">telecom</emphasis>
  482. </entry>
  483. <entry>No calls would be billed.</entry>
  484. </row>
  485. </tbody>
  486. </tgroup>
  487. </informaltable>
  488. </answer>
  489. </qandaentry>
  490. <qandaentry>
  491. <question id="q:developmentAndProductionAspects"
  492. xreflabel="Q:What is the difference between development and production aspects?">
  493. <para>
  494. What is the difference between development and production aspects?
  495. </para>
  496. </question>
  497. <answer>
  498. <para>
  499. Production aspects are delivered with the finished product,
  500. while development aspects are used during the development process.
  501. Often production aspects are also used during development.
  502. </para>
  503. </answer>
  504. </qandaentry>
  505. <qandaentry>
  506. <question id="q:devAspects"
  507. xreflabel="Q:What are some common development aspects?">
  508. <para>
  509. What are some common development aspects?
  510. </para>
  511. </question>
  512. <answer>
  513. <para>Aspects for logging, tracing, debugging, profiling
  514. or performance monitoring, or testing.
  515. </para>
  516. </answer>
  517. </qandaentry>
  518. <qandaentry>
  519. <question id="q:prodAspects"
  520. xreflabel="Q:What are some common production aspects?">
  521. <para>
  522. What are some common production aspects?
  523. </para>
  524. </question>
  525. <answer>
  526. <para>
  527. Aspects for performance monitoring and diagnostic systems,
  528. display updating or notifications generally, security,
  529. context passing, and error handling.
  530. </para>
  531. </answer>
  532. </qandaentry>
  533. </qandadiv>
  534. <qandadiv id="concepts" xreflabel="Basic AOP and AspectJ Concepts">
  535. <title>Basic AOP and AspectJ Concepts</title>
  536. <qandaentry>
  537. <question id="q:crosscutting"
  538. xreflabel="Q:What are scattering, tangling, and crosscutting?">
  539. <para>What are scattering, tangling, and crosscutting?</para>
  540. </question>
  541. <answer>
  542. <para>
  543. "Scattering" is when similar code is distributed throughout many
  544. program modules. This differs from a component being used by
  545. many other components since
  546. it involves the risk of misuse at each point and of inconsistencies
  547. across all points. Changes to the implementation may require
  548. finding and editing all affected code.
  549. </para>
  550. <para>"Tangling" is when two or more concerns are implemented in
  551. the same body of code or component, making it more difficult to understand.
  552. Changes to one implementation may cause unintended changes
  553. to other tangled concerns.
  554. </para>
  555. <para>"Crosscutting" is how to characterize a concern than spans
  556. multiple units of OO modularity - classes and objects. Crosscutting
  557. concerns resist modularization using normal OO constructs, but
  558. aspect-oriented programs can modularize crosscutting concerns.
  559. </para>
  560. </answer>
  561. </qandaentry>
  562. <qandaentry>
  563. <question id="q:joinpoints"
  564. xreflabel="Q: What are join points?">
  565. <para>What are join points?</para>
  566. </question>
  567. <answer>
  568. <para>Join points are well-defined points in the execution of a
  569. program. Not every execution point is a join point: only those
  570. points that can be used in a disciplined and principled manner are.
  571. So, in AspectJ, the execution of a method call is a join point, but
  572. "the execution of the expression at line 37 in file Foo.java" is
  573. not.
  574. </para>
  575. <para>The rationale for restricting join points is similar to the
  576. rationale for restricting access to memory (pointers) or
  577. restricting control flow expressions (<literal>goto</literal>) in
  578. Java: programs are easier to understand, maintain and extend
  579. without the full power of the feature.
  580. </para>
  581. <para>AspectJ join points include reading or writing a field; calling
  582. or executing an exception handler, method or constructor.
  583. </para>
  584. </answer>
  585. </qandaentry>
  586. <qandaentry>
  587. <question id="q:pointcut"
  588. xreflabel="Q; What is a pointcut?">
  589. <para>
  590. What is a pointcut?
  591. </para>
  592. </question>
  593. <answer>
  594. <para>A pointcut picks out
  595. <link linkend="q:joinpoints">
  596. join points
  597. </link>. These join points are described by the pointcut
  598. declaration. Pointcuts can be defined in classes or in aspects,
  599. and can be named or be anonymous.
  600. </para>
  601. </answer>
  602. </qandaentry>
  603. <qandaentry>
  604. <question id="q:advice"
  605. xreflabel="Q:What is advice?">
  606. <para>What is advice?</para>
  607. </question>
  608. <answer>
  609. <para>Advice is code that executes at each
  610. <link linkend="q:joinpoints">join point</link> picked out by a
  611. <link linkend="q:pointcut">pointcut</link>. There are three
  612. kinds of advice: before advice, around advice and after advice. As
  613. their names suggest, before advice runs before the join point
  614. executes; around advice executes before and after the join point;
  615. and after advice executes after the join point. The power of
  616. advice comes from the advice being able to access values in the
  617. execution context of a pointcut.
  618. </para>
  619. </answer>
  620. </qandaentry>
  621. <qandaentry>
  622. <question id="q:declarations"
  623. xreflabel="Q:What are inter-type declarations?">
  624. <para>What are inter-type declarations?</para>
  625. </question>
  626. <answer>
  627. <para>AspectJ enables you to declare members and supertypes of another class
  628. in an aspect, subject to Java's type-safety and access rules. These are
  629. visible to other classes only if you declare them as accessible.
  630. You can also declare compile-time errors and warnings based on pointcuts.
  631. </para>
  632. </answer>
  633. </qandaentry>
  634. <qandaentry>
  635. <question id="q:whatisanaspect"
  636. xreflabel="Q:What is an aspect?">
  637. <para>What is an aspect?</para>
  638. </question>
  639. <answer>
  640. <para>Aspects are a new class-like language element that has been
  641. added to Java by AspectJ. Aspects are how developers encapsulate
  642. concerns that cut across classes, the natural unit of modularity in
  643. Java.
  644. </para>
  645. <para>Aspects are similar to classes because...
  646. <itemizedlist>
  647. <listitem><para>aspects have type</para></listitem>
  648. <listitem>
  649. <para>
  650. aspects can extend classes and other aspects
  651. </para>
  652. </listitem>
  653. <listitem>
  654. <para>
  655. aspects can be abstract or concrete
  656. </para>
  657. </listitem>
  658. <listitem>
  659. <para>
  660. non-abstract aspects can be instantiated
  661. </para>
  662. </listitem>
  663. <listitem>
  664. <para>aspects can have static and non-static state and
  665. behavior
  666. </para>
  667. </listitem>
  668. <listitem>
  669. <para>aspects can have fields, methods, and types
  670. as members
  671. </para>
  672. </listitem>
  673. <listitem>
  674. <para>the members of non-privileged aspects follow the
  675. same accessibility rules as those of classes
  676. </para>
  677. </listitem>
  678. </itemizedlist>
  679. </para>
  680. <para>Aspects are different than classes because...
  681. <itemizedlist>
  682. <listitem>
  683. <para>aspects can additionally include as members pointcuts,
  684. advice, and inter-type declarations;
  685. </para>
  686. </listitem>
  687. <listitem>
  688. <para>aspects can be qualified by specifying the
  689. context in which the non-static state is available
  690. </para>
  691. </listitem>
  692. <listitem>
  693. <para>aspects can't be used interchangeably with
  694. classes
  695. </para>
  696. </listitem>
  697. <listitem>
  698. <para>aspects don't have constructors or finalizers,
  699. and they cannot be created with the new operator;
  700. they are automatically available as needed.
  701. </para>
  702. </listitem>
  703. <listitem>
  704. <para>privileged aspects can access private members of
  705. other types
  706. </para>
  707. </listitem>
  708. </itemizedlist>
  709. </para>
  710. </answer>
  711. </qandaentry>
  712. </qandadiv>
  713. <qandadiv id="whyaop" xreflabel="Why AOP?">
  714. <title>Why AOP?</title>
  715. <qandaentry>
  716. <question id="q:ccfromflaws"
  717. xreflabel="Q:Are crosscutting concerns induced by flaws?">
  718. <para>Are crosscutting concerns induced by flaws in parts of the
  719. system design, programming language, operating system, etc. Or is
  720. there something more fundamental going on?
  721. </para>
  722. </question>
  723. <answer>
  724. <para>AOP's fundamental assumption is that in any sufficiently
  725. complex system, there will inherently be some crosscutting
  726. concerns.
  727. </para>
  728. <para>So, while there are some cases where you could re-factor a
  729. system to make a concern no longer be crosscutting, the AOP idea
  730. is that there are many cases where that is not possible, or where
  731. doing so would damage the code in other ways.
  732. </para>
  733. </answer>
  734. </qandaentry>
  735. <qandaentry>
  736. <question id="q:definingaspectspercc"
  737. xreflabel="Q:Does it really make sense to define aspects in terms of crosscutting?">
  738. <para>Does it really make sense to define aspects in terms of
  739. crosscutting?
  740. </para>
  741. </question>
  742. <answer>
  743. <para>Yes.</para>
  744. <para>The short summary is that it is right to define AOP in terms of
  745. crosscutting, because well-written AOP programs have clear
  746. crosscutting structure. It would be a mistake to define AOP in
  747. terms of "cleaning up tangling and scattering", because that isn't
  748. particular to AOP, and past programming language innovations also
  749. do that, as will future developments.
  750. </para>
  751. <para>Slides for a long talk on this topic are at
  752. <ulink url="http://www.cs.ubc.ca/~gregor/vinst-2-17-01.zip">
  753. http://www.cs.ubc.ca/~gregor/vinst-2-17-01.zip
  754. </ulink>.
  755. </para>
  756. </answer>
  757. </qandaentry>
  758. <qandaentry>
  759. <question id="q:domainspecific"
  760. xreflabel="Q:Is AOP restricted to domain-specific applications?">
  761. <para>Is AOP restricted to domain-specific
  762. applications?
  763. </para>
  764. </question>
  765. <answer>
  766. <para>No. Some implementations of AOP are domain-specific, but
  767. AspectJ was specifically designed to be general-purpose.
  768. </para>
  769. </answer>
  770. </qandaentry>
  771. <qandaentry>
  772. <question id="q:whyaopifinterceptors"
  773. xreflabel="Q:Why do I need AOP if I can use interceptors?">
  774. <para>Why do I need AOP if I can use interceptors
  775. (or JVMPI or ref
  776. lection)?
  777. </para>
  778. </question>
  779. <answer>
  780. <para>There are many mechanisms people use now to implement
  781. some crosscutting concerns. But they don't have a way to express
  782. the actual structure of the program so you (and your tools)
  783. can reason about it. Using a language enables you to express the
  784. crosscutting in first-class constructs. You can not only avoid the
  785. maintenance problems and structural requirements of some other
  786. mechanisms, but also combine forms of crosscutting so that all
  787. the mechanisms for a particular concern are one piece of code.
  788. </para>
  789. </answer>
  790. </qandaentry>
  791. </qandadiv>
  792. <qandadiv id="related" xreflabel="Related Technology">
  793. <title>Related Technology</title>
  794. <qandaentry>
  795. <question id="q:comparetonewforms"
  796. xreflabel="Q:How does AspectJ compare to other new forms of programming?">
  797. <para>
  798. How does AspectJ compare to other new forms of programming?
  799. </para>
  800. </question>
  801. <answer>
  802. <para>There are many recent proposals for programming languages that
  803. provide control over crosscutting concerns. Aspect-oriented
  804. programming is an overall framework into which many of these
  805. approaches fit. AspectJ is one particular instance of AOP,
  806. distinguished by the fact that it was designed from the ground up
  807. to be compatible with Java.
  808. </para>
  809. <para>For more alternatives for aspect-oriented programming, see
  810. <ulink url="http://aosd.net">http://aosd.net</ulink>.
  811. </para>
  812. </answer>
  813. </qandaentry>
  814. <qandaentry>
  815. <question id="q:compartoreflection"
  816. xreflabel="Q:How do you compare the features of AspectJ with reflective systems?">
  817. <para>How do you compare the features of AspectJ with
  818. reflective systems?
  819. </para>
  820. </question>
  821. <answer>
  822. <para>Reflective and aspect-oriented languages have an important
  823. similarity: both provide programming support for dealing with
  824. crosscutting concerns. In this sense reflective systems proved
  825. that independent programming of crosscutting concerns is
  826. possible.
  827. </para>
  828. <para>But the control that reflection provides tends to be low-level
  829. and extremely powerful. In contrast, AspectJ provides more
  830. carefully controlled power, drawing on the rules learned from
  831. object-oriented development to encourage a clean and understandable
  832. program structure.
  833. </para>
  834. </answer>
  835. </qandaentry>
  836. <qandaentry>
  837. <question id="q:comparetomixin"
  838. xreflabel="Q:How do AspectJ features compare with those of mixin-based inheritance?">
  839. <para>How do AspectJ features compare with those of mixin-based
  840. inheritance?
  841. </para>
  842. </question>
  843. <answer>
  844. <para>Some features of AspectJ, such as introduction, are related to
  845. <emphasis>mixin-based inheritance</emphasis>. But, in order to
  846. support crosscutting, a core goal for AspectJ, AspectJ goes beyond
  847. mixin-based inheritance.
  848. </para>
  849. <para>Firstly, an aspect imposes behavior on a class, rather than a
  850. class requesting behavior from an aspect. An aspect can modify a
  851. class without needing to edit that class. This property is
  852. sometimes called <emphasis>reverse inheritance</emphasis>.
  853. </para>
  854. <para>Secondly, a single aspect can affect multiple classes in
  855. different ways. A single paint aspect can add different paint
  856. methods to all the classes that know how to paint, unlike mixin
  857. classes.
  858. </para>
  859. <para>
  860. So mixin-based inheritance doesn't have the reverse inheritance
  861. property, and mixins affect every class that mixes them in the same.
  862. If I want to do something like SubjectObserverProtocol, I need two
  863. mixins, SubjectPartofSubjectObserverProtocol and ObserverPartof...
  864. In AspectJ, both halves of the protocol can be captured in a single
  865. aspect.
  866. </para>
  867. </answer>
  868. </qandaentry>
  869. <qandaentry>
  870. <question id="q:aopandxp"
  871. xreflabel="Q:What is the relationship between AOP and
  872. XP (extreme programming AKA agile methods)?">
  873. <para>What is the relationship between AOP and
  874. XP (extreme programming AKA agile methods)?
  875. </para>
  876. </question>
  877. <answer>
  878. <para>From a question on the user list:
  879. <programlisting>
  880. > Anyone know the connections between AOP and Extreme Programming?
  881. > I am really confused. It seems AOP is a programming paradigm, which
  882. > is the next level of abstraction of OOP. Extreme Programming, however,
  883. > this is a lightweight software development process. One of the common
  884. > motivations of AOP and XP is designed to adopt to the requirement
  885. > changes, so that it can save the cost of software development.
  886. </programlisting>
  887. </para>
  888. <para>
  889. This is Raymond Lee's answer:
  890. </para>
  891. <para>
  892. You're not really that confused. AOP and XP are orthogonal concepts,
  893. although AOP can be used to help accomplish XP goals.
  894. One of the goals of XP is to respond to changing requirements.
  895. Another is to reduce the overall cost of development. These are
  896. not necessarily the same thing.
  897. </para>
  898. <para>
  899. One of the principles of XP that contribute to meeting those goals
  900. is to maintain clean, simple designs. One of the criteria for clean,
  901. simple designs is to factor out duplication from the code. Benefits
  902. of removing duplication include the code being easier to understand,
  903. better modularity of the design, lower costs of code changes, less
  904. chance of conflicting changes when practicing collective code
  905. ownership, etc.
  906. </para>
  907. <para>
  908. Different types of duplication lend themselves to being addressed by
  909. different design paradigms and language features. Duplicate snippets
  910. of code can be factored out into methods. Duplicate methods can be
  911. factored out to common classes, or pushed up to base classes.
  912. Duplicate patterns of methods and their use can be factored out to
  913. mechanisms of classes and methods (i.e. instantiations of design
  914. patterns).
  915. </para>
  916. <para>
  917. AOP addresses a type of duplication that is very difficult to handle
  918. in the other common paradigms, namely cross-cutting concerns. By
  919. factoring out duplicate cross-cutting code into aspects, the target
  920. code becomes simpler and cleaner, and the cross-cutting code becomes
  921. more centralized and modular.
  922. </para>
  923. <para>
  924. So, AOP as a paradigm, and the associated tools, gives an XPer, or
  925. anyone wanting to remove duplication from the code base, a powerful
  926. way to remove a form of duplication not easily addressed until now.
  927. </para>
  928. </answer>
  929. </qandaentry>
  930. <qandaentry>
  931. <question id="q:aspectjandcsharp"
  932. xreflabel="Q:Will you support C#?">
  933. <para>Will you support C#?</para>
  934. </question>
  935. <answer>
  936. <para>Not at this time. Although the resemblances between C# and Java
  937. means it would probably be a fairly straightforward matter to take
  938. the AspectJ language design and produce AspectC#, our current focus
  939. is only on supporting effective uses of AspectJ.
  940. </para>
  941. </answer>
  942. </qandaentry>
  943. </qandadiv>
  944. <qandadiv id="adoption" xreflabel="Deciding to adopt AspectJ">
  945. <title>Deciding to adopt AspectJ</title>
  946. <qandaentry>
  947. <question id="q:productplans"
  948. xreflabel="Q:Is it safe to use AspectJ in my product plans??">
  949. <para>
  950. Is it safe to use AspectJ in my product plans?
  951. </para>
  952. </question>
  953. <answer>
  954. <para>You may use AspectJ in your product or project with little
  955. risk. Several factors play a role in reducing the risk of adopting
  956. this new technology:
  957. <itemizedlist>
  958. <listitem>
  959. <para>AspectJ is an <emphasis>addition</emphasis> to
  960. Java, and can be incrementally introduced into a project
  961. in a way that limits risk.
  962. See <xref linkend="q:startUsingAJ"/> for
  963. some suggestions on how to do this.
  964. </para>
  965. </listitem>
  966. <listitem>
  967. <para>The AspectJ compiler accepts standard Java as
  968. input and produces standard Java bytecode as output.
  969. In 1.0, an optional mode produces standard Java source code
  970. which may then be compiled with any compliant Java compiler
  971. (e.g. Sun's <literal>javac</literal> compiler
  972. or IBM's <literal>jikes</literal> compiler).
  973. In 1.1, an optional mode accepts standard Java bytecode
  974. from any compliant Java compiler
  975. and weaves in the aspects to produce new bytecode.
  976. </para>
  977. </listitem>
  978. <listitem>
  979. <para>AspectJ is available under a non-proprietary, open source license,
  980. either the
  981. <ulink url="http://www.opensource.org/licenses/mozilla1.1">
  982. Mozilla Public License 1.1</ulink>
  983. for 1.0 or the
  984. <ulink url="http://eclipse.org/legal/cpl-v10.html">
  985. Common Public License 1.0</ulink> for 1.1.
  986. AspectJ will continue to evolve and be available, regardless
  987. of the fate of any particular organization involved with
  988. AspectJ.
  989. </para>
  990. </listitem>
  991. <listitem>
  992. <para>Removing AspectJ from your program is not
  993. difficult, although you will lose the flexibility and
  994. economy that AspectJ provided.
  995. </para>
  996. </listitem>
  997. </itemizedlist>
  998. </para>
  999. </answer>
  1000. </qandaentry>
  1001. <qandaentry>
  1002. <question id="q:effectonsize"
  1003. xreflabel="Q:What is the effect of using AspectJ on the source code size of programs?">
  1004. <para>What is the effect of using AspectJ on the source code
  1005. size of programs?
  1006. </para>
  1007. </question>
  1008. <answer>
  1009. <para>Using aspects reduces, as a side effect, the number of source
  1010. lines in a program. However, the major benefit of using aspects
  1011. comes from <emphasis>improving</emphasis> the modularity of a
  1012. program, not because the program is smaller. Aspects gather into a
  1013. module concerns that would otherwise be scattered across or
  1014. duplicated in multiple classes.
  1015. </para>
  1016. </answer>
  1017. </qandaentry>
  1018. <qandaentry>
  1019. <question id="q:effectonperformance"
  1020. xreflabel="Q:Does AspectJ add any performance overhead?">
  1021. <para>
  1022. Does AspectJ add any performance overhead?
  1023. </para>
  1024. </question>
  1025. <answer>
  1026. <para>The issue of performance overhead is an important one. It is
  1027. also quite subtle, since knowing what to measure is at least as
  1028. important as knowing how to measure it, and neither is always
  1029. apparent.
  1030. </para>
  1031. <para>There is currently no benchmark suite for AOP languages in
  1032. general nor for AspectJ in particular. It is probably too early to
  1033. develop such a suite because AspectJ needs more maturation of the
  1034. language and the coding styles first. Coding styles really drive
  1035. the development of the benchmark suites since they suggest what is
  1036. important to measure.
  1037. </para>
  1038. <para>In the absence of a benchmark suite, AspectJ probably has an
  1039. acceptable performance for everything except non-static advice.
  1040. Introductions and static advice should have extremely small
  1041. performance overheads compared to the same functionality
  1042. implemented by hand.
  1043. </para>
  1044. <para>The <literal>ajc</literal> compiler will use static typing information
  1045. to only insert those checks that are absolutely necessary. Unless you use
  1046. 'thisJoinPoint' or 'if', then the only dynamic checks that will be
  1047. inserted by ajc will be 'instanceof' checks which are generally quite fast.
  1048. These checks will only be inserted when they can not be inferred from
  1049. the static type information.
  1050. </para>
  1051. <para>If you'd like to measure the performance be sure to write code
  1052. fragments in AspectJ and compare them to the performance of the
  1053. corresponding code written without AspectJ. For example, don't
  1054. compare a method with before/after advice that grabs a lock to just
  1055. the method. That would be comparing apples and oranges. Also be
  1056. sure to watch out for JIT effects that come from empty method
  1057. bodies and the like. Our experience is that they can be quite
  1058. misleading in understanding what you've measured.
  1059. </para>
  1060. </answer>
  1061. </qandaentry>
  1062. <qandaentry>
  1063. <question id="q:modularityviolations"
  1064. xreflabel="Q:I've heard that AspectJ leads to modularity violations. Does it?">
  1065. <para>
  1066. I've heard that AspectJ leads to modularity violations. Does it?
  1067. </para>
  1068. </question>
  1069. <answer>
  1070. <para>
  1071. Well I haven't yet seen a language in which you can't write bad code!
  1072. </para>
  1073. <para>
  1074. But seriously, most AspectJ users find that just like when they learned
  1075. OO, it takes a while to really get the hang of it. They tend to start
  1076. in the usual way, by copying canonical examples and experimenting with
  1077. variations on them.
  1078. </para>
  1079. <para>
  1080. But users also find that rather than being dangerous, AspectJ helps them
  1081. write code that is more clear and has better encapsulation -- once they
  1082. understand the kind of modularity AspectJ supports. There are several
  1083. good papers that talk about this (see below), but here's a basic point
  1084. to keep in mind: when properly used, AspectJ makes it possible program
  1085. in a modular way, something that would otherwise be spread throughout
  1086. the code. Consider the following code, adapted from the AspectJ tutorial:
  1087. </para>
  1088. <programlisting>
  1089. aspect PublicErrorLogging {
  1090. Log log = new Log();
  1091. pointcut publicInterface(Object o):
  1092. call(public * com.xerox.*.*(..)) &amp;&amp; target(o);
  1093. after(Object o) throwing (Error e): publicInterface(o) {
  1094. log.write(o, e);
  1095. }
  1096. }
  1097. </programlisting>
  1098. <para>
  1099. The effect of this code is to ensure that whenever any public method of
  1100. an interface or class in the <literal>com.xerox</literal> package
  1101. throws an error, that error is logged before being thrown to its caller.
  1102. </para>
  1103. <para>
  1104. Of course in the alternative implementation a large number of methods
  1105. have a try/catch around their body.
  1106. </para>
  1107. <para>
  1108. The AspectJ implementation of this crosscutting concern is clearly
  1109. modular, whereas the other implementation is not. As a result, if you
  1110. want to change it, its easier in the AspectJ implementation. For
  1111. example, if you also want to pass the name of the method, or its
  1112. arguments to <literal>log.write</literal>, you only have to edit
  1113. one place in the AspectJ code.
  1114. </para>
  1115. <para>
  1116. This is just a short example, but I hope it shows how what happens
  1117. with AOP and AspectJ is that the usual benefits of modularity are
  1118. achieved for crosscutting concerns, and that leads to better code,
  1119. not more dangerous code.
  1120. </para>
  1121. <para>
  1122. One paper someone else just reminded me of that talks some more
  1123. about this is:
  1124. <ulink url="http://www.cs.ubc.ca/~kdvolder/Workshops/OOPSLA2001/submissions/12-nordberg.pdf">
  1125. http://www.cs.ubc.ca/~kdvolder/Workshops/OOPSLA2001/submissions/12-nordberg.pdf
  1126. </ulink>
  1127. </para>
  1128. </answer>
  1129. </qandaentry>
  1130. <qandaentry>
  1131. <question id="q:encapsulation"
  1132. xreflabel="Q:Why does AspectJ permit aspects to access and add members of another type?">
  1133. <para>
  1134. Why does AspectJ permit aspects to access and add members of another type?
  1135. Isn't that violating OO encapsulation?
  1136. </para>
  1137. </question>
  1138. <answer>
  1139. <para>In the spirit of Smalltalk, we have decided to give more power
  1140. to the language in order to let the user community experiment and
  1141. discover what is right. To date this has proven to be a successful
  1142. strategy because it has permitted the construction of many useful
  1143. aspects that crosscut the internal state of an object, and as such
  1144. need access the its private members. However, we are not
  1145. discounting that some sort of restrictions are useful, rather, we
  1146. are seeking input from the community in order to decide on what
  1147. these restrictions should be.
  1148. </para>
  1149. <para>
  1150. In that light, our position on encapsulation is :
  1151. </para>
  1152. <itemizedlist>
  1153. <listitem><para>we respect Java's visibility rules</para></listitem>
  1154. <listitem><para>we also provide open-classes, a mature OO technology</para></listitem>
  1155. <listitem><para>we provide "privileged" access if you really need it.</para></listitem>
  1156. </itemizedlist>
  1157. <para>
  1158. Introducing parents or members to classes is a well-studied OO technique
  1159. known as open classes.
  1160. </para>
  1161. <para>
  1162. Open classes have been used in many languages prior to AspectJ,
  1163. including CLOS, Python, Smalltalk, Objective-C, and others.
  1164. Building from Java, introduction in AspectJ provides better
  1165. name hygiene and access control than prior languages.
  1166. Introduced code obeys all of Java's normal accessibility rules
  1167. for its lexical location in the aspect that it is introduced from.
  1168. Such code can not even see, much less access, private members of
  1169. the class it is introduced into. Further, introductions can be
  1170. declared private to the aspect, so they are not visible to
  1171. other clients of the class.
  1172. </para>
  1173. <para>
  1174. Privileged aspects do permit access to private members of another
  1175. class. They are a response to the very few cases where developers
  1176. genuinely need such access (typically for testing purposes where it
  1177. access is necessary), but it would be more risky to open access by
  1178. putting the aspect in the same package, adding test code, or changing
  1179. access in the target class. We recommend using privileged aspects
  1180. only as necessary, and believe that marking them "privileged" makes
  1181. any potential misuse apparent.
  1182. </para>
  1183. </answer>
  1184. </qandaentry>
  1185. <qandaentry>
  1186. <question id="q:aspectjandj2ee"
  1187. xreflabel="Q:Can I use AspectJ with J2EE?">
  1188. <para>Can I use AspectJ with J2EE?</para>
  1189. </question>
  1190. <answer>
  1191. <para>
  1192. Consider the component types in J2EE:
  1193. </para>
  1194. <itemizedlist>
  1195. <listitem>
  1196. <para>
  1197. Servlet: AspectJ works well within servlets
  1198. </para>
  1199. </listitem>
  1200. <listitem>
  1201. <para>
  1202. JSP: It is possible to use AspectJ to affect code in JSPs by precompiling
  1203. them into Java sources and compiling these with ajc. This can be used, e.g., to
  1204. customize displays by turning on and off custom JSP taglibs. The mapping from a
  1205. given jsp source to java package and class name is not standardized, which means
  1206. doing this imposes dependencies on specific container versions.
  1207. </para>
  1208. </listitem>
  1209. <listitem>
  1210. <para>
  1211. EJB: AspectJ supports a wide variety of aspects for EJBs. It can be used for
  1212. logging, tracing, debugging, error handling by layers, correlated method-level
  1213. interception (e.g., chargebacks), metering, fine-grained transactions, etc.
  1214. Indeed, it can be used to enforce adherence to coding restrictions within an
  1215. EJB (e.g., not using java.io, creating a class loader, or listening on
  1216. sockets) using <literal>declare error</literal>.
  1217. </para>
  1218. </listitem>
  1219. </itemizedlist>
  1220. <para>
  1221. The basic limitations are that there is no built-in support for writing J2EE
  1222. analogs for AspectJ extensions to Java, like distributed aspects, distributed
  1223. cflow, or managing state between invocations. These don't prevent one from using
  1224. AspectJ to do useful intra-container implementation, nor need they prevent one
  1225. from building distributed support, state management, and inter-component
  1226. implementations that leverage AspectJ. It just takes some work. In more detail:
  1227. </para>
  1228. <para>
  1229. All AspectJ implementations may define "code the implementation controls".
  1230. The AspectJ 1.0 implementation defines this as the files passed to the compiler
  1231. (AspectJ 1.1 will also support bytecode weaving).
  1232. </para>
  1233. <para>
  1234. Some advice on EJB operations will generate methods that confuse ejb compilers.
  1235. To avoid this problem, you can use the -XaddSafePrefix flag when compiling with ajc.
  1236. </para>
  1237. <para>
  1238. EJB components may be invoked remotely, and containers may passivate and
  1239. pool EJB's. Servlets have similar limitations, and in both cases the
  1240. lifespan of the defining class loader is implementation-dependent
  1241. (though it must span the operation of a particular request).
  1242. </para>
  1243. <para>
  1244. Being limited by lifecycle and namespace, the AspectJ 1.0 implementation
  1245. supports aspects that operate through non-remote invocations during the lifetime
  1246. of the namespace for a particular
  1247. deployment unit compiled in its entirety by the ajc compiler.
  1248. This means AspectJ supports common aspects only within a single local runtime
  1249. namespace (usually implemented as a class loader hierarchy).
  1250. </para>
  1251. <para>
  1252. Further, AspectJ recognizes language-level join points (object initialization,
  1253. method calls, etc.), not their EJB analogs (ejb find or create methods...).
  1254. These lead to the following consequences:
  1255. </para>
  1256. <itemizedlist>
  1257. <listitem>
  1258. <para>
  1259. Issingleton aspects (the default) are limited to the lifetime of
  1260. the defining class loader, which in some implementations may not span
  1261. multiple invocations of the same application or EJB component.
  1262. </para>
  1263. </listitem>
  1264. <listitem>
  1265. <para>
  1266. EJB lifecycles are different from object lifecycles, so perthis
  1267. and pertarget aspects will make little sense. They do not work
  1268. in the current implementation, which uses synchronized methods
  1269. to ensure a correct association in threaded environments
  1270. (EJB's may not have synchronized methods).
  1271. </para>
  1272. </listitem>
  1273. <listitem>
  1274. <para>
  1275. Percflow or percflowbelow aspects are restricted to a chain of
  1276. non-remote invocations. While EJB 2.0 permits declaring an interface
  1277. local, this information is not available to the AspectJ compiler today.
  1278. For same reasons as stated above fore perthis, these will not work even
  1279. in the EJB container.
  1280. </para>
  1281. </listitem>
  1282. <listitem>
  1283. <para>
  1284. Evaluation of cflow or cflowbelow pointcuts will be valid only
  1285. with respect to a chain of non-remote invocations.
  1286. </para>
  1287. </listitem>
  1288. </itemizedlist>
  1289. <para>
  1290. In addition, any AspectJ code should respect EJB operations:
  1291. </para>
  1292. <itemizedlist>
  1293. <listitem>
  1294. <para>
  1295. The EJB container accesses EJB component fields directly, i.e.,
  1296. in code outside the control of the compiler. There is no join point for
  1297. these accesses, and hence no way to write a pointcut to advise that access.
  1298. </para>
  1299. </listitem>
  1300. <listitem>
  1301. <para>
  1302. The EJB container may pool EJB components, so any initialization
  1303. join points may run once per component constructed, not once per
  1304. component initialized for purposes of a client call.
  1305. </para>
  1306. </listitem>
  1307. <listitem>
  1308. <para>
  1309. The EJB container is permitted to change class loaders, even
  1310. between invocations of a particular EJB component (by passivating and
  1311. activating with a new class loader). In this case, instances of singleton
  1312. aspects will not operate over multiple invocations of the component, or that
  1313. static initialization join point recur for a given class as it is re-loaded.
  1314. This behavior depends on the container implementation.
  1315. </para>
  1316. </listitem>
  1317. </itemizedlist>
  1318. </answer>
  1319. </qandaentry>
  1320. <qandaentry>
  1321. <question id="q:aspectjandgj"
  1322. xreflabel="Q:Can I use AspectJ with Generic Java?">
  1323. <para>Can I use AspectJ with Generic Java?</para>
  1324. </question>
  1325. <answer>
  1326. <para>At this time, unfortunately not. The two compilers are just not
  1327. at all compatible. In an ideal world, there would be a wonderful
  1328. Open Source extensible compiler framework for Java that both GJ and
  1329. AspectJ would be built on top of, and they would seamlessly
  1330. interoperate along with all other extensions to Java that you might
  1331. be interested in, but that's not the case (yet?).
  1332. </para>
  1333. <para>However, on 09 October 2000, the Java Community Process
  1334. approved a proposal to add generic types to Java that is largely
  1335. based on GJ (JSR 14). A draft specification was submitted for
  1336. public review, which closed on 01 August 2001, and a
  1337. <ulink url="http://plan9.bell-labs.com/who/wadler/pizza/gj/">
  1338. prototype implementation
  1339. </ulink> has been released.
  1340. </para>
  1341. <para>We are committed to moving very rapidly to add support for
  1342. generic types in AspectJ when generic types become part of the Java
  1343. language specification. Everyone on the AspectJ team is looking
  1344. forward to this, because we too would really like to be able to
  1345. write code that includes both aspects and generic types.
  1346. </para>
  1347. </answer>
  1348. </qandaentry>
  1349. <qandaentry>
  1350. <question id="q:aopinjava"
  1351. xreflabel="Q: Are you working to put AOP into Java?">
  1352. <para> Are you working to put AOP into Java?
  1353. It seems that every AOP toolset currently uses proprietary mechanisms
  1354. to describe point-cuts, etc.
  1355. </para>
  1356. </question>
  1357. <answer>
  1358. <para>
  1359. We are working on standardization, but it's
  1360. a question of timing/ripeness (imagine going from thousands of users
  1361. to millions). (See <xref linkend="q:standardization"/>.) We believe
  1362. AspectJ addresses this question in the best way possible now:
  1363. <itemizedlist>
  1364. <listitem>
  1365. <para>
  1366. It's open-source. Rather than being proprietary or controlled by a
  1367. vendor, it's available for anybody to use and build upon, forever.
  1368. </para>
  1369. </listitem>
  1370. <listitem>
  1371. <para>
  1372. AspectJ is not a set of mechanisms, it's a language. It is currently
  1373. implemented using certain techniques, but there's nothing that prevents
  1374. it from being implemented with other techniques. That means users can
  1375. adopt the language with confidence that implementations will get better.
  1376. </para>
  1377. </listitem>
  1378. <listitem>
  1379. <para>
  1380. There is no engineering need to change Java. The AspectJ language uses
  1381. the join point model already in Java, so there is no need to extend the
  1382. programming model. Our implementation produces valid Java bytecode, which
  1383. runs in any compliant J2SE VM and supports standard debuggers for those VM's
  1384. that support JSR-45 (debugging support for multi-language/multi-file sources).
  1385. This is a huge benefit to Sun since Sun must be extremely cautious
  1386. about extensions to the language or VM; before adopting AOP, Sun should
  1387. demand the kind of actual-proof that AspectJ implementations offer.
  1388. </para>
  1389. </listitem>
  1390. <listitem>
  1391. <para>
  1392. On the issue of "proprietary mechanisms to describe pointcuts, etc.": Any AOP
  1393. has to have some language to describe pointcuts and the like ("pointcuts"
  1394. of course being the AspectJ term). Users would like to have one language
  1395. (to avoid having to learn or transform between many languages) and the
  1396. choice of multiple implementations (tailored for a configuration, subject
  1397. to competitive pressure, etc.). That's what AspectJ offers.
  1398. </para>
  1399. </listitem>
  1400. <listitem>
  1401. <para>
  1402. That said, we believe the AspectJ extensions to Java could form the basis
  1403. for bringing AOP to Java; when that happens, there will be engineering
  1404. opportunities to make the implementation and tool support better.
  1405. </para>
  1406. </listitem>
  1407. </itemizedlist>
  1408. </para>
  1409. </answer>
  1410. </qandaentry>
  1411. <qandaentry>
  1412. <question id="q:support"
  1413. xreflabel="Q: What kind of support is available?">
  1414. <para>What kind of support is available?</para>
  1415. </question>
  1416. <answer>
  1417. <para>
  1418. The AspectJ users mailing list
  1419. (<literal>aspectj-users@eclipse.org</literal>)
  1420. provides an informal network of AspectJ language experts who
  1421. can answer usage questions about AspectJ programs
  1422. and the AspectJ tools.
  1423. </para>
  1424. <para>
  1425. The AspectJ developers mailing list
  1426. (<literal>aspectj-dev@eclipse.org</literal>)
  1427. provides an informal network of AspectJ technology experts who
  1428. aim to understand the technology behind AspectJ.
  1429. They can answer questions about what's possible and about
  1430. integrating AspectJ technology with other technologies.
  1431. This is also the place to request commercial support,
  1432. tutorials, or presentations.
  1433. </para>
  1434. <para>
  1435. For both mailing lists, only subscribed members may post messages.
  1436. To subscribe, visit the
  1437. <ulink url="http://eclipse.org/aspectj">AspectJ web site</ulink>.
  1438. </para>
  1439. <para>
  1440. You may view and submit bug reports and feature requests at
  1441. <ulink url="http://dev.eclipse.org/bugs">http://dev.eclipse.org/bugs</ulink>,
  1442. using the product <literal>AspectJ</literal>. Here are direct links to
  1443. <ulink url="http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&amp;component=Compiler&amp;bug_status=UNCONFIRMED&amp;bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED">
  1444. view open compiler bugs</ulink>,
  1445. <ulink url="http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ">
  1446. view all Aspectj bugs (open or closed)</ulink>, or
  1447. <ulink url="http://dev.eclipse.org/bugs/enter_bug.cgi?product=AspectJ">
  1448. add new bugs</ulink>.
  1449. </para>
  1450. </answer>
  1451. </qandaentry>
  1452. </qandadiv>
  1453. <qandadiv id="compiler" xreflabel="Using the AspectJ compiler">
  1454. <title>Using the AspectJ compiler</title>
  1455. <qandaentry>
  1456. <question id="q:requiredsources"
  1457. xreflabel="Q:What files do I need to include when compiling AspectJ programs?">
  1458. <para>
  1459. What files do I need to include when compiling AspectJ programs?
  1460. </para>
  1461. </question>
  1462. <answer>
  1463. <para>You need to specify to the compiler the source files that
  1464. contain your aspects and the source files that contain the
  1465. types affected by your aspects.
  1466. See <xref linkend="q:knowWhenAspectsAffectClasses"/>.
  1467. The AspectJ compiler will not search the source path for types
  1468. that may be affected (unlike Javac and Jikes), and it only uses
  1469. aspects in source form.
  1470. </para>
  1471. <para>In some cases you should compile your entire system all at once.
  1472. If this is too slow, then you can try to make reasonable divisions
  1473. between sets of source files whose aspects do not interact to
  1474. achieve a shorter compile cycle (particularly for development
  1475. aspects). However, if you get any problems
  1476. or if you wish to run tests or do a release, you should recompile
  1477. the entire system.
  1478. </para>
  1479. </answer>
  1480. </qandaentry>
  1481. <qandaentry>
  1482. <question id="q:listingsources"
  1483. xreflabel="Q:Is there any other way to provide the file names to ajc?">
  1484. <para>I have to list many files in the command line to
  1485. compile with <literal>ajc</literal>. Is there any other way to
  1486. provide the file names to <literal>ajc</literal>?
  1487. </para>
  1488. </question>
  1489. <answer>
  1490. <para>
  1491. Yes, use the argfile option to ajc. List source
  1492. files in a line-delimited text file and direct ajc to that
  1493. file using <literal>-argfile</literal> or <literal>@</literal>:
  1494. </para>
  1495. <programlisting>ajc @sources.lst
  1496. ajc -argfile sources.lst
  1497. </programlisting>
  1498. <para>
  1499. For more information, see the <literal>ajc</literal> tool
  1500. section of the
  1501. <ulink url="devguide/index.html">
  1502. Development Environment Guide
  1503. </ulink>.
  1504. </para>
  1505. </answer>
  1506. </qandaentry>
  1507. <qandaentry>
  1508. <question id="q:compilerVM"
  1509. xreflabel="Q: What Java virtual machine (JVM) do I use to run the
  1510. AspectJ compiler? ">
  1511. <para>What Java virtual machine (JVM) do I use to run the
  1512. AspectJ compiler?
  1513. </para>
  1514. </question>
  1515. <answer>
  1516. <para>Use the latest, greatest, fastest JVM you can get your hands on
  1517. for your platform. The compiler's performance is dependent on the
  1518. performance of the JVM it is running on, so the faster a JVM you
  1519. can find to run it on, the shorter your compile times will be. At a
  1520. minimum you need to use a Java 2 or later JVM to run the compiler.
  1521. We realize that this constraint can be a problem for users who
  1522. don't currently have a Java 2 JVM available. We're sorry for the
  1523. inconvenience, but we had to make the hard decision that the
  1524. advantages of being able to rely on Java 2 were worth the cost of
  1525. losing a number of developers who are working on platforms without
  1526. Java 2 support. Here is a list of starting places where you might
  1527. find support for your system.
  1528. <itemizedlist>
  1529. <listitem>
  1530. <para>
  1531. <ulink url="http://java.sun.com/j2se/">Java 2
  1532. Platform, Standard Edition
  1533. </ulink>
  1534. </para>
  1535. </listitem>
  1536. <listitem>
  1537. <para>
  1538. <ulink
  1539. url="http://www.ibm.com/java/jdk/download/">
  1540. developerWorks : J
  1541. ava technology : Tools and products - Developer kits
  1542. </ulink>
  1543. </para>
  1544. </listitem>
  1545. <listitem>
  1546. <para>
  1547. <ulink
  1548. url="http://oss.software.ibm.com/developerworks/projects/jikes/?dwzone=opensource">
  1549. developerWorks : Open Source - Jikes Project
  1550. </ulink>
  1551. </para>
  1552. </listitem>
  1553. <listitem>
  1554. <para>
  1555. <ulink url="http://java.sun.com/cgi-bin/java-ports.cgi">Java
  1556. Platform Ports
  1557. </ulink>
  1558. </para>
  1559. </listitem>
  1560. </itemizedlist>
  1561. </para>
  1562. <para>The requirement of Java 2 support is only for
  1563. <emphasis>running</emphasis> the AspectJ compiler. The AspectJ
  1564. compiler can be used to build programs that will run on Java 1.1
  1565. (or probably even on Java 1.0) systems. This means that it can
  1566. build programs that will run on Macintosh, FreeBSD, and applets
  1567. that will run in Internet Explorer and Netscape Navigator that are
  1568. still not yet Java 2 compliant.
  1569. </para>
  1570. </answer>
  1571. </qandaentry>
  1572. <qandaentry>
  1573. <question id="q:compilingForDifferentVMs"
  1574. xreflabel="Q: How to use ajc to compile for a different VM?">
  1575. <para>How can I use <literal>ajc</literal> to compile
  1576. programs for a JVM that is different from the one used to run it?
  1577. </para>
  1578. </question>
  1579. <answer>
  1580. <para>
  1581. <literal>ajc</literal> can be used to develop programs that are
  1582. targeted at the Java 1.1 platform, even though the
  1583. <literal>ajc</literal> compiler won't run on that platform. Here's
  1584. an example of using <literal>ajc</literal> in this sort of
  1585. cross-compilation mode (assuming a Windows platform with all the
  1586. default installation directories):
  1587. </para>
  1588. <programlisting>
  1589. ajc -target 1.1 -bootclasspath c:\jdk1.1.7\lib\classes.zip \
  1590. -classpath c:\aspectj1.0\lib\aspectjrt.jar -extdirs "" \
  1591. -argfile jdk11system.lst
  1592. </programlisting>
  1593. <para>This same technique can be used if you want to run
  1594. <literal>ajc</literal> on a JDK 1.3 JVM (highly recommended) but
  1595. need to generate code for JDK 1.2. That would look something
  1596. like:
  1597. </para>
  1598. <programlisting>
  1599. ajc -bootclasspath c:\jdk1.2\jre\lib\rt.jar \
  1600. -classpath c:\aspectj1.0\lib\aspectjrt.jar \
  1601. -extdirs c:\jdk1.2\jre\lib\ext
  1602. -argfile jdk12system.lst
  1603. </programlisting>
  1604. </answer>
  1605. </qandaentry>
  1606. <qandaentry>
  1607. <question id="q:assert"
  1608. xreflabel="Q:Does the ajc compiler support the assert keyword in Java 1.4?">
  1609. <para>Does the <literal>ajc</literal> compiler support
  1610. the <literal>assert</literal> keyword in Java 1.4?
  1611. </para>
  1612. </question>
  1613. <answer>
  1614. <para>Yes. As with <literal>Javac</literal>,
  1615. use the <literal>-source 1.4</literal> option as described
  1616. in the <literal>ajc</literal> tool section
  1617. of the
  1618. <ulink url="devguide/index.html">
  1619. Development Environment Guide
  1620. </ulink>.
  1621. </para>
  1622. </answer>
  1623. </qandaentry>
  1624. <qandaentry>
  1625. <question id="q:msjvm"
  1626. xreflabel="Q:Are there any issues using AspectJ with the Microsoft JVM?">
  1627. <para>Are there any issues using AspectJ with the Microsoft
  1628. JVM?
  1629. </para>
  1630. </question>
  1631. <answer>
  1632. <para>Since AspectJ requires Java 2 or later, it will not run on the
  1633. Microsoft JVM, which does not support Java 2.
  1634. </para>
  1635. </answer>
  1636. </qandaentry>
  1637. <qandaentry>
  1638. <question id="q:javacbytecode"
  1639. xreflabel="Q:Does ajc rely on javac for generating bytecode?">
  1640. <para>Does <literal>ajc</literal> rely
  1641. on <literal>javac</literal> for generating Java bytecode
  1642. (<literal>.class</literal>) files?
  1643. </para>
  1644. </question>
  1645. <answer>
  1646. <para> No. Some previous versions of AspectJ had this requirement,
  1647. and <literal>javac</literal> can still be used as
  1648. <literal>ajc</literal> back end by using the
  1649. <literal>-usejavac</literal> flag. You can also run <literal>ajc</literal>
  1650. in preprocessor mode to generate Java source
  1651. (<literal>.java</literal>) files to be compiled using
  1652. <literal>javac</literal> or another java compiler.
  1653. </para>
  1654. </answer>
  1655. </qandaentry>
  1656. <qandaentry>
  1657. <question id="q:parsergenerators"
  1658. xreflabel="Q:I noticed the AspectJ compiler doesn't use a parser generator. Why is that?">
  1659. <para>
  1660. I noticed the AspectJ compiler doesn't use a parser generator. Why is that?
  1661. </para>
  1662. </question>
  1663. <answer>
  1664. <para>
  1665. The PARSER for ajc is written by hand. This choice was made with full
  1666. awareness of the generator tools out there. (Jim had for example used
  1667. the excellent javacc tool for building the parser for JPython (now Jython)).
  1668. One of the reasons that AspectJ uses a hand-written parser is that using
  1669. javacc taught Jim about the LL-k design for parsers (pioneered by antlr).
  1670. As opposed to the state-machine parsers produced by yacc, these parsers are
  1671. very readable and writable by humans.
  1672. </para>
  1673. <para>
  1674. Antlr and javacc did not really suit the project:
  1675. </para>
  1676. <itemizedlist>
  1677. <listitem>
  1678. <para>
  1679. Antlr's support for unicode in the lexer is still immature and this makes
  1680. using it with Java challenging. This was an even bigger issue 3 years ago
  1681. when we started on the Java implementation of ajc.
  1682. </para>
  1683. </listitem>
  1684. <listitem>
  1685. <para>
  1686. While javacc is freely available, it is not Open Source. Depending on a
  1687. closed-source tool to build an Open Source compiler would reduce some
  1688. of the transparency and control of open-source.
  1689. </para>
  1690. </listitem>
  1691. </itemizedlist>
  1692. <para>
  1693. There were also several things that were easier to implement with
  1694. a hand-written parser than with any of the exiting tools.
  1695. </para>
  1696. <itemizedlist>
  1697. <listitem>
  1698. <para>
  1699. Semi-keywords -- it's important to us that
  1700. "every legal Java program is also a legal AspectJ program."
  1701. This wouldn't be true if we made 'before' and 'call' full keywords in
  1702. AspectJ. It is easier to support these sorts of semi-keywords with a
  1703. hand-written parser. (Note: ajc-1.0.x handles 'aspect' and 'pointcut'
  1704. slightly specially which can break a few unusual pure Java programs.
  1705. This is a compiler limitation that will be fixed in a future release.)
  1706. </para>
  1707. </listitem>
  1708. <listitem>
  1709. <para>
  1710. Deprecated syntax warnings -- the syntax of AspectJ
  1711. changed many times from version 0.2 to the 1.0 release. It was easier
  1712. to provide helpful warning messages for these changes with our
  1713. hand-written parser.
  1714. </para>
  1715. </listitem>
  1716. <listitem>
  1717. <para>
  1718. Grammar modularity -- We like being able to have
  1719. AspectJParser extend JavaParser.
  1720. </para>
  1721. </listitem>
  1722. <listitem>
  1723. <para>
  1724. Part of the grammar for AspectJ is extremely hard for existing tools to
  1725. capture. This is the type pattern syntax, i.e. "com.xerox..*.*(..)".
  1726. The sort of case that gives standard parser generators fits is something
  1727. like "*1.f(..)" which no one would ever write, but which must be
  1728. supported for a consistent language.
  1729. </para>
  1730. </listitem>
  1731. </itemizedlist>
  1732. </answer>
  1733. </qandaentry>
  1734. </qandadiv>
  1735. <qandadiv id="devtools" xreflabel="Integrating AspectJ into your development environment">
  1736. <title>Integrating AspectJ into your development environment</title>
  1737. <qandaentry>
  1738. <question id="q:knowWhenAspectsAffectClasses"
  1739. xreflabel="Q: How do I know which aspects affect a class when looking at that class's source code?">
  1740. <para>How do I know which aspects affect a class when looking
  1741. at that class's source code?
  1742. </para>
  1743. </question>
  1744. <answer>
  1745. <para>When you are working with the IDE support, you can get an
  1746. understanding of which aspects affect any class.
  1747. This enables AspectJ programmers to get the benefits of
  1748. modularizing crosscutting concerns while still having immediate
  1749. access to what aspects affect a class.
  1750. </para>
  1751. <para>For example, the
  1752. <ulink url="devguide/index.html">
  1753. Development Environment Guide
  1754. </ulink> section
  1755. on <literal>ajbrowser</literal> shows that you can list or navigate
  1756. between method and advice affecting that method and between a type
  1757. and declarations in an aspect on that type. (The IDE support may
  1758. have more features than <literal>ajbrowser</literal>, depending
  1759. on the IDE.
  1760. See <xref linkend="q:integrateWithDevTools"/> for more
  1761. information on which Java development environments are
  1762. supported.)
  1763. </para>
  1764. <para>
  1765. When you are looking at documentation for AspectJ 1.0,
  1766. <literal>ajdoc</literal> will provide links from aspects and
  1767. advice to the affected code, but it provides less information
  1768. than the IDE support because it only parses declarations.
  1769. </para>
  1770. <para>
  1771. When you are compiling your program, pointcuts that are
  1772. statically-determinable can be used in declare statements
  1773. to identify the code picked out by the pointcut.
  1774. (A pointcut is statically determinable if it only uses
  1775. the pointcut designators
  1776. <literal>within</literal>,
  1777. <literal>withincode</literal>,
  1778. <literal>execution</literal>,
  1779. <literal>call</literal>,
  1780. <literal>get</literal>,
  1781. <literal>set</literal>,
  1782. <literal>initialiation</literal>, and
  1783. <literal>staticinitialiation</literal>.)
  1784. The compiler will list the static code points which will be
  1785. affected by any advice specifying the same pointcut.
  1786. For example, the following will print a warning
  1787. whereever some code in class Bar gets a field value from Foo:
  1788. <programlisting>
  1789. declare warning: get(* Foo.*) &amp;&amp; within(Bar)
  1790. : "reading Foo state from Bar";
  1791. </programlisting>
  1792. </para>
  1793. <para>
  1794. When you are running your program,
  1795. you can trace advice as it executes. This
  1796. enables you to identify advice on join points picked out
  1797. dynamically, which cannot be reflected precisely by IDE support.
  1798. For a related tracing question,
  1799. see <xref linkend="q:seeingjoinpoints"/>
  1800. </para>
  1801. </answer>
  1802. </qandaentry>
  1803. <qandaentry>
  1804. <question id="q:idesupport"
  1805. xreflabel="Q:What kind of IDE support is available for developing AspectJ programs?">
  1806. <para>What kind of IDE support is available for developing
  1807. AspectJ programs?
  1808. </para>
  1809. </question>
  1810. <answer>
  1811. <para>See <xref linkend="q:integrateWithDevTools"/></para>
  1812. </answer>
  1813. </qandaentry>
  1814. <qandaentry>
  1815. <question id="q:hybridbuilds"
  1816. xreflabel="Q:Setting up hybrid builds">
  1817. <para>I want the aspects for development builds but
  1818. remove them for production builds. How can I set up the build
  1819. system so they are unpluggable? And so I use <literal>javac</literal>
  1820. in my production build?
  1821. </para>
  1822. </question>
  1823. <answer>
  1824. <para>
  1825. If you are using development-time-only aspects - aspects that only
  1826. exist when you are developing the code, not when you ship it -
  1827. you can use implement a hybrid build process by listing
  1828. the production source files into a javac-compliant argfile,
  1829. and the development source files in another ajc argfiles:
  1830. </para>
  1831. <programlisting>
  1832. -- file "production.lst":
  1833. One.java
  1834. two/Three.java
  1835. ...
  1836. -- file "tracing.lst":
  1837. trace/Library.java
  1838. Trace.java
  1839. -- file "development.lst":
  1840. @production.lst
  1841. @tracing.lst
  1842. </programlisting>
  1843. <para>
  1844. Then your development build can use <literal>ajc</literal>:
  1845. </para>
  1846. <programlisting>
  1847. ajc @development.lst
  1848. </programlisting>
  1849. <para>
  1850. And your development build can use
  1851. <literal>ajc</literal> or <literal>javac</literal>
  1852. or <literal>jikes</literal>:
  1853. </para>
  1854. <programlisting>
  1855. jikes @production.lst
  1856. </programlisting>
  1857. </answer>
  1858. </qandaentry>
  1859. <qandaentry>
  1860. <question id="q:idesupportplans"
  1861. xreflabel="Q:What plans are there to support my IDE?">
  1862. <para>What plans are there to support my IDE?</para>
  1863. </question>
  1864. <answer>
  1865. <para>
  1866. The AspectJ team directly provided components for JBuilder, Forte,
  1867. and Emacs and supported the open-source AspectJ plugin project
  1868. at <ulink url="http://eclipse.org/ajdt">http://eclipse.org/ajdt</ulink>
  1869. which uses the AJDE API support for IDE's.
  1870. Supporting new IDE's is a matter of building on the AJDE API's,
  1871. mostly likely adopting one of the existing open-source IDE
  1872. extensions as a design template.
  1873. Here are the IDE's where we know people have expressed interest,
  1874. so interested developer may want to join with others in their
  1875. developer communities to build the integration.
  1876. <itemizedlist>
  1877. <title></title>
  1878. <listitem>
  1879. <para>IDEA/IntelliJ has an enthusiastic community and
  1880. the developers are working on an extensibility API
  1881. - <ulink url="http://intellij.com">http://intellij.com</ulink>
  1882. </para>
  1883. </listitem>
  1884. <listitem>
  1885. <para>jEdit comes from a very active open-source community.</para>
  1886. </listitem>
  1887. <listitem>
  1888. <para>
  1889. Oracle JDeveloper has an Extension SDK unfamiliar to us.
  1890. </para>
  1891. </listitem>
  1892. <listitem>
  1893. <para>Some have suggested Codeguide from Omnicore
  1894. <ulink url="http://www.omnicore.com">http://www.omnicore.com/</ulink>
  1895. </para>
  1896. </listitem>
  1897. </itemizedlist>
  1898. </para>
  1899. <para>
  1900. For questions on AJDE, join the developer's list
  1901. <literal>aspectj-dev@eclipse.org</literal>.
  1902. For questions on the current IDE integrations, contact those projects.
  1903. </para>
  1904. </answer>
  1905. </qandaentry>
  1906. <qandaentry>
  1907. <question id="q:portingajde"
  1908. xreflabel="Q:Can I port AJDE support to my development environment?">
  1909. <para>Can I port AJDE support to my development environment?</para>
  1910. </question>
  1911. <answer>
  1912. <para>Yes. The core AJDE API is extensible and the source code is
  1913. available for download. Start by studying the sources
  1914. for the existing IDE support.
  1915. </para>
  1916. </answer>
  1917. </qandaentry>
  1918. </qandadiv>
  1919. <qandadiv id="notes" xreflabel="Programming notes and tips">
  1920. <title>Programming notes and tips</title>
  1921. <qandaentry>
  1922. <question id="q:methodsignatures"
  1923. xreflabel="Q:Is it possible to change methods by introducing keywords, adding parameters, or changing the throws clause?">
  1924. <para>Is it possible to change methods by introducing keywords (like
  1925. <literal>synchronized</literal>), adding parameters,
  1926. or changing the "throws" clause?
  1927. </para>
  1928. </question>
  1929. <answer>
  1930. <para>AspectJ does not enable you to change the signature of a method,
  1931. but you can (by express declaration) work around some
  1932. limits imposed by the signature. You can convert a checked exception to
  1933. unchecked using <literal>declare soft</literal>, privileged aspects
  1934. have access to private methods, and you can use a percflow aspect to
  1935. ferry additional state to a callee without changing intervening
  1936. signatures. For more details, see
  1937. <ulink url="progguide/index.html">The AspectJ Programming Guide</ulink>.
  1938. In the case of <literal>synchronized</literal>,
  1939. we have what we consider a better solution that uses
  1940. around advice instead of introduction. This solution is described
  1941. in
  1942. <ulink url="http://aspectj.org/pipermail/users/2000/000534.html">
  1943. this thread (no longer available)
  1944. </ulink> on the AspectJ users list, with some
  1945. <ulink url="http://aspectj.org/pipermail/users/2000/000536.html">
  1946. additional comments (no longer available)
  1947. </ulink>.
  1948. </para>
  1949. </answer>
  1950. </qandaentry>
  1951. <qandaentry>
  1952. <question id="q:seeingjoinpoints"
  1953. xreflabel="Q:I don't understand what join points exist. How can I see them?">
  1954. <para>
  1955. I don't understand what join points exist. How can I see them?
  1956. </para>
  1957. </question>
  1958. <answer>
  1959. <para>
  1960. You can trace them using using an aspect.
  1961. For example, you can start logging at a particular method call and
  1962. see what join points occur after the call and before it returns.
  1963. </para>
  1964. <para>
  1965. Here's some code Jim Hugunin wrote to trace join points
  1966. and posted to the users list. To reuse the aspect,
  1967. define a subaspect and implement the pointcuts, for example:
  1968. <programlisting>
  1969. aspect JoinPointSampleAspect extends aj.TraceJoinPoints {
  1970. protected pointcut entry() :
  1971. execution(static void JoinPointSample.main(String[]));
  1972. protected pointcut exit() :
  1973. call(static void JoinPointSampleAspect.exit());
  1974. public static void main (String[] args) {
  1975. JoinPointSample.main(args);
  1976. JoinPointSampleAspect.exit();
  1977. }
  1978. public static void exit() {}
  1979. }
  1980. class JoinPointSample {
  1981. public static void main(String[] args) {}
  1982. }
  1983. </programlisting>
  1984. </para>
  1985. <para>Here's the aspect:
  1986. <programlisting>
  1987. <![CDATA[
  1988. /* TraceJoinPoints.java */
  1989. package aj;
  1990. import org.aspectj.lang.*;
  1991. import org.aspectj.lang.reflect.*;
  1992. import java.io.*;
  1993. public abstract aspect TraceJoinPoints dominates * {
  1994. protected abstract pointcut entry();
  1995. protected pointcut exit(): call(* java..*.*(..));
  1996. final pointcut start(): entry() && !cflowbelow(entry());
  1997. final pointcut trace():
  1998. cflow(entry()) && !cflowbelow(exit()) && !within(TraceJoinPoints+);
  1999. before(): start() { makeLogStream(); }
  2000. before(): trace() { logEnter(thisJoinPointStaticPart); }
  2001. after(): trace() { logExit(thisJoinPointStaticPart); }
  2002. after(): start() { closeLogStream(); }
  2003. //------------ added
  2004. /**
  2005. * Emit a message in the log, e.g.,
  2006. * <pre>TraceJoinPoints tjp = TraceJoinPoints.aspectOf();
  2007. * if (null != tjp) tjp.message("Hello, World!");</pre>
  2008. */
  2009. public void message(String s) {
  2010. out.println("<message>" + prepareMessage(s) + "</message>");
  2011. }
  2012. public void message(String sink, String s) {
  2013. if (null == sink) {
  2014. message(s);
  2015. } else {
  2016. out.println("<message sink=" + quoteXml(sink)
  2017. + " >" + prepareMessage(s) + "</message>");
  2018. }
  2019. }
  2020. protected String prepareMessage(String s) { return s; } // XXX implement
  2021. //--------- end of added
  2022. PrintStream out;
  2023. int logs = 0;
  2024. protected void makeLogStream() {
  2025. try {
  2026. out = new PrintStream(new FileOutputStream("log" + logs++ + ".xml"));
  2027. } catch (IOException ioe) {
  2028. out = System.err;
  2029. }
  2030. }
  2031. protected void closeLogStream() {
  2032. out.close();
  2033. }
  2034. int depth = 0;
  2035. boolean terminal = false;
  2036. protected void logEnter(JoinPoint.StaticPart jp) {
  2037. if (terminal) out.println(">");
  2038. indent(depth);
  2039. out.print("<" + jp.getKind());
  2040. writeSig(jp);
  2041. writePos(jp);
  2042. depth += 1;
  2043. terminal = true;
  2044. }
  2045. void writeSig(JoinPoint.StaticPart jp) {
  2046. out.print(" sig=");
  2047. out.print(quoteXml(jp.getSignature().toShortString()));
  2048. }
  2049. void writePos(JoinPoint.StaticPart jp) {
  2050. SourceLocation loc = jp.getSourceLocation();
  2051. if (loc == null) return;
  2052. out.print(" pos=");
  2053. out.print(quoteXml(loc.getFileName() +
  2054. ":" + loc.getLine() +
  2055. ":" + loc.getColumn()));
  2056. }
  2057. String quoteXml(String s) {
  2058. return "\"" + s.replace('<', '_').replace('>', '_') + "\"";
  2059. }
  2060. protected void logExit(JoinPoint.StaticPart jp) {
  2061. depth -= 1;
  2062. if (terminal) {
  2063. out.println("/>");
  2064. } else {
  2065. indent(depth);
  2066. out.println("</" + jp.getKind() + ">");
  2067. }
  2068. terminal = false;
  2069. }
  2070. void indent(int i) {
  2071. while (i-- > 0) out.print(" ");
  2072. }
  2073. }
  2074. ]]>
  2075. </programlisting>
  2076. </para>
  2077. </answer>
  2078. </qandaentry>
  2079. <qandaentry>
  2080. <question id="q:comparecallandexecution"
  2081. xreflabel="Q:What is the difference between call and execution join points?">
  2082. <para>
  2083. What is the difference between call and execution join points?
  2084. </para>
  2085. </question>
  2086. <answer>
  2087. <para>
  2088. Briefly, there are two interesting times when a constructor or method is
  2089. run. Those times are when it is called, and when it actually
  2090. executes.
  2091. </para>
  2092. <para>
  2093. The main difference is that a call join point happens outside of
  2094. the object (for non-static methods) or class (for static methods
  2095. and constructors), and that an execution join point happens inside
  2096. the object or class. This means that the <literal>within</literal>
  2097. and <literal>withincode</literal> pointcuts pick them out
  2098. differently: A call join point is picked out within the caller,
  2099. while an execution join point is picked
  2100. out where it is actually defined.
  2101. </para>
  2102. <para>
  2103. A call join point is the ``outermost'' join point for a particular
  2104. call. Once a call join point proceeds, then a number of different
  2105. things happen. For non-static methods, for example, method
  2106. dispatch happens, which will cause one method execution join point
  2107. -- perhaps more, if there are super calls. For constructors, the
  2108. super constructor is called, and fields are initialized, and then
  2109. various constructor execution join points will occur.
  2110. </para>
  2111. <para>
  2112. A call join point matches only the ``external'' calls of a method
  2113. or constructor, based on a signature, and it does not pick out
  2114. calls made with <literal>super</literal>, or
  2115. <literal>this</literal> constructor calls.
  2116. </para>
  2117. <para>Here's more detail:
  2118. </para>
  2119. <para>Consider method execution in Java as (1) the initial call from
  2120. this object to some method on the target object with a
  2121. particular signature; and (2) the execution of the actual code
  2122. in the particular method dispatched in the target object.
  2123. The call join point starts with the initial call and ends
  2124. when control returns to the call (by return or perhaps
  2125. thrown exception). The execution join point starts with
  2126. the method body and ends when the body completes (again
  2127. by return or throwing an exception), so the execution join
  2128. point always happens within the bounds of the corresponding
  2129. call join point. You can see this if you use the
  2130. join-point tracing aspect in see <xref linkend="q:seeingjoinpoints"/>.
  2131. </para>
  2132. <para>As you would expect, the context differs
  2133. in advice on pointcuts picking out execution and call join
  2134. points; for call, <literal>this</literal> refers to the caller, whereas
  2135. for execution <literal>this</literal> refers to the called
  2136. (executing) object.
  2137. </para>
  2138. <para>
  2139. There are some subtle interactions with other AspectJ semantics.
  2140. First, the meaning of the signature in the
  2141. <literal>execution()</literal> and <literal>call()</literal>
  2142. pointcut designators (PCD's) differ: the call type depends upon
  2143. the type of the reference making the call, while the execution
  2144. type depends on the enclosing class.
  2145. Second, you may choose one over another if you cannot bring all
  2146. your sources within the code the compiler controls
  2147. (described in the <ulink url="progguide/apb.html">appendix</ulink>
  2148. to the <literal>Programming Guide</literal>).
  2149. For example, to trace calls into a
  2150. method from classes which are outside the code the compiler controls
  2151. at compile time, then using <literal>execution()</literal> will work
  2152. while using <literal>call()</literal>may not. Finally, since
  2153. <literal>super</literal> invocations are not considered method calls,
  2154. to trace <literal>super.foo()</literal> would require using
  2155. <literal>execution</literal>.
  2156. </para>
  2157. <para>
  2158. In most cases you should use the <literal>call()</literal>
  2159. pointcut designator unless you have a good reason to use
  2160. <literal>execution()</literal>
  2161. </para>
  2162. </answer>
  2163. </qandaentry>
  2164. <qandaentry>
  2165. <question id="q:comparecflowandcflowbelow"
  2166. xreflabel="Q:What is the difference between cflow and cflowbelow?">
  2167. <para>
  2168. What is the difference between cflow and cflowbelow?
  2169. </para>
  2170. </question>
  2171. <answer>
  2172. <para>
  2173. Both pick out all the join points in the control flow of
  2174. the specified join points.
  2175. They differ only in that the <literal>cflowbelow()</literal>
  2176. pointcut designator does not pick out the join points
  2177. specified, while <literal>cflow()</literal> does.
  2178. </para>
  2179. </answer>
  2180. </qandaentry>
  2181. <qandaentry>
  2182. <question id="q:recursiveentrypoints"
  2183. xreflabel="Q:How do I say that I want the topmost entrypoint in a recursive call?">
  2184. <para>How do I say that I want the topmost entrypoint in a
  2185. recursive call? How about the most-recent prior entrypoint?
  2186. </para>
  2187. </question>
  2188. <answer>
  2189. <para>This is best seen by way of example.
  2190. Given a recursive call to <literal>int factorial(int)</literal>
  2191. you can print the arguments for
  2192. (a) the current and most-recent recursive call
  2193. or (b) the current and original recursive call:
  2194. </para>
  2195. <programlisting>
  2196. aspect LogFactorial {
  2197. pointcut f(int i) : call(int factorial(int)) &amp;&amp; args(i);
  2198. // most-recent
  2199. before(int i, final int j) : f(i) &amp;&amp; cflowbelow(f(j)) {
  2200. System.err.println(i + "-" + j);
  2201. }
  2202. // original
  2203. before(int i, final int j) : f(i)
  2204. &amp;&amp; cflowbelow(cflow(f(j)) &amp;&amp; !cflowbelow(f(int))) {
  2205. System.err.println(i + "@" + j);
  2206. }
  2207. }
  2208. </programlisting>
  2209. </answer>
  2210. </qandaentry>
  2211. <qandaentry>
  2212. <question id="q:initializationjoinpoints"
  2213. xreflabel="Q:What is the difference between constructor call, constructor execution, initialization, and static initialization join points?">
  2214. <para>What is the difference between constructor call,
  2215. constructor execution, initialization, and static
  2216. initialization join points?
  2217. </para>
  2218. </question>
  2219. <answer>
  2220. <para>Static initialization pertains to initialization of
  2221. a class or interface type. Constructor call and execution
  2222. are akin to method call, and initialization generalizes this and
  2223. picks out the first constructor called.
  2224. </para>
  2225. <para>Their relations are best
  2226. demonstrated by tracing the join points. Below is the class
  2227. Test which implements an interface and extends a class
  2228. along with a trace of the join points below and including
  2229. the constructor call obtained using
  2230. <literal>TraceJointPoints.java</literal>
  2231. from <xref linkend="q:seeingjoinpoints"/>.
  2232. </para>
  2233. <programlisting>
  2234. <![CDATA[
  2235. public class Init {
  2236. public static void main (String[] args) {
  2237. new Test();
  2238. end();
  2239. }
  2240. static void end() {}
  2241. }
  2242. class Super {}
  2243. interface I {}
  2244. class Test extends Super implements I {
  2245. Test() {}
  2246. }
  2247. <constructor-call sig="Test()" >
  2248. <staticinitialization sig="Super._init_" />
  2249. <staticinitialization sig="Test._init_" />
  2250. <initialization sig="Super()" >
  2251. <instanceinitializer-execution sig="Super._init_" />
  2252. <constructor-execution sig="Super()" />
  2253. </initialization>
  2254. <initialization sig="I()" >
  2255. <instanceinitializer-execution sig="I._init_" />
  2256. <constructor-execution sig="I()" />
  2257. </initialization>
  2258. <initialization sig="Test()" >
  2259. <instanceinitializer-execution sig="Test._init_" />
  2260. <constructor-execution sig="Test()" />
  2261. </initialization>
  2262. </constructor-call>
  2263. ]]>
  2264. </programlisting>
  2265. <para>
  2266. Ordinarily, using a <literal>call</literal> pointcut designator
  2267. is best because the call join point surrounds the others, but in
  2268. the case of constructors there is no target object for
  2269. the call (because it has not been constructed yet), so you
  2270. might prefer to use the <literal>initialization</literal>
  2271. pointcut designator.
  2272. </para>
  2273. </answer>
  2274. </qandaentry>
  2275. <qandaentry>
  2276. <question id="q:adviseconstructors"
  2277. xreflabel="Q:How do I work with an object right when it is created?">
  2278. <para>How do I work with an object right when it is created?
  2279. </para>
  2280. </question>
  2281. <answer>
  2282. <para>
  2283. You can advise some form of constructor join point.
  2284. Constructors are tricky in Java, and that's exposed in AspectJ.
  2285. Here are some rules of thumb:
  2286. <itemizedlist>
  2287. <listitem>
  2288. <para>If you want the join point on the "outside" of object creation,
  2289. use after returning from call to the constructor:
  2290. </para>
  2291. <programlisting>
  2292. after() returning (Foo newlyCreatedObject): call(Foo.new(..)) { ... }
  2293. </programlisting>
  2294. <para>
  2295. You might be tempted to use "this" or "target" to expose the new object, but remember
  2296. that if you're on the "outside" of object creation, the object itself might not be
  2297. created yet... it only exists "on the way out", when you return the object.
  2298. </para>
  2299. </listitem>
  2300. <listitem>
  2301. <para>If you want the join point inside a particular constructor, use:
  2302. </para>
  2303. <programlisting>
  2304. after(Foo newlyCreatedObject) returning: this(newlyCreatedObject) &amp;&amp; execution(Foo.new(..)) { ... }
  2305. </programlisting>
  2306. <para>
  2307. Remember, though, that if you use "before" advice here, the body of the constructor
  2308. will not have run, and so the object may be somewhat uninitialized.
  2309. </para>
  2310. </listitem>
  2311. <listitem>
  2312. <para>
  2313. In the rare case that there are all sorts of constructors for the object that call
  2314. each other with <literal>this(...)</literal> and you want exactly one join point
  2315. for each initialization of <literal>Foo</literal>, regardless of the path of
  2316. constructors it takes, then use:
  2317. </para>
  2318. <programlisting>
  2319. after(Foo f) returning: this(f) &amp;&amp; initialization(Foo.new(..)) { ... }
  2320. </programlisting>
  2321. </listitem>
  2322. </itemizedlist>
  2323. </para>
  2324. </answer>
  2325. </qandaentry>
  2326. <qandaentry>
  2327. <question id="q:andingpointcuts"
  2328. xreflabel="Q:I want advice to run at two pointcuts, but it doesn't run at all.">
  2329. <para>
  2330. I want advice to run at two pointcuts, but it doesn't run at all. What gives?
  2331. </para>
  2332. </question>
  2333. <answer>
  2334. <para>
  2335. This reflects both a conceptual error and a programming mistake.
  2336. Most likely you want to do something like "run the advice for all
  2337. public and private calls," and the code looks something like this:
  2338. </para>
  2339. <programlisting>
  2340. within(com.xerox.printing..*) &amp;&amp; call(public * *(..)) &amp;&amp; call(private * *(..))
  2341. </programlisting>
  2342. <para>
  2343. A pointcut picks out join points; it is evaluated at each join point.
  2344. The expression above would never pick out any call join point,
  2345. because no method signature has both public and private access.
  2346. In a pointcut, <literal>pc1() &amp;&amp; pc2()</literal> means both
  2347. must be true at a given join point for advice to run at that join point.
  2348. The correct pointcut would use <literal>||</literal> as follows:
  2349. </para>
  2350. <programlisting>
  2351. within(com.xerox.printing..*) &amp;&amp; (call(public * *(..)) || call(private * *(..)))
  2352. </programlisting>
  2353. <para>
  2354. Then the advice will run at the join point.
  2355. </para>
  2356. </answer>
  2357. </qandaentry>
  2358. <qandaentry>
  2359. <question id="q:staticfieldreferences"
  2360. xreflabel="Q:How do I refer to a static field when my advice crosscuts multiple classes?">
  2361. <para>
  2362. How do I refer to a static field when my advice crosscuts multiple classes?
  2363. </para>
  2364. </question>
  2365. <answer>
  2366. <para>There is no way in advice to refer to the type of the
  2367. code executing in a static context except by specification.
  2368. This makes it impossible to refer to static members using
  2369. runtime information.
  2370. </para>
  2371. </answer>
  2372. </qandaentry>
  2373. <qandaentry>
  2374. <question id="q:interfacesastypepatterns"
  2375. xreflabel="Q:How can I reuse a type pattern?">
  2376. <para>I would like to reuse a type pattern, e.g., to
  2377. write advice that is limited to a certain set of classes.
  2378. Do I have to retype it each time?
  2379. </para>
  2380. </question>
  2381. <answer>
  2382. <para>No. You can declare that all the types implement
  2383. an interface you define, and then use the interface type in
  2384. your program. For example:
  2385. </para>
  2386. <programlisting>
  2387. /**
  2388. * Example of using an interface to represent a type pattern.
  2389. * sub-aspects use declare parents to add to traced types, e.g.,
  2390. * declare parents: com.mycompany.whatever..* implements Marked;
  2391. */
  2392. abstract aspect MarkerExample {
  2393. /** marker interface for types that we want to trace */
  2394. interface Marked {}
  2395. /** calls to an instance of Marked not from an instance of Marked */
  2396. pointcut dynamicCallsIn(): call(* *(..)) &amp;&amp; target(Marked) &amp;&amp; !this(Marked);
  2397. /** calls to methods defined by a subtype of Marked
  2398. * that don't come from the body of a subtype of Marked
  2399. */
  2400. pointcut staticCallsIn(): call(* Marked+.*(..)) &amp;&amp; !within(Marked+);
  2401. /** print dynamic calls */
  2402. before(): dynamicCallsIn() { System.out.println("before " + thisJoinPoint); }
  2403. }
  2404. aspect MyMarker extends MarkerExample {
  2405. declare parents: com.mycompany.whatever..* implements Marked;
  2406. }
  2407. </programlisting>
  2408. </answer>
  2409. </qandaentry>
  2410. <qandaentry>
  2411. <question id="q:exampleprograms"
  2412. xreflabel="Q:Where do I find example programs?">
  2413. <para>Where do I find example programs?</para>
  2414. </question>
  2415. <answer>
  2416. <para>Some examples are distributed in the documentation release,
  2417. and you can find other code in the discussions on the users list.
  2418. </para>
  2419. </answer>
  2420. </qandaentry>
  2421. <qandaentry>
  2422. <question id="q:aspectlibraries"
  2423. xreflabel="Q:Are aspect libraries available?">
  2424. <para>Are aspect libraries available?</para>
  2425. </question>
  2426. <answer>
  2427. <para>Some libraries are distributed in the release under the
  2428. examples folder in the distribution.
  2429. If you develop a library and want to make it available to
  2430. other users, join the users mailing list
  2431. <literal>aspectj-users@eclipse.org</literal>.
  2432. </para>
  2433. </answer>
  2434. </qandaentry>
  2435. <qandaentry>
  2436. <question id="q:serialversionuid"
  2437. xreflabel="Q:How does ajc interact with the serialVersionUID?">
  2438. <para>How does <literal>ajc</literal> interact with the
  2439. <literal>serialVersionUID</literal>?
  2440. </para>
  2441. </question>
  2442. <answer>
  2443. <para>The current version of <literal>ajc</literal> can change the
  2444. <varname>serialVersionUID</varname> of generated
  2445. <filename>.class</filename> files as a result of weaving in advice.
  2446. This is an important fact that developers using both aspects and
  2447. serialization should be aware of. It is likely that a future
  2448. version of the compiler will be better behaved regarding the
  2449. <varname>serialVersionUID</varname>.
  2450. </para>
  2451. <para>However, changes to the <literal>serialVersionUID</literal>
  2452. attribute are typically only important when using serialization for
  2453. the long-term persistence of objects. Using standard Java
  2454. serialization for long-term persistence has a number of drawbacks
  2455. and many developers already use alternative solutions. For one
  2456. possibly standard solution, see
  2457. <ulink url="http://jcp.org/jsr/detail/057.jsp">
  2458. Lon
  2459. g-Term Persistence for JavaBeans Specification
  2460. </ulink>.
  2461. </para>
  2462. </answer>
  2463. </qandaentry>
  2464. <qandaentry>
  2465. <question id="q:applets"
  2466. xreflabel="Q:How can I use AspectJ with applets?">
  2467. <para>How can I use AspectJ with applets?</para>
  2468. </question>
  2469. <answer>
  2470. <para>
  2471. Just include the aspectjrt.jar as a required archive.
  2472. For example, here is the HTML code for an HTML editor
  2473. applet that contains some debugging aspects:
  2474. </para>
  2475. <programlisting>
  2476. <![CDATA[
  2477. <APPLET
  2478. CODE='com.company.swing.applets.EditorApplet'
  2479. WIDTH='700'
  2480. HEIGHT='525'>
  2481. <PARAM NAME="CODE" VALUE="com.company.swing.applets.EditorApplet" >
  2482. <PARAM NAME="ARCHIVE"
  2483. VALUE ="../company-applets.jar,../aspectjrt.jar,../xmlrpc-applet.jar" >
  2484. <PARAM NAME="type" VALUE="application/x-java-applet;version=1.4">
  2485. <PARAM NAME="scriptable" VALUE="false">
  2486. </APPLET>
  2487. ]]>
  2488. </programlisting>
  2489. <para>
  2490. The above markup has worked reliably with the Java Plugin
  2491. (included in the JRE 1.4.x) in IE 6, Mozilla 1.1 (Win32),
  2492. and Mozilla 1.0.1 (Red Hat Linux 8.0).
  2493. The following link describes how to configure Mozilla/Netscape
  2494. 6.x/7.x to use the Java Plugin from a JRE/SDK installation:
  2495. <ulink url="http://java.sun.com/j2se/1.4.1/manual_install_linux.html">
  2496. http://java.sun.com/j2se/1.4.1/manual_install_linux.html</ulink>.
  2497. (Thanks to Chris Bartling for this answer.)
  2498. </para>
  2499. </answer>
  2500. </qandaentry>
  2501. <qandaentry>
  2502. <question id="q:typeoblivious"
  2503. xreflabel="Q:How can I specify types for advice that captures primitives, void, etc.?">
  2504. <para>How can I specify types for advice that captures primitives, void, etc.?</para>
  2505. </question>
  2506. <answer>
  2507. <para>
  2508. In some cases, AspectJ allows conversion from values of primitive types to Object,
  2509. so that highly polymorphic advice may be written. This works if an advice parameter
  2510. or the return type for around is typed to Object. So:
  2511. </para>
  2512. <programlisting>
  2513. class Test {
  2514. static int i;
  2515. public static void main(String[] args) {
  2516. i = 37;
  2517. }
  2518. }
  2519. aspect TraceSet {
  2520. before(Object val): set(* Test.*) &amp;&amp; args(val) {
  2521. System.err.println(val);
  2522. System.err.println(val.class);
  2523. }
  2524. }
  2525. </programlisting>
  2526. <para>
  2527. will print out
  2528. </para>
  2529. <programlisting>
  2530. 37
  2531. java.lang.Integer
  2532. </programlisting>
  2533. <para>
  2534. For more information, see the Programming Guide
  2535. <ulink url="progguide/apbs02.html">
  2536. semantics section "Context Exposure"
  2537. </ulink>.
  2538. </para>
  2539. </answer>
  2540. </qandaentry>
  2541. <qandaentry>
  2542. <question id="q:versioninfo"
  2543. xreflabel="Q:How do I detect which version I am running?">
  2544. <para>How do I detect which version I am running?</para>
  2545. </question>
  2546. <answer>
  2547. <para>The <literal>ajc</literal>
  2548. compiler emits the version when passed the
  2549. <literal>-version</literal> flag as an argument.
  2550. </para>
  2551. <para>To programmatically
  2552. detect the version of the AspectJ runtime while running
  2553. under Java 1.4 or later, get the version from the package:
  2554. <programlisting>
  2555. Package lang = org.aspectj.lang.JoinPoint.class.getPackage();
  2556. String version = lang.getImplementationVersion();
  2557. </programlisting>
  2558. </para>
  2559. <para>When running under Java 1.3 or earlier, read the manifest
  2560. directly. For example code, see the source for
  2561. <literal>AjBuildManager.checkRtJar(AjBuildConfig)</literal>
  2562. in the <literal>org.aspectj.ajdt.internal.core.builder</literal>
  2563. package of the <literal>org.aspectj.ajdt.core</literal> module,
  2564. available as described in
  2565. <xref linkend="q:buildingsource"/>.
  2566. </para>
  2567. <para>Note that the version of AspectJ for the tools in
  2568. <literal>aspectjtools.jar</literal> is in
  2569. <literal>org.aspectj.bridge.Version</literal>.
  2570. </para>
  2571. </answer>
  2572. </qandaentry>
  2573. </qandadiv>
  2574. <qandadiv id="problems" xreflabel="Common Problems">
  2575. <title>Common Problems</title>
  2576. <qandaentry>
  2577. <question id="q:infiniterecursion"
  2578. xreflabel="Q:When I run, I get a StackOverflowError or no output.">
  2579. <para>When I run, I get a <literal>StackOverflowError</literal>
  2580. (or a long stack trace or no output whatsoever)
  2581. </para>
  2582. </question>
  2583. <answer>
  2584. <para>Most likely this is a case of infinite recursion,
  2585. where advice is advising itself. It presents as a
  2586. <literal>StackOverflowError</literal>
  2587. or silence as the VM exhausts itself in the recursion.
  2588. </para>
  2589. <para>Of course, infinite recursion is possible in Java:</para>
  2590. <programlisting>
  2591. public class Main {
  2592. public static void main(String[] args) {
  2593. try {
  2594. main(args);
  2595. } finally {
  2596. main(args);
  2597. }
  2598. }
  2599. }
  2600. </programlisting>
  2601. <para>If you compile and run this program, and it will fail silently, trying
  2602. to process the finally clause even after throwing the StackOverflowError.
  2603. </para>
  2604. <para>Here's a similar AspectJ program where the recursion is
  2605. not so obvious:
  2606. </para>
  2607. <programlisting>
  2608. aspect A {
  2609. after(): call(* *(..)) { System.out.println("after " + thisJoinPoint); }
  2610. }
  2611. </programlisting>
  2612. <para>This re-invokes itself because it advises any call.
  2613. It invokes itself even after an exception is thrown, since
  2614. <literal>after</literal> advice, like a finally clause, runs even
  2615. after exceptions are thrown. You can fix this by following two practices:
  2616. </para>
  2617. <para>
  2618. (1) Use <literal>after returning</literal> to advise normal completions
  2619. or <literal>after throwing</literal> to advise abrupt completions.
  2620. If you use <literal>after</literal> or <literal>after throwing</literal>,
  2621. write the advice with the same care you would a finally clause,
  2622. understanding that it may run after some failure.
  2623. </para>
  2624. <para>(2) Avoid writing advice that advises itself. One simple way to
  2625. do so is to exclude the code within the current aspect:
  2626. </para>
  2627. <programlisting>
  2628. aspect A {
  2629. after() returning: !within(A) &amp;&amp; call(* *(..)) {
  2630. System.out.println("after " + thisJoinPoint);
  2631. }
  2632. }
  2633. </programlisting>
  2634. <para>A better way is often to re-write the pointcut.
  2635. If the advice is advising itself accidentally, that's a sign that
  2636. the pointcut is not saying what you mean.
  2637. </para>
  2638. <programlisting>
  2639. aspect A {
  2640. pointcut withinTargetClasses() : within(A+) || within(B+);
  2641. after() returning: withinTargetClasses() &amp;&amp; call(* *(..)) {
  2642. System.out.println("after " + thisJoinPoint);
  2643. }
  2644. }
  2645. </programlisting>
  2646. </answer>
  2647. </qandaentry>
  2648. <qandaentry>
  2649. <question id="q:typelessdeclarations"
  2650. xreflabel="Q:I've declared a field on every class in my package; how do I use it in advice?">
  2651. <para>I've declared a field on every class in
  2652. my package; how do I use it in advice?
  2653. </para>
  2654. <programlisting>
  2655. aspect A {
  2656. boolean com.xerox..*.dirtyFlag;
  2657. after (Object target) returning
  2658. : target(target) &amp;&amp; call(* com.xerox..*.set*(..)) {
  2659. target.dirtyFlag = true; // compile fails here
  2660. }
  2661. }
  2662. </programlisting>
  2663. </question>
  2664. <answer>
  2665. <para>You need a type to refer to any member, field or method.
  2666. It's generally better to introduce onto an interface and
  2667. declare classes to implement the interface, which permits you
  2668. to use the interface type in advice formals.
  2669. </para>
  2670. <programlisting>
  2671. aspect A {
  2672. interface TrackingSets {}
  2673. boolean TrackingSets.dirtyFlag;
  2674. declare parents : com.xerox..* implements TrackingSets;
  2675. after (TrackingSets target) returning
  2676. : target(target) &amp;&amp; call(* com.xerox..*.set*(..)) {
  2677. target.dirtyFlag = true;
  2678. }
  2679. }
  2680. </programlisting>
  2681. </answer>
  2682. </qandaentry>
  2683. <qandaentry>
  2684. <question id="q:ajcoom"
  2685. xreflabel="Q:The AspectJ compiler aborts with an OutOfMemoryError when compiling many classes. How can I fix this?">
  2686. <para>The AspectJ compiler aborts with an OutOfMemoryError when
  2687. compiling many classes. How can I fix this?
  2688. </para>
  2689. </question>
  2690. <answer>
  2691. <para>The command <literal>ajc</literal> is actually a script that
  2692. launches a Java virtual machine with the correct classpath. You
  2693. should make a copy of this script, rename it, and then edit it.
  2694. Change the -Xmx option, size of memory allocation pool (heap). You
  2695. might try <literal>-Xmx128M</literal> or even
  2696. <literal>-Xmx256M</literal>.
  2697. </para>
  2698. </answer>
  2699. </qandaentry>
  2700. <qandaentry>
  2701. <question id="q:ajcrecompile"
  2702. xreflabel="Q:ajc recompiles all files every time. How can I make it recompile only the files that have changed?">
  2703. <para>
  2704. <literal>ajc</literal> recompiles all files every time.
  2705. How can I make it recompile only the files that have changed?
  2706. </para>
  2707. </question>
  2708. <answer>
  2709. <para>
  2710. <literal>ajc</literal> 1.0 does not currently support incremental
  2711. compilation, but we are working on this for the 1.1 release.
  2712. </para>
  2713. <para>As a limited workaround, many build systems enable you to avoid
  2714. doing a compile if no sources have changed. (See, e.g., Ant's
  2715. "uptodate" task.)
  2716. </para>
  2717. </answer>
  2718. </qandaentry>
  2719. <qandaentry>
  2720. <question id="q:ajcjvm"
  2721. xreflabel="Q:ajc is using the wrong JVM. How do I fix it?">
  2722. <para>
  2723. <literal>ajc</literal> is using the wrong JVM. How do I
  2724. fix it?
  2725. </para>
  2726. </question>
  2727. <answer>
  2728. <para>The easiest way to fix this is to re-install
  2729. <literal>ajc</literal> (using the same <literal>.class</literal> or
  2730. <literal>.exe</literal> file that you originally downloaded) and
  2731. this time make sure to tell it to use the desired JDK (typically
  2732. the JDK versions 1.2 or 1.3 from Sun).
  2733. </para>
  2734. <para>If you are familiar with DOS batch files or shell programming,
  2735. you could also fix this by simply editing the
  2736. <literal>bin\ajc.bat</literal> or <literal>bin/ajc</literal>
  2737. script.
  2738. </para>
  2739. </answer>
  2740. </qandaentry>
  2741. <qandaentry>
  2742. <question id="q:idebalkingataspects"
  2743. xreflabel="Q:My IDE is trying to parse AspectJ files which makes my project unusable. What can I do?">
  2744. <para>My IDE is trying to parse AspectJ files which makes my project unusable.
  2745. What can I do?
  2746. </para>
  2747. </question>
  2748. <answer>
  2749. <para>
  2750. When working with an unsupported IDE that objects to the syntax of
  2751. AspectJ source files (and, e.g., automatically gathers them
  2752. in a source tree as Java files based on the .java extension),
  2753. you can use the .aj extension for your AspectJ files.
  2754. The ajc compiler accepts both .java and .aj files, and you can
  2755. set up your build scripts to include the correct list of
  2756. source files. (You will have to find another editor for
  2757. editing AspectJ files; you can use the ajbrowser to view
  2758. edit your AspectJ files and navigate the crosscutting structure.)
  2759. </para>
  2760. </answer>
  2761. </qandaentry>
  2762. <qandaentry>
  2763. <question id="q:idememory"
  2764. xreflabel="Q:I used to be able to compile my program, but now I run out of memory.">
  2765. <para>I used to be able to compile my program in my IDE, but when I
  2766. use AJDE, I run out of memory (or it goes really slow).
  2767. </para>
  2768. </question>
  2769. <answer>
  2770. <para>
  2771. The ajc compiler does more analysis than (e.g.,) javac,
  2772. and AJDE may in some IDE's hold a copy of the structure tree until the
  2773. next tree is available from the compile process. Both mean that you may
  2774. need extra memory to compile the same program. However, increasing
  2775. available memory to the point that you are swapping to disk can
  2776. slow the process considerably.
  2777. </para>
  2778. <para>
  2779. If you are having problems and would like to find the optimal memory
  2780. allocation, iteratively decrease the amount of memory available until
  2781. AJDE or ajc signals out-of-memory errors, and then increase that
  2782. amount by 5-10%.
  2783. </para>
  2784. <para>
  2785. To increase memory for the ajc compiler, see <xref linkend="q:ajcoom"/>.
  2786. For your IDE, do something similar or follow the provider's instructions.
  2787. For example, to increase memory in JBuilder, edit the
  2788. <literal>jbuilderX/bin/jbuilder.config</literal>
  2789. file to have an entry like:
  2790. <programlisting>
  2791. vmparam -Xmx384m
  2792. </programlisting>
  2793. </para>
  2794. <para>
  2795. If it turns out that your project is too big to use with AJDE, your IDE
  2796. may nonetheless support external commands or Ant build processes, which
  2797. run outside the IDE memory space. For a JBuilder Ant plugin, some
  2798. people have directed us to <ulink url="http://antrunner.sourceforge.net"/>.
  2799. </para>
  2800. </answer>
  2801. </qandaentry>
  2802. <qandaentry>
  2803. <question id="q:stacktraces"
  2804. xreflabel="Q:My stack traces don't make sense. What gives?">
  2805. <para>
  2806. My stack traces don't make sense. What gives?
  2807. </para>
  2808. </question>
  2809. <answer>
  2810. <para>Unless you are using the <literal>ajdb</literal> debugger,
  2811. stack traces may
  2812. have synthetic methods in the stack, and the line numbers may
  2813. not track your source code. The
  2814. <ulink url="devguide/index.html">Development Environment Guide</ulink>.
  2815. discusses how to interpret stack at the end of the section
  2816. on the <literal>ajc</literal> compiler.
  2817. </para>
  2818. </answer>
  2819. </qandaentry>
  2820. <qandaentry>
  2821. <question id="q:advicenotrunning"
  2822. xreflabel="Q:My advice is not running (or running twice), and I don't know why.">
  2823. <para>
  2824. My advice is not running (or running twice), and I don't know why.
  2825. </para>
  2826. </question>
  2827. <answer>
  2828. <para>When advice is not running, it is probably a problem in the
  2829. pointcut.
  2830. Sometimes users specify pointcuts that do not mean what they intend -
  2831. most often when they misspell a type name. Run the compiler in
  2832. <literal>-Xlint</literal> mode, which will flag some likely mistakes,
  2833. like the type name.
  2834. If that does not work, and your pointcut is staticly-determinable,
  2835. use a declare statement to identify affected code. (For more
  2836. information, see <xref linkend="q:knowWhenAspectsAffectClasses"/>.)
  2837. If that does not work and your pointcut is dynamically determined,
  2838. see if your join points are executing at all by using
  2839. TraceJoinPoints.java from <xref linkend="q:seeingjoinpoints"/>.
  2840. </para>
  2841. <para>When advice is running more than it should, it may be that your
  2842. pointcut picks out more join points than you intend.
  2843. If you are using IDE support, you should be able to trace back from
  2844. the pointcut or advice to the join points which can be statically
  2845. determined to be affected. To identify advised dynamic join points,
  2846. you can try using <literal>TraceJoinPoints.java</literal> as above,
  2847. or update the advice to print the source location of the join point.
  2848. This will show if the advice applies to code that you did
  2849. not consider.
  2850. </para>
  2851. <para>If you've done this and convinced yourself it's not working,
  2852. it may be a bug. See <xref linkend="q:bugreports"/>.
  2853. </para>
  2854. </answer>
  2855. </qandaentry>
  2856. <qandaentry>
  2857. <question id="q:packagedeclares"
  2858. xreflabel="Q:I declared a member on a class with package access, but other classes in the package cannot see it.">
  2859. <para>
  2860. I declared a member on a class with package access, but other classes in the package cannot see it.
  2861. </para>
  2862. </question>
  2863. <answer>
  2864. <para>When declaring parents on other types from an aspect, package access only
  2865. applies to code the implementation controls. For AspectJ 1.0, that is the set of files
  2866. passed to the compiler. That means other classes not compiled with the aspect will not
  2867. be able to access the aspect-declared members even if they are in the same package.
  2868. The only way for classes outside the control of the implementation to access aspect-declared
  2869. members is to declare them public.
  2870. </para>
  2871. </answer>
  2872. </qandaentry>
  2873. <qandaentry>
  2874. <question id="q:cantfindjavac"
  2875. xreflabel="Q:ajc complains that it can't find javac. What's wrong?">
  2876. <para>
  2877. <literal>ajc</literal> complains that it can't find
  2878. <literal>javac</literal>. What's wrong?
  2879. </para>
  2880. </question>
  2881. <answer>
  2882. <para>
  2883. <literal>ajc</literal> does not try to locate
  2884. <literal>javac</literal> in your path: it uses the
  2885. <literal>javac</literal> classes directly. In JDK 1.2 and 1.3 these
  2886. classes are found in <literal>tools.jar</literal> (in the
  2887. <literal>lib</literal> directory of the JDK distribution), which
  2888. must be on your classpath to make
  2889. <literal>ajc</literal> work with <literal>javac</literal>.
  2890. Inspect the java command that launches ajc to make sure that
  2891. <literal>tools.jar</literal> is on the classpath for ajc;
  2892. the -classpath option only applies to the sources compiled.
  2893. </para>
  2894. </answer>
  2895. </qandaentry>
  2896. <qandaentry>
  2897. <question id="q:ajdocneeds13"
  2898. xreflabel="Q:I'm running under 1.4, but ajdoc asks for 1.3 (or throws IllegalAccessError for HtmlWriter.configuration)">
  2899. <para>
  2900. I'm running under 1.4, but <literal>ajdoc</literal> asks for 1.3
  2901. (or throws IllegalAccessError for HtmlWriter.configuration)
  2902. </para>
  2903. </question>
  2904. <answer>
  2905. <para>
  2906. The current implementation of <literal>ajdoc</literal> uses
  2907. specific javadoc classes in the J2SE 1.3 tools.jar.
  2908. We are working on addressing this limitation, but in the interim
  2909. it is best to run ajdoc under 1.3.
  2910. </para>
  2911. <para>
  2912. When running from the command-line scripts, edit the scripts directly
  2913. to put the 1.3 tools.jar first on the classpath. (The installer does
  2914. not know about this limitation of ajdoc.)
  2915. </para>
  2916. <para>
  2917. When running from Ant, users often have tools.jar in ${ant.classpath}
  2918. (to make javac, et al work). That makes it impossible to run the ajdoc
  2919. taskdef (which does not currently support forking), so you'll need to
  2920. run a separate ant process, either from the command-line or via Ant's
  2921. exec task (the Ant task will propagate the classpath).
  2922. If the wrong tools.jar is not on the ant classpath, then it should work
  2923. to put the 1.3 tools.jar in the taskdef classpath.
  2924. </para>
  2925. </answer>
  2926. </qandaentry>
  2927. <qandaentry>
  2928. <question id="q:compileunits"
  2929. xreflabel="Q:I set up different files to my compiles to change what the aspects see, but now I don't understand how the aspects are working?">
  2930. <para>I set up different files to my compiles to change what
  2931. the aspects see, but now I don't
  2932. understand how the aspects are working.
  2933. </para>
  2934. </question>
  2935. <answer>
  2936. <para>It is a bad practice to use the compilation unit
  2937. to control crosscutting. Aspects and pointcuts especially
  2938. should be written to specify crosscutting precisely.
  2939. Aspects will behave the same when you add files if
  2940. you initially included all files affected by your aspects.
  2941. If you use the compilation unit, then your code will behave
  2942. differently in AspectJ implementations that do not limit
  2943. themselves to specified files.
  2944. </para>
  2945. </answer>
  2946. </qandaentry>
  2947. <qandaentry>
  2948. <question id="q:readingpreprocessedcode"
  2949. xreflabel="Q:I'm reading the code generated by ajc in -preprocess mode, and it seems like it would not work.">
  2950. <para>I'm reading the code generated by <literal>ajc</literal>
  2951. in <literal>-preprocess</literal> mode, and it seems like it would not
  2952. work (or "like it works this way").
  2953. </para>
  2954. </question>
  2955. <answer>
  2956. <para>The generated code can be difficult for a human to read and
  2957. understand. The compiler uses implementation techniques which might
  2958. not be apparent. To determine if the code is behaving correctly, you
  2959. should write and run a program that attempts to provoke the error you
  2960. suspect. Similarly, you should not rely on invariants you infer from
  2961. the generated code (especially naming conventions for generated members).
  2962. Please rely only on the semantics stated in the appendix of the
  2963. AspectJ <ulink url="progguide/index.html">Programming Guide</ulink>.
  2964. </para>
  2965. </answer>
  2966. </qandaentry>
  2967. <qandaentry>
  2968. <question id="q:injection"
  2969. xreflabel="Q:I've heard AspectJ can generate or inject code into my code. Is this true?">
  2970. <para>I've heard AspectJ can generate or inject code into my code.
  2971. Is this true?
  2972. </para>
  2973. </question>
  2974. <answer>
  2975. <para>
  2976. This is a misconception spawned from the early implementation.
  2977. </para>
  2978. <para>
  2979. AspectJ does not "inject" or "generate" code. In AspectJ the
  2980. pointcut constructs allow the programmer to identify join points,
  2981. and the advice constructs define additional code to run at those
  2982. join points.
  2983. </para>
  2984. <para>
  2985. So the semantic model of advice is like the semantic model of a
  2986. method -- it says "when any of these things happen, do this".
  2987. </para>
  2988. <para>
  2989. People who worked with earlier versions of AspectJ, in which ajc
  2990. was very explicitly a pre-processor, sometimes thought of AspectJ
  2991. as injecting code. But that was an artifact of the implementation,
  2992. not the underlying language semantics.
  2993. </para>
  2994. <para>
  2995. This distinction is important for two reasons. One is that thinking
  2996. about it this way will make more sense at the implementation continues
  2997. to evolve towards load-time or runtime weaving. The other is that
  2998. it makes it much easier to understand the semantics of advice on
  2999. cflow pointcuts.
  3000. </para>
  3001. </answer>
  3002. </qandaentry>
  3003. <qandaentry>
  3004. <question id="q:currentbugs"
  3005. xreflabel="Q:What are the bugs now most affecting users?">
  3006. <para>What are the bugs now most affecting users?</para>
  3007. </question>
  3008. <answer>
  3009. <itemizedlist>
  3010. <listitem>
  3011. <para>
  3012. </para>
  3013. </listitem>
  3014. </itemizedlist>
  3015. </answer>
  3016. </qandaentry>
  3017. </qandadiv>
  3018. <qandadiv id="aj11" xreflabel="AspectJ 1.1 and eclipse.org">
  3019. <title>AspectJ 1.1 and eclipse.org</title>
  3020. <qandaentry>
  3021. <question id="q:whyeclipse"
  3022. xreflabel="Q:Why did the AspectJ project move to eclipse.org?">
  3023. <para>Why did the AspectJ project move to eclipse.org?
  3024. </para>
  3025. </question>
  3026. <answer>
  3027. <para>From the message sent to users:
  3028. </para>
  3029. <para>
  3030. AspectJ has come a long way -- the language has
  3031. stabilized; there are a rapidly growing number of
  3032. commercial users; the 1.1 release is imminent and will
  3033. include byte-code weaving and incremental compilation;
  3034. and the tool support is now well integrated with several
  3035. major IDEs.
  3036. </para>
  3037. <para>
  3038. This growth of the community and the technology means
  3039. that the original research and prototype development of
  3040. AspectJ is complete. As such it is time for ongoing
  3041. development and support of AspectJ to move outside of
  3042. PARC. This has already started to happen; the Eclipse
  3043. AJDT plug-in and the several books in preparation are
  3044. examples.
  3045. </para>
  3046. <para>
  3047. To encourage the growth of the AspectJ technology and
  3048. community, PARC is transferring AspectJ to an
  3049. openly-developed eclipse.org project. This project will
  3050. include documentation, web site, mailing lists, bug
  3051. database, and sources for the compiler. The
  3052. command-line AspectJ compiler is still the primary tool
  3053. produced by this project, in addition to APIs that support
  3054. integration with a variety of IDEs. The Eclipse plug-in will
  3055. remain at eclipse.org, while the NetBeans, JBuilder and
  3056. Emacs support will move to SourceForge.net projects.
  3057. We look forward to your involvement with and
  3058. contribution to those projects.
  3059. </para>
  3060. <para>
  3061. We see Eclipse as an excellent new home for core
  3062. AspectJ technology development -- it is an active
  3063. community of Open Source development and innovation
  3064. in the Java space. Once development moves to
  3065. Eclipse.org, others will be able to contribute more easily.
  3066. </para>
  3067. </answer>
  3068. </qandaentry>
  3069. <qandaentry>
  3070. <question id="q:eclipserequired"
  3071. xreflabel="Q:Do I have to download Eclipse to use AspectJ?">
  3072. <para>Do I have to download Eclipse to use AspectJ?
  3073. </para>
  3074. </question>
  3075. <answer>
  3076. <para>No. The AspectJ tools download is completely self-contained
  3077. and does not require that you work in Eclipse.
  3078. For information on IDE support, see
  3079. <xref linkend="q:integrateWithDevTools"/>.
  3080. </para>
  3081. </answer>
  3082. </qandaentry>
  3083. <qandaentry>
  3084. <question id="q:contributions"
  3085. xreflabel="Q:What can I do to help on the AspectJ project?">
  3086. <para>What can I do to help on the AspectJ project?
  3087. </para>
  3088. </question>
  3089. <answer>
  3090. <para>Here's a general list, in no particular order:
  3091. <itemizedlist>
  3092. <listitem>
  3093. <para>Participate effectively in the mailing lists.
  3094. The quality of the mailing lists makes a big difference
  3095. in the ability of new and experienced AspectJ users
  3096. to write good code. For guidance on effective
  3097. participation, see
  3098. <xref id="q:talktousers"/> and
  3099. <xref id="q:writingbugsandemails"/>.
  3100. </para>
  3101. </listitem>
  3102. <listitem>
  3103. <para>Write test cases for compiler bugs without test cases.
  3104. Compiler bugs without test cases are much less likely to be fixed;
  3105. until they are rendered in code, they might be user mistakes,
  3106. and they might duplicate another bug or actually cover many bugs.
  3107. </para>
  3108. <para>Find them by searching open compiler bugs and picking out
  3109. any which do not have test case attachments or a comment that
  3110. a test case has been written.
  3111. Here is a query for open compiler bugs:
  3112. <!-- ulink gacks on the = next - quote it -->
  3113. <ulink url="http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&amp;component=Compiler&amp;bug_status=UNCONFIRMED&amp;bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED">
  3114. http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&amp;component=Compiler&amp;bug_status=UNCONFIRMED&amp;bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED
  3115. </ulink>
  3116. </para>
  3117. <para>For how to write test cases, see
  3118. <xref linkend="q:harnesstestcases"/>.
  3119. </para>
  3120. </listitem>
  3121. </itemizedlist>
  3122. </para>
  3123. </answer>
  3124. </qandaentry>
  3125. <qandaentry>
  3126. <question id="q:harnesstestcases"
  3127. xreflabel="Q:How should I submit test cases for bugs?">
  3128. <para>How should I submit test cases for bugs?
  3129. </para>
  3130. </question>
  3131. <answer>
  3132. <para>You can attach files to a bug after it has been created.
  3133. The code of course should replicate the actual behavior
  3134. described in the bug when run on the target version.
  3135. If you have a single source file, you can attach it directly,
  3136. describing in the comments the expected result
  3137. (e.g., error on line 14, or successful compile/run).
  3138. The most helpful form for describing the test scenario
  3139. and the expected results are the test definitions
  3140. described next.
  3141. </para>
  3142. <para>For more complex bugs requiring many files,
  3143. create a zip file of a directory containing all the files
  3144. and an XML test definition file.
  3145. The XML test definition file contains specifications
  3146. for how to compile, recompile, or run the test sources.
  3147. Complete documentation is available in the CVS tree
  3148. at <literal>tests/readme-writing-compiler-tests.html</literal>
  3149. but here is a sample file with some example definitions,
  3150. preceded by comments showing the directory layout
  3151. of the files referred to in the test definitions.
  3152. </para>
  3153. <para>
  3154. <programlisting>
  3155. <![CDATA[
  3156. <!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd">
  3157. <suite>
  3158. <!-- Compile and run
  3159. using the following files:
  3160. {testDefinitions}.xml
  3161. one/
  3162. pack1/
  3163. Main.java
  3164. p2/
  3165. BeforeConstructor.java
  3166. Note the bug number goes in the pr attribute
  3167. ("pr" for "problem report");
  3168. -->
  3169. <ajc-test dir="one" pr="234" title="before constructor call">
  3170. <compile files="pack1/Main.java,p2/BeforeConstructor.java"/>
  3171. <run class="pack1.Main"/>
  3172. </ajc-test>
  3173. <!-- Check that compiler warning was emitted
  3174. using the following files:
  3175. {testDefinitions}.xml
  3176. two/
  3177. UsesDeprecated.java
  3178. -->
  3179. <ajc-test dir="two" pr="244" title="deprecated, noImportError">
  3180. <compile options="-warn:deprecated,-noImportError"
  3181. files="UsesDeprecated.java">
  3182. <message kind="warning" line="20"/>
  3183. </compile>
  3184. </ajc-test>
  3185. <!-- Cooked example that uses all compiler attributes
  3186. and the following files:
  3187. {testDefinitions}.xml
  3188. testCaseDir/
  3189. jars/
  3190. injar.jar
  3191. required.jar
  3192. requiredAspects.jar
  3193. pack/
  3194. Main.java
  3195. providedClassesDir/
  3196. ClassInDefaultPackage.class
  3197. org/
  3198. foo/
  3199. AnotherRequired.class
  3200. -->
  3201. <ajc-test dir="testCaseDir" title="attributes test">
  3202. <compile files="pack/Main.java,jars/injar.jar"
  3203. staging="true"
  3204. options="-Xlint,-g:none"
  3205. argfiles="debug.lst,aspects/test.lst"
  3206. aspectpath="jars/requiredAspects.jar"
  3207. classpath="providedClassesDir,jars/required.jar"/>
  3208. <run class="Main"/>
  3209. </ajc-test>
  3210. <!-- Compiler errors, recompile after changing files, and run
  3211. using the following files:
  3212. {testDefinitions}.xml
  3213. three/
  3214. pack/
  3215. IncCompileFix.java
  3216. IncCompileFix.20.java
  3217. Before compiling, IncCompileFix.java is copied to a staging
  3218. directory. Before recompiling, IncCompileFix.20.java
  3219. replaces it, so the compiler treats file as updated.
  3220. -->
  3221. <ajc-test dir="three" pr="622" title="incremental fix">
  3222. <compile staging="true" files="pack/IncCompileFix.java">
  3223. <message kind="error" line="20"/>
  3224. <message kind="error" line="42"/>
  3225. </compile>
  3226. <inc-compile tag="20"/>
  3227. <run class="pack.IncCompileFix"/>
  3228. </ajc-test>
  3229. </suite>
  3230. ]]>
  3231. </programlisting>
  3232. </para>
  3233. </answer>
  3234. </qandaentry>
  3235. <qandaentry>
  3236. <question id="q:buildingsource"
  3237. xreflabel="Q:How do I get and compile the source code for AspectJ?">
  3238. <para>How do I get and compile the source code for AspectJ?
  3239. </para>
  3240. </question>
  3241. <answer>
  3242. <para>AspectJ 1.1 source code is available through CVS using the CVS Root
  3243. <literal>dev.eclipse.org:/home/technology</literal>. For more information
  3244. on accessing the CVS tree at eclipse.org, see the documentation
  3245. from <ulink url="http://eclipse.org">http://eclipse.org</ulink>.
  3246. </para>
  3247. <para>The AspectJ tree is organized into modules as follows:
  3248. <programlisting>
  3249. org.aspectj/
  3250. modules/
  3251. ajbrowser/
  3252. ajde/
  3253. ...
  3254. </programlisting>
  3255. </para>
  3256. <para>
  3257. You can check out the entire modules directory and build using the
  3258. Ant build script <literal>modules/build/build.xml</literal>.
  3259. All required libraries are included in <literal>modules/lib/</literal>,
  3260. (including Ant 1.5.1 in <literal>modules/lib/ant</literal>).
  3261. If you are using Eclipse, you can check out any <literal>modules/</literal>
  3262. subdirectory as an eclipse Java project.
  3263. Depending on what you are trying to build, you need not check out
  3264. all modules; as of this writing, here are the modules to get
  3265. when trying to build something:
  3266. </para>
  3267. <para>
  3268. <itemizedlist>
  3269. <listitem>For any builds: build, lib
  3270. </listitem>
  3271. <listitem>For the documentation: docs
  3272. </listitem>
  3273. <listitem>For the compiler: bridge, util, testing-util,
  3274. weaver, asm, org.eclipse.jdt.core, org.aspectj.ajdt.core,
  3275. and runtime.
  3276. </listitem>
  3277. <listitem>For ajbrowser: the compiler modules, plus
  3278. ajbrowser, taskdefs, and ajde.
  3279. </listitem>
  3280. <listitem>For the test harness: the ajbrowser modules, plus
  3281. testing, testing-client, and testing-drivers.
  3282. </listitem>
  3283. <listitem>To run the test suite: the test harness modules, plus
  3284. tests.
  3285. </listitem>
  3286. </itemizedlist>
  3287. </para>
  3288. <para>
  3289. Note that module interdependencies are recorded only in the eclipse
  3290. <literal>modules/{module}/.classpath
  3291. </literal>
  3292. files and may
  3293. change, so the list above may not be correct when you read it.
  3294. </para>
  3295. </answer>
  3296. </qandaentry>
  3297. <qandaentry>
  3298. <question id="q:testharness"
  3299. xreflabel="Q:I'd like to run my test case. How do I get the test harness?">
  3300. <para>I'd like to run my test case. How do I get the test harness?
  3301. </para>
  3302. </question>
  3303. <answer>
  3304. <para>The test harness is not distributed
  3305. (though we may put it on an AspectJ page.)
  3306. To build it, get the source tree as
  3307. described in <xref linkend="q:buildingsource"/> and then
  3308. build the <literal>build-testing-drivers</literal> target:
  3309. <programlisting>
  3310. cd build
  3311. ../lib/ant/bin/ant -f build.xml build-testing-drivers
  3312. </programlisting>
  3313. This produces
  3314. <literal>../aj-build/jars/testing-drivers-all.jar</literal>
  3315. which you can run as described in
  3316. <literal>tests/readme-tests-module.html</literal>.
  3317. </para>
  3318. </answer>
  3319. </qandaentry>
  3320. </qandadiv>
  3321. <qandadiv id="help" xreflabel="Getting Help">
  3322. <title>Getting Help</title>
  3323. <qandaentry>
  3324. <question id="q:moreaboutaj"
  3325. xreflabel="Q:How do I find out more about AspectJ?">
  3326. <para>
  3327. How do I find out more about AspectJ?
  3328. </para>
  3329. </question>
  3330. <answer>
  3331. <para>Visit the AspectJ project web site:
  3332. <ulink url="http://eclipse.org/aspectj">http://eclipse.org/aspectj</ulink>.
  3333. </para>
  3334. </answer>
  3335. </qandaentry>
  3336. <qandaentry>
  3337. <question id="q:bugreports"
  3338. xreflabel="Q:How do I submit a bug report?">
  3339. <para>How do I submit a bug report?</para>
  3340. </question>
  3341. <answer>
  3342. <para>You can submit a bug from
  3343. <ulink url="http://dev.eclipse.org/bugs/enter_bug.cgi?product=AspectJ">
  3344. http://dev.eclipse.org/bugs/enter_bug.cgi?product=AspectJ
  3345. </ulink>.
  3346. If it seems to be a bug in the compiler,
  3347. please attach a small test case (source code)
  3348. to reproduce the problem.
  3349. For more information on writing compiler test cases, see
  3350. <xref linkend="q:ajcbugs"/>.
  3351. </para>
  3352. </answer>
  3353. </qandaentry>
  3354. <qandaentry>
  3355. <question id="q:talktousers"
  3356. xreflabel="Q:How do I communicate with other AspectJ users?">
  3357. <para>
  3358. How do I communicate with other AspectJ users?
  3359. </para>
  3360. </question>
  3361. <answer>
  3362. <para>You can reach other AspectJ users by using the
  3363. aspectj-users mailing list. You can subscribe to the list or view the
  3364. list archives from the AspectJ home page
  3365. <ulink url="http://eclipse.org/aspectj">
  3366. http://eclipse.org/aspectj
  3367. </ulink>.
  3368. </para>
  3369. </answer>
  3370. </qandaentry>
  3371. <qandaentry>
  3372. <question id="q:searchingsite"
  3373. xreflabel="Q:How can I search the email archives or the web site?">
  3374. <para>
  3375. How can I search the email archives or the web site?
  3376. </para>
  3377. </question>
  3378. <answer>
  3379. <para>
  3380. It is generally most effective to do a google search of the form,
  3381. <ulink url="http://www.google.com/search?q=site:eclipse.org+cflowbelow">
  3382. http://www.google.com/search?q=site:eclipse.org+cflowbelow
  3383. </ulink>
  3384. but this may not get results inside the mail archives.
  3385. Be sure to check the old archives available for download from
  3386. the AspectJ home page. <ulink url="http://eclipse.org/aspectj">
  3387. http://eclipse.org/aspectj
  3388. </ulink>.
  3389. </para>
  3390. </answer>
  3391. </qandaentry>
  3392. <qandaentry>
  3393. <question id="q:writingbugsandemails"
  3394. xreflabel="Q:How should I write email queries?">
  3395. <para>
  3396. How should I write email queries?
  3397. </para>
  3398. </question>
  3399. <answer>
  3400. <para>Here's the general form of a good email:
  3401. </para>
  3402. <orderedlist>
  3403. <listitem>
  3404. <para>
  3405. Describe the big picture of what you are trying to do...
  3406. </para>
  3407. </listitem>
  3408. <listitem>
  3409. <para>
  3410. Describe what you think it takes, in AspectJ terms
  3411. (concepts, syntax, and semantics) from the
  3412. <ulink url="progguide/index.html">Programming Guide</ulink>...
  3413. </para>
  3414. </listitem>
  3415. <listitem>
  3416. <para>
  3417. Show the AspectJ code you are using, what output it
  3418. produces when run, and what output you expect...
  3419. </para>
  3420. </listitem>
  3421. </orderedlist>
  3422. <para>
  3423. The big picture helps others redirect you to other approaches.
  3424. Using AspectJ terms helps others correct mistakes in thinking
  3425. about the problem (the most common being to confuse join points
  3426. and pointcuts).
  3427. The code is key to clarifying your question and getting a good
  3428. response. On the mail list, someone can reply by fixing your
  3429. code. In bugs, the developers can reproduce the problem immediately
  3430. and start analyzing the fix.
  3431. The code should not be incomplete; it should run (or fail) as-is,
  3432. without additional libraries or source files.
  3433. </para>
  3434. <para>
  3435. For the mail lists, we try to follow the conventions for open-source
  3436. discussions that help avoid "the tragedy of the commons."
  3437. For example conventions, see
  3438. <ulink url="http://jakarta.apache.org/site/mail.html">
  3439. http://jakarta.apache.org/site/mail.html
  3440. </ulink> and
  3441. <ulink url="http://www.tuxedo.org/%7Eesr/faqs/smart-questions.html">
  3442. http://www.tuxedo.org/%7Eesr/faqs/smart-questions.html
  3443. </ulink>.
  3444. </para>
  3445. </answer>
  3446. </qandaentry>
  3447. <qandaentry>
  3448. <question id="q:idebugs"
  3449. xreflabel="Q:How do I write bugs for the IDE support?">
  3450. <para>
  3451. How do I write bugs for IDE support?
  3452. </para>
  3453. </question>
  3454. <answer>
  3455. <para>
  3456. Bugs appearing in the IDE's may apply to the affected IDE
  3457. or to the compiler. Compiler stack traces in IDE message windows
  3458. are prefixed "Internal Compiler Error" and should be written up
  3459. as compiler bugs. If you are unsure, try redoing the compile
  3460. from the command line.
  3461. </para>
  3462. <para>
  3463. Bug report for the IDE extensions go to their respective projects,
  3464. listed in
  3465. <xref linkend="q:integrateWithDevTools"/>
  3466. (including bug reports for the AJDE Eclipse support,
  3467. which you can submit at
  3468. <ulink url="http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AJDT">
  3469. http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AJDT
  3470. </ulink>).
  3471. </para>
  3472. <para>
  3473. Bug reports on ajbrowser should have version
  3474. information for both Java and AspectJ, and
  3475. (most importantly) clear steps for reproducing the bug.
  3476. You may submit ajbrowser bugs against the IDE component of AspectJ
  3477. via the web form
  3478. <ulink url="http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ">
  3479. http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ
  3480. </ulink>.
  3481. </para>
  3482. <para>
  3483. One of the benefits of open-source is that you can
  3484. find and fix the bug for yourself; when you submit
  3485. the fix back to us, we can validate the fix for you
  3486. and incorporate it into the next release.
  3487. You can submit a patch by attaching it to the bug.
  3488. </para>
  3489. </answer>
  3490. </qandaentry>
  3491. <qandaentry>
  3492. <question id="q:ajcbugs"
  3493. xreflabel="Q:How do I write bugs for the AspectJ compiler?">
  3494. <para>
  3495. How do I write bugs for the AspectJ compiler?
  3496. </para>
  3497. </question>
  3498. <answer>
  3499. <para>
  3500. The best compiler bug report is a reproducible test case,
  3501. standalone code that demonstrates the problem.
  3502. Sometimes with aspects, a test case requires several
  3503. files, if not some way to capture the behavior.
  3504. Here's how we recommend submitting test cases:
  3505. <orderedlist>
  3506. <listitem>
  3507. <para>
  3508. Write the test case so that when the compiler bug
  3509. is fixed, the test completes normally without output
  3510. (e.g., expected compiler errors are issued,
  3511. or classes produced run correctly). This usually
  3512. means writing one or more source files.
  3513. </para>
  3514. </listitem>
  3515. <listitem>
  3516. <para>
  3517. In the bug report, briefly summarize the bug.
  3518. If it is not obvious, be sure to specify
  3519. the expected output/behavior (e.g., compiler error on line 32)
  3520. and, if the compile should complete, the main class to run.
  3521. </para>
  3522. </listitem>
  3523. <listitem>
  3524. <para>
  3525. Submit the bugs via the web form
  3526. <ulink url="http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ">
  3527. http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ
  3528. </ulink>.
  3529. </para>
  3530. </listitem>
  3531. <listitem>
  3532. <para>Attach the test case to the bug.
  3533. The test case may be a single file
  3534. or it may be multiple files in a single zip archive,
  3535. of the form discussed in
  3536. <xref linkend="q:harnesstestcases"/>.
  3537. </para>
  3538. </listitem>
  3539. </orderedlist>
  3540. </para>
  3541. </answer>
  3542. </qandaentry>
  3543. <qandaentry>
  3544. <question id="q:teachingmaterials"
  3545. xreflabel="Q:Can you recommend reading or teaching material for AspectJ?">
  3546. <para>
  3547. Can you recommend reading or teaching material for AspectJ?
  3548. </para>
  3549. </question>
  3550. <answer>
  3551. <para>The documentation available in the distribution is the
  3552. best source for language and usage questions. You can also find
  3553. selected AspectJ papers and presentations on the
  3554. <ulink url="http://www.parc.com/groups/csl/projects/aspectj/index.html">
  3555. PARC AspectJ page</ulink>.
  3556. For links to Aspect-oriented programming materials in general, see
  3557. <ulink url="http://aosd.net">http://aosd.net</ulink>.
  3558. </para>
  3559. </answer>
  3560. </qandaentry>
  3561. <qandaentry>
  3562. <question id="q:consulting"
  3563. xreflabel="Q:Where can our group get consulting and support?">
  3564. <para>
  3565. Where can our group get consulting and support?
  3566. </para>
  3567. </question>
  3568. <answer>
  3569. <para>The best thing to to is join and email the
  3570. <literal>aspectj-dev@eclipse.org</literal> mailing list.
  3571. </para>
  3572. </answer>
  3573. </qandaentry>
  3574. <qandaentry>
  3575. <question id="q:faqchanges"
  3576. xreflabel="Q:What has changed since the last FAQ version?">
  3577. <para>
  3578. What has changed since the last FAQ version?
  3579. </para>
  3580. </question>
  3581. <answer>
  3582. <para>
  3583. The FAQ has been updated to reflect the move to eclipse.org;
  3584. but some answers apply to the released 1.0 version
  3585. rather than the 1.1 version in development.
  3586. Entries changes to reflect the move are not listed here.
  3587. Other entries changed since the earlier November 26 version:
  3588. <itemizedlist>
  3589. <listitem><para><xref linkend="q:adviseconstructors"/></para></listitem>
  3590. <listitem><para><xref linkend="q:whyeclipse"/></para></listitem>
  3591. <listitem><para><xref linkend="q:eclipserequired"/></para></listitem>
  3592. <listitem><para><xref linkend="q:contributions"/></para></listitem>
  3593. <listitem><para><xref linkend="q:harnesstestcases"/></para></listitem>
  3594. <listitem><para><xref linkend="q:buildingsource"/></para></listitem>
  3595. <listitem><para><xref linkend="q:testharness"/></para></listitem>
  3596. <listitem><para><xref linkend="q:integrateWithDevTools"/></para></listitem>
  3597. <listitem><para><xref linkend="q:versioninfo"/></para></listitem>
  3598. </itemizedlist>
  3599. </para>
  3600. </answer>
  3601. </qandaentry>
  3602. </qandadiv>
  3603. <qandadiv id="project" xreflabel="About the AspectJ Project">
  3604. <title>About the AspectJ Project</title>
  3605. <qandaentry>
  3606. <question id="q:opensource"
  3607. xreflabel="Q:What does the fact that AspectJ is an Open Source Project mean to me?">
  3608. <para>What does the fact that AspectJ is an Open Source
  3609. Project mean to me?
  3610. </para>
  3611. </question>
  3612. <answer>
  3613. <para>Open source protects your interest in a correct, long-lived,
  3614. up-to-date, and widely-accepted implementation of AspectJ.
  3615. <itemizedlist>
  3616. <listitem>
  3617. <para>With the source code, you control your own destiny
  3618. in perpetuity. You can continue to use the implementation
  3619. and update it as necessary to fix bugs and add things you need.
  3620. </para>
  3621. </listitem>
  3622. <listitem>
  3623. <para>Because the code is available to all, anyone can find
  3624. and fix bugs. There is no need to hope for it to be fixed
  3625. in the next product release. Those who encounter the bugs
  3626. are motivated to fix them, and there are more eyeballs on
  3627. the code than in closed-source, so the quality tends to be high.
  3628. This can be particularly true for the AspectJ community,
  3629. which tends to be highly skilled.
  3630. </para>
  3631. </listitem>
  3632. <listitem>
  3633. <para>The same is true of new features or behavior, so the
  3634. implementation should be up-to-date. This is important as
  3635. the field of AOP develops, to capture the latest solutions.
  3636. </para>
  3637. </listitem>
  3638. <listitem>
  3639. <para>For a programming language which forms the basis of
  3640. an entire solution stack, open source facilitates the kind
  3641. of adoption -- tool integrations and significant projects --
  3642. that develop and prove the technology for wider adoption. This
  3643. limits delays caused by waiting for the completion of standards
  3644. process or promulgation by industry leaders, and also provides
  3645. the proofs necessary for such adoption.
  3646. </para>
  3647. </listitem>
  3648. </itemizedlist>
  3649. </para>
  3650. </answer>
  3651. </qandaentry>
  3652. <qandaentry>
  3653. <question id="q:standardization"
  3654. xreflabel="Q:What are your plans to make AspectJ a general feature of Java supported by Sun and the other key-players in the Java Industry?">
  3655. <para>What are your plans to make AspectJ a general feature
  3656. of Java supported by Sun and the other key players in the Java
  3657. Industry?
  3658. </para>
  3659. </question>
  3660. <answer>
  3661. <para>Although we are committed to making AspectJ available to a wide
  3662. range of users, it is too early to decide on a strategy. Some
  3663. options include continuing AspectJ as a stand-alone product,
  3664. integrating it into IDEs, or possibly incorporating it into
  3665. standard Java with Sun's blessing.
  3666. </para>
  3667. <para>We currently focus on developing for the 1.1 implementation
  3668. which improves AspectJ in key areas: rapid
  3669. incremental compilation, bytecode weaving, and IDE integration.
  3670. </para>
  3671. <para>Through all of this our goal is to make AspectJ integrate as
  3672. seamlessly as possible with the Java programming language. The
  3673. AspectJ language design is becoming more integrated, the compiler
  3674. is becoming faster and more integrated, the IDE extensions are
  3675. becoming more integrated. All of this is designed to help users
  3676. really use AspectJ and give us feedback on it.
  3677. </para>
  3678. <para>As the system is improved and we work more closely
  3679. with users, we will be in good position to explore the best path
  3680. for AspectJ in the long term.
  3681. </para>
  3682. </answer>
  3683. </qandaentry>
  3684. <qandaentry>
  3685. <question id="q:bytecodeweaving"
  3686. xreflabel="Q:When will AspectJ work from class files? When will it work at class-loading time?">
  3687. <para>When will AspectJ work from class files?
  3688. When will it work at class-loading time?
  3689. </para>
  3690. </question>
  3691. <answer>
  3692. <para>Bytecode weaving is scheduled for AspectJ 1.1. We believe it
  3693. will work as described in an email to the users list by Jim Hugugin:
  3694. </para>
  3695. <para>
  3696. The AspectJ language was designed to support weaving at many different times:
  3697. compile, load, or even run-time in the JVM. Weaving into bytecodes at both
  3698. compile and load-time will definitely be provided in a future release. This
  3699. will allow weaving at compile-time into libraries for which source code is
  3700. not available. It will also support aspect-aware class loaders that can
  3701. perform weaving at load time on arbitrary classes. One advantage of a
  3702. language like AspectJ, rather than an explicit meta-tool like jiapi, is
  3703. that it separates the specification of a crosscutting concern from any
  3704. particular implementation strategy for weaving.
  3705. </para>
  3706. <para>
  3707. ...AspectJ provides a language that can cleanly
  3708. capture crosscutting concerns while preserving the static type checking,
  3709. modularity, and composability of Java.
  3710. </para>
  3711. <para>If you have an application for using aspects and bytecode,
  3712. please let the AspectJ team know of your requirements.
  3713. </para>
  3714. </answer>
  3715. </qandaentry>
  3716. <qandaentry>
  3717. <question id="q:differences"
  3718. xreflabel="Q:What are the differences between the current and previously released versions of AspectJ?">
  3719. <para>What are the differences between the current and
  3720. previously released versions of AspectJ?
  3721. </para>
  3722. </question>
  3723. <answer>
  3724. <para>The AspectJ team aims to keep the implementation up-to-date
  3725. and bug-free, but to limit language changes to those that
  3726. are carefully considered, compelling, and backwards-compatible,
  3727. and to deliver those language changes only in significant releases (1.0, 1.1).
  3728. </para>
  3729. <table>
  3730. <title></title>
  3731. <tgroup cols="2">
  3732. <tbody>
  3733. <row>
  3734. <entry align="left">Version</entry>
  3735. <entry align="left">Description</entry>
  3736. </row>
  3737. <row>
  3738. <entry>AspectJ 1.0</entry>
  3739. <entry>Many language changes, fixes, cleanup and
  3740. clarifications, some significant.
  3741. </entry>
  3742. </row>
  3743. <row>
  3744. <entry>AspectJ 0.8</entry>
  3745. <entry>More cleanup of the syntax and semantics.</entry>
  3746. </row>
  3747. <row>
  3748. <entry>AspectJ 0.7</entry>
  3749. <entry>Clean up of the semantics, 0.7 beta 4 is the first
  3750. open source release.
  3751. </entry>
  3752. </row>
  3753. <row>
  3754. <entry>AspectJ 0.6</entry>
  3755. <entry>Advice and crosscuts get explicit type signatures
  3756. which describe the values that are available to advice at a
  3757. crosscut.
  3758. </entry>
  3759. </row>
  3760. <row>
  3761. <entry>AspectJ 0.5</entry>
  3762. <entry>Improved tool support: better Emacs environment
  3763. support and <literal>ajdoc</literal> to parallel
  3764. <literal>javadoc</literal>. around advice is added, and the
  3765. <literal>aspect</literal> keyword is removed and replaced
  3766. by the Java keyword class.
  3767. </entry>
  3768. </row>
  3769. <row>
  3770. <entry>AspectJ 0.4</entry>
  3771. <entry>Clear separation of crosscuts and crosscut actions
  3772. makes it possible to define extensible library
  3773. aspects.
  3774. </entry>
  3775. </row>
  3776. <row>
  3777. <entry>AspectJ 0.3</entry>
  3778. <entry>First all Java implementation, also includes many
  3779. small language improvements.
  3780. </entry>
  3781. </row>
  3782. <row>
  3783. <entry>AspectJ 0.2</entry>
  3784. <entry>General-purpose support for crosscutting. Users could
  3785. program any kind of aspects, not just coordination. This
  3786. release dropped COOL.
  3787. </entry>
  3788. </row>
  3789. <row>
  3790. <entry>AspectJ 0.1</entry>
  3791. <entry>A single domain-specific aspect language, called COOL,
  3792. for programming coordination in multi-threaded
  3793. programs.
  3794. </entry>
  3795. </row>
  3796. </tbody>
  3797. </tgroup>
  3798. </table>
  3799. <para> More detailed comments are available in the
  3800. <literal>doc/changes.html</literal> file in the
  3801. distribution.
  3802. </para>
  3803. </answer>
  3804. </qandaentry>
  3805. <qandaentry>
  3806. <question id="q:schedule"
  3807. xreflabel="Q:What is the AspectJ development schedule?">
  3808. <para>
  3809. What is the AspectJ development schedule?
  3810. </para>
  3811. </question>
  3812. <answer>
  3813. <table>
  3814. <title>The AspectJ Development Schedule</title>
  3815. <tgroup cols="2">
  3816. <tbody>
  3817. <row>
  3818. <entry align="left">Version</entry>
  3819. <entry align="left">Description</entry>
  3820. </row>
  3821. <row>
  3822. <entry valign="top" align="center">1.1</entry>
  3823. <entry>Language changes, bytecode weaving and incremental compilation.
  3824. </entry>
  3825. </row>
  3826. <row>
  3827. <entry valign="top" align="center">1.0</entry>
  3828. <entry>Final syntax and semantic changes. Standalone structure
  3829. browser. Complete documentation.
  3830. </entry>
  3831. </row>
  3832. <row>
  3833. <entry valign="top" align="center">1.1</entry>
  3834. <entry>Faster incremental compilation, bytecode weaving,
  3835. and a small number of language changes.</entry>
  3836. </row>
  3837. <row>
  3838. <entry valign="top" align="center">2.0</entry>
  3839. <entry>New, dynamic crosscuts (bytecode-only)</entry>
  3840. </row>
  3841. </tbody>
  3842. </tgroup>
  3843. </table>
  3844. </answer>
  3845. </qandaentry>
  3846. </qandadiv>
  3847. </qandaset>
  3848. <para>AspectJ is a registered trademark of Palo Alto Research Center, Incorporated (PARC).
  3849. Java and all Java-based marks are trademarks or registered trademarks of
  3850. Sun Microsystems, Inc. in the United States and other countries. All other
  3851. trademarks are the property of their respective owners.
  3852. </para>
  3853. </article>
  3854. <!--
  3855. Local variables:
  3856. compile-command: "java com.icl.saxon.StyleSheet -o faq.html faq.xml /usr/local/docbook/docbook-xsl-1.44/html/docbook.xsl"
  3857. fill-column: 79
  3858. sgml-local-ecat-files: faq.ced
  3859. End:
  3860. -->