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

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