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.

faq.xml 235KB

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