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 238KB

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