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

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