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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844
  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,
  20. 2003 Contributors. All rights reserved.
  21. </para>
  22. <!-- todo Update me! -->
  23. <para>Last updated November 30, 2004
  24. </para>
  25. <para>
  26. For a list of recently-updated FAQ entries, see <xref linkend="q:faqchanges"/>
  27. </para>
  28. <qandaset defaultlabel="number">
  29. <qandadiv id="overview" xreflabel="Overview">
  30. <title>Overview</title>
  31. <qandaentry>
  32. <question id="q:whatisaj" xreflabel="Q:What is AspectJ?">
  33. <para>What is AspectJ?</para>
  34. </question>
  35. <answer>
  36. <para>
  37. AspectJ(tm) is a simple and practical extension to the
  38. Java(tm) programming
  39. language that adds to Java aspect-oriented programming (AOP)
  40. capabilities. AOP allows developers to reap the benefits of
  41. modularity for concerns that cut across the natural units of
  42. modularity. In object-oriented programs like Java, the natural unit
  43. of modularity is the class. In AspectJ, aspects modularize concerns that
  44. affect more than one class.
  45. </para>
  46. <para>You compile your program using the AspectJ compiler
  47. (perhaps using the supported development environments)
  48. and then run it,
  49. supplying a small (&lt; 100K) runtime library.
  50. </para>
  51. <para>The AspectJ technologies include
  52. a compiler (<literal>ajc</literal>),
  53. a debugger (<literal>ajdb</literal>),
  54. a documentation generator (<literal>ajdoc</literal>),
  55. a program structure browser (<literal>ajbrowser</literal>),
  56. and integration with
  57. Eclipse, Sun-ONE/Netbeans, GNU Emacs/XEmacs,
  58. JBuilder, and Ant.
  59. </para>
  60. </answer>
  61. </qandaentry>
  62. <qandaentry>
  63. <question id="q:benefits"
  64. xreflabel="Q:What are the benefits of using AspectJ?">
  65. <para>What are the benefits of using AspectJ?</para>
  66. </question>
  67. <answer>
  68. <para>AspectJ can be used to improve the modularity of software
  69. systems.
  70. </para>
  71. <para> Using ordinary Java, it can be difficult to modularize design
  72. concerns such as
  73. </para>
  74. <itemizedlist>
  75. <listitem><para>system-wide error-handling</para></listitem>
  76. <listitem><para>contract enforcement</para></listitem>
  77. <listitem><para>distribution concerns</para></listitem>
  78. <listitem><para>feature variations</para></listitem>
  79. <listitem><para>context-sensitive behavior</para></listitem>
  80. <listitem><para>persistence</para></listitem>
  81. <listitem><para>testing</para></listitem>
  82. </itemizedlist>
  83. <para>The code for these concerns tends to be spread out across the
  84. system. Because these concerns won't stay inside of any one module
  85. boundary, we say that they <emphasis>crosscut</emphasis> the
  86. system's modularity.
  87. </para>
  88. <para>AspectJ adds constructs to Java that enable the modular
  89. implementation of crosscutting concerns. This ability is
  90. particularly valuable because crosscutting concerns tend to be both
  91. complex and poorly localized, making them hard to deal with.
  92. </para>
  93. <!--
  94. <para>Initial studies have shown code size reductions of up to 40%
  95. and programmer productivity gains of 20%-40%. These studies were in
  96. an earlier version of the language and only for small sample sizes.
  97. So while the results are encouraging, they aren't conclusive. We
  98. intend to run a new set of studies once the current phase of
  99. language development stabilizes.</para>
  100. -->
  101. </answer>
  102. </qandaentry>
  103. <qandaentry>
  104. <question id="q:compability"
  105. xreflabel="Q:Can AspectJ work with any Java program?">
  106. <para>Can AspectJ work with any Java program?</para>
  107. </question>
  108. <answer>
  109. <para>AspectJ has been designed as a <emphasis>compatible</emphasis>
  110. extension to Java. By compatible, we mean
  111. </para>
  112. <informaltable frame="none">
  113. <tgroup cols="2">
  114. <tbody>
  115. <row>
  116. <entry align="right">
  117. <emphasis>upward compatible</emphasis>
  118. </entry>
  119. <entry>All legal Java programs are legal AspectJ
  120. programs.
  121. </entry>
  122. </row>
  123. <row>
  124. <entry align="right">
  125. <emphasis>platform
  126. compatible
  127. </emphasis>
  128. </entry>
  129. <entry>All legal AspectJ programs run on standard Java
  130. virtual machines.
  131. </entry>
  132. </row>
  133. <row>
  134. <entry align="right">
  135. <emphasis>tool
  136. compatible
  137. </emphasis>
  138. </entry>
  139. <entry>Existing tools can be extended to work with
  140. AspectJ.
  141. </entry>
  142. </row>
  143. <row>
  144. <entry align="right">
  145. <emphasis>programmer compatible</emphasis>
  146. </entry>
  147. <entry>Programming in AspectJ feels natural to Java
  148. programmers.
  149. </entry>
  150. </row>
  151. </tbody>
  152. </tgroup>
  153. </informaltable>
  154. <para>The AspectJ tools run on any Java 2 Platform compatible
  155. platform. The AspectJ compiler produces classes that run
  156. on any Java 1.1 (or later) compatible platform.
  157. </para>
  158. </answer>
  159. </qandaentry>
  160. <qandaentry>
  161. <question id="q:license" xreflabel="Q:How is AspectJ licensed?">
  162. <para>How is AspectJ licensed?</para>
  163. </question>
  164. <answer>
  165. <para>AspectJ 1.1 source code and documentation is available under the
  166. <ulink url="http://eclipse.org/legal/cpl-v10.html">Common Public License 1.0</ulink>.
  167. </para>
  168. <para>The AspectJ 1.0 tools are open-source software available under the
  169. <ulink url="http://www.opensource.org/licenses/mozilla1.1">Mozilla Public License 1.1</ulink>.
  170. That documentation is available under a separate license
  171. that precludes for-profit or commercial
  172. redistribution.
  173. </para>
  174. <para>Most users only want to use AspectJ to build programs they distribute.
  175. There are no restrictions here. When you distribute your program, be sure to
  176. include all the runtime classes from the aspectjrt.jar for that version of AspectJ.
  177. When distributing only the runtime classes, you need not provide any notice that
  178. the program was compiled with AspectJ or includes binaries from the AspectJ project,
  179. except as necessary to preserve the warranty disclaimers in our license.
  180. </para>
  181. <para>
  182. </para>
  183. </answer>
  184. </qandaentry>
  185. <qandaentry>
  186. <question id="q:project" xreflabel="Q:What is the AspectJ Project?">
  187. <para>What is the AspectJ Project?</para>
  188. </question>
  189. <answer>
  190. <para>AspectJ is based on over ten years of research at
  191. <ulink url="http://www.parc.xerox.com">
  192. Xerox Palo Alto Research Center
  193. </ulink>
  194. as funded by Xerox, a U.S. Government grant (NISTATP), and a
  195. DARPA contract.
  196. </para>
  197. <para>It has evolved through open-source releases
  198. to a strong user community and now operates as an
  199. open source project at
  200. <ulink url="http://eclipse.org/aspectj">
  201. http://eclipse.org/aspectj</ulink>
  202. The AspectJ team works closely with the community
  203. to ensure AspectJ continues to evolve as an effective
  204. aspect-oriented programming language and tool set.
  205. </para>
  206. <para>
  207. The latest release is 1.2 <!-- XXX todo Update me! -->
  208. which can be downloaded from the
  209. <ulink url="http://eclipse.org/aspectj">AspectJ project page</ulink>,
  210. including sources as described
  211. <xref linkend="q:buildingsource"/>.
  212. Development is focused on supporting applications,
  213. improving quality and performance,
  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 J2SE 1.3 or later to run,
  236. but the compiler can produce classes for 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://eclipse.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:dynamicaop"
  871. xreflabel="Q:How does AspectJ compare with more dynamic AOP?">
  872. <para>How does AspectJ compare with more dynamic AOP?
  873. </para>
  874. </question>
  875. <answer>
  876. <para>
  877. Some AOP techniques are presented as "dynamic" because the weaving
  878. occurs when classes are loaded, because aspects can be configured
  879. in a separate XML file before launch, or because some advice
  880. depends on runtime reflection. They are said to be more flexible
  881. than AspectJ.
  882. </para>
  883. <para>
  884. This is a misconception. First, the AspectJ 1.1 weaver has always
  885. supported weaving at compile-time or class-load-time. Weaving at
  886. compile-time reduces application launch and running time, and it helps
  887. IDE's offer support for tracking down weaving errors and understanding
  888. the impact of aspects on a system.
  889. On the other hand, weaving at load-time simplifies build and deployment.
  890. Before AspectJ 1.2, the user had to write a class loader that used the
  891. weaver API to weave at load time; since 1.2, AspectJ come with a
  892. command-line launcher to support weaving at class-load-time without
  893. any other changes to a build configuration.
  894. </para>
  895. <para>
  896. Second, AspectJ programs, like Java programs generally, can be
  897. written to support any level of XML configuration or to depend on
  898. runtime reflection. There are some benefits to using AspectJ;
  899. e.g., the proceed() form within around advice simplifies a lot of
  900. the work that otherwise would go into writing a generalized
  901. interceptor, without introducing many of the runtime errors that can
  902. result from interceptors.
  903. For AspectJ examples of configurable or reflection-dependent programs,
  904. see the sample code linked off the AspectJ documentation page
  905. or the examples discussed on the mailing list, e.g.,
  906. <ulink url="http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg02151.html">
  907. Incremental and runtime weaving support?</ulink>.
  908. </para>
  909. </answer>
  910. </qandaentry>
  911. <qandaentry>
  912. <question id="q:aopandxp"
  913. xreflabel="Q:What is the relationship between AOP and
  914. XP (extreme programming AKA agile methods)?">
  915. <para>What is the relationship between AOP and
  916. XP (extreme programming AKA agile methods)?
  917. </para>
  918. </question>
  919. <answer>
  920. <para>From a question on the user list:
  921. <programlisting>
  922. > Anyone know the connections between AOP and Extreme Programming?
  923. > I am really confused. It seems AOP is a programming paradigm, which
  924. > is the next level of abstraction of OOP. Extreme Programming, however,
  925. > this is a lightweight software development process. One of the common
  926. > motivations of AOP and XP is designed to adopt to the requirement
  927. > changes, so that it can save the cost of software development.
  928. </programlisting>
  929. </para>
  930. <para>
  931. This is Raymond Lee's answer:
  932. </para>
  933. <para>
  934. You're not really that confused. AOP and XP are orthogonal concepts,
  935. although AOP can be used to help accomplish XP goals.
  936. One of the goals of XP is to respond to changing requirements.
  937. Another is to reduce the overall cost of development. These are
  938. not necessarily the same thing.
  939. </para>
  940. <para>
  941. One of the principles of XP that contribute to meeting those goals
  942. is to maintain clean, simple designs. One of the criteria for clean,
  943. simple designs is to factor out duplication from the code. Benefits
  944. of removing duplication include the code being easier to understand,
  945. better modularity of the design, lower costs of code changes, less
  946. chance of conflicting changes when practicing collective code
  947. ownership, etc.
  948. </para>
  949. <para>
  950. Different types of duplication lend themselves to being addressed by
  951. different design paradigms and language features. Duplicate snippets
  952. of code can be factored out into methods. Duplicate methods can be
  953. factored out to common classes, or pushed up to base classes.
  954. Duplicate patterns of methods and their use can be factored out to
  955. mechanisms of classes and methods (i.e. instantiations of design
  956. patterns).
  957. </para>
  958. <para>
  959. AOP addresses a type of duplication that is very difficult to handle
  960. in the other common paradigms, namely cross-cutting concerns. By
  961. factoring out duplicate cross-cutting code into aspects, the target
  962. code becomes simpler and cleaner, and the cross-cutting code becomes
  963. more centralized and modular.
  964. </para>
  965. <para>
  966. So, AOP as a paradigm, and the associated tools, gives an XPer, or
  967. anyone wanting to remove duplication from the code base, a powerful
  968. way to remove a form of duplication not easily addressed until now.
  969. </para>
  970. </answer>
  971. </qandaentry>
  972. <qandaentry>
  973. <question id="q:aspectjandcsharp"
  974. xreflabel="Q:Will you support C#?">
  975. <para>Will you support C#?</para>
  976. </question>
  977. <answer>
  978. <para>Not at this time. Although the resemblances between C# and Java
  979. means it would probably be a fairly straightforward matter to take
  980. the AspectJ language design and produce AspectC#, our current focus
  981. is only on supporting effective uses of AspectJ.
  982. </para>
  983. </answer>
  984. </qandaentry>
  985. </qandadiv>
  986. <qandadiv id="adoption" xreflabel="Deciding to adopt AspectJ">
  987. <title>Deciding to adopt AspectJ</title>
  988. <qandaentry>
  989. <question id="q:productplans"
  990. xreflabel="Q:Is it safe to use AspectJ in my product plans??">
  991. <para>
  992. Is it safe to use AspectJ in my product plans?
  993. </para>
  994. </question>
  995. <answer>
  996. <para>You may use AspectJ in your product or project with little
  997. risk. Several factors play a role in reducing the risk of adopting
  998. this new technology:
  999. <itemizedlist>
  1000. <listitem>
  1001. <para>AspectJ is an <emphasis>addition</emphasis> to
  1002. Java, and can be incrementally introduced into a project
  1003. in a way that limits risk.
  1004. See <xref linkend="q:startUsingAJ"/> for
  1005. some suggestions on how to do this.
  1006. </para>
  1007. </listitem>
  1008. <listitem>
  1009. <para>The AspectJ compiler accepts standard Java as
  1010. input and produces standard Java bytecode as output.
  1011. In 1.0, an optional mode produces standard Java source code
  1012. which may then be compiled with any compliant Java compiler
  1013. (e.g. Sun's <literal>javac</literal> compiler
  1014. or IBM's <literal>jikes</literal> compiler).
  1015. In 1.1, an optional mode accepts standard Java bytecode
  1016. from any compliant Java compiler
  1017. and weaves in the aspects to produce new bytecode.
  1018. </para>
  1019. </listitem>
  1020. <listitem>
  1021. <para>AspectJ is available under a non-proprietary, open source license,
  1022. either the
  1023. <ulink url="http://www.opensource.org/licenses/mozilla1.1">
  1024. Mozilla Public License 1.1</ulink>
  1025. for 1.0 or the
  1026. <ulink url="http://eclipse.org/legal/cpl-v10.html">
  1027. Common Public License 1.0</ulink> for 1.1.
  1028. AspectJ will continue to evolve and be available, regardless
  1029. of the fate of any particular organization involved with
  1030. AspectJ.
  1031. </para>
  1032. </listitem>
  1033. <listitem>
  1034. <para>Removing AspectJ from your program is not
  1035. difficult, although you will lose the flexibility and
  1036. economy that AspectJ provided.
  1037. </para>
  1038. </listitem>
  1039. </itemizedlist>
  1040. </para>
  1041. </answer>
  1042. </qandaentry>
  1043. <qandaentry>
  1044. <question id="q:effectonsize"
  1045. xreflabel="Q:What is the effect of using AspectJ on the source code size of programs?">
  1046. <para>What is the effect of using AspectJ on the source code
  1047. size of programs?
  1048. </para>
  1049. </question>
  1050. <answer>
  1051. <para>Using aspects reduces, as a side effect, the number of source
  1052. lines in a program. However, the major benefit of using aspects
  1053. comes from <emphasis>improving</emphasis> the modularity of a
  1054. program, not because the program is smaller. Aspects gather into a
  1055. module concerns that would otherwise be scattered across or
  1056. duplicated in multiple classes.
  1057. </para>
  1058. </answer>
  1059. </qandaentry>
  1060. <qandaentry>
  1061. <question id="q:effectonperformance"
  1062. xreflabel="Q:Does AspectJ add any performance overhead?">
  1063. <para>
  1064. Does AspectJ add any performance overhead?
  1065. </para>
  1066. </question>
  1067. <answer>
  1068. <para>The issue of performance overhead is an important one. It is
  1069. also quite subtle, since knowing what to measure is at least as
  1070. important as knowing how to measure it, and neither is always
  1071. apparent.
  1072. </para>
  1073. <para>We aim for the performance of our implementation of AspectJ to
  1074. be on par with the same functionality hand-coded in Java. Anything
  1075. significantly less should be considered a bug.
  1076. </para>
  1077. <para>There is currently no benchmark suite for AOP languages in
  1078. general or for AspectJ in particular. It is probably too early to
  1079. develop such a suite because AspectJ needs more maturation of the
  1080. language and the coding styles first. Coding styles really drive
  1081. the development of the benchmark suites since they suggest what is
  1082. important to measure.
  1083. </para>
  1084. <para>Though we cannot show it without a benchmark suite, we believe
  1085. that code generated by AspectJ has negligible performance overhead.
  1086. Inter-type member and parent introductions should have very little
  1087. overhead, and advice should only have some indirection which
  1088. could be optimized away by modern VM's.
  1089. </para>
  1090. <para>The <literal>ajc</literal> compiler will use static typing information
  1091. to only insert the advice and dynamic pointcut tests that are absolutely necessary.
  1092. Unless you use 'thisJoinPoint' or 'if', the main dynamic checks will be
  1093. 'instanceof' checks which are generally quite fast.
  1094. These checks will only be inserted when they can not be inferred from
  1095. the static type information.
  1096. </para>
  1097. <para>When measuring performance, write AspectJ code
  1098. fragments and compare them to the performance of the
  1099. corresponding code written without AspectJ. For example, don't
  1100. compare a method with before/after advice that grabs a lock to just
  1101. the method. That would be comparing apples and oranges. Also be
  1102. sure to watch out for JIT effects that come from empty method
  1103. bodies and the like. Our experience is that they can be quite
  1104. misleading in understanding what you've measured.
  1105. </para>
  1106. </answer>
  1107. </qandaentry>
  1108. <qandaentry>
  1109. <question id="q:modularityviolations"
  1110. xreflabel="Q:I've heard that AspectJ leads to modularity violations. Does it?">
  1111. <para>
  1112. I've heard that AspectJ leads to modularity violations. Does it?
  1113. </para>
  1114. </question>
  1115. <answer>
  1116. <para>
  1117. Well I haven't yet seen a language in which you can't write bad code!
  1118. </para>
  1119. <para>
  1120. But seriously, most AspectJ users find that just like when they learned
  1121. OO, it takes a while to really get the hang of it. They tend to start
  1122. in the usual way, by copying canonical examples and experimenting with
  1123. variations on them.
  1124. </para>
  1125. <para>
  1126. But users also find that rather than being dangerous, AspectJ helps them
  1127. write code that is more clear and has better encapsulation -- once they
  1128. understand the kind of modularity AspectJ supports. There are several
  1129. good papers that talk about this (see below), but here's a basic point
  1130. to keep in mind: when properly used, AspectJ makes it possible program
  1131. in a modular way, something that would otherwise be spread throughout
  1132. the code. Consider the following code, adapted from the AspectJ tutorial:
  1133. </para>
  1134. <programlisting>
  1135. aspect PublicErrorLogging {
  1136. Log log = new Log();
  1137. pointcut publicInterface(Object o):
  1138. call(public * com.xerox.*.*(..)) &amp;&amp; target(o);
  1139. after(Object o) throwing (Error e): publicInterface(o) {
  1140. log.write(o, e);
  1141. }
  1142. }
  1143. </programlisting>
  1144. <para>
  1145. The effect of this code is to ensure that whenever any public method of
  1146. an interface or class in the <literal>com.xerox</literal> package
  1147. throws an error, that error is logged before being thrown to its caller.
  1148. </para>
  1149. <para>
  1150. Of course in the alternative implementation a large number of methods
  1151. have a try/catch around their body.
  1152. </para>
  1153. <para>
  1154. The AspectJ implementation of this crosscutting concern is clearly
  1155. modular, whereas the other implementation is not. As a result, if you
  1156. want to change it, its easier in the AspectJ implementation. For
  1157. example, if you also want to pass the name of the method, or its
  1158. arguments to <literal>log.write</literal>, you only have to edit
  1159. one place in the AspectJ code.
  1160. </para>
  1161. <para>
  1162. This is just a short example, but I hope it shows how what happens
  1163. with AOP and AspectJ is that the usual benefits of modularity are
  1164. achieved for crosscutting concerns, and that leads to better code,
  1165. not more dangerous code.
  1166. </para>
  1167. <para>
  1168. One paper someone else just reminded me of that talks some more
  1169. about this is:
  1170. <ulink url="http://www.cs.ubc.ca/~kdvolder/Workshops/OOPSLA2001/submissions/12-nordberg.pdf">
  1171. http://www.cs.ubc.ca/~kdvolder/Workshops/OOPSLA2001/submissions/12-nordberg.pdf
  1172. </ulink>
  1173. </para>
  1174. </answer>
  1175. </qandaentry>
  1176. <qandaentry>
  1177. <question id="q:encapsulation"
  1178. xreflabel="Q:Why does AspectJ permit aspects to access and add members of another type?">
  1179. <para>
  1180. Why does AspectJ permit aspects to access and add members of another type?
  1181. Isn't that violating OO encapsulation?
  1182. </para>
  1183. </question>
  1184. <answer>
  1185. <para>In the spirit of Smalltalk, we have decided to give more power
  1186. to the language in order to let the user community experiment and
  1187. discover what is right. To date this has proven to be a successful
  1188. strategy because it has permitted the construction of many useful
  1189. aspects that crosscut the internal state of an object, and as such
  1190. need access the its private members. However, we are not
  1191. discounting that some sort of restrictions are useful, rather, we
  1192. are seeking input from the community in order to decide on what
  1193. these restrictions should be.
  1194. </para>
  1195. <para>
  1196. In that light, our position on encapsulation is :
  1197. </para>
  1198. <itemizedlist>
  1199. <listitem><para>we respect Java's visibility rules</para></listitem>
  1200. <listitem><para>we also provide open-classes, a mature OO technology</para></listitem>
  1201. <listitem><para>we provide "privileged" access if you really need it.</para></listitem>
  1202. </itemizedlist>
  1203. <para>
  1204. Introducing parents or members to classes is a well-studied OO technique
  1205. known as open classes.
  1206. </para>
  1207. <para>
  1208. Open classes have been used in many languages prior to AspectJ,
  1209. including CLOS, Python, Smalltalk, Objective-C, and others.
  1210. Building from Java, introduction in AspectJ provides better
  1211. name hygiene and access control than prior languages.
  1212. Introduced code obeys all of Java's normal accessibility rules
  1213. for its lexical location in the aspect that it is introduced from.
  1214. Such code can not even see, much less access, private members of
  1215. the class it is introduced into. Further, introductions can be
  1216. declared private to the aspect, so they are not visible to
  1217. other clients of the class.
  1218. </para>
  1219. <para>
  1220. Privileged aspects do permit access to private members of another
  1221. class. They are a response to the very few cases where developers
  1222. genuinely need such access (typically for testing purposes where it
  1223. access is necessary), but it would be more risky to open access by
  1224. putting the aspect in the same package, adding test code, or changing
  1225. access in the target class. We recommend using privileged aspects
  1226. only as necessary, and believe that marking them "privileged" makes
  1227. any potential misuse apparent.
  1228. </para>
  1229. </answer>
  1230. </qandaentry>
  1231. <qandaentry>
  1232. <question id="q:aspectjandj2ee"
  1233. xreflabel="Q:Can I use AspectJ with J2EE?">
  1234. <para>Can I use AspectJ with J2EE?</para>
  1235. </question>
  1236. <answer>
  1237. <para>
  1238. Consider the component types in J2EE:
  1239. </para>
  1240. <itemizedlist>
  1241. <listitem>
  1242. <para>
  1243. Servlet: AspectJ works well within servlets
  1244. </para>
  1245. </listitem>
  1246. <listitem>
  1247. <para>
  1248. JSP: It is possible to use AspectJ to affect code in JSPs by precompiling
  1249. them into Java sources and compiling these with ajc. This can be used, e.g., to
  1250. customize displays by turning on and off custom JSP taglibs. The mapping from a
  1251. given jsp source to java package and class name is not standardized, which means
  1252. doing this imposes dependencies on specific container versions.
  1253. </para>
  1254. </listitem>
  1255. <listitem>
  1256. <para>
  1257. EJB: AspectJ supports a wide variety of aspects for EJBs. It can be used for
  1258. logging, tracing, debugging, error handling by layers, correlated method-level
  1259. interception (e.g., chargebacks), metering, fine-grained transactions, etc.
  1260. Indeed, it can be used to enforce adherence to coding restrictions within an
  1261. EJB (e.g., not using java.io, creating a class loader, or listening on
  1262. sockets) using <literal>declare error</literal>.
  1263. </para>
  1264. </listitem>
  1265. </itemizedlist>
  1266. <para>
  1267. The basic limitations are that there is no built-in support for writing J2EE
  1268. analogs for AspectJ extensions to Java, like distributed aspects, distributed
  1269. cflow, or managing state between invocations. These don't prevent one from using
  1270. AspectJ to do useful intra-container implementation, nor need they prevent one
  1271. from building distributed support, state management, and inter-component
  1272. implementations that leverage AspectJ. It just takes some work. In more detail:
  1273. </para>
  1274. <para>
  1275. All AspectJ implementations may define "code the implementation controls".
  1276. The AspectJ 1.0 implementation defines this as the files passed to the compiler
  1277. (AspectJ 1.1 will also support bytecode weaving).
  1278. </para>
  1279. <para>
  1280. Some advice on EJB operations will generate methods that confuse ejb compilers.
  1281. To avoid this problem, you can use the -XaddSafePrefix flag when compiling with ajc.
  1282. </para>
  1283. <para>
  1284. EJB components may be invoked remotely, and containers may passivate and
  1285. pool EJB's. Servlets have similar limitations, and in both cases the
  1286. lifespan of the defining class loader is implementation-dependent
  1287. (though it must span the operation of a particular request).
  1288. </para>
  1289. <para>
  1290. Being limited by lifecycle and namespace, the AspectJ 1.0 implementation
  1291. supports aspects that operate through non-remote invocations during the lifetime
  1292. of the namespace for a particular
  1293. deployment unit compiled in its entirety by the ajc compiler.
  1294. This means AspectJ supports common aspects only within a single local runtime
  1295. namespace (usually implemented as a class loader hierarchy).
  1296. </para>
  1297. <para>
  1298. Further, AspectJ recognizes language-level join points (object initialization,
  1299. method calls, etc.), not their EJB analogs (ejb find or create methods...).
  1300. These lead to the following consequences:
  1301. </para>
  1302. <itemizedlist>
  1303. <listitem>
  1304. <para>
  1305. Issingleton aspects (the default) are limited to the lifetime of
  1306. the defining class loader, which in some implementations may not span
  1307. multiple invocations of the same application or EJB component.
  1308. </para>
  1309. </listitem>
  1310. <listitem>
  1311. <para>
  1312. EJB lifecycles are different from object lifecycles, so perthis
  1313. and pertarget aspects will make little sense. They do not work
  1314. in the current implementation, which uses synchronized methods
  1315. to ensure a correct association in threaded environments
  1316. (EJB's may not have synchronized methods).
  1317. </para>
  1318. </listitem>
  1319. <listitem>
  1320. <para>
  1321. Percflow or percflowbelow aspects are restricted to a chain of
  1322. non-remote invocations. While EJB 2.0 permits declaring an interface
  1323. local, this information is not available to the AspectJ compiler today.
  1324. For same reasons as stated above fore perthis, these will not work even
  1325. in the EJB container.
  1326. </para>
  1327. </listitem>
  1328. <listitem>
  1329. <para>
  1330. Evaluation of cflow or cflowbelow pointcuts will be valid only
  1331. with respect to a chain of non-remote invocations.
  1332. </para>
  1333. </listitem>
  1334. </itemizedlist>
  1335. <para>
  1336. In addition, any AspectJ code should respect EJB operations:
  1337. </para>
  1338. <itemizedlist>
  1339. <listitem>
  1340. <para>
  1341. The EJB container accesses EJB component fields directly, i.e.,
  1342. in code outside the control of the compiler. There is no join point for
  1343. these accesses, and hence no way to write a pointcut to advise that access.
  1344. </para>
  1345. </listitem>
  1346. <listitem>
  1347. <para>
  1348. The EJB container may pool EJB components, so any initialization
  1349. join points may run once per component constructed, not once per
  1350. component initialized for purposes of a client call.
  1351. </para>
  1352. </listitem>
  1353. <listitem>
  1354. <para>
  1355. The EJB container is permitted to change class loaders, even
  1356. between invocations of a particular EJB component (by passivating and
  1357. activating with a new class loader). In this case, instances of singleton
  1358. aspects will not operate over multiple invocations of the component, or that
  1359. static initialization join point recur for a given class as it is re-loaded.
  1360. This behavior depends on the container implementation.
  1361. </para>
  1362. </listitem>
  1363. </itemizedlist>
  1364. </answer>
  1365. </qandaentry>
  1366. <qandaentry>
  1367. <question id="q:aspectjandgj"
  1368. xreflabel="Q:Can I use AspectJ with Generic Java?">
  1369. <para>Can I use AspectJ with Generic Java?</para>
  1370. </question>
  1371. <answer>
  1372. <para>We plan to support Generics when Java 1.5 is available.
  1373. </para>
  1374. <para>But at this time, unfortunately not. The two compilers are just not
  1375. at all compatible. In an ideal world, there would be a wonderful
  1376. Open Source extensible compiler framework for Java that both GJ and
  1377. AspectJ would be built on top of, and they would seamlessly
  1378. interoperate along with all other extensions to Java that you might
  1379. be interested in, but that's not the case (yet?).
  1380. </para>
  1381. <para>However, on 09 October 2000, the Java Community Process
  1382. approved a proposal to add generic types to Java that is largely
  1383. based on GJ (JSR 14). A draft specification was submitted for
  1384. public review, which closed on 01 August 2001, and a
  1385. prototype implementation has been released by Sun.
  1386. </para>
  1387. <para>We are committed to moving very rapidly to add support for
  1388. generic types in AspectJ when generic types become part of the Java
  1389. language specification. Everyone on the AspectJ team is looking
  1390. forward to this, because we too would really like to be able to
  1391. write code that includes both aspects and generic types.
  1392. </para>
  1393. </answer>
  1394. </qandaentry>
  1395. <qandaentry>
  1396. <question id="q:aspectjandj2me"
  1397. xreflabel="Q:Can I use AspectJ with J2ME?">
  1398. <para>Can I use AspectJ with J2ME?</para>
  1399. </question>
  1400. <answer>
  1401. <para>We have not tested with J2ME, but we understand that users
  1402. are deploying AspectJ-compiled programs successfully in J2ME.
  1403. It should work if your program is otherwise J2ME-compatible
  1404. and if you avoid using <literal>cflow</literal>-based pointcuts
  1405. or <literal>thisJoinPoint</literal>.
  1406. To ensure that the program is limited to J2ME API's,
  1407. you should supply the runtime on the bootclasspath.
  1408. (Fair warning: there was an email about this not working,
  1409. but there has been no bug report.)
  1410. </para>
  1411. </answer>
  1412. </qandaentry>
  1413. <qandaentry>
  1414. <question id="q:aopinjava"
  1415. xreflabel="Q: Are you working to put AOP into Java?">
  1416. <para> Are you working to put AOP into Java?
  1417. It seems that every AOP toolset currently uses proprietary mechanisms
  1418. to describe point-cuts, etc.
  1419. </para>
  1420. </question>
  1421. <answer>
  1422. <para>
  1423. We are working on standardization, but it's
  1424. a question of timing/ripeness (imagine going from thousands of users
  1425. to millions). (See <xref linkend="q:standardization"/>.) We believe
  1426. AspectJ addresses this question in the best way possible now:
  1427. <itemizedlist>
  1428. <listitem>
  1429. <para>
  1430. It's open-source. Rather than being proprietary or controlled by a
  1431. vendor, it's available for anybody to use and build upon, forever.
  1432. </para>
  1433. </listitem>
  1434. <listitem>
  1435. <para>
  1436. AspectJ is not a set of mechanisms, it's a language. It is currently
  1437. implemented using certain techniques, but there's nothing that prevents
  1438. it from being implemented with other techniques. That means users can
  1439. adopt the language with confidence that implementations will get better.
  1440. </para>
  1441. </listitem>
  1442. <listitem>
  1443. <para>
  1444. There is no engineering need to change Java. The AspectJ language uses
  1445. the join point model already in Java, so there is no need to extend the
  1446. programming model. Our implementation produces valid Java bytecode, which
  1447. runs in any compliant J2SE VM and supports standard debuggers for those VM's
  1448. that support JSR-45 (debugging support for multi-language/multi-file sources).
  1449. This is a huge benefit to Sun since Sun must be extremely cautious
  1450. about extensions to the language or VM; before adopting AOP, Sun should
  1451. demand the kind of actual-proof that AspectJ implementations offer.
  1452. </para>
  1453. </listitem>
  1454. <listitem>
  1455. <para>
  1456. On the issue of "proprietary mechanisms to describe pointcuts, etc.": Any AOP
  1457. has to have some language to describe pointcuts and the like ("pointcuts"
  1458. of course being the AspectJ term). Users would like to have one language
  1459. (to avoid having to learn or transform between many languages) and the
  1460. choice of multiple implementations (tailored for a configuration, subject
  1461. to competitive pressure, etc.). That's what AspectJ offers.
  1462. </para>
  1463. </listitem>
  1464. <listitem>
  1465. <para>
  1466. That said, we believe the AspectJ extensions to Java could form the basis
  1467. for bringing AOP to Java; when that happens, there will be engineering
  1468. opportunities to make the implementation and tool support better.
  1469. </para>
  1470. </listitem>
  1471. </itemizedlist>
  1472. </para>
  1473. </answer>
  1474. </qandaentry>
  1475. <qandaentry>
  1476. <question id="q:support"
  1477. xreflabel="Q: What kind of support is available?">
  1478. <para>What kind of support is available?</para>
  1479. </question>
  1480. <answer>
  1481. <para>
  1482. The mailing lists provide the primary support for everyone
  1483. in the community
  1484. (See <xref linkend="q:mailingLists"/>).
  1485. To request commercial support, tutorials, or presentations,
  1486. use the developer mailing list,
  1487. <literal>aspectj-dev@eclipse.org</literal>.
  1488. </para>
  1489. <para>
  1490. To find out about known issues, see the
  1491. <ulink url="progguide/implementation.html">
  1492. AspectJ Programming Guide Appendix, "Implementation Notes"</ulink>
  1493. and the AspectJ bugs in the database at
  1494. <ulink url="http://bugs.eclipse.org/bugs">http://bugs.eclipse.org/bugs</ulink>
  1495. (using the product <literal>AspectJ</literal>). Here are direct links to
  1496. <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">
  1497. view open compiler bugs</ulink>,
  1498. <ulink url="http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ">
  1499. view all Aspectj bugs (open or closed)</ulink>, or
  1500. <ulink url="http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ">
  1501. add new bugs</ulink>.
  1502. </para>
  1503. </answer>
  1504. </qandaentry>
  1505. <qandaentry>
  1506. <question id="q:mailingLists"
  1507. xreflabel="Q: What mailing lists are there?">
  1508. <para>What mailing lists are there?</para>
  1509. </question>
  1510. <answer>
  1511. <para>
  1512. The AspectJ users mailing list
  1513. (<literal>aspectj-users@eclipse.org</literal>)
  1514. provides an informal network of AspectJ language users who
  1515. can answer usage questions about AspectJ programs
  1516. and the AspectJ tools.
  1517. This is the place to ask how to code something in AspectJ
  1518. or how to write Ant or shell scripts to invoke the tools.
  1519. </para>
  1520. <para>
  1521. The AspectJ developers mailing list
  1522. (<literal>aspectj-dev@eclipse.org</literal>)
  1523. provides an informal network of AspectJ technology experts who
  1524. aim to understand the technology behind AspectJ.
  1525. The committers to the AspectJ project use this list
  1526. for open technical and planning discussions.
  1527. Developers can answer questions about what's possible and about
  1528. integrating AspectJ technology with other technologies.
  1529. </para>
  1530. <para>
  1531. For both mailing lists, only subscribed members may post messages.
  1532. To subscribe, visit the
  1533. <ulink url="http://eclipse.org/aspectj">AspectJ web site</ulink>.
  1534. </para>
  1535. <para>
  1536. There you can also subscribe to
  1537. <literal>aspectj-announce@eclipse.org</literal>,
  1538. a low-traffic list containing only announcements
  1539. about significant AspectJ events and product releases.
  1540. To get on a similar list for aspect-oriented software
  1541. development generally, see
  1542. <ulink url="http://aosd.net">http://aosd.net</ulink>.
  1543. </para>
  1544. </answer>
  1545. </qandaentry>
  1546. </qandadiv>
  1547. <qandadiv id="compiler" xreflabel="Using the AspectJ compiler">
  1548. <title>Using the AspectJ compiler</title>
  1549. <qandaentry>
  1550. <question id="q:requiredsources"
  1551. xreflabel="Q:What files do I need to include when compiling AspectJ programs?">
  1552. <para>
  1553. What files do I need to include when compiling AspectJ programs?
  1554. </para>
  1555. </question>
  1556. <answer>
  1557. <para>You need to specify to the compiler the files that
  1558. contain your aspects and the files that contain the
  1559. types affected by your aspects.
  1560. See <xref linkend="q:knowWhenAspectsAffectClasses"/>.
  1561. The AspectJ compiler will not search the source path for types
  1562. that may be affected (unlike Javac and Jikes).
  1563. In AspectJ 1.0, ajc requires all code to be in source form;
  1564. in AspectJ 1.1, Java and AspectJ code may be in either source
  1565. or binary form.
  1566. </para>
  1567. <para>In some cases you should compile your entire system all at once.
  1568. If this is too slow, then you can try to make reasonable divisions
  1569. between sets of source files whose aspects do not interact to
  1570. achieve a shorter compile cycle (particularly for development
  1571. aspects). If you have aspects that apply to different modules,
  1572. you can try compiling them into a binary form and using them
  1573. to weave each module. However, if you get any problems
  1574. or if you wish to run tests or do a release, you should recompile
  1575. the entire system.
  1576. </para>
  1577. <para>
  1578. For more information, see the
  1579. <ulink url="devguide/index.html">
  1580. Development Environment Guide</ulink>
  1581. <ulink url="devguide/ajc-ref.html">
  1582. Reference for ajc</ulink>.
  1583. </para>
  1584. </answer>
  1585. </qandaentry>
  1586. <qandaentry>
  1587. <question id="q:listingsources"
  1588. xreflabel="Q:Is there any other way to provide the file names to ajc?">
  1589. <para>I have to list many files in the command line to
  1590. compile with <literal>ajc</literal>. Is there any other way to
  1591. provide the file names to <literal>ajc</literal>?
  1592. </para>
  1593. </question>
  1594. <answer>
  1595. <para>
  1596. Yes, use the argfile option to ajc. List source
  1597. files in a line-delimited text file and direct ajc to that
  1598. file using <literal>-argfile</literal> or <literal>@</literal>:
  1599. </para>
  1600. <programlisting>ajc @sources.lst
  1601. ajc -argfile sources.lst
  1602. </programlisting>
  1603. <para>Another way in AspectJ 1.1 is to use the
  1604. <literal>-sourceroots</literal> options, which reads all
  1605. source files in a given set of directories:
  1606. </para>
  1607. <programlisting>ajc -sourceroots "src;testsrc"
  1608. </programlisting>
  1609. <para>
  1610. For more information, see the
  1611. <ulink url="devguide/index.html">
  1612. Development Environment Guide</ulink>
  1613. <ulink url="devguide/ajc-ref.html">
  1614. Reference for ajc</ulink>.
  1615. </para>
  1616. </answer>
  1617. </qandaentry>
  1618. <qandaentry>
  1619. <question id="q:compilerVM"
  1620. xreflabel="Q: What Java virtual machine (JVM) do I use to run the
  1621. AspectJ compiler? ">
  1622. <para>What Java virtual machine (JVM) do I use to run the
  1623. AspectJ compiler?
  1624. </para>
  1625. </question>
  1626. <answer>
  1627. <para>Use the latest, greatest, fastest JVM you can get your hands on
  1628. for your platform. The compiler's performance is dependent on the
  1629. performance of the JVM it is running on, so the faster a JVM you
  1630. can find to run it on, the shorter your compile times will be. At a
  1631. minimum you need to use a Java 2 or later JVM to run the compiler
  1632. (J2SE 1.3 for AspectJ 1.1).
  1633. We realize that this constraint can be a problem for users who
  1634. don't currently have a Java 2 JVM available. We're sorry for the
  1635. inconvenience, but we had to make the hard decision that the
  1636. advantages of being able to rely on Java 2 were worth the cost of
  1637. losing a number of developers who are working on platforms without
  1638. Java 2 support. Here is a list of starting places where you might
  1639. find support for your system.
  1640. <itemizedlist>
  1641. <listitem>
  1642. <para>
  1643. <ulink url="http://java.sun.com/j2se/">Java 2
  1644. Platform, Standard Edition
  1645. </ulink>
  1646. </para>
  1647. </listitem>
  1648. <listitem>
  1649. <para>
  1650. <ulink
  1651. url="http://www-106.ibm.com/developerworks/java/jdk/">
  1652. developerWorks : Java technology : Tools and products - Developer kits
  1653. </ulink>
  1654. </para>
  1655. </listitem>
  1656. <listitem>
  1657. <para>
  1658. <ulink
  1659. url="http://www-124.ibm.com/developerworks/oss/jikes/">
  1660. developerWorks : Open Source - Jikes Project
  1661. </ulink>
  1662. </para>
  1663. </listitem>
  1664. <listitem>
  1665. <para>
  1666. <ulink url="http://java.sun.com/cgi-bin/java-ports.cgi">Java
  1667. Platform Ports
  1668. </ulink>
  1669. </para>
  1670. </listitem>
  1671. </itemizedlist>
  1672. </para>
  1673. <para>The requirement of Java 2 support is only for
  1674. <emphasis>running</emphasis> the AspectJ compiler. The AspectJ
  1675. compiler can be used to build programs that will run on Java 1.1
  1676. (or probably even on Java 1.0) systems. This means that it can
  1677. build programs that will run on Macintosh, FreeBSD, and applets
  1678. that will run in Internet Explorer and Netscape Navigator that are
  1679. still not yet Java 2 compliant.
  1680. </para>
  1681. </answer>
  1682. </qandaentry>
  1683. <qandaentry>
  1684. <question id="q:compilingForDifferentVMs"
  1685. xreflabel="Q: How to use ajc to compile for a different VM?">
  1686. <para>How can I use <literal>ajc</literal> to compile
  1687. programs for a JVM that is different from the one used to run it?
  1688. </para>
  1689. </question>
  1690. <answer>
  1691. <para>
  1692. <literal>ajc</literal> can be used to develop programs that are
  1693. targeted at the Java 1.1 platform, even though the
  1694. <literal>ajc</literal> compiler won't run on that platform. Here's
  1695. an example of using <literal>ajc</literal> in this sort of
  1696. cross-compilation mode (assuming a Windows platform with all the
  1697. default installation directories):
  1698. </para>
  1699. <programlisting>
  1700. ajc -target 1.1 -bootclasspath c:\jdk1.1.7\lib\classes.zip \
  1701. -classpath c:\aspectj1.0\lib\aspectjrt.jar -extdirs "" \
  1702. -argfile jdk11system.lst
  1703. </programlisting>
  1704. <para>This same technique can be used if you want to run
  1705. <literal>ajc</literal> on a JDK 1.3 JVM (highly recommended) but
  1706. need to generate code for JDK 1.2. That would look something
  1707. like:
  1708. </para>
  1709. <programlisting>
  1710. ajc -bootclasspath c:\jdk1.2\jre\lib\rt.jar \
  1711. -classpath c:\aspectj1.0\lib\aspectjrt.jar \
  1712. -extdirs c:\jdk1.2\jre\lib\ext
  1713. -argfile jdk12system.lst
  1714. </programlisting>
  1715. </answer>
  1716. </qandaentry>
  1717. <qandaentry>
  1718. <question id="q:assert"
  1719. xreflabel="Q:Does the ajc compiler support the assert keyword in Java 1.4?">
  1720. <para>Does the <literal>ajc</literal> compiler support
  1721. the <literal>assert</literal> keyword in Java 1.4?
  1722. </para>
  1723. </question>
  1724. <answer>
  1725. <para>Yes. As with <literal>Javac</literal>,
  1726. use the <literal>-source 1.4</literal> option as described
  1727. in the
  1728. <ulink url="devguide/index.html">
  1729. Development Environment Guide</ulink>
  1730. <ulink url="devguide/ajc-ref.html">
  1731. Reference for ajc</ulink>.
  1732. </para>
  1733. </answer>
  1734. </qandaentry>
  1735. <qandaentry>
  1736. <question id="q:msjvm"
  1737. xreflabel="Q:Are there any issues using AspectJ with the Microsoft JVM?">
  1738. <para>Are there any issues using AspectJ with the Microsoft
  1739. JVM?
  1740. </para>
  1741. </question>
  1742. <answer>
  1743. <para>Since AspectJ requires Java 2 or later, it will not run on the
  1744. Microsoft JVM, which does not support Java 2.
  1745. </para>
  1746. </answer>
  1747. </qandaentry>
  1748. <qandaentry>
  1749. <question id="q:javacbytecode"
  1750. xreflabel="Q:Does ajc rely on javac for generating bytecode?">
  1751. <para>Does <literal>ajc</literal> rely
  1752. on <literal>javac</literal> for generating Java bytecode
  1753. (<literal>.class</literal>) files?
  1754. </para>
  1755. </question>
  1756. <answer>
  1757. <para> No. Some previous versions of AspectJ had this requirement.
  1758. In AspectJ 1.0, <literal>javac</literal> can still be used as
  1759. <literal>ajc</literal> back end by using the
  1760. <literal>-usejavac</literal> flag. You can also run <literal>ajc</literal>
  1761. in preprocessor mode to generate Java source
  1762. (<literal>.java</literal>) files to be compiled using
  1763. <literal>javac</literal> or another java compiler.
  1764. Neither option is supported in AspectJ 1.1.
  1765. </para>
  1766. </answer>
  1767. </qandaentry>
  1768. <qandaentry>
  1769. <question id="q:parsergenerators"
  1770. xreflabel="Q:I noticed the AspectJ compiler doesn't use a parser generator. Why is that?">
  1771. <para>
  1772. I noticed the AspectJ compiler doesn't use a parser generator. Why is that?
  1773. </para>
  1774. </question>
  1775. <answer>
  1776. <para>In AspectJ 1.0,
  1777. the PARSER for ajc is written by hand. This choice was made with full
  1778. awareness of the generator tools out there. (Jim had for example used
  1779. the excellent javacc tool for building the parser for JPython (now Jython)).
  1780. One of the reasons that AspectJ uses a hand-written parser is that using
  1781. javacc taught Jim about the LL-k design for parsers (pioneered by antlr).
  1782. As opposed to the state-machine parsers produced by yacc, these parsers are
  1783. very readable and writable by humans.
  1784. </para>
  1785. <para>
  1786. Antlr and javacc did not really suit the project:
  1787. </para>
  1788. <itemizedlist>
  1789. <listitem>
  1790. <para>
  1791. Antlr's support for unicode in the lexer is still immature and this makes
  1792. using it with Java challenging. This was an even bigger issue 3 years ago
  1793. when we started on the Java implementation of ajc.
  1794. </para>
  1795. </listitem>
  1796. <listitem>
  1797. <para>
  1798. While javacc is freely available, it is not Open Source. Depending on a
  1799. closed-source tool to build an Open Source compiler would reduce some
  1800. of the transparency and control of open-source.
  1801. </para>
  1802. </listitem>
  1803. </itemizedlist>
  1804. <para>
  1805. There were also several things that were easier to implement with
  1806. a hand-written parser than with any of the exiting tools.
  1807. </para>
  1808. <itemizedlist>
  1809. <listitem>
  1810. <para>
  1811. Semi-keywords -- it's important to us that
  1812. "every legal Java program is also a legal AspectJ program."
  1813. This wouldn't be true if we made 'before' and 'call' full keywords in
  1814. AspectJ. It is easier to support these sorts of semi-keywords with a
  1815. hand-written parser. (Note: ajc-1.0.x handles 'aspect' and 'pointcut'
  1816. slightly specially which can break a few unusual pure Java programs.
  1817. This is a compiler limitation that will be fixed in a future release.)
  1818. </para>
  1819. </listitem>
  1820. <listitem>
  1821. <para>
  1822. Deprecated syntax warnings -- the syntax of AspectJ
  1823. changed many times from version 0.2 to the 1.0 release. It was easier
  1824. to provide helpful warning messages for these changes with our
  1825. hand-written parser.
  1826. </para>
  1827. </listitem>
  1828. <listitem>
  1829. <para>
  1830. Grammar modularity -- We like being able to have
  1831. AspectJParser extend JavaParser.
  1832. </para>
  1833. </listitem>
  1834. <listitem>
  1835. <para>
  1836. Part of the grammar for AspectJ is extremely hard for existing tools to
  1837. capture. This is the type pattern syntax, i.e. "com.xerox..*.*(..)".
  1838. The sort of case that gives standard parser generators fits is something
  1839. like "*1.f(..)" which no one would ever write, but which must be
  1840. supported for a consistent language.
  1841. </para>
  1842. <para>
  1843. In AspectJ 1.1, the parser was written as it is for the underlying
  1844. Eclipse compiler,
  1845. with some hand-coding of the sort that avoids adding keywords to
  1846. the language.
  1847. </para>
  1848. </listitem>
  1849. </itemizedlist>
  1850. </answer>
  1851. </qandaentry>
  1852. </qandadiv>
  1853. <qandadiv id="devtools" xreflabel="Integrating AspectJ into your development environment">
  1854. <title>Integrating AspectJ into your development environment</title>
  1855. <qandaentry>
  1856. <question id="q:knowWhenAspectsAffectClasses"
  1857. xreflabel="Q: How do I know which aspects affect a class when looking at that class's source code?">
  1858. <para>How do I know which aspects affect a class when looking
  1859. at that class's source code?
  1860. </para>
  1861. </question>
  1862. <answer>
  1863. <para>When you are working with the IDE support, you can get an
  1864. understanding of which aspects affect any class.
  1865. This enables AspectJ programmers to get the benefits of
  1866. modularizing crosscutting concerns while still having immediate
  1867. access to what aspects affect a class.
  1868. </para>
  1869. <para>For example, the
  1870. <ulink url="devguide/index.html">
  1871. Development Environment Guide</ulink>
  1872. <ulink url="devguide/ajbrowser.html">
  1873. ajbrowser section</ulink>.
  1874. shows that you can list or navigate
  1875. between method and advice affecting that method and between a type
  1876. and declarations in an aspect on that type. (The IDE support may
  1877. have more features than <literal>ajbrowser</literal>, depending
  1878. on the IDE.
  1879. See <xref linkend="q:integrateWithDevTools"/> for more
  1880. information on which Java development environments are
  1881. supported.)
  1882. </para>
  1883. <para>
  1884. When you are looking at documentation for AspectJ 1.0 programs,
  1885. <literal>ajdoc</literal> will provide links from aspects and
  1886. advice to the affected code, but it provides less information
  1887. than the IDE support because it only parses declarations.
  1888. </para>
  1889. <para>
  1890. When you are compiling your program, pointcuts that are
  1891. statically-determinable can be used in declare statements
  1892. to identify the code picked out by the pointcut.
  1893. (A pointcut is statically determinable if it only uses
  1894. the pointcut designators
  1895. <literal>within</literal>,
  1896. <literal>withincode</literal>,
  1897. <literal>execution</literal>,
  1898. <literal>call</literal>,
  1899. <literal>get</literal>,
  1900. <literal>set</literal>,
  1901. <literal>initialiation</literal>, and
  1902. <literal>staticinitialiation</literal>.)
  1903. The compiler will list the static code points which will be
  1904. affected by any advice specifying the same pointcut.
  1905. For example, the following will print a warning
  1906. whereever some code in class Bar gets a field value from Foo:
  1907. <programlisting>
  1908. declare warning: get(* Foo.*) &amp;&amp; within(Bar)
  1909. : "reading Foo state from Bar";
  1910. </programlisting>
  1911. </para>
  1912. <para>
  1913. When you are running your program,
  1914. you can trace advice as it executes. This
  1915. enables you to identify advice on join points picked out
  1916. dynamically, which cannot be reflected precisely by IDE support.
  1917. For a related tracing question,
  1918. see <xref linkend="q:seeingjoinpoints"/>
  1919. </para>
  1920. </answer>
  1921. </qandaentry>
  1922. <qandaentry>
  1923. <question id="q:idesupport"
  1924. xreflabel="Q:What kind of IDE support is available for developing AspectJ programs?">
  1925. <para>What kind of IDE support is available for developing
  1926. AspectJ programs?
  1927. </para>
  1928. </question>
  1929. <answer>
  1930. <para>See <xref linkend="q:integrateWithDevTools"/></para>
  1931. </answer>
  1932. </qandaentry>
  1933. <qandaentry>
  1934. <question id="q:idesupportplans"
  1935. xreflabel="Q:What plans are there to support my IDE?">
  1936. <para>What plans are there to support my IDE?</para>
  1937. </question>
  1938. <answer>
  1939. <para>
  1940. The AspectJ team directly provided components for JBuilder, Forte,
  1941. and Emacs and supported the open-source AspectJ plugin project
  1942. at <ulink url="http://eclipse.org/ajdt">http://eclipse.org/ajdt</ulink>
  1943. which uses the AJDE API support for IDE's.
  1944. Supporting new IDE's is a matter of building on the AJDE API's,
  1945. mostly likely adopting one of the existing open-source IDE
  1946. extensions as a design template.
  1947. Here are the IDE's where we know people have expressed interest,
  1948. so interested developer may want to join with others in their
  1949. developer communities to build the integration.
  1950. <itemizedlist>
  1951. <title></title>
  1952. <listitem>
  1953. <para>IDEA/IntelliJ has an enthusiastic community and
  1954. the developers are working on an extensibility API
  1955. - <ulink url="http://intellij.com">http://intellij.com</ulink>
  1956. </para>
  1957. </listitem>
  1958. <listitem>
  1959. <para>jEdit comes from a very active open-source community.</para>
  1960. </listitem>
  1961. <listitem>
  1962. <para>
  1963. Oracle JDeveloper is supported at
  1964. <ulink url="https://jdeveloperaop.dev.java.net/">
  1965. https://jdeveloperaop.dev.java.net/</ulink>.
  1966. </para>
  1967. </listitem>
  1968. <listitem>
  1969. <para>Some have suggested Codeguide from Omnicore
  1970. <ulink url="http://www.omnicore.com">http://www.omnicore.com/</ulink>
  1971. </para>
  1972. </listitem>
  1973. </itemizedlist>
  1974. </para>
  1975. <para>
  1976. For questions on AJDE, join the developer's list
  1977. <literal>aspectj-dev@eclipse.org</literal>.
  1978. For questions on the current IDE integrations, contact those projects.
  1979. </para>
  1980. </answer>
  1981. </qandaentry>
  1982. <qandaentry>
  1983. <question id="q:portingajde"
  1984. xreflabel="Q:Can I port AJDE support to my development environment?">
  1985. <para>Can I port AJDE support to my development environment?</para>
  1986. </question>
  1987. <answer>
  1988. <para>Yes. The core AJDE API is extensible and the source code is
  1989. available for download. Start by studying the sources
  1990. for the existing IDE support linked off the AspectJ site
  1991. <ulink url="http://eclipse.org/aspectj">http://eclipse.org/aspectj</ulink>.
  1992. </para>
  1993. </answer>
  1994. </qandaentry>
  1995. <qandaentry>
  1996. <question id="q:hybridbuilds"
  1997. xreflabel="Q:Setting up hybrid builds">
  1998. <para>I want the aspects for development builds but
  1999. remove them for production builds. How can I set up the build
  2000. system so they are unpluggable? And so I use <literal>javac</literal>
  2001. in my production build?
  2002. </para>
  2003. </question>
  2004. <answer>
  2005. <para>
  2006. If you are using development-time-only aspects - aspects that only
  2007. exist when you are developing the code, not when you ship it -
  2008. you can use implement a hybrid build process by listing
  2009. the production source files into a javac-compliant argfile,
  2010. and the development source files in another ajc argfiles:
  2011. </para>
  2012. <programlisting>
  2013. -- file "production.lst":
  2014. One.java
  2015. two/Three.java
  2016. ...
  2017. -- file "tracing.lst":
  2018. trace/Library.java
  2019. Trace.java
  2020. -- file "development.lst":
  2021. @production.lst
  2022. @tracing.lst
  2023. </programlisting>
  2024. <para>
  2025. Then your development build can use <literal>ajc</literal>:
  2026. </para>
  2027. <programlisting>
  2028. ajc @development.lst
  2029. </programlisting>
  2030. <para>
  2031. And your development build can use
  2032. <literal>ajc</literal> or <literal>javac</literal>
  2033. or <literal>jikes</literal>:
  2034. </para>
  2035. <programlisting>
  2036. jikes @production.lst
  2037. </programlisting>
  2038. </answer>
  2039. </qandaentry>
  2040. <qandaentry>
  2041. <question id="q:stepwiseBuilds"
  2042. xreflabel="Q:We compile module jars and then assemble them. Can we continue this with AspectJ?">
  2043. <para>
  2044. We compile module jars and then assemble them. Can we continue this with AspectJ?
  2045. </para>
  2046. </question>
  2047. <answer>
  2048. <para>
  2049. Aspects apply to everything in a namespace, as if everything is
  2050. compiled together.
  2051. Sometimes you can break the build down into separate steps without breaking
  2052. this model, but we haven't stated exactly where it could break
  2053. because it depends on the interactions between all types.
  2054. You can try the approaches below, but remember to rebuild
  2055. everything in one go if there are problems.
  2056. </para>
  2057. <para>
  2058. The simplest scenario is when the aspects apply to all modules
  2059. and the modules compile without the aspects. In that case,
  2060. weaving in the aspects is just the final assembly step for
  2061. the build.
  2062. </para>
  2063. <para>
  2064. Next is the case where the aspects make changes to a common
  2065. library that are visible to other clients, which themselves
  2066. are otherwise unaffected by the aspects. In this case, the
  2067. common library can be built using ajc, and used on the
  2068. classpath for the module builds:
  2069. <programlisting>
  2070. <![CDATA[
  2071. ajc -outjar common.jar -sourceroots "aspectj-src:src" ...
  2072. cd ../otherProject
  2073. javac -classpath "../common/common.jar:${aspectjrt.jar}" {src}
  2074. ]]>
  2075. </programlisting>
  2076. </para>
  2077. <para>
  2078. Combining these last two,
  2079. there's the case where a common set of aspects should
  2080. affect two or more modules that are in a dependency relationship
  2081. to one another. It should work to reuse the aspects
  2082. in binary form for each compile, in dependency order:
  2083. <programlisting>
  2084. <![CDATA[
  2085. ajc -outjar common-aspects.jar
  2086. -sourceroots "aspectj-src" ...
  2087. ajc -outjar common.jar
  2088. -sourceroots "src"
  2089. -aspectpath common-aspects.jar ...
  2090. cd ../module1
  2091. ajc -outjar module1.jar
  2092. -sourceroots "src"
  2093. -classpath common.jar
  2094. -aspectpath ../common-aspects.jar ...
  2095. cd ../module2
  2096. ajc -outjar module2.jar
  2097. -sourceroots "src"
  2098. -classpath "common.jar;../module1.jar"
  2099. -aspectpath ../common-aspects.jar ...
  2100. ]]>
  2101. </programlisting>
  2102. </para>
  2103. <para>
  2104. If two modules are visibly affected by aspects and
  2105. mutually-dependent, the only thing to do is compile
  2106. them together.
  2107. </para>
  2108. <para>
  2109. It's safest to assume that all aspects can affect all
  2110. types in a namespace; using build boundaries to effect
  2111. crosscutting limits causes a dangerous dependency on
  2112. the build process and might cause problems.
  2113. </para>
  2114. </answer>
  2115. </qandaentry>
  2116. <qandaentry>
  2117. <question id="q:incrementalModuleCompiles"
  2118. xreflabel="Q: We use modules and would like to use incremental compilation.
  2119. Is that possible?">
  2120. <para>We use modules and would like to use incremental compilation.
  2121. Is that possible?
  2122. </para>
  2123. </question>
  2124. <answer>
  2125. <para>
  2126. Just incrementally-compile the whole system.
  2127. Specify to ajc the modules as multiple source roots
  2128. (or input jars if you are weaving libraries).
  2129. </para>
  2130. <para>
  2131. In Eclipse's AJDT, you can create a top-level project with symbolic
  2132. links out to the sources:
  2133. <programlisting>
  2134. <![CDATA[
  2135. app-assembly/
  2136. {link common/aspects}
  2137. {link common/src}
  2138. {link module1/src}
  2139. ...
  2140. ]]>
  2141. </programlisting>
  2142. Then everything is part of one huge incremental compile. Also, you
  2143. can close this master project and work the others using the Java
  2144. compiler or AJDT.
  2145. </para>
  2146. <para>
  2147. The links make incremental development possible without affecting
  2148. the modularized Ant builds. (Our practice runs along those lines.)
  2149. </para>
  2150. </answer>
  2151. </qandaentry>
  2152. </qandadiv>
  2153. <qandadiv id="notes" xreflabel="Programming notes and tips">
  2154. <title>Programming notes and tips</title>
  2155. <qandaentry>
  2156. <question id="q:methodsignatures"
  2157. xreflabel="Q:Is it possible to change methods by introducing keywords, adding parameters, or changing the throws clause?">
  2158. <para>Is it possible to change methods by introducing keywords (like
  2159. <literal>synchronized</literal>), adding parameters,
  2160. or changing the "throws" clause?
  2161. </para>
  2162. </question>
  2163. <answer>
  2164. <para>AspectJ does not enable you to change the signature of a method,
  2165. but you can (by express declaration) work around some
  2166. limits imposed by the signature. You can convert a checked exception to
  2167. unchecked using <literal>declare soft</literal>, privileged aspects
  2168. have access to private methods, and you can use a percflow aspect to
  2169. ferry additional state to a callee without changing intervening
  2170. signatures. For more details, see
  2171. <ulink url="progguide/index.html">The AspectJ Programming Guide</ulink>.
  2172. In the case of <literal>synchronized</literal>,
  2173. we have what we consider a better solution that uses
  2174. around advice instead of introduction. This solution is described
  2175. in
  2176. <ulink url="http://aspectj.org/pipermail/users/2000/000534.html">
  2177. this thread (no longer available)
  2178. </ulink> on the AspectJ users list, with some
  2179. <ulink url="http://aspectj.org/pipermail/users/2000/000536.html">
  2180. additional comments (no longer available)
  2181. </ulink>.
  2182. </para>
  2183. </answer>
  2184. </qandaentry>
  2185. <qandaentry>
  2186. <question id="q:seeingjoinpoints"
  2187. xreflabel="Q:I don't understand what join points exist. How can I see them?">
  2188. <para>
  2189. I don't understand what join points exist. How can I see them?
  2190. </para>
  2191. </question>
  2192. <answer>
  2193. <para>
  2194. You can trace them using using an aspect.
  2195. For example, you can start logging at a particular method call and
  2196. see what join points occur after the call and before it returns.
  2197. </para>
  2198. <para>
  2199. Here's some code Jim Hugunin wrote to trace join points
  2200. and posted to the users list. To reuse the aspect,
  2201. define a subaspect and implement the pointcuts, for example:
  2202. <programlisting>
  2203. aspect JoinPointSampleAspect extends aj.TraceJoinPoints {
  2204. protected pointcut entry() :
  2205. execution(static void JoinPointSample.main(String[]));
  2206. protected pointcut exit() :
  2207. call(static void JoinPointSampleAspect.exit());
  2208. public static void main (String[] args) {
  2209. JoinPointSample.main(args);
  2210. JoinPointSampleAspect.exit();
  2211. }
  2212. public static void exit() {}
  2213. }
  2214. class JoinPointSample {
  2215. public static void main(String[] args) {}
  2216. }
  2217. </programlisting>
  2218. </para>
  2219. <para>Here's the aspect:
  2220. <programlisting>
  2221. <![CDATA[
  2222. /* TraceJoinPoints.java */
  2223. package aj;
  2224. import org.aspectj.lang.*;
  2225. import org.aspectj.lang.reflect.*;
  2226. import java.io.*;
  2227. public abstract aspect TraceJoinPoints {
  2228. protected abstract pointcut entry();
  2229. protected pointcut exit(): call(* java..*.*(..));
  2230. // this line is for AspectJ 1.1; for 1.0, use "dominates"
  2231. declare precedence : TraceJoinPoints, *;
  2232. final pointcut start(): entry() && !cflowbelow(entry());
  2233. final pointcut trace():
  2234. cflow(entry()) && !cflowbelow(exit()) && !within(TraceJoinPoints+);
  2235. before(): start() { makeLogStream(); }
  2236. before(): trace() { logEnter(thisJoinPointStaticPart); }
  2237. after(): trace() { logExit(thisJoinPointStaticPart); }
  2238. after(): start() { closeLogStream(); }
  2239. //------------ added
  2240. /**
  2241. * Emit a message in the log, e.g.,
  2242. * <pre>TraceJoinPoints tjp = TraceJoinPoints.aspectOf();
  2243. * if (null != tjp) tjp.message("Hello, World!");</pre>
  2244. */
  2245. public void message(String s) {
  2246. out.println("<message>" + prepareMessage(s) + "</message>");
  2247. }
  2248. public void message(String sink, String s) {
  2249. if (null == sink) {
  2250. message(s);
  2251. } else {
  2252. out.println("<message sink=" + quoteXml(sink)
  2253. + " >" + prepareMessage(s) + "</message>");
  2254. }
  2255. }
  2256. protected String prepareMessage(String s) { return s; } // XXX implement
  2257. //--------- end of added
  2258. PrintStream out;
  2259. int logs = 0;
  2260. protected void makeLogStream() {
  2261. try {
  2262. out = new PrintStream(new FileOutputStream("log" + logs++ + ".xml"));
  2263. } catch (IOException ioe) {
  2264. out = System.err;
  2265. }
  2266. }
  2267. protected void closeLogStream() {
  2268. out.close();
  2269. }
  2270. int depth = 0;
  2271. boolean terminal = false;
  2272. protected void logEnter(JoinPoint.StaticPart jp) {
  2273. if (terminal) out.println(">");
  2274. indent(depth);
  2275. out.print("<" + jp.getKind());
  2276. writeSig(jp);
  2277. writePos(jp);
  2278. depth += 1;
  2279. terminal = true;
  2280. }
  2281. void writeSig(JoinPoint.StaticPart jp) {
  2282. out.print(" sig=");
  2283. out.print(quoteXml(jp.getSignature().toShortString()));
  2284. }
  2285. void writePos(JoinPoint.StaticPart jp) {
  2286. SourceLocation loc = jp.getSourceLocation();
  2287. if (loc == null) return;
  2288. out.print(" pos=");
  2289. out.print(quoteXml(loc.getFileName() +
  2290. ":" + loc.getLine() +
  2291. ":" + loc.getColumn()));
  2292. }
  2293. String quoteXml(String s) {
  2294. return "\"" + s.replace('<', '_').replace('>', '_') + "\"";
  2295. }
  2296. protected void logExit(JoinPoint.StaticPart jp) {
  2297. depth -= 1;
  2298. if (terminal) {
  2299. out.println("/>");
  2300. } else {
  2301. indent(depth);
  2302. out.println("</" + jp.getKind() + ">");
  2303. }
  2304. terminal = false;
  2305. }
  2306. void indent(int i) {
  2307. while (i-- > 0) out.print(" ");
  2308. }
  2309. }
  2310. ]]>
  2311. </programlisting>
  2312. </para>
  2313. <para>Note that if you are using AspectJ 1.0,
  2314. the line starting with <literal>declare precedence</literal>
  2315. would be removed, and the aspect declaration would look like
  2316. <literal>aspect TraceMyJoinPoints dominates *</literal>.
  2317. </para>
  2318. </answer>
  2319. </qandaentry>
  2320. <qandaentry>
  2321. <question id="q:comparecallandexecution"
  2322. xreflabel="Q:What is the difference between call and execution join points?">
  2323. <para>
  2324. What is the difference between call and execution join points?
  2325. </para>
  2326. </question>
  2327. <answer>
  2328. <para>
  2329. Briefly, there are two interesting times when a constructor or method is
  2330. run. Those times are when it is called, and when it actually
  2331. executes.
  2332. </para>
  2333. <para>
  2334. The main difference is that a call join point happens outside of
  2335. the target object (for non-static methods) or class (for static methods
  2336. and constructors), and that an execution join point happens inside
  2337. the object or class. This means that the <literal>within</literal>
  2338. and <literal>withincode</literal> pointcuts pick them out
  2339. differently: A call join point is picked out within the caller,
  2340. while an execution join point is picked
  2341. out where it is actually defined.
  2342. </para>
  2343. <para>
  2344. A call join point is the ``outermost'' join point for a particular
  2345. call. Once a call join point proceeds, then a number of different
  2346. things happen. For non-static methods, for example, method
  2347. dispatch happens, which will cause one method execution join point
  2348. -- perhaps more, if there are super calls. For constructors, the
  2349. super constructor is called, and fields are initialized, and then
  2350. various constructor execution join points will occur.
  2351. </para>
  2352. <para>
  2353. A call join point matches only the ``external'' calls of a method
  2354. or constructor, based on a signature, and it does not pick out
  2355. calls made with <literal>super</literal>, or
  2356. <literal>this</literal> constructor calls.
  2357. </para>
  2358. <para>Here's more detail:
  2359. </para>
  2360. <para>Consider method execution in Java as (1) the initial call from
  2361. this object to some method on the target object with a
  2362. particular signature; and (2) the execution of the actual code
  2363. in the particular method dispatched in the target object.
  2364. The call join point starts with the initial call and ends
  2365. when control returns to the call (by return or perhaps
  2366. thrown exception). The execution join point starts with
  2367. the method body and ends when the body completes (again
  2368. by return or throwing an exception), so the execution join
  2369. point always happens within the bounds of the corresponding
  2370. call join point. You can see this if you use the
  2371. join-point tracing aspect in see <xref linkend="q:seeingjoinpoints"/>.
  2372. </para>
  2373. <para>As you would expect, the context differs
  2374. in advice on pointcuts picking out execution and call join
  2375. points; for call, <literal>this</literal> refers to the caller, whereas
  2376. for execution <literal>this</literal> refers to the called
  2377. (executing) object.
  2378. </para>
  2379. <para>
  2380. There are some subtle interactions with other AspectJ semantics.
  2381. First, the meaning of the signature in the
  2382. <literal>execution()</literal> and <literal>call()</literal>
  2383. pointcut designators (PCD's) differ: the call type depends upon
  2384. the type of the reference making the call, while the execution
  2385. type depends on the enclosing class.
  2386. Second, you may choose one over another if you cannot bring all
  2387. your sources within the code the compiler controls
  2388. (described in the <ulink url="progguide/semantics.html">appendix</ulink>
  2389. to the <literal>Programming Guide</literal>).
  2390. For example, to trace calls into a
  2391. method from classes which are outside the code the compiler controls
  2392. at compile time, then using <literal>execution()</literal> will work
  2393. while using <literal>call()</literal>may not. Finally, since
  2394. <literal>super</literal> invocations are not considered method calls,
  2395. to trace <literal>super.foo()</literal> would require using
  2396. <literal>execution</literal>.
  2397. </para>
  2398. <para>
  2399. Because of differences in the way AspectJ 1.0 and 1.1
  2400. are implemented, in 1.0
  2401. you should use the <literal>call()</literal>
  2402. pointcut designator unless you have a good reason to use
  2403. <literal>execution()</literal>; in AspectJ 1.1, the
  2404. reverse is true.
  2405. </para>
  2406. </answer>
  2407. </qandaentry>
  2408. <qandaentry>
  2409. <question id="q:comparecflowandcflowbelow"
  2410. xreflabel="Q:What is the difference between cflow and cflowbelow?">
  2411. <para>
  2412. What is the difference between cflow and cflowbelow?
  2413. </para>
  2414. </question>
  2415. <answer>
  2416. <para>
  2417. Both pick out all the join points in the control flow of
  2418. the specified join points.
  2419. They differ only in that the <literal>cflowbelow()</literal>
  2420. pointcut designator does not pick out the join points
  2421. specified, while <literal>cflow()</literal> does.
  2422. </para>
  2423. </answer>
  2424. </qandaentry>
  2425. <qandaentry>
  2426. <question id="q:recursiveentrypoints"
  2427. xreflabel="Q:How do I say that I want the topmost entrypoint in a recursive call?">
  2428. <para>How do I say that I want the topmost entrypoint in a
  2429. recursive call? How about the most-recent prior entrypoint?
  2430. </para>
  2431. </question>
  2432. <answer>
  2433. <para>This is best seen by way of example.
  2434. Given a recursive call to <literal>int factorial(int)</literal>
  2435. you can print the arguments for
  2436. (a) the current and most-recent recursive call
  2437. or (b) the current and original recursive call:
  2438. </para>
  2439. <programlisting>
  2440. aspect LogFactorial {
  2441. pointcut f(int i) : call(int factorial(int)) &amp;&amp; args(i);
  2442. // most-recent
  2443. before(int i, final int j) : f(i) &amp;&amp; cflowbelow(f(j)) {
  2444. System.err.println(i + "-" + j);
  2445. }
  2446. // original
  2447. before(int i, final int j) : f(i)
  2448. &amp;&amp; cflowbelow(cflow(f(j)) &amp;&amp; !cflowbelow(f(int))) {
  2449. System.err.println(i + "@" + j);
  2450. }
  2451. }
  2452. </programlisting>
  2453. </answer>
  2454. </qandaentry>
  2455. <qandaentry>
  2456. <question id="q:initializationjoinpoints"
  2457. xreflabel="Q:What is the difference between constructor call, constructor execution, initialization, and static initialization join points?">
  2458. <para>What is the difference between constructor call,
  2459. constructor execution, initialization, and static
  2460. initialization join points?
  2461. </para>
  2462. </question>
  2463. <answer>
  2464. <para>Static initialization pertains to initialization of
  2465. a class or interface type. Constructor call and execution
  2466. are akin to method call, and initialization generalizes this and
  2467. picks out the first constructor called.
  2468. </para>
  2469. <para>Their relations are best
  2470. demonstrated by tracing the join points. Below is the class
  2471. Test which implements an interface and extends a class
  2472. along with a trace of the join points below and including
  2473. the constructor call obtained using
  2474. <literal>TraceJointPoints.java</literal>
  2475. from <xref linkend="q:seeingjoinpoints"/>.
  2476. </para>
  2477. <programlisting>
  2478. <![CDATA[
  2479. public class Init {
  2480. public static void main (String[] args) {
  2481. new Test();
  2482. end();
  2483. }
  2484. static void end() {}
  2485. }
  2486. class Super {}
  2487. interface I {}
  2488. class Test extends Super implements I {
  2489. Test() {}
  2490. }
  2491. ]]>
  2492. </programlisting>
  2493. <para>For a program compiled with AspectJ 1.0,
  2494. the result is this:</para>
  2495. <programlisting>
  2496. <![CDATA[
  2497. <constructor-call sig="Test()" >
  2498. <staticinitialization sig="Super._init_" />
  2499. <staticinitialization sig="Test._init_" />
  2500. <initialization sig="Super()" >
  2501. <instanceinitializer-execution sig="Super._init_" />
  2502. <constructor-execution sig="Super()" />
  2503. </initialization>
  2504. <initialization sig="I()" >
  2505. <instanceinitializer-execution sig="I._init_" />
  2506. <constructor-execution sig="I()" />
  2507. </initialization>
  2508. <initialization sig="Test()" >
  2509. <instanceinitializer-execution sig="Test._init_" />
  2510. <constructor-execution sig="Test()" />
  2511. </initialization>
  2512. </constructor-call>
  2513. ]]>
  2514. </programlisting>
  2515. <para>
  2516. Ordinarily, using a <literal>call</literal> pointcut designator
  2517. is best because the call join point surrounds the others, but in
  2518. the case of constructors there is no target object for
  2519. the call (because it has not been constructed yet), so you
  2520. might prefer to use the <literal>initialization</literal>
  2521. pointcut designator.
  2522. </para>
  2523. </answer>
  2524. </qandaentry>
  2525. <qandaentry>
  2526. <question id="q:adviseconstructors"
  2527. xreflabel="Q:How do I work with an object right when it is created?">
  2528. <para>How do I work with an object right when it is created?
  2529. </para>
  2530. </question>
  2531. <answer>
  2532. <para>
  2533. You can advise some form of constructor join point.
  2534. Constructors are tricky in Java, and that's exposed in AspectJ.
  2535. Here are some rules of thumb:
  2536. <itemizedlist>
  2537. <listitem>
  2538. <para>If you want the join point on the "outside" of object creation,
  2539. use after returning from call to the constructor:
  2540. </para>
  2541. <programlisting>
  2542. after() returning (Foo newlyCreatedObject): call(Foo.new(..)) { ... }
  2543. </programlisting>
  2544. <para>
  2545. You might be tempted to use "this" or "target" to expose the new object, but remember
  2546. that if you're on the "outside" of object creation, the object itself might not be
  2547. created yet... it only exists "on the way out", when you return the object.
  2548. </para>
  2549. </listitem>
  2550. <listitem>
  2551. <para>If you want the join point inside a particular constructor, use:
  2552. </para>
  2553. <programlisting>
  2554. after(Foo newlyCreatedObject) returning: this(newlyCreatedObject) &amp;&amp; execution(Foo.new(..)) { ... }
  2555. </programlisting>
  2556. <para>
  2557. Remember, though, that if you use "before" advice here, the body of the constructor
  2558. will not have run, and so the object may be somewhat uninitialized.
  2559. </para>
  2560. </listitem>
  2561. <listitem>
  2562. <para>
  2563. In the rare case that there are all sorts of constructors for the object that call
  2564. each other with <literal>this(...)</literal> and you want exactly one join point
  2565. for each initialization of <literal>Foo</literal>, regardless of the path of
  2566. constructors it takes, then use:
  2567. </para>
  2568. <programlisting>
  2569. after(Foo f) returning: this(f) &amp;&amp; initialization(Foo.new(..)) { ... }
  2570. </programlisting>
  2571. </listitem>
  2572. </itemizedlist>
  2573. </para>
  2574. </answer>
  2575. </qandaentry>
  2576. <qandaentry>
  2577. <question id="q:andingpointcuts"
  2578. xreflabel="Q:I want advice to run at two join points, but it doesn't run at all.">
  2579. <para>
  2580. I want advice to run at two join points, but it doesn't run at all. What gives?
  2581. </para>
  2582. </question>
  2583. <answer>
  2584. <para>
  2585. This usually reflects both a conceptual error and a programming mistake.
  2586. Most likely you want to do something like "run the advice for all
  2587. public and private calls," and the code looks something like this:
  2588. </para>
  2589. <programlisting>
  2590. within(com.xerox.printing..*) &amp;&amp; call(public * *(..)) &amp;&amp; call(private * *(..))
  2591. </programlisting>
  2592. <para>
  2593. But a pointcut is evaluated at *each* join point.
  2594. The expression above would never pick out any call join point,
  2595. because no method signature has both public and private access.
  2596. In a pointcut, <literal>pc1() &amp;&amp; pc2()</literal> means both
  2597. must be true at a given join point for advice to run at that join point.
  2598. The correct pointcut would use <literal>||</literal> as follows:
  2599. </para>
  2600. <programlisting>
  2601. within(com.xerox.printing..*) &amp;&amp; (call(public * *(..)) || call(private * *(..)))
  2602. </programlisting>
  2603. <para>
  2604. Then the advice will run at the join point.
  2605. </para>
  2606. </answer>
  2607. </qandaentry>
  2608. <qandaentry>
  2609. <question id="q:staticfieldreferences"
  2610. xreflabel="Q:How do I refer to a static field when my advice crosscuts multiple classes?">
  2611. <para>
  2612. How do I refer to a static field when my advice crosscuts multiple classes?
  2613. </para>
  2614. </question>
  2615. <answer>
  2616. <para>There is no way in advice to refer to the type of the
  2617. code executing in a static context except by specification.
  2618. This makes it impossible to refer to static members using
  2619. runtime information.
  2620. </para>
  2621. <para>However, AspectJ can determine the class for something
  2622. in the join point context, which you can use as a per-class key.
  2623. Then you can actually declare an instance field to contain
  2624. the per-class value (see the next question). This comes at
  2625. the cost of an extra reference, but the field can be final.
  2626. </para>
  2627. </answer>
  2628. </qandaentry>
  2629. <qandaentry>
  2630. <question id="q:interfacesastypepatterns"
  2631. xreflabel="Q:How can I reuse a type pattern?">
  2632. <para>I would like to reuse a type pattern, e.g., to
  2633. write advice that is limited to a certain set of classes.
  2634. Do I have to retype it each time?
  2635. </para>
  2636. </question>
  2637. <answer>
  2638. <para>No. You can declare that all the types implement
  2639. an interface you define, and then use the interface type in
  2640. your program. For example:
  2641. </para>
  2642. <programlisting>
  2643. /**
  2644. * Example of using an interface to represent a type pattern.
  2645. * sub-aspects use declare parents to add to traced types, e.g.,
  2646. * declare parents: com.mycompany.whatever..* implements Marked;
  2647. */
  2648. abstract aspect MarkerExample {
  2649. /** marker interface for types that we want to trace */
  2650. interface Marked {}
  2651. /** calls to an instance of Marked not from an instance of Marked */
  2652. pointcut dynamicCallsIn(): call(* *(..)) &amp;&amp; target(Marked) &amp;&amp; !this(Marked);
  2653. /** calls to methods defined by a subtype of Marked
  2654. * that don't come from the body of a subtype of Marked
  2655. */
  2656. pointcut staticCallsIn(): call(* Marked+.*(..)) &amp;&amp; !within(Marked+);
  2657. /** print dynamic calls */
  2658. before(): dynamicCallsIn() { System.out.println("before " + thisJoinPoint); }
  2659. }
  2660. aspect MyMarker extends MarkerExample {
  2661. declare parents: com.mycompany.whatever..* implements Marked;
  2662. }
  2663. </programlisting>
  2664. </answer>
  2665. </qandaentry>
  2666. <qandaentry>
  2667. <question id="q:exampleprograms"
  2668. xreflabel="Q:Where do I find example programs and how-to's?">
  2669. <para>Where do I find example programs and how-to's?</para>
  2670. </question>
  2671. <answer>
  2672. <para>There are a number of places to find sample code
  2673. and instructions for using AspectJ with other programming tools.
  2674. <orderedlist>
  2675. <listitem><para>
  2676. The AspectJ release includes examples in its
  2677. <literal>doc</literal> directory.
  2678. </para></listitem>
  2679. <listitem><para>
  2680. There is a community repository of sample code and tutorials
  2681. in the AspectJ CVS tree
  2682. <literal>docs</literal> module <literal>sandbox</literal> directory.
  2683. These are extracted and published (online only)
  2684. <ulink url="http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/sample-code.html">
  2685. here
  2686. </ulink>.
  2687. </para></listitem>
  2688. <listitem><para>
  2689. The <literal>teaching</literal> directory of the
  2690. <literal>docs</literal> module contains public materials
  2691. the AspectJ committers use for presentations, some of
  2692. which include example code. To access CVS, see
  2693. <xref linkend="q:buildingsource"/>.
  2694. </para></listitem>
  2695. <listitem><para>
  2696. The archives for the user and developer mailing lists
  2697. contain many good examples. To search the archives, see
  2698. <xref linkend="q:searchingsite"/>.
  2699. </para></listitem>
  2700. </orderedlist>
  2701. This code can vary in quality.
  2702. Code that we publish or include with AspectJ is generally
  2703. correct. However, code found in our CVS tree might not have
  2704. been tested thoroughly, and code from the mailing lists might
  2705. be untested or use older versions of the language.
  2706. </para>
  2707. </answer>
  2708. </qandaentry>
  2709. <qandaentry>
  2710. <question id="q:aspectlibraries"
  2711. xreflabel="Q:Are aspect libraries available?">
  2712. <para>Are aspect libraries available?</para>
  2713. </question>
  2714. <answer>
  2715. <para>Some libraries are distributed in the release under the
  2716. examples folder in the distribution.
  2717. These are "libraries" in the sense that they are reusable,
  2718. but they are delivered in source form.
  2719. Similarly, some of the sample code is reusable; for that,
  2720. see <xref linkend="q:exampleprograms"/>.
  2721. If you develop such a library and want to make it available to
  2722. other users, feel to send it to the users mailing list
  2723. <literal>aspectj-users@eclipse.org</literal>.
  2724. </para>
  2725. <para>In AspectJ 1.1, ajc supports binary aspects, so
  2726. you can distribute aspect libraries without distributing the
  2727. source. For more information, see the
  2728. <literal>-aspectpath</literal>
  2729. option in the
  2730. <ulink url="devguide/ajc-ref.html">
  2731. Reference for ajc</ulink>.
  2732. </para>
  2733. </answer>
  2734. </qandaentry>
  2735. <qandaentry>
  2736. <question id="q:serialversionuid"
  2737. xreflabel="Q:How does ajc interact with the serialVersionUID?">
  2738. <para>How does <literal>ajc</literal> interact with the
  2739. <literal>serialVersionUID</literal>?
  2740. </para>
  2741. </question>
  2742. <answer>
  2743. <para>The current version of <literal>ajc</literal> can change the
  2744. <varname>serialVersionUID</varname> of generated
  2745. <filename>.class</filename> files as a result of weaving in advice.
  2746. This is an important fact that developers using both aspects and
  2747. serialization should be aware of. It is likely that a future
  2748. version of the compiler will be better behaved regarding the
  2749. <varname>serialVersionUID</varname>.
  2750. </para>
  2751. <para>However, changes to the <literal>serialVersionUID</literal>
  2752. attribute are typically only important when using serialization for
  2753. the long-term persistence of objects. Using standard Java
  2754. serialization for long-term persistence has a number of drawbacks
  2755. and many developers already use alternative solutions. For one
  2756. possibly standard solution, see
  2757. <ulink url="http://jcp.org/jsr/detail/057.jsp">
  2758. Long-Term Persistence for JavaBeans Specification
  2759. </ulink>.
  2760. </para>
  2761. </answer>
  2762. </qandaentry>
  2763. <qandaentry>
  2764. <question id="q:applets"
  2765. xreflabel="Q:How can I use AspectJ with applets?">
  2766. <para>How can I use AspectJ with applets?</para>
  2767. </question>
  2768. <answer>
  2769. <para>
  2770. Just include the aspectjrt.jar as a required archive.
  2771. For example, here is the HTML code for an HTML editor
  2772. applet that contains some debugging aspects:
  2773. </para>
  2774. <programlisting>
  2775. <![CDATA[
  2776. <APPLET
  2777. CODE='com.company.swing.applets.EditorApplet'
  2778. WIDTH='700'
  2779. HEIGHT='525'>
  2780. <PARAM NAME="CODE" VALUE="com.company.swing.applets.EditorApplet" >
  2781. <PARAM NAME="ARCHIVE"
  2782. VALUE ="../company-applets.jar,../aspectjrt.jar,../xmlrpc-applet.jar" >
  2783. <PARAM NAME="type" VALUE="application/x-java-applet;version=1.4">
  2784. <PARAM NAME="scriptable" VALUE="false">
  2785. </APPLET>
  2786. ]]>
  2787. </programlisting>
  2788. <para>
  2789. The above markup has worked reliably with the Java Plugin
  2790. (included in the JRE 1.4.x) in IE 6, Mozilla 1.1 (Win32),
  2791. and Mozilla 1.0.1 (Red Hat Linux 8.0).
  2792. The following link describes how to configure Mozilla/Netscape
  2793. 6.x/7.x to use the Java Plugin from a JRE/SDK installation:
  2794. <ulink url="http://java.sun.com/j2se/1.4.1/manual_install_linux.html">
  2795. http://java.sun.com/j2se/1.4.1/manual_install_linux.html</ulink>.
  2796. (Thanks to Chris Bartling for this answer.)
  2797. </para>
  2798. </answer>
  2799. </qandaentry>
  2800. <qandaentry>
  2801. <question id="q:typeoblivious"
  2802. xreflabel="Q:How can I specify types for advice that captures primitives, void, etc.?">
  2803. <para>How can I specify types for advice that captures primitives, void, etc.?</para>
  2804. </question>
  2805. <answer>
  2806. <para>
  2807. In some cases, AspectJ allows conversion from values of primitive types to Object,
  2808. so that highly polymorphic advice may be written. This works if an advice parameter
  2809. or the return type for around is typed to Object. So:
  2810. </para>
  2811. <programlisting>
  2812. class Test {
  2813. static int i;
  2814. public static void main(String[] args) {
  2815. i = 37;
  2816. }
  2817. }
  2818. aspect TraceSet {
  2819. before(Object val): set(* Test.*) &amp;&amp; args(val) {
  2820. System.err.println(val);
  2821. System.err.println(val.class);
  2822. }
  2823. }
  2824. </programlisting>
  2825. <para>
  2826. will print out
  2827. </para>
  2828. <programlisting>
  2829. 37
  2830. java.lang.Integer
  2831. </programlisting>
  2832. <para>
  2833. For more information, see the Programming Guide
  2834. <ulink url="progguide/semantics-pointcuts.html">
  2835. semantics section "Context Exposure"
  2836. </ulink>.
  2837. </para>
  2838. </answer>
  2839. </qandaentry>
  2840. <qandaentry>
  2841. <question id="q:versioninfo"
  2842. xreflabel="Q:How do I detect which version I am running?">
  2843. <para>How do I detect which version I am running?</para>
  2844. </question>
  2845. <answer>
  2846. <para>The <literal>ajc</literal>
  2847. compiler emits the version when passed the
  2848. <literal>-version</literal> flag as an argument.
  2849. </para>
  2850. <para>To programmatically
  2851. detect the version of the AspectJ runtime while running
  2852. under Java 1.4 or later, get the version from the package:
  2853. <programlisting>
  2854. Package lang = org.aspectj.lang.JoinPoint.class.getPackage();
  2855. String version = lang.getImplementationVersion();
  2856. </programlisting>
  2857. </para>
  2858. <para>When running under Java 1.3 or earlier, read the manifest
  2859. directly. For example code, see the source for
  2860. <literal>AjBuildManager.checkRtJar(AjBuildConfig)</literal>
  2861. in the <literal>org.aspectj.ajdt.internal.core.builder</literal>
  2862. package of the <literal>org.aspectj.ajdt.core</literal> module,
  2863. available as described in
  2864. <xref linkend="q:buildingsource"/>.
  2865. </para>
  2866. <para>Note that the version of AspectJ for the tools in
  2867. <literal>aspectjtools.jar</literal> is in
  2868. <literal>org.aspectj.bridge.Version</literal>.
  2869. </para>
  2870. </answer>
  2871. </qandaentry>
  2872. </qandadiv>
  2873. <qandadiv id="problems" xreflabel="Common Problems">
  2874. <title>Common Problems</title>
  2875. <qandaentry>
  2876. <question id="q:infiniterecursion"
  2877. xreflabel="Q:When I run, I get a StackOverflowError or no output.">
  2878. <para>When I run, I get a <literal>StackOverflowError</literal>
  2879. (or a long stack trace or no output whatsoever)
  2880. </para>
  2881. </question>
  2882. <answer>
  2883. <para>Most likely this is a case of infinite recursion,
  2884. where advice is advising itself. It presents as a
  2885. <literal>StackOverflowError</literal>
  2886. or silence as the VM exhausts itself in the recursion.
  2887. </para>
  2888. <para>Of course, infinite recursion is possible in Java:</para>
  2889. <programlisting>
  2890. public class Main {
  2891. public static void main(String[] args) {
  2892. try {
  2893. main(args);
  2894. } finally {
  2895. main(args);
  2896. }
  2897. }
  2898. }
  2899. </programlisting>
  2900. <para>If you compile and run this program, and it will fail silently, trying
  2901. to process the finally clause even after throwing the StackOverflowError.
  2902. </para>
  2903. <para>Here's a similar AspectJ program where the recursion is
  2904. not so obvious:
  2905. </para>
  2906. <programlisting>
  2907. aspect A {
  2908. after(): call(* *(..)) { System.out.println("after " + thisJoinPoint); }
  2909. }
  2910. </programlisting>
  2911. <para>This re-invokes itself because it advises any call.
  2912. It invokes itself even after an exception is thrown, since
  2913. <literal>after</literal> advice, like a finally clause, runs even
  2914. after exceptions are thrown. You can fix this by following two practices:
  2915. </para>
  2916. <para>In AspectJ 1.1, the String concatenation operator (+) is
  2917. advised in its StringBuffer form, so if your advise uses
  2918. String + in a way that is picked out by your pointcut,
  2919. you will get infinite recursion.</para>
  2920. <para>
  2921. (1) Use <literal>after returning</literal> to advise normal completions
  2922. or <literal>after throwing</literal> to advise abrupt completions.
  2923. If you use <literal>after</literal> or <literal>after throwing</literal>,
  2924. write the advice with the same care you would a finally clause,
  2925. understanding that it may run after some failure.
  2926. </para>
  2927. <para>(2) Avoid writing advice that advises itself. One simple way to
  2928. do so is to exclude the code within the current aspect:
  2929. </para>
  2930. <programlisting>
  2931. aspect A {
  2932. after() returning: !within(A) &amp;&amp; call(* *(..)) {
  2933. System.out.println("after " + thisJoinPoint);
  2934. }
  2935. }
  2936. </programlisting>
  2937. <para>A better way is often to re-write the pointcut.
  2938. If the advice is advising itself accidentally, that's a sign that
  2939. the pointcut is not saying what you mean.
  2940. </para>
  2941. <programlisting>
  2942. aspect A {
  2943. pointcut withinTargetClasses() : within(A+) || within(B+);
  2944. after() returning: withinTargetClasses() &amp;&amp; call(* *(..)) {
  2945. System.out.println("after " + thisJoinPoint);
  2946. }
  2947. }
  2948. </programlisting>
  2949. </answer>
  2950. </qandaentry>
  2951. <qandaentry>
  2952. <question id="q:typelessdeclarations"
  2953. xreflabel="Q:I've declared a field on every class in my package; how do I use it in advice?">
  2954. <para>I've declared a field on every class in
  2955. my package; how do I use it in advice?
  2956. </para>
  2957. <programlisting>
  2958. aspect A {
  2959. boolean com.xerox..*.dirtyFlag;
  2960. after (Object target) returning
  2961. : target(target) &amp;&amp; call(* com.xerox..*.set*(..)) {
  2962. target.dirtyFlag = true; // compile fails here
  2963. }
  2964. }
  2965. </programlisting>
  2966. </question>
  2967. <answer>
  2968. <para>You need a type to refer to any member, field or method.
  2969. It's generally better to introduce onto an interface and
  2970. declare classes to implement the interface, which permits you
  2971. to use the interface type in advice formals.
  2972. </para>
  2973. <programlisting>
  2974. aspect A {
  2975. interface TrackingSets {}
  2976. boolean TrackingSets.dirtyFlag;
  2977. declare parents : com.xerox..* implements TrackingSets;
  2978. after (TrackingSets target) returning
  2979. : target(target) &amp;&amp; call(* com.xerox..*.set*(..)) {
  2980. target.dirtyFlag = true;
  2981. }
  2982. }
  2983. </programlisting>
  2984. </answer>
  2985. </qandaentry>
  2986. <qandaentry>
  2987. <question id="q:ajcoom"
  2988. xreflabel="Q:The AspectJ compiler aborts with an OutOfMemoryError when compiling many classes. How can I fix this?">
  2989. <para>The AspectJ compiler aborts with an OutOfMemoryError when
  2990. compiling many classes. How can I fix this?
  2991. </para>
  2992. </question>
  2993. <answer>
  2994. <para><literal>ajc</literal> can use more memory than a javac
  2995. compile of the corresponding pure-java sources when aspects
  2996. are added to the mix. You'll need to increase the memory
  2997. available.
  2998. </para>
  2999. <para>The command <literal>ajc</literal> is actually a script that
  3000. launches a Java virtual machine with the correct classpath. You
  3001. should make a copy of this script, rename it, and then edit it.
  3002. Change the -Xmx option, size of memory allocation pool (heap). You
  3003. might try <literal>-Xmx128M</literal> or even
  3004. <literal>-Xmx256M</literal>.
  3005. </para>
  3006. <para>When running under Ant, give Ant more memory or
  3007. use the <literal>fork</literal> option together with
  3008. the <literal>Xmaxmem</literal> option.
  3009. </para>
  3010. <para>When running under an IDE, look to the documentation
  3011. for the IDE to determine how to increase available memory.
  3012. </para>
  3013. </answer>
  3014. </qandaentry>
  3015. <qandaentry>
  3016. <question id="q:duplicateclass"
  3017. xreflabel="Q:Why do I get a message that my class is already defined?">
  3018. <para>
  3019. Why do I get a message that my class is already defined?
  3020. </para>
  3021. </question>
  3022. <answer>
  3023. <para>
  3024. Most commonly, a source file was specified twice on the command line
  3025. (e.g., directly and by a *.java entry in a .lst file).
  3026. However, sometimes you have defined a class in two files in the
  3027. same package, and you need to rename the class or change its
  3028. scope. You should get this message from any Java compiler.
  3029. </para>
  3030. </answer>
  3031. </qandaentry>
  3032. <qandaentry>
  3033. <question id="q:ajcrecompile"
  3034. xreflabel="Q:ajc recompiles all files every time. How can I make it recompile only the files that have changed?">
  3035. <para>
  3036. <literal>ajc</literal> recompiles all files every time.
  3037. How can I make it recompile only the files that have changed?
  3038. </para>
  3039. </question>
  3040. <answer>
  3041. <para>
  3042. <literal>ajc</literal> 1.0 does not support incremental
  3043. compilation, but the 1.1 release does when passed the
  3044. <literal>-incremental</literal> option. It may still recompile
  3045. files that have not changed, if they could be affected by aspects
  3046. in particular ways, but the files compiled should be fewer
  3047. and result in faster compiles.
  3048. Further, the 1.1 release supports binary weaving, so you
  3049. need not recompile if you already have .class files.
  3050. </para>
  3051. </answer>
  3052. </qandaentry>
  3053. <qandaentry>
  3054. <question id="q:ajcjvm"
  3055. xreflabel="Q:ajc is using the wrong JVM. How do I fix it?">
  3056. <para>
  3057. <literal>ajc</literal> is using the wrong JVM. How do I
  3058. fix it?
  3059. </para>
  3060. </question>
  3061. <answer>
  3062. <para>The easiest way to fix this is to re-install
  3063. <literal>ajc</literal> (using the same <literal>.class</literal> or
  3064. <literal>.exe</literal> file that you originally downloaded) and
  3065. this time make sure to tell it to use the desired JDK (typically
  3066. the JDK versions 1.2 or 1.3 from Sun).
  3067. </para>
  3068. <para>If you are familiar with DOS batch files or shell programming,
  3069. you could also fix this by simply editing the
  3070. <literal>bin\ajc.bat</literal> or <literal>bin/ajc</literal>
  3071. script.
  3072. </para>
  3073. </answer>
  3074. </qandaentry>
  3075. <qandaentry>
  3076. <question id="q:idebalkingataspects"
  3077. xreflabel="Q:My IDE is trying to parse AspectJ files which makes my project unusable. What can I do?">
  3078. <para>My IDE is trying to parse AspectJ files which makes my project unusable.
  3079. What can I do?
  3080. </para>
  3081. </question>
  3082. <answer>
  3083. <para>
  3084. When working with an unsupported IDE that objects to the syntax of
  3085. AspectJ source files (and, e.g., automatically gathers them
  3086. in a source tree as Java files based on the .java extension),
  3087. you can use the .aj extension for your AspectJ files.
  3088. The ajc compiler accepts both .java and .aj files, and you can
  3089. set up your build scripts to include the correct list of
  3090. source files. (You will have to find another editor for
  3091. editing AspectJ files; you can use the ajbrowser to view
  3092. edit your AspectJ files and navigate the crosscutting structure.)
  3093. </para>
  3094. </answer>
  3095. </qandaentry>
  3096. <qandaentry>
  3097. <question id="q:idememory"
  3098. xreflabel="Q:I used to be able to compile my program, but now I run out of memory.">
  3099. <para>I used to be able to compile my program in my IDE, but when I
  3100. use AJDE, I run out of memory (or it goes really slow).
  3101. </para>
  3102. </question>
  3103. <answer>
  3104. <para>
  3105. The ajc compiler does more analysis than (e.g.,) javac,
  3106. and AJDE may in some IDE's hold a copy of the structure tree until the
  3107. next tree is available from the compile process. Both mean that you may
  3108. need extra memory to compile the same program. However, increasing
  3109. available memory to the point that you are swapping to disk can
  3110. slow the process considerably.
  3111. </para>
  3112. <para>
  3113. If you are having problems and would like to find the optimal memory
  3114. allocation, iteratively decrease the amount of memory available until
  3115. AJDE or ajc signals out-of-memory errors, and then increase that
  3116. amount by 5-10%.
  3117. </para>
  3118. <para>
  3119. To increase memory for the ajc compiler, see <xref linkend="q:ajcoom"/>.
  3120. For your IDE, do something similar or follow the provider's instructions.
  3121. For example, to increase memory in JBuilder, edit the
  3122. <literal>jbuilderX/bin/jbuilder.config</literal>
  3123. file to have an entry like:
  3124. <programlisting>
  3125. vmparam -Xmx384m
  3126. </programlisting>
  3127. </para>
  3128. <para>
  3129. If it turns out that your project is too big to use with AJDE, your IDE
  3130. may nonetheless support external commands or Ant build processes, which
  3131. run outside the IDE memory space. For a JBuilder Ant plugin, some
  3132. people have directed us to <ulink url="http://antrunner.sourceforge.net"/>.
  3133. </para>
  3134. </answer>
  3135. </qandaentry>
  3136. <qandaentry>
  3137. <question id="q:noaspectbound"
  3138. xreflabel="Q:When I run, I get a NoAspectBoundException or a
  3139. ClassNotFound message for NoAspectBoundException.">
  3140. <para>
  3141. When I run, I get a <literal>NoAspectBoundException</literal> or a
  3142. ClassNotFound message for <literal>NoAspectBoundException</literal>.
  3143. </para>
  3144. </question>
  3145. <answer>
  3146. <para>This happens when an aspect is not associated with an object
  3147. that is being advised. We have seen this happen two ways:
  3148. <itemizedlist>
  3149. <listitem>
  3150. <para>You get a ClassNotFound message for
  3151. <literal>NoAspectBoundException</literal> when loading a
  3152. class affected by aspects if <literal>aspectjrt.jar</literal>
  3153. classes are not on the runtime classpath.
  3154. To fix this, put the classes on the classpath.
  3155. </para>
  3156. </listitem>
  3157. <listitem>
  3158. <para>
  3159. You can get a <literal>NoAspectBoundException</literal> when
  3160. there is a cycle in aspect initialization or static
  3161. initialization, most commonly when an aspect advises
  3162. its own initializer. To fix this, first find the class that
  3163. fails to load by running java in debug mode or looking
  3164. at the <literal>NoAspectBoundException</literal> trace,
  3165. and then fix the offending (probably unintended) dependency.
  3166. Most often, it comes from a pointcut like
  3167. <literal>staticinitialization(com.company..*)</literal>
  3168. or <literal>within(com.company..*)</literal>, which
  3169. can include any aspects in the same subpackages.
  3170. You can avoid advising most join points associated with
  3171. the aspect <literal>TheAspect</literal>
  3172. by adding <literal>&amp;&amp; !within(TheAspect)</literal>
  3173. to your pointcut.
  3174. </para>
  3175. </listitem>
  3176. </itemizedlist>
  3177. </para>
  3178. </answer>
  3179. </qandaentry>
  3180. <qandaentry>
  3181. <question id="q:stacktraces"
  3182. xreflabel="Q:My stack traces don't make sense. What gives?">
  3183. <para>
  3184. My stack traces don't make sense. What gives?
  3185. </para>
  3186. </question>
  3187. <answer>
  3188. <para>In 1.0, unless you are using the <literal>ajdb</literal> debugger,
  3189. stack traces may
  3190. have synthetic methods in the stack, and the line numbers may
  3191. not track your source code. The
  3192. <ulink url="devguide/index.html">
  3193. Development Environment Guide</ulink>
  3194. discusses how to interpret stack at the end of the
  3195. <ulink url="devguide/ajc-ref.html">
  3196. Reference for ajc</ulink>.
  3197. </para>
  3198. <para>In 1.1, line numbers should work correctly.
  3199. The only difference from a normal stack might be the addition
  3200. of extra stack frames for call-backs.
  3201. </para>
  3202. </answer>
  3203. </qandaentry>
  3204. <qandaentry>
  3205. <question id="q:advicenotrunning"
  3206. xreflabel="Q:My advice is not running (or running twice), and I don't know why.">
  3207. <para>
  3208. My advice is not running (or running twice), and I don't know why.
  3209. </para>
  3210. </question>
  3211. <answer>
  3212. <para>
  3213. When advice is not running,
  3214. there is probably a problem in the pointcut.
  3215. Sometimes users specify pointcuts that
  3216. do not mean what they intend -
  3217. most often when they misspell a type name. Run the compiler in
  3218. <literal>-Xlint</literal> mode, which will flag some likely mistakes,
  3219. like the type name.
  3220. If that does not work, and your pointcut is staticly-determinable,
  3221. use a declare statement to identify affected code. (For more
  3222. information, see <xref linkend="q:knowWhenAspectsAffectClasses"/>.)
  3223. If that does not work and your pointcut is dynamically determined,
  3224. see if your join points are executing at all by using
  3225. TraceJoinPoints.java from <xref linkend="q:seeingjoinpoints"/>.
  3226. </para>
  3227. <para>When advice is running more than it should, either
  3228. (1) your advice is in an abstract aspect and the pointcut picks
  3229. out the same join point for more than one concrete instantiation
  3230. of the aspect, or
  3231. (2) your pointcut picks out more join points than you intend.
  3232. </para>
  3233. <para>
  3234. In the case of advice in abstract aspects, the advice will run once
  3235. for each concrete instance of the aspect.
  3236. If the pointcut for that advice picks out the same join point for two
  3237. concrete aspects, then the correct behavior is for the advice to run
  3238. the advice twice at that join point.
  3239. </para>
  3240. <para>
  3241. To see if your pointcut picks out the join points you intend, you
  3242. can use IDE support, logging, or declare-warnings.
  3243. If you are using IDE support, you should be able to trace back from
  3244. the pointcut or advice to the join points which can be statically
  3245. determined to be affected.
  3246. Without IDE support, you can write
  3247. declare-warning statements to identify code affected by staticly-
  3248. determinable pointcuts.
  3249. To identify advised dynamic join points,
  3250. you can try using <literal>TraceJoinPoints.java</literal> as above,
  3251. or update the advice to print the source location of the join point.
  3252. Doing any of these should show if the advice applies to code that
  3253. you did not expect.
  3254. </para>
  3255. <para>If you've done this and convinced yourself it's not working,
  3256. it may be a bug. See <xref linkend="q:bugreports"/>.
  3257. </para>
  3258. </answer>
  3259. </qandaentry>
  3260. <qandaentry>
  3261. <question id="q:adviceOnOveriddenMethods"
  3262. xreflabel="Q:My advice runs for each overridden method!">
  3263. <para>
  3264. My advice runs for each overridden method!
  3265. </para>
  3266. </question>
  3267. <answer>
  3268. <para>Most likely you are advising the method execution join
  3269. point and specifying the defining signature.
  3270. Since all overriding methods share this signature,
  3271. the advice runs for each method executed.
  3272. (This happens, e.g., when one method invokes the same method
  3273. in the superclass using <literal>super.{method}(..)</literal>).
  3274. This is the correct behavior.
  3275. </para>
  3276. <para>To avoid this, use the <literal>call(..)</literal> pointcut
  3277. designator, or use <literal>!cflow(..)</literal> to pick
  3278. out only the initial method-execution.
  3279. </para>
  3280. </answer>
  3281. </qandaentry>
  3282. <qandaentry>
  3283. <question id="q:tejpsp"
  3284. xreflabel="Q:I don't understand when thisEnclosingJoinPointStaticPart is available.">
  3285. <para>
  3286. I don't understand when thisEnclosingJoinPointStaticPart is available.
  3287. </para>
  3288. </question>
  3289. <answer>
  3290. <para>
  3291. <literal>thisEnclosingJoinPointStaticPart</literal> is a special
  3292. variable available in the context of advice to refer to the
  3293. join point, if any, lexically enclosing the current join point:
  3294. <table>
  3295. <title>thisEnclosingJoinPointStaticPart</title>
  3296. <tgroup cols="2">
  3297. <tbody>
  3298. <row>
  3299. <entry>One of these...</entry>
  3300. <entry>will be tEJSP for each of these:</entry>
  3301. </row>
  3302. <row>
  3303. <entry>
  3304. constructor-execution, method-execution,
  3305. advice execution, initialization,
  3306. pre-initialization, static initialization
  3307. </entry>
  3308. <entry>
  3309. constructor-call, method-call, handler,
  3310. field-set, field-get
  3311. </entry>
  3312. </row>
  3313. </tbody>
  3314. </tgroup>
  3315. </table>
  3316. Expressions in the body of handlers have the same
  3317. <literal>thisEnclosingJoinPointStaticPart</literal>
  3318. as the handler itself.
  3319. </para>
  3320. </answer>
  3321. </qandaentry>
  3322. <qandaentry>
  3323. <question id="q:packagedeclares"
  3324. xreflabel="Q:I declared a member on a class with package access, but other classes in the package cannot see it.">
  3325. <para>
  3326. I declared a member on a class with package access, but other classes in the package cannot see it.
  3327. </para>
  3328. </question>
  3329. <answer>
  3330. <para>When declaring parents on other types from an aspect, package access only
  3331. applies to code the implementation controls. For AspectJ 1.0, that is the set of files
  3332. passed to the compiler. That means other classes not compiled with the aspect will not
  3333. be able to access the aspect-declared members even if they are in the same package.
  3334. The only way for classes outside the control of the implementation to access aspect-declared
  3335. members is to declare them public.
  3336. </para>
  3337. </answer>
  3338. </qandaentry>
  3339. <qandaentry>
  3340. <question id="q:interfaceDeclarations"
  3341. xreflabel="Q:I declared a member on a interface, but javac does not see it.">
  3342. <para>I declared a member on a interface, but javac does not see it.
  3343. </para>
  3344. </question>
  3345. <answer>
  3346. <para>
  3347. You have to compile all the top-level implementating
  3348. classes of the interface using <literal>ajc</literal>.
  3349. From an email by Jim Hugunin on the requirements for AspectJ 1.1 to
  3350. implement members declared by an aspect on an interface:
  3351. </para>
  3352. <para>
  3353. If you introduce non-static fields or non-abstract methods on an interface
  3354. from an aspect, then all of the top-most implementors of that interface must
  3355. be woven by that same aspect.
  3356. (A class C is a top-most implementor of an interface I if C implements I
  3357. and the superclass of C does not implement I.)
  3358. </para>
  3359. </answer>
  3360. </qandaentry>
  3361. <qandaentry>
  3362. <question id="q:cantfindjavac"
  3363. xreflabel="Q:ajc 1.0 complains that it can't find javac. What's wrong?">
  3364. <para>
  3365. <literal>ajc</literal> 1.0 complains that it can't find
  3366. <literal>javac</literal>. What's wrong?
  3367. </para>
  3368. </question>
  3369. <answer>
  3370. <para>
  3371. <literal>ajc</literal> 1.0 does not try to locate
  3372. <literal>javac</literal> in your path: it uses the
  3373. <literal>javac</literal> classes directly. In JDK 1.2 and 1.3 these
  3374. classes are found in <literal>tools.jar</literal> (in the
  3375. <literal>lib</literal> directory of the JDK distribution), which
  3376. must be on your classpath to make
  3377. <literal>ajc</literal> work with <literal>javac</literal>.
  3378. Inspect the java command that launches ajc to make sure that
  3379. <literal>tools.jar</literal> is on the classpath for ajc;
  3380. the -classpath option only applies to the sources compiled.
  3381. </para>
  3382. </answer>
  3383. </qandaentry>
  3384. <qandaentry>
  3385. <question id="q:ajdocneeds13"
  3386. xreflabel="Q:I'm running under 1.4, but ajdoc asks for 1.3 (or throws IllegalAccessError for HtmlWriter.configuration)">
  3387. <para>
  3388. I'm running under 1.4, but <literal>ajdoc</literal> asks for 1.3
  3389. (or throws IllegalAccessError for HtmlWriter.configuration)
  3390. </para>
  3391. </question>
  3392. <answer>
  3393. <para>
  3394. The 1.0 implementation of <literal>ajdoc</literal> uses
  3395. specific javadoc classes in the J2SE 1.3 tools.jar.
  3396. We are working on addressing this limitation, but in the interim
  3397. it is best to run ajdoc under 1.3.
  3398. </para>
  3399. <para>
  3400. When running from the command-line scripts, edit the scripts directly
  3401. to put the 1.3 tools.jar first on the classpath. (The installer does
  3402. not know about this limitation of ajdoc.)
  3403. </para>
  3404. <para>
  3405. When running from Ant, users often have tools.jar in ${ant.classpath}
  3406. (to make javac, et al work). That makes it impossible to run the ajdoc
  3407. taskdef (which does not currently support forking), so you'll need to
  3408. run a separate ant process, either from the command-line or via Ant's
  3409. exec task (the Ant task will propagate the classpath).
  3410. If the wrong tools.jar is not on the ant classpath, then it should work
  3411. to put the 1.3 tools.jar in the taskdef classpath.
  3412. </para>
  3413. </answer>
  3414. </qandaentry>
  3415. <qandaentry>
  3416. <question id="q:compileunits"
  3417. 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?">
  3418. <para>I set up different files to my compiles to change what
  3419. the aspects see, but now I don't
  3420. understand how the aspects are working.
  3421. </para>
  3422. </question>
  3423. <answer>
  3424. <para>It is a bad practice to use the compilation unit
  3425. to control crosscutting. Aspects and pointcuts especially
  3426. should be written to specify crosscutting precisely.
  3427. Aspects will behave the same when you add files if
  3428. you initially included all files affected by your aspects.
  3429. If you use the compilation unit, then your code will behave
  3430. differently in AspectJ implementations that do not limit
  3431. themselves to specified files.
  3432. </para>
  3433. </answer>
  3434. </qandaentry>
  3435. <qandaentry>
  3436. <question id="q:readingpreprocessedcode"
  3437. xreflabel="Q:I'm reading the code generated by ajc 1.0 in -preprocess mode, and it seems like it would not work.">
  3438. <para>I'm reading the code generated by <literal>ajc</literal> 1.0
  3439. in <literal>-preprocess</literal> mode, and it seems like it would not
  3440. work (or "like it works this way").
  3441. </para>
  3442. </question>
  3443. <answer>
  3444. <para>The generated code can be difficult for a human to read and
  3445. understand. The compiler uses implementation techniques which might
  3446. not be apparent. To determine if the code is behaving correctly, you
  3447. should write and run a program that attempts to provoke the error you
  3448. suspect. Similarly, you should not rely on invariants you infer from
  3449. the generated code (especially naming conventions for generated members).
  3450. Please rely only on the semantics stated in the appendix of the
  3451. AspectJ <ulink url="progguide/index.html">Programming Guide</ulink>.
  3452. </para>
  3453. </answer>
  3454. </qandaentry>
  3455. <qandaentry>
  3456. <question id="q:injection"
  3457. xreflabel="Q:I've heard AspectJ can generate or inject code into my code. Is this true?">
  3458. <para>I've heard AspectJ can generate or inject code into my code.
  3459. Is this true?
  3460. </para>
  3461. </question>
  3462. <answer>
  3463. <para>
  3464. This is a misconception spawned from the early implementation.
  3465. </para>
  3466. <para>
  3467. AspectJ does not "inject" or "generate" code. In AspectJ the
  3468. pointcut constructs allow the programmer to identify join points,
  3469. and the advice constructs define additional code to run at those
  3470. join points.
  3471. </para>
  3472. <para>
  3473. So the semantic model of advice is like the semantic model of a
  3474. method -- it says "when any of these things happen, do this".
  3475. </para>
  3476. <para>
  3477. People who worked with earlier versions of AspectJ, in which ajc
  3478. was very explicitly a pre-processor, sometimes thought of AspectJ
  3479. as injecting code. But that was an artifact of the implementation,
  3480. not the underlying language semantics.
  3481. </para>
  3482. <para>
  3483. This distinction is important for two reasons. One is that thinking
  3484. about it this way will make more sense at the implementation continues
  3485. to evolve towards load-time or runtime weaving. The other is that
  3486. it makes it much easier to understand the semantics of advice on
  3487. cflow pointcuts.
  3488. </para>
  3489. </answer>
  3490. </qandaentry>
  3491. <qandaentry>
  3492. <question id="q:newjoinpoints"
  3493. xreflabel="Q:Why can't AspectJ pick out local variables (or array elements or ...)?">
  3494. <para>Why can't AspectJ pick out local variables (or array elements or ...)?
  3495. </para>
  3496. </question>
  3497. <answer>
  3498. <para>Users have sometimes wanted AspectJ to pick out
  3499. many more join points, including
  3500. <itemizedlist>
  3501. <listitem><para>method-local field access</para></listitem>
  3502. <listitem><para>array-element access</para></listitem>
  3503. <listitem><para>loop iteration</para></listitem>
  3504. <listitem><para>method parameter evaluation</para></listitem>
  3505. </itemizedlist>
  3506. Most of these have turned out not to make sense,
  3507. for a variety of reasons:
  3508. <itemizedlist>
  3509. <listitem><para>it is not a commonly-understood unit for Java programmers</para></listitem>
  3510. <listitem><para>there are very few use-cases for advice on the join point</para></listitem>
  3511. <listitem><para>a seemingly-insignificant change to the underlying program
  3512. causes a change in the join point</para></listitem>
  3513. <listitem><para>pointcuts can't really distinguish the join point in question</para></listitem>
  3514. <listitem><para>the join point would differ too much for different
  3515. implementations of AspectJ, or would only be implementable
  3516. in one way
  3517. </para></listitem>
  3518. </itemizedlist>
  3519. We prefer to be very conservative in the join point model for the language,
  3520. so a new join point would have to be useful, sensible, and implementable.
  3521. The most promising of the new join points proposed are for exception
  3522. throws clauses and for synchronized blocks.
  3523. </para>
  3524. </answer>
  3525. </qandaentry>
  3526. <qandaentry>
  3527. <question id="q:currentbugs"
  3528. xreflabel="Q:What are the bugs now most affecting users?">
  3529. <para>What are the bugs now most affecting users?</para>
  3530. </question>
  3531. <answer>
  3532. <itemizedlist>
  3533. <listitem>
  3534. <para>The bugs affecting the semantics of the language
  3535. are marked with the "info" keyword. Find them with
  3536. the query
  3537. <ulink url="http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&amp;keywords=info">
  3538. http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&amp;keywords=info
  3539. </ulink>
  3540. </para>
  3541. </listitem>
  3542. </itemizedlist>
  3543. </answer>
  3544. </qandaentry>
  3545. </qandadiv>
  3546. <qandadiv id="aj11" xreflabel="AspectJ 1.1 and eclipse.org">
  3547. <title>AspectJ 1.1 and eclipse.org</title>
  3548. <qandaentry>
  3549. <question id="q:whyeclipse"
  3550. xreflabel="Q:Why did the AspectJ project move to eclipse.org?">
  3551. <para>Why did the AspectJ project move to eclipse.org?
  3552. </para>
  3553. </question>
  3554. <answer>
  3555. <para>From the message sent to users:
  3556. </para>
  3557. <para>
  3558. AspectJ has come a long way -- the language has
  3559. stabilized; there are a rapidly growing number of
  3560. commercial users; the 1.1 release is imminent and will
  3561. include byte-code weaving and incremental compilation;
  3562. and the tool support is now well integrated with several
  3563. major IDEs.
  3564. </para>
  3565. <para>
  3566. This growth of the community and the technology means
  3567. that the original research and prototype development of
  3568. AspectJ is complete. As such it is time for ongoing
  3569. development and support of AspectJ to move outside of
  3570. PARC. This has already started to happen; the Eclipse
  3571. AJDT plug-in and the several books in preparation are
  3572. examples.
  3573. </para>
  3574. <para>
  3575. To encourage the growth of the AspectJ technology and
  3576. community, PARC is transferring AspectJ to an
  3577. openly-developed eclipse.org project. This project will
  3578. include documentation, web site, mailing lists, bug
  3579. database, and sources for the compiler. The
  3580. command-line AspectJ compiler is still the primary tool
  3581. produced by this project, in addition to APIs that support
  3582. integration with a variety of IDEs. The Eclipse plug-in will
  3583. remain at eclipse.org, while the NetBeans, JBuilder and
  3584. Emacs support will move to SourceForge.net projects.
  3585. We look forward to your involvement with and
  3586. contribution to those projects.
  3587. </para>
  3588. <para>
  3589. We see Eclipse as an excellent new home for core
  3590. AspectJ technology development -- it is an active
  3591. community of Open Source development and innovation
  3592. in the Java space. Once development moves to
  3593. Eclipse.org, others will be able to contribute more easily.
  3594. </para>
  3595. </answer>
  3596. </qandaentry>
  3597. <qandaentry>
  3598. <question id="q:eclipserequired"
  3599. xreflabel="Q:Do I have to download Eclipse to use AspectJ?">
  3600. <para>Do I have to download Eclipse to use AspectJ?
  3601. </para>
  3602. </question>
  3603. <answer>
  3604. <para>No. The AspectJ tools download is completely self-contained
  3605. and does not require that you work in Eclipse.
  3606. For information on IDE support, see
  3607. <xref linkend="q:integrateWithDevTools"/>.
  3608. </para>
  3609. </answer>
  3610. </qandaentry>
  3611. <qandaentry>
  3612. <question id="q:eclipseetc"
  3613. xreflabel="Q:What are the relationships between AspectJ, JDT,
  3614. Eclipse, AJDT, and IDE support generally?">
  3615. <para>What are the relationships between AspectJ, JDT,
  3616. Eclipse, AJDT, and IDE support generally?
  3617. </para>
  3618. </question>
  3619. <answer>
  3620. <para>Eclipse is a software platform.
  3621. </para>
  3622. <para>JDT is an eclipse project to support Java development.
  3623. JDT has a Java compiler.
  3624. </para>
  3625. <para>AspectJ 1.1 is built on Eclipse/JDT's Java compiler
  3626. but is distributed standalone and can run standalone.
  3627. With the AspectJ distribution, you can compile and run
  3628. AspectJ programs and use the AspectJ structure browser.
  3629. </para>
  3630. <para>AJDT is an eclipse project to integrate AspectJ
  3631. into Eclipse/JDT so you can use Eclipse to develop
  3632. AspectJ programs. AJDT aims to support the full Eclipse
  3633. experience - searching, compiler-error tasks, etc.
  3634. AJDT will use the AspectJ Development Environment (AJDE)
  3635. API's for creating IDE integrations, as well as hooking
  3636. in to the model underlying the Java compiler.
  3637. </para>
  3638. <para>Similarly, Sourceforge has projects integrating
  3639. AspectJ into other development environments
  3640. using the AJDE API's:
  3641. <ulink url="http://aspectj4emacs.sourceforge.net">
  3642. AspectJ for Emacs</ulink>,
  3643. <ulink url="http://aspectj4jbuildr.sourceforge.net">
  3644. AspectJ for JBuilder</ulink>, and
  3645. <ulink url="http://aspectj4netbean.sourceforge.net">
  3646. AspectJ for NetBeans</ulink>.
  3647. </para>
  3648. <para>This is the right level of separation/integration.
  3649. AspectJ is available standalone, leverages an existing open-source
  3650. compliant Java compiler, and supports external projects
  3651. doing IDE integrations in Eclipse, Emacs, JBuilder, and NetBeans
  3652. through a common API, AJDE.
  3653. </para>
  3654. </answer>
  3655. </qandaentry>
  3656. </qandadiv>
  3657. <qandadiv id="Technology" xreflabel="Understanding AspectJ Technology">
  3658. <title>Understanding AspectJ Technology</title>
  3659. <qandaentry>
  3660. <question id="q:implementation"
  3661. xreflabel="Q:Do I need to know how the compiler works?">
  3662. <para>Do I need to know how the compiler or weaver works?
  3663. </para>
  3664. </question>
  3665. <answer>
  3666. <para>Writing AspectJ programs only requires understanding the
  3667. <ulink url="progguide/index.html">Programming Guide</ulink>.
  3668. However, current implementations do not control everything in
  3669. a system, so AspectJ program semantics may be limited to code
  3670. the implementation controls. For our implementation, these
  3671. limitations are stated in
  3672. <ulink url="progguide/implementation.html">
  3673. Programming Guide Appendix: Implementation Notes</ulink>.
  3674. Aside from understanding the use and limitations of the
  3675. implementation, there is no need to understand the underlying
  3676. technology when writing AspectJ programs.
  3677. </para>
  3678. <para>
  3679. The technology that implements AspectJ interests
  3680. some academic researchers and some developers
  3681. who want new features or new ways to weave.
  3682. These extensions are not discussed in the documentation.
  3683. Some are being developed already,
  3684. others are on the drawing board (or perhaps were left off
  3685. long ago), and still others haven't been considered.
  3686. If you are interested in a certain extension,
  3687. check the bug database for feature requests
  3688. and the mailing list archives for any past discussions.
  3689. Then email the list to see if it's been considered.
  3690. For more information, see
  3691. <xref linkend="Developers"/>.
  3692. </para>
  3693. </answer>
  3694. </qandaentry>
  3695. <qandaentry>
  3696. <question id="q:whitepapers"
  3697. xreflabel="Q:How does the compiler/weaver work? Are there any white papers?">
  3698. <para>How does the compiler/weaver work? Are there any white papers?
  3699. </para>
  3700. </question>
  3701. <answer>
  3702. <para>
  3703. There are currently no documents describing this process in detail.
  3704. You can compile programs and inspect the generated source or bytecode,
  3705. or view the source code (see <xref linkend="Developers"/>).
  3706. We hope to write papers on the bytecode weaving model used in
  3707. AspectJ-1.1 if we can find the time.
  3708. Erik Hilsdale and Jim Hugunin did draft a paper for AOSD 2004,
  3709. now available on Jim's web site:
  3710. <ulink url="http://hugunin.net/papers.html">
  3711. http://hugunin.net/papers.html</ulink>
  3712. Jim summarized advice weaving in the AspectJ 1.1 implementation in the
  3713. <ulink url="http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg00519.html">
  3714. following mailing-list reply</ulink>:
  3715. </para>
  3716. <para>
  3717. Each piece of advice in an aspect is associated with a pointcut.
  3718. This pointcut is stored in an attribute on the methods
  3719. corresponding to each piece of advice.
  3720. Before weaving, all of these pieces of advice are gathered
  3721. into one large list.
  3722. </para>
  3723. <para>
  3724. Each .class file is woven independently.
  3725. A .class file is woven by the following steps:
  3726. <itemizedlist>
  3727. <listitem><para>
  3728. Collect all of the joinpoint shadows in the .class file.
  3729. For every dynamic joinpoint in the AspectJ language model,
  3730. there is a corresponding static shadow of that joinpoint
  3731. in the bytecode.
  3732. For example, every method call joinpoint has an INVOKE
  3733. bytecode as its static shadow. Some joinpoints
  3734. (such as initialization) have much more
  3735. complicated static shadows.
  3736. </para></listitem>
  3737. <listitem><para>
  3738. Each piece of advice is matched to each static shadow.
  3739. There are three results possible from this match.
  3740. <itemizedlist>
  3741. <listitem><para>
  3742. Never matches,
  3743. in which case nothing is done to the shadow
  3744. </para></listitem>
  3745. <listitem><para>
  3746. Always matches,
  3747. in which case the advice is woven into this joinpoint shadow
  3748. </para></listitem>
  3749. <listitem><para>
  3750. Sometimes matches,
  3751. in which case the advice is woven into the shadow
  3752. along with the minimal dynamic tests to determine
  3753. if any particular joinpoint in the actual running
  3754. program matches the advice.
  3755. The simplest example of sometimes matches is
  3756. when the pointcut uses if(test()).
  3757. </para></listitem>
  3758. </itemizedlist>
  3759. </para></listitem>
  3760. <listitem><para>
  3761. If any advice matched any static shadows in the .class file,
  3762. then the transformed .class file is written out,
  3763. otherwise it is left unchanged.
  3764. </para></listitem>
  3765. </itemizedlist>
  3766. See <literal>BcelClassWeaver</literal> and
  3767. <literal>BcelShadow</literal> in the
  3768. <literal>org.aspectj.weaver.bcel</literal> package
  3769. for the two primary classes involved in this process.
  3770. </para>
  3771. <para>
  3772. Note: This explanation ignores the implementations of inter-type
  3773. declarations completely.
  3774. It also ignores performance optimizations such as fast-match
  3775. that speed up the weaving process.
  3776. </para>
  3777. </answer>
  3778. </qandaentry>
  3779. <qandaentry>
  3780. <question id="q:reflection"
  3781. xreflabel="Q:Does AspectJ use reflection at runtime?">
  3782. <para>Does AspectJ use reflection at runtime?
  3783. </para>
  3784. </question>
  3785. <answer>
  3786. <para>
  3787. The only time that reflection is used during run-time is when the special
  3788. thisJoinPoint object is used to discover reflective information about the
  3789. join point. If you don't use thisJoinPoint then no reflection will be used.
  3790. </para>
  3791. </answer>
  3792. </qandaentry>
  3793. <qandaentry>
  3794. <question id="q:loadtimeWeaving"
  3795. xreflabel="Q:What about load-time weaving? Can I weave aspects at runtime?">
  3796. <para>What about load-time weaving? Can I weave aspects at runtime?
  3797. </para>
  3798. </question>
  3799. <answer>
  3800. <para>
  3801. AspectJ 1.1 can weave binary aspects
  3802. into classes in bytecode form. Hooked up to a class loader,
  3803. this can weave class bytecodes after they are read in,
  3804. before the
  3805. class is defined by the VM. In the 1.1 release (or soon
  3806. thereafter) we will provide a proof-of-concept class loader,
  3807. but we expect most people will already have a custom
  3808. class loader which they will adapt to invoke our weaver.
  3809. </para>
  3810. <para>Some have asked about only weaving particular classes
  3811. specified at run-time.
  3812. Aspects should work across an entire namespace, and problems
  3813. will likely result from weaving
  3814. some classes but not others. Also, it's confusing to
  3815. specify crosscutting both in the aspect and in the
  3816. list of runtime classes; the crosscutting specification
  3817. should be in the aspect itself,
  3818. where it can be processed by tools.
  3819. </para>
  3820. <para>And just to state the obvious:
  3821. do not use bytecode weaving, at load-time or otherwise,
  3822. to modify .class files protected by license,
  3823. without permission from the licensor.
  3824. </para>
  3825. </answer>
  3826. </qandaentry>
  3827. </qandadiv>
  3828. <qandadiv id="Developers" xreflabel="AspectJ Project Development">
  3829. <title>AspectJ Project Development</title>
  3830. <qandaentry>
  3831. <question id="q:howitworks"
  3832. xreflabel="Q:I'm interested in the code implementing AspectJ.">
  3833. <para>I'm interested in the code implementing AspectJ.
  3834. </para>
  3835. </question>
  3836. <answer>
  3837. <para>Most people do not need to see the code for AspectJ;
  3838. they can download the binary distribution for documentation
  3839. and tools for writing AspectJ programs.
  3840. </para>
  3841. <para>For people who want to know how the AspectJ technology works,
  3842. the source code is the best resource, until we write some
  3843. proper white papers
  3844. (see <xref linkend="q:implementation"/>).
  3845. To get and compile the Java source code for the AspectJ
  3846. distribution, see
  3847. <xref linkend="q:buildingsource"/>.
  3848. </para>
  3849. <para>Bear in mind when looking at the code that there are many
  3850. ways to implement the AspectJ language, and the code inspected
  3851. might be an initial version of a new architecture (e.g., bytecode
  3852. weaving).
  3853. </para>
  3854. </answer>
  3855. </qandaentry>
  3856. <qandaentry>
  3857. <question id="q:contributions"
  3858. xreflabel="Q:How can I get involved with developing the AspectJ project?">
  3859. <para>How can I get involved with developing the AspectJ project?
  3860. </para>
  3861. </question>
  3862. <answer>
  3863. <para>For those who want to contribute to the project,
  3864. here's a general list of ways to do so, in no particular order:
  3865. <itemizedlist>
  3866. <listitem>
  3867. <para>Participate effectively in the mailing lists.
  3868. The quality of the mailing lists makes a huge difference
  3869. in the ability of new and experienced AspectJ users
  3870. to write good code. For guidance on effective
  3871. participation, see
  3872. <xref linkend="q:talktousers"/> and
  3873. <xref linkend="q:writingbugsandemails"/>.
  3874. Also, the time that experienced users take in answering emails
  3875. can directly translate to time developers can use (instead)
  3876. for fixing bugs or adding features.
  3877. </para>
  3878. </listitem>
  3879. <listitem>
  3880. <para>Write bugs. Good bugs, especially with test cases,
  3881. are always appreciated. We especially like proposals for
  3882. new <literal>XLint</literal> messages, since they are
  3883. sometimes easy to implement and help users learn
  3884. AspectJ, and for other implementable features
  3885. grounded in a compelling use-case.
  3886. </para>
  3887. </listitem>
  3888. <listitem>
  3889. <para>Write test cases for compiler bugs without test cases.
  3890. Compiler bugs without test cases are much less likely to be fixed;
  3891. until they are rendered in code, they might be user mistakes,
  3892. and they might duplicate another bug or actually cover many bugs.
  3893. </para>
  3894. <para>Find them by searching open compiler bugs and picking out
  3895. any which do not have test case attachments or a comment that
  3896. a test case has been written.
  3897. Here is a query for open compiler bugs:
  3898. <!-- ulink gacks on ampersands in url value, so quote them -->
  3899. <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">
  3900. 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
  3901. </ulink>
  3902. </para>
  3903. <para>For how to write test cases, see
  3904. <xref linkend="q:harnesstestcases"/>.
  3905. </para>
  3906. </listitem>
  3907. <listitem>
  3908. <para>Write patches to fix bugs.
  3909. If you particularly need a bug to be fixed, or if you're interested in
  3910. learning about the system, then get the source code and try to fix the
  3911. bug. Most likely you'll want to email aspectj-dev@eclipse.org to
  3912. declare your intentions and the approach you propose (based on having
  3913. looked at the code).
  3914. Mailing the list gives those experienced with the code a chance to
  3915. guide you away from pitfalls. To submit the patch, attach it to
  3916. the bug. (When creating patches, do so on a per-module basis; that
  3917. means if fixing the bug involves changes to three modules, submit
  3918. three patches.)
  3919. </para>
  3920. </listitem>
  3921. <listitem>
  3922. <para>Write patches for other reasons.
  3923. Often documentation needs to be fixed, or there may be a small new
  3924. feature you'd like to see. You can just do it and then submit it
  3925. as a patch to a bug you create. As with bugs, in some cases you
  3926. might want to declare your intentions on the mailing list to avoid
  3927. wasting time on something that's been fixed but not committed or
  3928. on an approach that will be fruitless.
  3929. </para>
  3930. </listitem>
  3931. </itemizedlist>
  3932. </para>
  3933. </answer>
  3934. </qandaentry>
  3935. <qandaentry>
  3936. <question id="q:buildingsource"
  3937. xreflabel="Q:How do I get and compile the source code for AspectJ?">
  3938. <para>How do I get and compile the source code for AspectJ?
  3939. </para>
  3940. </question>
  3941. <answer>
  3942. <para>AspectJ 1.0 source code is available in an archive available
  3943. with the 1.0 downloads. It contains instructions for building
  3944. from sources.
  3945. </para>
  3946. <para>AspectJ 1.1 source code is available through CVS using the CVS Root
  3947. <literal>dev.eclipse.org:/home/technology</literal>. For more information
  3948. on accessing the CVS tree at eclipse.org, see the documentation
  3949. from <ulink url="http://eclipse.org">http://eclipse.org</ulink>.
  3950. Find specific instructions in the AspectJ tree at
  3951. <ulink url="http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/org.aspectj/modules/build/readme-build-and-test-aspectj.html?rev=HEAD&amp;content-type=text/html&amp;cvsroot=Technology_Project">
  3952. org.aspectj/modules/build/readme-build-and-test-aspectj.html</ulink>.
  3953. If you would like to use Ant to checkout the sources,
  3954. build the distribution, and test everything, see
  3955. <ulink url="http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/org.aspectj/modules/build/release/build.xml?rev=HEAD&amp;content-type=text/xml&amp;cvsroot=Technology_Project">
  3956. org.aspectj/modules/build/release/build.xml</ulink>.
  3957. </para>
  3958. <para>The AspectJ tree is organized into modules as follows:
  3959. <programlisting>
  3960. org.aspectj/
  3961. modules/
  3962. ajbrowser/
  3963. ajde/
  3964. ...
  3965. lib/
  3966. ...
  3967. </programlisting>
  3968. </para>
  3969. <para>
  3970. You can check out the entire modules directory and build using the
  3971. Ant build script <literal>modules/build/build.xml</literal>.
  3972. All required libraries are included in <literal>modules/lib/</literal>,
  3973. (including Ant 1.5.1 in <literal>modules/lib/ant</literal>).
  3974. If you are using Eclipse, you can check out any <literal>modules/</literal>
  3975. subdirectory as an eclipse Java project.
  3976. Depending on what you are trying to build, you need not check out
  3977. all modules; as of this writing, here are the modules to get
  3978. when trying to build something:
  3979. </para>
  3980. <para>
  3981. <itemizedlist>
  3982. <listitem><para>For any builds: build, lib
  3983. </para></listitem>
  3984. <listitem><para>For the documentation: docs
  3985. </para></listitem>
  3986. <listitem><para>For the compiler: bridge, util, testing-util,
  3987. weaver, asm, org.eclipse.jdt.core, org.aspectj.ajdt.core,
  3988. and runtime.
  3989. </para></listitem>
  3990. <listitem><para>For ajbrowser: the compiler modules, plus
  3991. ajbrowser, taskdefs, and ajde.
  3992. </para></listitem>
  3993. <listitem><para>For the test harness: the ajbrowser modules, plus
  3994. testing, testing-client, and testing-drivers.
  3995. </para></listitem>
  3996. <listitem><para>To run the test suite: the test harness modules, plus
  3997. tests.
  3998. </para></listitem>
  3999. </itemizedlist>
  4000. </para>
  4001. <para>
  4002. Note that module interdependencies are recorded only in the eclipse
  4003. <literal>modules/{module}/.classpath
  4004. </literal>
  4005. files and may
  4006. change, so the list above may not be correct when you read it.
  4007. </para>
  4008. </answer>
  4009. </qandaentry>
  4010. <qandaentry>
  4011. <question id="q:devDocs"
  4012. xreflabel="Q:Where do I find developer documentation on building and testing AspectJ source code?">
  4013. <para>Where do I find developer documentation on building and testing AspectJ source code?
  4014. </para>
  4015. </question>
  4016. <answer>
  4017. <para>Find the developer documentation in HTML files in the CVS tree,
  4018. inside the <literal>build</literal> and <literal>testing</literal> modules
  4019. (i.e., in <literal>org.aspectj/modules/build/...</literal>).
  4020. Most pertinant:
  4021. <itemizedlist>
  4022. <listitem><para>
  4023. <literal>../build/readme-build-and-test-aspectj.html</literal>
  4024. describes how to build the AspectJ distribution in Eclipse
  4025. and in Ant.
  4026. </para></listitem>
  4027. <listitem>
  4028. <para><literal>../build/readme-docs-module.html</literal>
  4029. describes the AspectJ documentation sources and
  4030. how to build the documentation using Ant.
  4031. </para></listitem>
  4032. <listitem><para><literal>../build/readme-tests-module.html</literal>
  4033. describes the all the tests
  4034. in the <literal>tests</literal> module.
  4035. </para></listitem>
  4036. <listitem><para><literal>../build/readme-writing-compiler-tests.html</literal>
  4037. describes how to write compiler tests that can be run by
  4038. the AspectJ test harness.
  4039. </para></listitem>
  4040. <listitem><para><literal>../build/readme-testing-drivers-module.html</literal>
  4041. describes the test harness used to run the compiler tests
  4042. in the <literal>tests</literal> module.
  4043. </para></listitem>
  4044. <listitem><para><literal>../build/readme-testing-drivers-module.html</literal>
  4045. describes the test harness used to run the compiler tests
  4046. in the <literal>testing</literal> module.
  4047. </para></listitem>
  4048. </itemizedlist>
  4049. </para>
  4050. </answer>
  4051. </qandaentry>
  4052. <qandaentry>
  4053. <question id="q:harnesstestcases"
  4054. xreflabel="Q:How should I submit test cases for bugs?">
  4055. <para>How should I submit test cases for bugs?
  4056. </para>
  4057. </question>
  4058. <answer>
  4059. <para>You can attach files to a bug after it has been created.
  4060. The code of course should replicate the actual behavior
  4061. described in the bug when run on the target version.
  4062. If you have a single source file, you can attach it directly,
  4063. describing in the comments the expected result
  4064. (e.g., error on line 14, or successful compile/run).
  4065. The most helpful form for describing the test scenario
  4066. and the expected results are the test definitions
  4067. described next.
  4068. </para>
  4069. <para>For more complex bugs requiring many files,
  4070. create a zip file of a directory containing all the files
  4071. and an XML test definition file.
  4072. The XML test definition file contains specifications
  4073. for how to compile, recompile, or run the test sources.
  4074. Complete documentation is available in the CVS tree
  4075. at <literal>tests/readme-writing-compiler-tests.html</literal>
  4076. but here is a sample file with some example definitions,
  4077. preceded by comments showing the directory layout
  4078. of the files referred to in the test definitions.
  4079. </para>
  4080. <para>
  4081. <programlisting>
  4082. <![CDATA[
  4083. <!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd">
  4084. <suite>
  4085. <!-- Compile and run
  4086. using the following files:
  4087. {testDefinitions}.xml
  4088. one/
  4089. pack1/
  4090. Main.java
  4091. p2/
  4092. BeforeConstructor.java
  4093. Note the bug number goes in the pr attribute.
  4094. ("pr" stands for "problem report")
  4095. -->
  4096. <ajc-test dir="one" pr="234" title="before constructor call">
  4097. <compile files="pack1/Main.java,p2/BeforeConstructor.java"/>
  4098. <run class="pack1.Main"/>
  4099. </ajc-test>
  4100. <!-- Check that compiler warning was emitted
  4101. using the following files:
  4102. {testDefinitions}.xml
  4103. two/
  4104. UsesDeprecated.java
  4105. -->
  4106. <ajc-test dir="two" pr="244" title="deprecated, noImportError">
  4107. <compile options="-warn:deprecated,-noImportError"
  4108. files="UsesDeprecated.java">
  4109. <message kind="warning" line="20"/>
  4110. </compile>
  4111. </ajc-test>
  4112. <!-- Cooked example that uses all compiler attributes
  4113. and the following files:
  4114. {testDefinitions}.xml
  4115. testCaseDir/
  4116. jars/
  4117. injar.jar
  4118. required.jar
  4119. requiredAspects.jar
  4120. pack/
  4121. Main.java
  4122. providedClassesDir/
  4123. ClassInDefaultPackage.class
  4124. org/
  4125. foo/
  4126. AnotherRequired.class
  4127. -->
  4128. <ajc-test dir="testCaseDir" title="attributes test">
  4129. <compile files="pack/Main.java,jars/injar.jar"
  4130. staging="true"
  4131. options="-Xlint,-g:none"
  4132. argfiles="debug.lst,aspects/test.lst"
  4133. aspectpath="jars/requiredAspects.jar"
  4134. classpath="providedClassesDir,jars/required.jar"/>
  4135. <run class="Main"/>
  4136. </ajc-test>
  4137. <!-- Compiler errors, recompile after changing files, and run
  4138. using the following files:
  4139. {testDefinitions}.xml
  4140. three/
  4141. pack/
  4142. IncCompileFix.java
  4143. IncCompileFix.20.java
  4144. Before compiling, IncCompileFix.java is copied to a staging
  4145. directory. Before recompiling, IncCompileFix.20.java
  4146. replaces it, so the compiler treats file as updated.
  4147. -->
  4148. <ajc-test dir="three" pr="622" title="incremental fix">
  4149. <compile staging="true" files="pack/IncCompileFix.java">
  4150. <message kind="error" line="20"/>
  4151. <message kind="error" line="42"/>
  4152. </compile>
  4153. <inc-compile tag="20"/>
  4154. <run class="pack.IncCompileFix"/>
  4155. </ajc-test>
  4156. </suite>
  4157. ]]>
  4158. </programlisting>
  4159. </para>
  4160. </answer>
  4161. </qandaentry>
  4162. <qandaentry>
  4163. <question id="q:testharness"
  4164. xreflabel="Q:I'd like to run my test case. How do I get the test harness?">
  4165. <para>I'd like to run my test case. How do I get the test harness?
  4166. </para>
  4167. </question>
  4168. <answer>
  4169. <para>The test harness is not distributed.
  4170. To build it, get the source tree as
  4171. described in <xref linkend="q:buildingsource"/> and then
  4172. build the <literal>build-testing-drivers</literal> target:
  4173. <programlisting>
  4174. cd build
  4175. ../lib/ant/bin/ant -f build.xml build-testing-drivers
  4176. </programlisting>
  4177. This produces
  4178. <literal>../aj-build/jars/testing-drivers-all.jar</literal>
  4179. which you can run as described in
  4180. <literal>tests/readme-tests-module.html</literal>.
  4181. </para>
  4182. </answer>
  4183. </qandaentry>
  4184. </qandadiv>
  4185. <qandadiv id="help" xreflabel="Getting Help">
  4186. <title>Getting Help</title>
  4187. <qandaentry>
  4188. <question id="q:moreaboutaj"
  4189. xreflabel="Q:How do I find out more about AspectJ?">
  4190. <para>
  4191. How do I find out more about AspectJ?
  4192. </para>
  4193. </question>
  4194. <answer>
  4195. <para>Visit the AspectJ project web site:
  4196. <ulink url="http://eclipse.org/aspectj">http://eclipse.org/aspectj</ulink>.
  4197. </para>
  4198. </answer>
  4199. </qandaentry>
  4200. <qandaentry>
  4201. <question id="q:bugreports"
  4202. xreflabel="Q:How do I submit a bug report?">
  4203. <para>How do I submit a bug report?</para>
  4204. </question>
  4205. <answer>
  4206. <para>You can submit a bug from
  4207. <ulink url="http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ">
  4208. http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ
  4209. </ulink>.
  4210. If it seems to be a bug in the compiler,
  4211. please attach a small test case (source code)
  4212. to reproduce the problem.
  4213. For more information on writing compiler test cases, see
  4214. <xref linkend="q:ajcbugs"/>.
  4215. </para>
  4216. </answer>
  4217. </qandaentry>
  4218. <qandaentry>
  4219. <question id="q:talktousers"
  4220. xreflabel="Q:How do I communicate with other AspectJ users?">
  4221. <para>
  4222. How do I communicate with other AspectJ users?
  4223. </para>
  4224. </question>
  4225. <answer>
  4226. <para>You can reach other AspectJ users by using the
  4227. aspectj-users mailing list. You can subscribe to the list or view the
  4228. list archives from the AspectJ home page
  4229. <ulink url="http://eclipse.org/aspectj">
  4230. http://eclipse.org/aspectj
  4231. </ulink>.
  4232. </para>
  4233. </answer>
  4234. </qandaentry>
  4235. <qandaentry>
  4236. <question id="q:searchingsite"
  4237. xreflabel="Q:How can I search the email archives or the web site?">
  4238. <para>
  4239. How can I search the email archives or the web site?
  4240. </para>
  4241. </question>
  4242. <answer>
  4243. <para>
  4244. It is very effective to do a google search of the form,
  4245. <ulink url="http://www.google.com/search?q=site:eclipse.org+cflowbelow">
  4246. http://www.google.com/search?q=site:eclipse.org+cflowbelow
  4247. </ulink>,
  4248. and you can use the eclipse.org search at
  4249. <ulink url="http://www.eclipse.org/search/search.cgi">
  4250. http://www.eclipse.org/search/search.cgi
  4251. </ulink>.
  4252. You can also check the old archives available for download from
  4253. the AspectJ home page
  4254. <ulink url="http://eclipse.org/aspectj">
  4255. http://eclipse.org/aspectj
  4256. </ulink>.
  4257. </para>
  4258. </answer>
  4259. </qandaentry>
  4260. <qandaentry>
  4261. <question id="q:writingbugsandemails"
  4262. xreflabel="Q:How should I write email queries?">
  4263. <para>
  4264. How should I write email queries?
  4265. </para>
  4266. </question>
  4267. <answer>
  4268. <para>Here's the general form of a good email:
  4269. </para>
  4270. <orderedlist>
  4271. <listitem>
  4272. <para>
  4273. Describe the big picture of what you are trying to do...
  4274. </para>
  4275. </listitem>
  4276. <listitem>
  4277. <para>
  4278. Describe what you think it takes, in AspectJ terms
  4279. (concepts, syntax, and semantics) from the
  4280. <ulink url="progguide/index.html">Programming Guide</ulink>...
  4281. </para>
  4282. </listitem>
  4283. <listitem>
  4284. <para>
  4285. Show the AspectJ code you are using, what output it
  4286. produces when run, and what output you expect...
  4287. </para>
  4288. </listitem>
  4289. </orderedlist>
  4290. <para>
  4291. The big picture helps others redirect you to other approaches.
  4292. Using AspectJ terms helps others correct mistakes in thinking
  4293. about the problem (the most common being to confuse join points
  4294. and pointcuts).
  4295. The code is key to clarifying your question and getting a good
  4296. response. On the mail list, someone can reply by fixing your
  4297. code. In bugs, the developers can reproduce the problem immediately
  4298. and start analyzing the fix.
  4299. The code should not be incomplete; it should run (or fail) as-is,
  4300. without additional libraries or source files.
  4301. </para>
  4302. <para>
  4303. For the mail lists, we try to follow the conventions for open-source
  4304. discussions that help avoid "the tragedy of the commons."
  4305. For example conventions, see
  4306. <ulink url="http://jakarta.apache.org/site/mail.html">
  4307. http://jakarta.apache.org/site/mail.html
  4308. </ulink> and
  4309. <ulink url="http://www.tuxedo.org/%7Eesr/faqs/smart-questions.html">
  4310. http://www.tuxedo.org/%7Eesr/faqs/smart-questions.html
  4311. </ulink>.
  4312. </para>
  4313. </answer>
  4314. </qandaentry>
  4315. <qandaentry>
  4316. <question id="q:idebugs"
  4317. xreflabel="Q:How do I write bugs for the IDE support?">
  4318. <para>
  4319. How do I write bugs for IDE support?
  4320. </para>
  4321. </question>
  4322. <answer>
  4323. <para>
  4324. Bugs appearing in the IDE's may apply to the affected IDE
  4325. or to the compiler. Compiler stack traces in IDE message windows
  4326. are prefixed "Internal Compiler Error" and should be written up
  4327. as compiler bugs. If you are unsure, try redoing the compile
  4328. from the command line.
  4329. </para>
  4330. <para>
  4331. Bug report for the IDE extensions go to their respective projects,
  4332. listed in
  4333. <xref linkend="q:integrateWithDevTools"/>
  4334. (including bug reports for the AJDE Eclipse support,
  4335. which you can submit at
  4336. <ulink url="http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AJDT">
  4337. http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AJDT
  4338. </ulink>).
  4339. </para>
  4340. <para>
  4341. Bug reports on ajbrowser should have version
  4342. information for both Java and AspectJ, and
  4343. (most importantly) clear steps for reproducing the bug.
  4344. You may submit ajbrowser bugs against the IDE component of AspectJ
  4345. via the web form
  4346. <ulink url="http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ">
  4347. http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ
  4348. </ulink>.
  4349. </para>
  4350. <para>
  4351. One of the benefits of open-source is that you can
  4352. find and fix the bug for yourself; when you submit
  4353. the fix back to us, we can validate the fix for you
  4354. and incorporate it into the next release.
  4355. You can submit a patch by attaching it to the bug.
  4356. </para>
  4357. </answer>
  4358. </qandaentry>
  4359. <qandaentry>
  4360. <question id="q:ajcbugs"
  4361. xreflabel="Q:How do I write bugs for the AspectJ compiler?">
  4362. <para>
  4363. How do I write bugs for the AspectJ compiler?
  4364. </para>
  4365. </question>
  4366. <answer>
  4367. <para>
  4368. The best compiler bug report is a reproducible test case,
  4369. standalone code that demonstrates the problem.
  4370. Sometimes with aspects, a test case requires several
  4371. files, if not some way to capture the behavior.
  4372. Here's how we recommend submitting test cases:
  4373. <orderedlist>
  4374. <listitem>
  4375. <para>
  4376. Write the test case so that when the compiler bug
  4377. is fixed, the test completes normally without output
  4378. (e.g., expected compiler errors are issued,
  4379. or classes produced run correctly). This usually
  4380. means writing one or more source files.
  4381. </para>
  4382. </listitem>
  4383. <listitem>
  4384. <para>
  4385. In the bug report, briefly summarize the bug.
  4386. If it is not obvious, be sure to specify
  4387. the expected output/behavior (e.g., compiler error on line 32)
  4388. and, if the compile should complete, the main class to run.
  4389. </para>
  4390. </listitem>
  4391. <listitem>
  4392. <para>
  4393. Submit the bugs via the web form
  4394. <ulink url="http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ">
  4395. http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ
  4396. </ulink>.
  4397. </para>
  4398. </listitem>
  4399. <listitem>
  4400. <para>Attach the test case to the bug.
  4401. The test case may be a single file
  4402. or it may be multiple files in a single zip archive,
  4403. of the form discussed in
  4404. <xref linkend="q:harnesstestcases"/>.
  4405. </para>
  4406. </listitem>
  4407. </orderedlist>
  4408. </para>
  4409. </answer>
  4410. </qandaentry>
  4411. <qandaentry>
  4412. <question id="q:teachingmaterials"
  4413. xreflabel="Q:Can you recommend reading or teaching material for AspectJ?">
  4414. <para>
  4415. Can you recommend reading or teaching material for AspectJ?
  4416. </para>
  4417. </question>
  4418. <answer>
  4419. <para>The documentation available in the distribution is the
  4420. best source for language and usage questions. You can also find
  4421. selected AspectJ papers and presentations on the
  4422. <ulink url="http://www.parc.com/groups/csl/projects/aspectj/index.html">
  4423. PARC AspectJ page</ulink>.
  4424. For links to Aspect-oriented programming materials in general, see
  4425. <ulink url="http://aosd.net">http://aosd.net</ulink>.
  4426. </para>
  4427. </answer>
  4428. </qandaentry>
  4429. <qandaentry>
  4430. <question id="q:consulting"
  4431. xreflabel="Q:Where can our group get consulting and support?">
  4432. <para>
  4433. Where can our group get consulting and support?
  4434. </para>
  4435. </question>
  4436. <answer>
  4437. <para>The best thing to to is join and email the
  4438. <literal>aspectj-dev@eclipse.org</literal> mailing list.
  4439. </para>
  4440. </answer>
  4441. </qandaentry>
  4442. <qandaentry>
  4443. <question id="q:faqchanges"
  4444. xreflabel="Q:What has changed since the last FAQ version?">
  4445. <para>
  4446. What has changed since the last FAQ version?
  4447. </para>
  4448. </question>
  4449. <answer>
  4450. <para>
  4451. Entries changed recently:
  4452. <itemizedlist>
  4453. <listitem><para><xref linkend="q:dynamicaop"/></para></listitem>
  4454. <listitem><para><xref linkend="q:java5"/></para></listitem>
  4455. <listitem><para><xref linkend="q:idesupportplans"/></para></listitem>
  4456. </itemizedlist>
  4457. </para>
  4458. </answer>
  4459. </qandaentry>
  4460. </qandadiv>
  4461. <qandadiv id="project" xreflabel="About the AspectJ Project">
  4462. <title>About the AspectJ Project</title>
  4463. <qandaentry>
  4464. <question id="q:opensource"
  4465. xreflabel="Q:What does the fact that AspectJ is an Open Source Project mean to me?">
  4466. <para>What does the fact that AspectJ is an Open Source
  4467. Project mean to me?
  4468. </para>
  4469. </question>
  4470. <answer>
  4471. <para>Open source protects your interest in a correct, long-lived,
  4472. up-to-date, and widely-accepted implementation of AspectJ.
  4473. <itemizedlist>
  4474. <listitem>
  4475. <para>With the source code, you control your own destiny
  4476. in perpetuity. You can continue to use the implementation
  4477. and update it as necessary to fix bugs and add things you need.
  4478. </para>
  4479. </listitem>
  4480. <listitem>
  4481. <para>Because the code is available to all, anyone can find
  4482. and fix bugs. There is no need to hope for it to be fixed
  4483. in the next product release. Those who encounter the bugs
  4484. are motivated to fix them, and there are more eyeballs on
  4485. the code than in closed-source, so the quality tends to be high.
  4486. This can be particularly true for the AspectJ community,
  4487. which tends to be highly skilled.
  4488. </para>
  4489. </listitem>
  4490. <listitem>
  4491. <para>The same is true of new features or behavior, so the
  4492. implementation should be up-to-date. This is important as
  4493. the field of AOP develops, to capture the latest solutions.
  4494. </para>
  4495. </listitem>
  4496. <listitem>
  4497. <para>For a programming language which forms the basis of
  4498. an entire solution stack, open source facilitates the kind
  4499. of adoption -- tool integrations and significant projects --
  4500. that develop and prove the technology for wider adoption. This
  4501. limits delays caused by waiting for the completion of standards
  4502. process or promulgation by industry leaders, and also provides
  4503. the proofs necessary for such adoption.
  4504. </para>
  4505. </listitem>
  4506. </itemizedlist>
  4507. </para>
  4508. </answer>
  4509. </qandaentry>
  4510. <qandaentry>
  4511. <question id="q:standardization"
  4512. 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?">
  4513. <para>What are your plans to make AspectJ a general feature
  4514. of Java supported by Sun and the other key players in the Java
  4515. Industry?
  4516. </para>
  4517. </question>
  4518. <answer>
  4519. <para>Although we are committed to making AspectJ available to a wide
  4520. range of users, it is too early to decide on a strategy. Some
  4521. options include continuing AspectJ as a stand-alone product,
  4522. integrating it into IDEs, or possibly incorporating it into
  4523. standard Java with Sun's blessing.
  4524. </para>
  4525. <para>We currently focus on developing for the 1.1 implementation
  4526. which improves AspectJ in key areas: rapid
  4527. incremental compilation, bytecode weaving, and IDE integration.
  4528. </para>
  4529. <para>Through all of this our goal is to make AspectJ integrate as
  4530. seamlessly as possible with the Java programming language. The
  4531. AspectJ language design is becoming more integrated, the compiler
  4532. is becoming faster and more integrated, the IDE extensions are
  4533. becoming more integrated. All of this is designed to help users
  4534. really use AspectJ and give us feedback on it.
  4535. </para>
  4536. <para>As the system is improved and we work more closely
  4537. with users, we will be in good position to explore the best path
  4538. for AspectJ in the long term.
  4539. </para>
  4540. </answer>
  4541. </qandaentry>
  4542. <qandaentry>
  4543. <question id="q:bytecodeweaving"
  4544. xreflabel="Q:When will AspectJ work from class files? When will it work at class-loading time?">
  4545. <para>When will AspectJ work from class files?
  4546. When will it work at class-loading time?
  4547. </para>
  4548. </question>
  4549. <answer>
  4550. <para>Bytecode weaving is in AspectJ 1.1. We believe it
  4551. works as described in an email to the users list by Jim Hugugin:
  4552. </para>
  4553. <para>
  4554. The AspectJ language was designed to support weaving at many different times:
  4555. compile, load, or even run-time in the JVM. Weaving into bytecodes at both
  4556. compile and load-time will definitely be provided in a future release. This
  4557. will allow weaving at compile-time into libraries for which source code is
  4558. not available. It will also support aspect-aware class loaders that can
  4559. perform weaving at load time on arbitrary classes. One advantage of a
  4560. language like AspectJ, rather than an explicit meta-tool like jiapi, is
  4561. that it separates the specification of a crosscutting concern from any
  4562. particular implementation strategy for weaving.
  4563. </para>
  4564. <para>
  4565. ...AspectJ provides a language that can cleanly
  4566. capture crosscutting concerns while preserving the static type checking,
  4567. modularity, and composability of Java.
  4568. </para>
  4569. <para>If you have an application for using aspects and bytecode,
  4570. please let the AspectJ team know of your requirements.
  4571. We expect to have a demonstration classloader available in
  4572. the 1.1 release or soon thereafter.
  4573. </para>
  4574. </answer>
  4575. </qandaentry>
  4576. <qandaentry>
  4577. <question id="q:differences"
  4578. xreflabel="Q:What are the differences between the current and previously released versions of AspectJ?">
  4579. <para>What are the differences between the current and
  4580. previously released versions of AspectJ?
  4581. </para>
  4582. </question>
  4583. <answer>
  4584. <para>The AspectJ team aims to keep the implementation bug-free and
  4585. up-to-date with the Java language,
  4586. to limit AspectJ language changes to those that
  4587. are carefully considered, compelling, and backwards-compatible,
  4588. and to deliver those language changes only in significant releases (1.0, 1.1).
  4589. </para>
  4590. <table>
  4591. <title></title>
  4592. <tgroup cols="2">
  4593. <tbody>
  4594. <row>
  4595. <entry align="left">Version</entry>
  4596. <entry align="left">Description</entry>
  4597. </row>
  4598. <row>
  4599. <entry>AspectJ 1.1</entry>
  4600. <entry>A few language changes and clarifications;
  4601. bytecode weaving and incremental compilation.
  4602. See <ulink url="README-11.html">README-11.html</ulink>
  4603. for more detail.
  4604. </entry>
  4605. </row>
  4606. <row>
  4607. <entry>AspectJ 1.0</entry>
  4608. <entry>Many language changes, fixes, cleanup and
  4609. clarifications, some significant.
  4610. </entry>
  4611. </row>
  4612. <row>
  4613. <entry>AspectJ 0.8</entry>
  4614. <entry>More cleanup of the syntax and semantics.</entry>
  4615. </row>
  4616. <row>
  4617. <entry>AspectJ 0.7</entry>
  4618. <entry>Clean up of the semantics, 0.7 beta 4 is the first
  4619. open source release.
  4620. </entry>
  4621. </row>
  4622. <row>
  4623. <entry>AspectJ 0.6</entry>
  4624. <entry>Advice and crosscuts get explicit type signatures
  4625. which describe the values that are available to advice at a
  4626. crosscut.
  4627. </entry>
  4628. </row>
  4629. <row>
  4630. <entry>AspectJ 0.5</entry>
  4631. <entry>Improved tool support: better Emacs environment
  4632. support and <literal>ajdoc</literal> to parallel
  4633. <literal>javadoc</literal>. around advice is added, and the
  4634. <literal>aspect</literal> keyword is removed and replaced
  4635. by the Java keyword class.
  4636. </entry>
  4637. </row>
  4638. <row>
  4639. <entry>AspectJ 0.4</entry>
  4640. <entry>Clear separation of crosscuts and crosscut actions
  4641. makes it possible to define extensible library
  4642. aspects.
  4643. </entry>
  4644. </row>
  4645. <row>
  4646. <entry>AspectJ 0.3</entry>
  4647. <entry>First all Java implementation, also includes many
  4648. small language improvements.
  4649. </entry>
  4650. </row>
  4651. <row>
  4652. <entry>AspectJ 0.2</entry>
  4653. <entry>General-purpose support for crosscutting. Users could
  4654. program any kind of aspects, not just coordination. This
  4655. release dropped COOL.
  4656. </entry>
  4657. </row>
  4658. <row>
  4659. <entry>AspectJ 0.1</entry>
  4660. <entry>A single domain-specific aspect language, called COOL,
  4661. for programming coordination in multi-threaded
  4662. programs.
  4663. </entry>
  4664. </row>
  4665. </tbody>
  4666. </tgroup>
  4667. </table>
  4668. <para> More details for 1.0 and earlier releases are available in
  4669. <ulink url="changes.html">changes.html</ulink>.
  4670. </para>
  4671. </answer>
  4672. </qandaentry>
  4673. <qandaentry>
  4674. <question id="q:schedule"
  4675. xreflabel="Q:What is the AspectJ development schedule?">
  4676. <para>
  4677. What is the AspectJ development schedule?
  4678. </para>
  4679. </question>
  4680. <answer>
  4681. <para>
  4682. Below is a table describing the goals for the major releases.
  4683. For information about specific features, search the bug database
  4684. for <literal>RFE</literal>'s ("requests for enhancement") by
  4685. <ulink url="http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&amp;bug_severity=enhancement">
  4686. selecting severity of "enhancement"</ulink>.
  4687. Like many open-source projects, we don't make or promise
  4688. schedules, but we do follow a pattern of issuing preview releases
  4689. which can give observers an idea of when
  4690. a particular release might be available.
  4691. </para>
  4692. <table>
  4693. <title>The AspectJ Development Schedule</title>
  4694. <tgroup cols="2">
  4695. <tbody>
  4696. <row>
  4697. <entry align="left">Version</entry>
  4698. <entry align="left">Description</entry>
  4699. </row>
  4700. <row>
  4701. <entry valign="top" align="center">1.0</entry>
  4702. <entry>Final syntax and semantic changes. Standalone structure
  4703. browser. Complete documentation.
  4704. </entry>
  4705. </row>
  4706. <row>
  4707. <entry valign="top" align="center">1.1</entry>
  4708. <entry>Faster incremental compilation, bytecode weaving,
  4709. and a small number of language changes.</entry>
  4710. </row>
  4711. <row>
  4712. <entry valign="top" align="center">1.2</entry>
  4713. <entry>Faster weaving, -inpath option, better error messages,
  4714. better handling of binary input and resources
  4715. during incremental compilation, faster runtime
  4716. </entry>
  4717. </row>
  4718. <row>
  4719. <entry valign="top" align="center">1.3</entry>
  4720. <entry>Support for Java 1.5
  4721. </entry>
  4722. </row>
  4723. </tbody>
  4724. </tgroup>
  4725. </table>
  4726. </answer>
  4727. </qandaentry>
  4728. <qandaentry>
  4729. <question id="q:java5"
  4730. xreflabel="Q:Will AspectJ support Java 5?">
  4731. <para>
  4732. Will AspectJ support Java 5?
  4733. </para>
  4734. </question>
  4735. <answer>
  4736. <para>
  4737. Yes. We are working on Java 5 support in phases:
  4738. </para>
  4739. <itemizedlist>
  4740. <listitem><para>
  4741. Ensure the weaver can cope with class files
  4742. produced by a Java 5 compiler.
  4743. We know we should not create join points for execution or call
  4744. of methods that have the ACC_BRIDGE attribute (bug 70704), and
  4745. we will look at covariance and members with the ACC_ENUM attribute.
  4746. When we are done, users will be able to compile Java source using
  4747. a Java 5 compiler, and weave with AspectJ.
  4748. </para></listitem>
  4749. <listitem><para>
  4750. Extend the AspectJ compiler so that it can compile the
  4751. new Java 5 features correctly. Mostly this involves waiting for the
  4752. Eclipse JDT team to get their Java 5 support sufficiently down the road,
  4753. and then we will pick this up and work out how to re-integrate it into
  4754. AspectJ. When this is done, users will be able to use ajc to compile
  4755. code with Java 5 constructs.
  4756. </para></listitem>
  4757. <listitem><para>
  4758. Finally, we'll consider changes in the AspectJ language (pointcut
  4759. expressions, treatment of generics, support of annotations, etc.).
  4760. </para></listitem>
  4761. </itemizedlist>
  4762. </answer>
  4763. </qandaentry>
  4764. </qandadiv>
  4765. </qandaset>
  4766. <para>AspectJ is a registered trademark of Palo Alto Research Center, Incorporated (PARC),
  4767. used with permission.
  4768. Java and all Java-based marks are trademarks or registered trademarks of
  4769. Sun Microsystems, Inc. in the United States and other countries. All other
  4770. trademarks are the property of their respective owners.
  4771. </para>
  4772. </article>
  4773. <!--
  4774. Local variables:
  4775. compile-command: "java com.icl.saxon.StyleSheet -o faq.html faq.xml /usr/local/docbook/docbook-xsl-1.44/html/docbook.xsl"
  4776. fill-column: 79
  4777. sgml-local-ecat-files: faq.ced
  4778. End:
  4779. -->