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

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