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.

MultiProjectIncrementalTests.java 160KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038
  1. /********************************************************************
  2. * Copyright (c) 2005 Contributors. All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution and is available at
  6. * http://eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * Andy Clement initial implementation
  10. * Helen Hawkins Converted to new interface (bug 148190)
  11. *******************************************************************/
  12. package org.aspectj.systemtest.incremental.tools;
  13. import java.io.File;
  14. import java.io.IOException;
  15. import java.io.PrintWriter;
  16. import java.util.ArrayList;
  17. import java.util.Collections;
  18. import java.util.Comparator;
  19. import java.util.Enumeration;
  20. import java.util.HashMap;
  21. import java.util.HashSet;
  22. import java.util.Hashtable;
  23. import java.util.Iterator;
  24. import java.util.List;
  25. import java.util.Map;
  26. import java.util.Set;
  27. import java.util.zip.ZipEntry;
  28. import java.util.zip.ZipFile;
  29. import org.aspectj.ajde.core.ICompilerConfiguration;
  30. import org.aspectj.ajde.core.TestOutputLocationManager;
  31. import org.aspectj.ajde.core.internal.AjdeCoreBuildManager;
  32. import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
  33. import org.aspectj.ajdt.internal.core.builder.AjBuildManager;
  34. import org.aspectj.ajdt.internal.core.builder.AjState;
  35. import org.aspectj.ajdt.internal.core.builder.IncrementalStateManager;
  36. import org.aspectj.asm.AsmManager;
  37. import org.aspectj.asm.IHierarchy;
  38. import org.aspectj.asm.IProgramElement;
  39. import org.aspectj.asm.IProgramElement.Kind;
  40. import org.aspectj.asm.IRelationship;
  41. import org.aspectj.asm.IRelationshipMap;
  42. import org.aspectj.asm.internal.ProgramElement;
  43. import org.aspectj.asm.internal.Relationship;
  44. import org.aspectj.bridge.IMessage;
  45. import org.aspectj.bridge.ISourceLocation;
  46. import org.aspectj.bridge.Message;
  47. import org.aspectj.tools.ajc.Ajc;
  48. import org.aspectj.util.FileUtil;
  49. import org.aspectj.weaver.ResolvedMember;
  50. import org.aspectj.weaver.ResolvedType;
  51. import org.aspectj.weaver.World;
  52. /**
  53. * The superclass knows all about talking through Ajde to the compiler. The superclass isn't in charge of knowing how to simulate
  54. * overlays for incremental builds, that is in here. As is the ability to generate valid build configs based on a directory
  55. * structure. To support this we just need access to a sandbox directory - this sandbox is managed by the superclass (it only
  56. * assumes all builds occur in <sandboxDir>/<projectName>/ )
  57. *
  58. * The idea is you can initialize multiple projects in the sandbox and they can all be built independently, hopefully exploiting
  59. * incremental compilation. Between builds you can alter the contents of a project using the alter() method that overlays some set
  60. * of new files onto the current set (adding new files/changing existing ones) - you can then drive a new build and check it behaves
  61. * as expected.
  62. */
  63. public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementalAjdeInteractionTestbed {
  64. public void testIncremental_344326() throws Exception {
  65. AjdeInteractionTestbed.VERBOSE = true;
  66. String p = "pr344326";
  67. initialiseProject(p);
  68. build(p);
  69. checkWasFullBuild();
  70. checkCompileWeaveCount(p, 3, 4);
  71. alter(p, "inc1");
  72. build(p);
  73. checkWasntFullBuild();
  74. checkCompileWeaveCount(p, 1, 1);
  75. }
  76. public void testMissingRel_328121() throws Exception {
  77. String p = "pr328121";
  78. initialiseProject(p);
  79. build(p);
  80. checkWasFullBuild();
  81. assertNoErrors(p);
  82. // Check the annotations:
  83. runMethod(p, "TestRequirements.TestRequirements", "foo");
  84. assertEquals(4, getRelationshipCount(p));
  85. }
  86. public void testEncoding_pr290741() throws Exception {
  87. String p = "pr290741";
  88. initialiseProject(p);
  89. setProjectEncoding(p, "UTF-8");
  90. build(p);
  91. checkWasFullBuild();
  92. assertNoErrors(p);
  93. runMethod(p, "demo.ConverterTest", "run");
  94. }
  95. public void testRogueConstantReference() throws Exception {
  96. String p = "pr404345";
  97. initialiseProject(p);
  98. setProjectEncoding(p, "UTF-8");
  99. build(p);
  100. checkWasFullBuild();
  101. // Should both indicate that Location cannot be resolved
  102. assertEquals(2,getErrorMessages(p).size());
  103. }
  104. public void testIncrementalITDInners4() throws Exception {
  105. String p = "prInner4";
  106. initialiseProject(p);
  107. build(p);
  108. checkWasFullBuild();
  109. assertNoErrors(p);
  110. // touch the aspect making the ITD member type
  111. alter(p, "inc1");
  112. build(p);
  113. checkWasntFullBuild();
  114. assertNoErrors(p);
  115. }
  116. public void testIncrementalITDInners3() throws Exception {
  117. AjdeInteractionTestbed.VERBOSE = true;
  118. String p = "prInner3";
  119. initialiseProject(p);
  120. build(p);
  121. checkWasFullBuild();
  122. // touch the aspect making the ITD member type
  123. alter(p, "inc1");
  124. build(p);
  125. checkWasntFullBuild();
  126. // touch the aspect making the ITD that depends on the member type
  127. alter(p, "inc2");
  128. build(p);
  129. checkWasntFullBuild();
  130. // touch the type affected by the ITDs
  131. alter(p, "inc3");
  132. build(p);
  133. checkWasntFullBuild();
  134. }
  135. // mixing ITDs with inner type intertypes
  136. public void testIncrementalITDInners2() throws Exception {
  137. String p = "prInner2";
  138. initialiseProject(p);
  139. build(p);
  140. checkWasFullBuild();
  141. // touch the aspect making the ITD member type
  142. alter(p, "inc1");
  143. build(p);
  144. checkWasntFullBuild();
  145. // touch the aspect making the ITD that depends on the member type
  146. alter(p, "inc2");
  147. build(p);
  148. checkWasntFullBuild();
  149. // touch the type affected by the ITDs
  150. alter(p, "inc3");
  151. build(p);
  152. checkWasntFullBuild();
  153. }
  154. public void testIncrementalITDInners() throws Exception {
  155. String p = "prInner";
  156. initialiseProject(p);
  157. build(p);
  158. checkWasFullBuild();
  159. alter(p, "inc1");
  160. build(p);
  161. checkWasntFullBuild();
  162. }
  163. /*
  164. * public void testIncrementalAspectWhitespace() throws Exception { AjdeInteractionTestbed.VERBOSE = true; String p = "xxx";
  165. * initialiseProject(p); configureNonStandardCompileOptions(p, "-showWeaveInfo"); configureShowWeaveInfoMessages(p, true);
  166. * build(p);
  167. *
  168. * List weaveMessages = getWeavingMessages(p); if (weaveMessages.size() != 0) { for (Iterator iterator =
  169. * weaveMessages.iterator(); iterator.hasNext();) { Object object = iterator.next(); System.out.println(object); } }
  170. * checkWasFullBuild(); assertNoErrors(p); alter(p, "inc1"); build(p); checkWasntFullBuild(); assertNoErrors(p); }
  171. */
  172. public void testIncrementalGenericItds_pr280676() throws Exception {
  173. String p = "pr280676";
  174. initialiseProject(p);
  175. build(p);
  176. checkWasFullBuild();
  177. assertNoErrors(p);
  178. alter(p, "inc1"); // remove type variables from ITD field
  179. build(p);
  180. checkWasFullBuild();
  181. assertNoErrors(p);
  182. alter(p, "inc2"); // remove type variables from ITD method
  183. build(p);
  184. checkWasFullBuild();
  185. assertNoErrors(p);
  186. alter(p, "inc3"); // readded type variables on ITD method
  187. build(p);
  188. checkWasFullBuild();
  189. assertNoErrors(p);
  190. }
  191. public void testIncrementalGenericItds_pr280676_2() throws Exception {
  192. String p = "pr280676_2";
  193. initialiseProject(p);
  194. build(p);
  195. checkWasFullBuild();
  196. assertNoErrors(p);
  197. alter(p, "inc1"); // remove type variables from target type
  198. build(p);
  199. List<IMessage> errors = getErrorMessages(p);
  200. // Build errors:
  201. // error at N:\temp\ajcSandbox\aspectj16_3\ajcTest60379.tmp\pr280676_2\src\p\A.java:8:0::0 a.ls cannot be resolved or is not
  202. // a field
  203. // error at N:\temp\ajcSandbox\aspectj16_3\ajcTest60379.tmp\pr280676_2\src\p\Foo.aj:8:0::0 Type parameters can not be
  204. // specified in the ITD target type - the target type p.A is not generic.
  205. // error at N:\temp\ajcSandbox\aspectj16_3\ajcTest60379.tmp\pr280676_2\src\p\Foo.aj:12:0::0 Type parameters can not be
  206. // specified in the ITD target type - the target type p.A is not generic.
  207. // error at N:\temp\ajcSandbox\aspectj16_3\ajcTest60379.tmp\pr280676_2\src\p\Foo.aj:8:0::0 Type parameters can not be
  208. // specified in the ITD target type - the target type p.A is not generic.
  209. // error at N:\temp\ajcSandbox\aspectj16_3\ajcTest60379.tmp\pr280676_2\src\p\Foo.aj:12:0::0 Type parameters can not be
  210. // specified in the ITD target type - the target type p.A is not generic.
  211. assertEquals(5, errors.size());
  212. }
  213. public void testAdviceHandles_pr284771() throws Exception {
  214. String p = "pr284771";
  215. initialiseProject(p);
  216. build(p);
  217. IRelationshipMap irm = getModelFor(p).getRelationshipMap();
  218. List<IRelationship> rels = irm.get("=pr284771<test*AspectTrace.aj'AspectTrace&before");
  219. assertNotNull(rels);
  220. assertEquals(2, ((Relationship) rels.get(0)).getTargets().size());
  221. rels = irm.get("=pr284771<test*AspectTrace.aj'AspectTrace&before!2");
  222. assertNotNull(rels);
  223. assertEquals(2, ((Relationship) rels.get(0)).getTargets().size());
  224. }
  225. public void testDeclareSoftHandles_329111() throws Exception {
  226. String p = "pr329111";
  227. initialiseProject(p);
  228. build(p);
  229. printModel(p);
  230. IRelationshipMap irm = getModelFor(p).getRelationshipMap();
  231. List<IRelationship> rels = irm.get("=pr329111<{AJ.java'AJ`declare soft");
  232. assertNotNull(rels);
  233. rels = irm.get("=pr329111<{AJ2.java'AJ2`declare soft");
  234. assertNotNull(rels);
  235. rels = irm.get("=pr329111<{AJ2.java'AJ2`declare soft!2");
  236. assertNotNull(rels);
  237. rels = irm.get("=pr329111<{AJ2.java'AJ2`declare soft!3");
  238. assertNotNull(rels);
  239. rels = irm.get("=pr329111<{AJ3.java'AJ3`declare warning");
  240. assertNotNull(rels);
  241. rels = irm.get("=pr329111<{AJ3.java'AJ3`declare warning!2");
  242. assertNotNull(rels);
  243. rels = irm.get("=pr329111<{AJ3.java'AJ3`declare error");
  244. assertNotNull(rels);
  245. rels = irm.get("=pr329111<{AJ3.java'AJ3`declare error!2");
  246. assertNotNull(rels);
  247. }
  248. /**
  249. * Test that the declare parents in the super aspect gets a relationship from the type declaring it.
  250. */
  251. public void testAspectInheritance_322446() throws Exception {
  252. String p = "pr322446";
  253. initialiseProject(p);
  254. build(p);
  255. IRelationshipMap irm = getModelFor(p).getRelationshipMap();
  256. // Hid:1:(targets=1) =pr322446<{Class.java[Class (aspect declarations) =pr322446<{AbstractAspect.java'AbstractAspect`declare
  257. // parents
  258. // Hid:2:(targets=1) =pr322446<{AbstractAspect.java'AbstractAspect`declare parents (declared on) =pr322446<{Class.java[Class
  259. List<IRelationship> rels = irm.get("=pr322446<{AbstractAspect.java'AbstractAspect`declare parents");
  260. assertNotNull(rels);
  261. }
  262. public void testAspectInheritance_322446_2() throws Exception {
  263. String p = "pr322446_2";
  264. initialiseProject(p);
  265. build(p);
  266. IProgramElement thisAspectNode = getModelFor(p).getHierarchy().findElementForType("", "Sub");
  267. assertEquals("{Code=[I]}", thisAspectNode.getDeclareParentsMap().toString());
  268. }
  269. public void testBinaryAspectsAndTheModel_343001() throws Exception {
  270. String lib = "pr343001_lib";
  271. initialiseProject(lib);
  272. build(lib);
  273. // Check the 'standard build' - the library also has a type affected by the decp so we can check what happens on an 'all
  274. // source' build
  275. IProgramElement theAspect = getModelFor(lib).getHierarchy().findElementForHandleOrCreate("=pr343001_lib<{Super.java'Super",
  276. false);
  277. assertNotNull(theAspect);
  278. IProgramElement sourcelevelDecp = getModelFor(lib).getHierarchy().findElementForHandleOrCreate(
  279. "=pr343001_lib<{Super.java'Super`declare parents", false);
  280. assertNotNull(sourcelevelDecp);
  281. assertEquals("[java.io.Serializable]", sourcelevelDecp.getParentTypes().toString());
  282. String p = "pr343001";
  283. initialiseProject(p);
  284. configureAspectPath(p, getProjectRelativePath(lib, "bin"));
  285. build(p);
  286. IProgramElement theBinaryAspect = getModelFor(p).getHierarchy().findElementForHandleOrCreate(
  287. "=pr343001/binaries<(Super.class'Super", false);
  288. assertNotNull(theBinaryAspect);
  289. IProgramElement binaryDecp = getModelFor(p).getHierarchy().findElementForHandleOrCreate(
  290. "=pr343001/binaries<(Super.class'Super`declare parents", false);
  291. assertNotNull(binaryDecp);
  292. assertEquals("[java.io.Serializable]", (binaryDecp.getParentTypes() == null ? "" : binaryDecp.getParentTypes().toString()));
  293. }
  294. // found whilst looking at 322446 hence that is the testdata name
  295. public void testAspectInheritance_322664() throws Exception {
  296. AjdeInteractionTestbed.VERBOSE = true;
  297. String p = "pr322446_3";
  298. initialiseProject(p);
  299. build(p);
  300. assertNoErrors(p);
  301. alter(p, "inc1");
  302. build(p);
  303. // should be some errors:
  304. // error at N:\temp\ajcSandbox\aspectj16_1\ajcTest3209787521625191676.tmp\pr322446_3\src\AbstractAspect.java:5:0::0 can't
  305. // bind type name 'T'
  306. // error at N:\temp\ajcSandbox\aspectj16_1\ajcTest3209787521625191676.tmp\pr322446_3\src\AbstractAspect.java:8:0::0
  307. // Incorrect number of arguments for type AbstractAspect<S>; it cannot be parameterized with arguments <X, Y>
  308. List<IMessage> errors = getErrorMessages(p);
  309. assertTrue(errors != null && errors.size() > 0);
  310. alter(p, "inc2");
  311. build(p);
  312. // that build would contain an exception if the bug were around
  313. assertNoErrors(p);
  314. }
  315. // TODO (asc) these tests don't actually verify anything!
  316. // public void testAtDeclareParents_280658() throws Exception {
  317. // AjdeInteractionTestbed.VERBOSE = true;
  318. // String lib = "pr280658_decp";
  319. // initialiseProject(lib);
  320. // build(lib);
  321. // checkWasFullBuild();
  322. //
  323. // String cli = "pr280658_target";
  324. // initialiseProject(cli);
  325. //
  326. // configureAspectPath(cli, getProjectRelativePath(lib, "bin"));
  327. // build(cli);
  328. // checkWasFullBuild();
  329. // printModel(cli);
  330. // }
  331. //
  332. // public void testAtDeclareMixin_280651() throws Exception {
  333. // AjdeInteractionTestbed.VERBOSE = true;
  334. // String lib = "pr280651_decmix";
  335. // initialiseProject(lib);
  336. // build(lib);
  337. // checkWasFullBuild();
  338. //
  339. // String cli = "pr280658_target";
  340. // initialiseProject(cli);
  341. //
  342. // configureAspectPath(cli, getProjectRelativePath(lib, "bin"));
  343. // build(cli);
  344. // checkWasFullBuild();
  345. // printModel(cli);
  346. // }
  347. // Testing that declare annotation model entries preserve the fully qualified type of the annotation
  348. public void testDecAnnoState_pr286539() throws Exception {
  349. String p = "pr286539";
  350. initialiseProject(p);
  351. build(p);
  352. printModel(p);
  353. IProgramElement decpPE = getModelFor(p).getHierarchy().findElementForHandle(
  354. "=pr286539<p.q.r{Aspect.java'Asp`declare parents");
  355. assertNotNull(decpPE);
  356. String s = ((decpPE.getParentTypes()).get(0));
  357. assertEquals("p.q.r.Int", s);
  358. decpPE = getModelFor(p).getHierarchy().findElementForHandle("=pr286539<p.q.r{Aspect.java'Asp`declare parents!2");
  359. assertNotNull(decpPE);
  360. s = ((decpPE.getParentTypes()).get(0));
  361. assertEquals("p.q.r.Int", s);
  362. IProgramElement decaPE = getModelFor(p).getHierarchy().findElementForHandle(
  363. "=pr286539<p.q.r{Aspect.java'Asp`declare \\@type");
  364. assertNotNull(decaPE);
  365. assertEquals("p.q.r.Foo", decaPE.getAnnotationType());
  366. decaPE = getModelFor(p).getHierarchy().findElementForHandle("=pr286539<p.q.r{Aspect.java'Asp`declare \\@type!2");
  367. assertNotNull(decaPE);
  368. assertEquals("p.q.r.Goo", decaPE.getAnnotationType());
  369. decaPE = getModelFor(p).getHierarchy().findElementForHandle("=pr286539<p.q.r{Aspect.java'Asp`declare \\@field");
  370. assertNotNull(decaPE);
  371. assertEquals("p.q.r.Foo", decaPE.getAnnotationType());
  372. decaPE = getModelFor(p).getHierarchy().findElementForHandle("=pr286539<p.q.r{Aspect.java'Asp`declare \\@method");
  373. assertNotNull(decaPE);
  374. assertEquals("p.q.r.Foo", decaPE.getAnnotationType());
  375. decaPE = getModelFor(p).getHierarchy().findElementForHandle("=pr286539<p.q.r{Aspect.java'Asp`declare \\@constructor");
  376. assertNotNull(decaPE);
  377. assertEquals("p.q.r.Foo", decaPE.getAnnotationType());
  378. }
  379. public void testQualifiedInnerTypeRefs_269082() throws Exception {
  380. String p = "pr269082";
  381. initialiseProject(p);
  382. configureNonStandardCompileOptions(p, "-Xset:minimalModel=false");
  383. build(p);
  384. printModel(p);
  385. IProgramElement root = getModelFor(p).getHierarchy().getRoot();
  386. IProgramElement ipe = findElementAtLine(root, 7);
  387. assertEquals("=pr269082<a{ClassUsingInner.java[ClassUsingInner~foo~QMyInner;~QObject;~QString;", ipe.getHandleIdentifier());
  388. ipe = findElementAtLine(root, 9);
  389. assertEquals("=pr269082<a{ClassUsingInner.java[ClassUsingInner~goo~QClassUsingInner.MyInner;~QObject;~QString;",
  390. ipe.getHandleIdentifier());
  391. ipe = findElementAtLine(root, 11);
  392. assertEquals("=pr269082<a{ClassUsingInner.java[ClassUsingInner~hoo~Qa.ClassUsingInner.MyInner;~QObject;~QString;",
  393. ipe.getHandleIdentifier());
  394. }
  395. // just simple incremental build - no code change, just the aspect touched
  396. public void testIncrementalFqItds_280380() throws Exception {
  397. String p = "pr280380";
  398. initialiseProject(p);
  399. build(p);
  400. // printModel(p);
  401. alter(p, "inc1");
  402. build(p);
  403. // should not be an error about f.AClass not being found
  404. assertNoErrors(p);
  405. // printModel(p);
  406. }
  407. public void testIncrementalAdvisingItdJoinpointsAccessingPrivFields_307120() throws Exception {
  408. String p = "pr307120";
  409. initialiseProject(p);
  410. build(p);
  411. // Hid:1:(targets=1) =pr307120<{Test.java}Test)A.getFoo?field-get(int A.foo) (advised by) =pr307120<{Test.java}Test&before
  412. // Hid:2:(targets=1) =pr307120<{A.java[A (aspect declarations) =pr307120<{Test.java}Test)A.getFoo
  413. // Hid:3:(targets=1) =pr307120<{Test.java}Test&before (advises) =pr307120<{Test.java}Test)A.getFoo?field-get(int A.foo)
  414. // Hid:4:(targets=1) =pr307120<{Test.java}Test)A.getFoo (declared on) =pr307120<{A.java[A
  415. alter(p, "inc1");
  416. assertEquals(4, getRelationshipCount(p));
  417. build(p);
  418. // Hid:1:(targets=1) =pr307120<{A.java[A (aspect declarations) =pr307120<{Test.java}Test)A.getFoo
  419. // Hid:2:(targets=1) =pr307120<{Test.java}Test)A.getFoo (declared on) =pr307120<{A.java[A
  420. // These two are missing without the fix:
  421. // Hid:1:(targets=1) =pr307120<{Test.java}Test)A.getFoo?field-get(int A.foo) (advised by) =pr307120<{Test.java}Test&before
  422. // Hid:7:(targets=1) =pr307120<{Test.java}Test&before (advises) =pr307120<{Test.java}Test)A.getFoo?field-get(int A.foo)
  423. assertNoErrors(p);
  424. assertEquals(4, getRelationshipCount(p));
  425. }
  426. public void testIncrementalAdvisingItdJoinpointsAccessingPrivFields_307120_pipelineOff() throws Exception {
  427. String p = "pr307120";
  428. initialiseProject(p);
  429. configureNonStandardCompileOptions(p, "-Xset:pipelineCompilation=false");
  430. build(p);
  431. // Hid:1:(targets=1) =pr307120<{Test.java}Test)A.getFoo?field-get(int A.foo) (advised by) =pr307120<{Test.java}Test&before
  432. // Hid:2:(targets=1) =pr307120<{A.java[A (aspect declarations) =pr307120<{Test.java}Test)A.getFoo
  433. // Hid:3:(targets=1) =pr307120<{Test.java}Test&before (advises) =pr307120<{Test.java}Test)A.getFoo?field-get(int A.foo)
  434. // Hid:4:(targets=1) =pr307120<{Test.java}Test)A.getFoo (declared on) =pr307120<{A.java[A
  435. alter(p, "inc1");
  436. assertEquals(4, getRelationshipCount(p));
  437. build(p);
  438. // Hid:1:(targets=1) =pr307120<{A.java[A (aspect declarations) =pr307120<{Test.java}Test)A.getFoo
  439. // Hid:2:(targets=1) =pr307120<{Test.java}Test)A.getFoo (declared on) =pr307120<{A.java[A
  440. // These two are missing without the fix:
  441. // Hid:1:(targets=1) =pr307120<{Test.java}Test)A.getFoo?field-get(int A.foo) (advised by) =pr307120<{Test.java}Test&before
  442. // Hid:7:(targets=1) =pr307120<{Test.java}Test&before (advises) =pr307120<{Test.java}Test)A.getFoo?field-get(int A.foo)
  443. assertNoErrors(p);
  444. assertEquals(4, getRelationshipCount(p));
  445. }
  446. // More sophisticated variant of above.
  447. public void testIncrementalAdvisingItdJoinpointsAccessingPrivFields_307120_2_pipelineOff() throws Exception {
  448. String p = "pr307120_3";
  449. initialiseProject(p);
  450. configureNonStandardCompileOptions(p, "-Xset:pipelineCompilation=false");
  451. build(p);
  452. assertNoErrors(p);
  453. // Hid:1:(targets=1) =pr307120_3<{TargetAugmenter.java}TargetAugmenter)Target.setIt)QString; (declared on)
  454. // =pr307120_3<{Target.java[Target
  455. // Hid:2:(targets=1) =pr307120_3<{Target.java[Target (aspect declarations)
  456. // =pr307120_3<{TargetAugmenter.java}TargetAugmenter)Target.setIt)QString;
  457. // these are missing under this bug:
  458. // Hid:3:(targets=1) =pr307120_3<{Advisor.java}Advisor&around&QObject;&QObject; (advises)
  459. // =pr307120_3<{TargetAugmenter.java}TargetAugmenter)Target.setIt)QString;?field-set(java.lang.String Target.it)
  460. // Hid:4:(targets=1) =pr307120_3<{TargetAugmenter.java}TargetAugmenter)Target.setIt)QString;?field-set(java.lang.String
  461. // Target.it) (advised by) =pr307120_3<{Advisor.java}Advisor&around&QObject;&QObject;
  462. assertEquals(4, getRelationshipCount(p));
  463. alter(p, "inc1");
  464. build(p);
  465. assertEquals(4, getRelationshipCount(p));
  466. assertNoErrors(p);
  467. }
  468. // More sophisticated variant of above.
  469. public void testIncrementalAdvisingItdJoinpointsAccessingPrivFields_307120_2() throws Exception {
  470. String p = "pr307120_2";
  471. initialiseProject(p);
  472. build(p);
  473. assertNoErrors(p);
  474. // Hid:2:(targets=1) =pr307120_2<{TargetAugmenter.java}TargetAugmenter)Target.setIt)QString; (declared on)
  475. // =pr307120_2<{Target.java[Target
  476. // Hid:8:(targets=1) =pr307120_2<{TargetAugmenter.java}TargetAugmenter)Target.getIt (declared on)
  477. // =pr307120_2<{Target.java[Target
  478. // Hid:5:(targets=2) =pr307120_2<{Target.java[Target (aspect declarations)
  479. // =pr307120_2<{TargetAugmenter.java}TargetAugmenter)Target.getIt
  480. // Hid:6:(targets=2) =pr307120_2<{Target.java[Target (aspect declarations)
  481. // =pr307120_2<{TargetAugmenter.java}TargetAugmenter)Target.setIt)QString;
  482. // Hid:1:(targets=1) =pr307120_2<{TargetAugmenter.java}TargetAugmenter)Target.setIt)QString;?field-set(java.lang.String
  483. // Target.it) (advised by) =pr307120_2<{Advisor.java}Advisor&around&QObject;&QObject;
  484. // Hid:3:(targets=1) =pr307120_2<{TargetAugmenter.java}TargetAugmenter)Target.getIt?field-get(java.lang.String Target.it)
  485. // (advised by) =pr307120_2<{Advisor.java}Advisor&around&QObject;
  486. // Hid:4:(targets=1) =pr307120_2<{Advisor.java}Advisor&around&QObject; (advises)
  487. // =pr307120_2<{TargetAugmenter.java}TargetAugmenter)Target.getIt?field-get(java.lang.String Target.it)
  488. // Hid:7:(targets=1) =pr307120_2<{Advisor.java}Advisor&around&QObject;&QObject; (advises)
  489. // =pr307120_2<{TargetAugmenter.java}TargetAugmenter)Target.setIt)QString;?field-set(java.lang.String Target.it)
  490. assertEquals(8, getRelationshipCount(p));
  491. alter(p, "inc1");
  492. build(p);
  493. assertEquals(8, getRelationshipCount(p));
  494. assertNoErrors(p);
  495. }
  496. // // More sophisticated variant of above.
  497. // public void testIncrementalAdvisingItdJoinpointsAccessingPrivFields_307120_4_pipelineOff() throws Exception {
  498. // String p = "pr307120_4";
  499. // initialiseProject(p);
  500. // configureNonStandardCompileOptions(p, "-Xset:pipelineCompilation=false");
  501. // build(p);
  502. // assertNoErrors(p);
  503. //
  504. // printModel(p);
  505. // assertEquals(4, getRelationshipCount(p));
  506. // alter(p, "inc1");
  507. // build(p);
  508. //
  509. // assertEquals(4, getRelationshipCount(p));
  510. // assertNoErrors(p);
  511. // }
  512. // modified aspect so target is fully qualified on the incremental change
  513. public void testIncrementalFqItds_280380_2() throws Exception {
  514. String p = "pr280380";
  515. initialiseProject(p);
  516. build(p);
  517. // printModel(p);
  518. assertEquals(4, getModelFor(p).getRelationshipMap().getEntries().size());
  519. // Hid:1:(targets=3) =pr280380<f{AClass.java[AClass (aspect declarations) =pr280380<g*AnAspect.aj}AnAspect)AClass.xxxx
  520. // Hid:2:(targets=3) =pr280380<f{AClass.java[AClass (aspect declarations) =pr280380<g*AnAspect.aj}AnAspect)AClass.y
  521. // Hid:3:(targets=3) =pr280380<f{AClass.java[AClass (aspect declarations) =pr280380<g*AnAspect.aj}AnAspect)AClass.AClass_new
  522. // Hid:4:(targets=1) =pr280380<g*AnAspect.aj}AnAspect)AClass.y (declared on) =pr280380<f{AClass.java[AClass
  523. // Hid:5:(targets=1) =pr280380<g*AnAspect.aj}AnAspect)AClass.AClass_new (declared on) =pr280380<f{AClass.java[AClass
  524. // Hid:6:(targets=1) =pr280380<g*AnAspect.aj}AnAspect)AClass.xxxx (declared on) =pr280380<f{AClass.java[AClass
  525. alter(p, "inc2");
  526. build(p);
  527. // should not be an error about f.AClass not being found
  528. assertNoErrors(p);
  529. // printModel(p);
  530. assertEquals(4, getModelFor(p).getRelationshipMap().getEntries().size());
  531. // Hid:1:(targets=3) =pr280380<f{AClass.java[AClass (aspect declarations) =pr280380<g*AnAspect.aj}AnAspect)AClass.xxxx
  532. // Hid:2:(targets=3) =pr280380<f{AClass.java[AClass (aspect declarations) =pr280380<g*AnAspect.aj}AnAspect)AClass.y
  533. // Hid:3:(targets=3) =pr280380<f{AClass.java[AClass (aspect declarations) =pr280380<g*AnAspect.aj}AnAspect)AClass.AClass_new
  534. // Hid:4:(targets=1) =pr280380<g*AnAspect.aj}AnAspect)AClass.y (declared on) =pr280380<f{AClass.java[AClass
  535. // Hid:5:(targets=1) =pr280380<g*AnAspect.aj}AnAspect)AClass.AClass_new (declared on) =pr280380<f{AClass.java[AClass
  536. // Hid:6:(targets=1) =pr280380<g*AnAspect.aj}AnAspect)AClass.xxxx (declared on) =pr280380<f{AClass.java[AClass
  537. }
  538. public void testIncrementalFqItds_280380_3() throws Exception {
  539. String p = "pr280380";
  540. initialiseProject(p);
  541. build(p);
  542. // printModel(p);
  543. assertEquals(4, getModelFor(p).getRelationshipMap().getEntries().size());
  544. // Hid:1:(targets=3) =pr280380<f{AClass.java[AClass (aspect declarations) =pr280380<g*AnAspect.aj}AnAspect)AClass.xxxx
  545. // Hid:2:(targets=3) =pr280380<f{AClass.java[AClass (aspect declarations) =pr280380<g*AnAspect.aj}AnAspect)AClass.y
  546. // Hid:3:(targets=3) =pr280380<f{AClass.java[AClass (aspect declarations) =pr280380<g*AnAspect.aj}AnAspect)AClass.AClass_new
  547. // Hid:4:(targets=1) =pr280380<g*AnAspect.aj}AnAspect)AClass.y (declared on) =pr280380<f{AClass.java[AClass
  548. // Hid:5:(targets=1) =pr280380<g*AnAspect.aj}AnAspect)AClass.AClass_new (declared on) =pr280380<f{AClass.java[AClass
  549. // Hid:6:(targets=1) =pr280380<g*AnAspect.aj}AnAspect)AClass.xxxx (declared on) =pr280380<f{AClass.java[AClass
  550. printModel(p);
  551. assertNotNull(getModelFor(p).getRelationshipMap().get("=pr280380<g*AnAspect.aj'AnAspect,AClass.xxxx"));
  552. alter(p, "inc2");
  553. build(p);
  554. assertNoErrors(p);
  555. printModel(p);
  556. // On this build the relationship should have changed to include the fully qualified target
  557. assertEquals(4, getModelFor(p).getRelationshipMap().getEntries().size());
  558. assertNotNull(getModelFor(p).getRelationshipMap().get("=pr280380<g*AnAspect.aj'AnAspect,AClass.xxxx"));
  559. // Hid:1:(targets=3) =pr280380<f{AClass.java[AClass (aspect declarations) =pr280380<g*AnAspect.aj}AnAspect)AClass.xxxx
  560. // Hid:2:(targets=3) =pr280380<f{AClass.java[AClass (aspect declarations) =pr280380<g*AnAspect.aj}AnAspect)AClass.y
  561. // Hid:3:(targets=3) =pr280380<f{AClass.java[AClass (aspect declarations) =pr280380<g*AnAspect.aj}AnAspect)AClass.AClass_new
  562. // Hid:4:(targets=1) =pr280380<g*AnAspect.aj}AnAspect)AClass.y (declared on) =pr280380<f{AClass.java[AClass
  563. // Hid:5:(targets=1) =pr280380<g*AnAspect.aj}AnAspect)AClass.AClass_new (declared on) =pr280380<f{AClass.java[AClass
  564. // Hid:6:(targets=1) =pr280380<g*AnAspect.aj}AnAspect)AClass.xxxx (declared on) =pr280380<f{AClass.java[AClass
  565. }
  566. public void testFQItds_322039() throws Exception {
  567. String p = "pr322039";
  568. initialiseProject(p);
  569. build(p);
  570. printModel(p);
  571. IRelationshipMap irm = getModelFor(p).getRelationshipMap();
  572. List<IRelationship> rels = irm.get("=pr322039<p{Azpect.java'Azpect)q2.Code.something2");
  573. assertNotNull(rels);
  574. }
  575. public void testIncrementalCtorItdHandle_280383() throws Exception {
  576. String p = "pr280383";
  577. initialiseProject(p);
  578. build(p);
  579. printModel(p);
  580. IRelationshipMap irm = getModelFor(p).getRelationshipMap();
  581. List<IRelationship> rels = irm.get("=pr280383<f{AnAspect.java'AnAspect)f.AClass.f_AClass_new");
  582. assertNotNull(rels);
  583. }
  584. // public void testArraysGenerics() throws Exception {
  585. // String p = "pr283864";
  586. // initialiseProject(p);
  587. // build(p);
  588. // printModel(p);
  589. // // IRelationshipMap irm = getModelFor(p).getRelationshipMap();
  590. // // List rels = irm.get("=pr280383<f{AnAspect.java}AnAspect)f.AClass.f_AClass_new");
  591. // // assertNotNull(rels);
  592. // }
  593. public void testSimilarITDS() throws Exception {
  594. String p = "pr283657";
  595. initialiseProject(p);
  596. build(p);
  597. printModel(p);
  598. // Hid:1:(targets=1) =pr283657<{Aspect.java}Aspect)Target.foo (declared on) =pr283657<{Aspect.java[Target
  599. // Hid:2:(targets=1) =pr283657<{Aspect.java}Aspect)Target.foo!2 (declared on) =pr283657<{Aspect.java[Target
  600. // Hid:3:(targets=2) =pr283657<{Aspect.java[Target (aspect declarations) =pr283657<{Aspect.java}Aspect)Target.foo
  601. // Hid:4:(targets=2) =pr283657<{Aspect.java[Target (aspect declarations) =pr283657<{Aspect.java}Aspect)Target.foo!2
  602. IRelationshipMap irm = getModelFor(p).getRelationshipMap();
  603. List<IRelationship> rels = irm.get("=pr283657<{Aspect.java'Aspect,Target.foo");
  604. assertNotNull(rels);
  605. rels = irm.get("=pr283657<{Aspect.java'Aspect)Target.foo!2");
  606. assertNotNull(rels);
  607. }
  608. public void testIncrementalAnnotationMatched_276399() throws Exception {
  609. String p = "pr276399";
  610. initialiseProject(p);
  611. addSourceFolderForSourceFile(p, getProjectRelativePath(p, "src/X.aj"), "src");
  612. addSourceFolderForSourceFile(p, getProjectRelativePath(p, "src/C.java"), "src");
  613. build(p);
  614. IRelationshipMap irm = getModelFor(p).getRelationshipMap();
  615. IRelationship ir = irm.get("=pr276399/src<*X.aj'X&after").get(0);
  616. assertNotNull(ir);
  617. alter(p, "inc1");
  618. build(p);
  619. printModel(p);
  620. irm = getModelFor(p).getRelationshipMap();
  621. List<IRelationship> rels = irm.get("=pr276399/src<*X.aj'X&after"); // should be gone after the inc build
  622. assertNull(rels);
  623. }
  624. public void testHandleCountDecA_pr278255() throws Exception {
  625. String p = "pr278255";
  626. initialiseProject(p);
  627. build(p);
  628. printModelAndRelationships(p);
  629. IRelationshipMap irm = getModelFor(p).getRelationshipMap();
  630. List<IRelationship> l = irm.get("=pr278255<{A.java'X`declare \\@type");
  631. assertNotNull(l);
  632. IRelationship ir = l.get(0);
  633. assertNotNull(ir);
  634. }
  635. public void testIncrementalItdDefaultCtor() {
  636. String p = "pr275032";
  637. initialiseProject(p);
  638. build(p);
  639. assertEquals(0, getErrorMessages(p).size());
  640. alter(p, "inc1");
  641. build(p);
  642. // error is: inter-type declaration from X conflicts with existing member: void A.<init>()
  643. // List ms =
  644. getErrorMessages(p);
  645. assertEquals(4, getErrorMessages(p).size());
  646. // Why 4 errors? I believe the problem is:
  647. // 2 errors are reported when there is a clash - one against the aspect, one against the affected target type.
  648. // each of the two errors are recorded against the compilation result for the aspect and the target
  649. // So it comes out as 4 - but for now I am tempted to leave it because at least it shows there is a problem...
  650. assertTrue("Was:" + getErrorMessages(p).get(0), getErrorMessages(p).get(0).toString().indexOf("conflicts") != -1);
  651. }
  652. public void testOutputLocationCallbacks2() {
  653. String p = "pr268827_ol_res";
  654. initialiseProject(p);
  655. Map<String,File> m = new HashMap<String,File>();
  656. m.put("a.txt", new File(getFile(p, "src/a.txt")));
  657. configureResourceMap(p, m);
  658. CustomOLM olm = new CustomOLM(getProjectRelativePath(p, ".").toString());
  659. configureOutputLocationManager(p, olm);
  660. build(p);
  661. checkCompileWeaveCount(p, 2, 2);
  662. assertEquals(3, olm.writeCount);
  663. alter(p, "inc1"); // this contains a new B.java that doesn't have the aspect inside it
  664. build(p);
  665. checkCompileWeaveCount(p, 3, 1);
  666. assertEquals(1, olm.removeCount); // B.class removed
  667. }
  668. public void testOutputLocationCallbacks() {
  669. String p = "pr268827_ol";
  670. initialiseProject(p);
  671. CustomOLM olm = new CustomOLM(getProjectRelativePath(p, ".").toString());
  672. configureOutputLocationManager(p, olm);
  673. build(p);
  674. checkCompileWeaveCount(p, 2, 3);
  675. alter(p, "inc1"); // this contains a new Foo.java that no longer has Extra class in it
  676. build(p);
  677. checkCompileWeaveCount(p, 1, 1);
  678. assertEquals(1, olm.removeCount);
  679. }
  680. public void testOutputLocationCallbacksFileAdd() {
  681. String p = "pr268827_ol2";
  682. initialiseProject(p);
  683. CustomOLM olm = new CustomOLM(getProjectRelativePath(p, ".").toString());
  684. configureOutputLocationManager(p, olm);
  685. build(p);
  686. assertEquals(3, olm.writeCount);
  687. olm.writeCount = 0;
  688. checkCompileWeaveCount(p, 2, 3);
  689. alter(p, "inc1"); // this contains a new file Boo.java
  690. build(p);
  691. assertEquals(1, olm.writeCount);
  692. checkCompileWeaveCount(p, 1, 1);
  693. // assertEquals(1, olm.removeCount);
  694. }
  695. static class CustomOLM extends TestOutputLocationManager {
  696. public int writeCount = 0;
  697. public int removeCount = 0;
  698. public CustomOLM(String testProjectPath) {
  699. super(testProjectPath);
  700. }
  701. @Override
  702. public void reportFileWrite(String outputfile, int filetype) {
  703. super.reportFileWrite(outputfile, filetype);
  704. writeCount++;
  705. System.out.println("Written " + outputfile);
  706. // System.out.println("Written " + outputfile + " " + filetype);
  707. }
  708. @Override
  709. public void reportFileRemove(String outputfile, int filetype) {
  710. super.reportFileRemove(outputfile, filetype);
  711. removeCount++;
  712. System.out.println("Removed " + outputfile);
  713. // System.out.println("Removed " + outputfile + " " + filetype);
  714. }
  715. }
  716. public void testBrokenCodeDeca_268611() {
  717. String p = "pr268611";
  718. initialiseProject(p);
  719. build(p);
  720. checkWasFullBuild();
  721. assertEquals(1, getErrorMessages(p).size());
  722. assertTrue(((Message) getErrorMessages(p).get(0)).getMessage().indexOf(
  723. "Syntax error on token \")\", \"name pattern\" expected") != -1);
  724. }
  725. public void testIncrementalMixin() {
  726. String p = "mixin";
  727. initialiseProject(p);
  728. build(p);
  729. checkWasFullBuild();
  730. assertEquals(0, getErrorMessages(p).size());
  731. alter(p, "inc1");
  732. build(p);
  733. checkWasntFullBuild();
  734. assertEquals(0, getErrorMessages(p).size());
  735. }
  736. public void testUnusedPrivates_pr266420() {
  737. String p = "pr266420";
  738. initialiseProject(p);
  739. Hashtable<String,String> javaOptions = new Hashtable<String,String>();
  740. javaOptions.put("org.eclipse.jdt.core.compiler.compliance", "1.6");
  741. javaOptions.put("org.eclipse.jdt.core.compiler.codegen.targetPlatform", "1.6");
  742. javaOptions.put("org.eclipse.jdt.core.compiler.source", "1.6");
  743. javaOptions.put("org.eclipse.jdt.core.compiler.problem.unusedPrivateMember", "warning");
  744. configureJavaOptionsMap(p, javaOptions);
  745. build(p);
  746. checkWasFullBuild();
  747. List<IMessage> warnings = getWarningMessages(p);
  748. assertEquals(0, warnings.size());
  749. alter(p, "inc1");
  750. build(p);
  751. checkWasntFullBuild();
  752. warnings = getWarningMessages(p);
  753. assertEquals(0, warnings.size());
  754. }
  755. public void testExtendingITDAspectOnClasspath_PR298704() throws Exception {
  756. String base = "pr298704_baseaspects";
  757. String test = "pr298704_testaspects";
  758. initialiseProject(base);
  759. initialiseProject(test);
  760. configureNewProjectDependency(test, base);
  761. build(base);
  762. build(test);
  763. checkWasFullBuild();
  764. assertNoErrors(test);
  765. IRelationshipMap irm = getModelFor(test).getRelationshipMap();
  766. assertEquals(7, irm.getEntries().size());
  767. }
  768. public void testPR265729() {
  769. AjdeInteractionTestbed.VERBOSE = true;
  770. String lib = "pr265729_lib";
  771. initialiseProject(lib);
  772. // addClasspathEntryChanged(lib, getProjectRelativePath(p1,
  773. // "bin").toString());
  774. build(lib);
  775. checkWasFullBuild();
  776. String cli = "pr265729_client";
  777. initialiseProject(cli);
  778. // addClasspathEntry(cli, new File("../lib/junit/junit.jar"));
  779. configureAspectPath(cli, getProjectRelativePath(lib, "bin"));
  780. build(cli);
  781. checkWasFullBuild();
  782. IProgramElement root = getModelFor(cli).getHierarchy().getRoot();
  783. // dumptree(root, 0);
  784. // PrintWriter pw = new PrintWriter(System.out);
  785. // try {
  786. // getModelFor(cli).dumprels(pw);
  787. // pw.flush();
  788. // } catch (Exception e) {
  789. // }
  790. IRelationshipMap irm = getModelFor(cli).getRelationshipMap();
  791. IRelationship ir = irm.get("=pr265729_client<be.cronos.aop{App.java[App").get(0);
  792. // This type should be affected by an ITD and a declare parents
  793. // could be either way round
  794. String h1 = ir.getTargets().get(0);
  795. String h2 = ir.getTargets().get(1);
  796. // For some ITD: public void I.g(String s) {}
  797. // Node in tree: I.g(java.lang.String) [inter-type method]
  798. // Handle: =pr265729_client<be.cronos.aop{App.java}X)I.g)QString;
  799. if (!h1.endsWith("parents")) {
  800. String h3 = h1;
  801. h1 = h2;
  802. h2 = h3;
  803. }
  804. // ITD from the test program:
  805. // public String InterTypeAspectInterface.foo(int i,List list,App a) {
  806. assertEquals("=pr265729_client/binaries<be.cronos.aop.aspects(InterTypeAspect.class'InterTypeAspect`declare parents", h1);
  807. assertEquals(
  808. "=pr265729_client/binaries<be.cronos.aop.aspects(InterTypeAspect.class'InterTypeAspect)InterTypeAspectInterface.foo)I)QList;)QSerializable;",
  809. h2);
  810. IProgramElement binaryDecp = getModelFor(cli).getHierarchy().getElement(h1);
  811. assertNotNull(binaryDecp);
  812. IProgramElement binaryITDM = getModelFor(cli).getHierarchy().getElement(h2);
  813. assertNotNull(binaryITDM);
  814. // @see AsmRelationshipProvider.createIntertypeDeclaredChild()
  815. List<char[]> ptypes = binaryITDM.getParameterTypes();
  816. assertEquals("int", new String((char[]) ptypes.get(0)));
  817. assertEquals("java.util.List", new String((char[]) ptypes.get(1)));
  818. assertEquals("java.io.Serializable", new String((char[]) ptypes.get(2)));
  819. // param names not set
  820. // List pnames = binaryITDM.getParameterNames();
  821. // assertEquals("i", new String((char[]) pnames.get(0)));
  822. // assertEquals("list", new String((char[]) pnames.get(1)));
  823. // assertEquals("b", new String((char[]) pnames.get(2)));
  824. assertEquals("java.lang.String", binaryITDM.getCorrespondingType(true));
  825. }
  826. public void testXmlConfiguredProject() {
  827. AjdeInteractionTestbed.VERBOSE = true;
  828. String p = "xmlone";
  829. initialiseProject(p);
  830. configureNonStandardCompileOptions(p, "-showWeaveInfo");// -xmlConfigured");
  831. configureShowWeaveInfoMessages(p, true);
  832. addXmlConfigFile(p, getProjectRelativePath(p, "p/aop.xml").toString());
  833. build(p);
  834. checkWasFullBuild();
  835. List<IMessage> weaveMessages = getWeavingMessages(p);
  836. if (weaveMessages.size() != 1) {
  837. for (Iterator<IMessage> iterator = weaveMessages.iterator(); iterator.hasNext();) {
  838. Object object = iterator.next();
  839. System.out.println(object);
  840. }
  841. fail("Expected just one weave message. The aop.xml should have limited the weaving");
  842. }
  843. }
  844. public void testDeclareParentsInModel() {
  845. String p = "decps";
  846. initialiseProject(p);
  847. build(p);
  848. IProgramElement decp = getModelFor(p).getHierarchy().findElementForHandle("=decps<a{A.java'A`declare parents");
  849. List<String> ps = decp.getParentTypes();
  850. assertNotNull(ps);
  851. assertEquals(2, ps.size());
  852. int count = 0;
  853. for (Iterator<String> iterator = ps.iterator(); iterator.hasNext();) {
  854. String type = iterator.next();
  855. if (type.equals("java.io.Serializable")) {
  856. count++;
  857. }
  858. if (type.equals("a.Goo")) {
  859. count++;
  860. }
  861. }
  862. assertEquals("Should have found the two types in: " + ps, 2, count);
  863. }
  864. public void testConstructorAdvice_pr261380() throws Exception {
  865. String p = "261380";
  866. initialiseProject(p);
  867. build(p);
  868. IRelationshipMap irm = getModelFor(p).getRelationshipMap();
  869. IRelationship ir = irm.get("=261380<test{C.java'X&before").get(0);
  870. List<String> targets = ir.getTargets();
  871. assertEquals(1, targets.size());
  872. System.out.println(targets.get(0));
  873. String handle = (String) targets.get(0);
  874. assertEquals("Expected the handle for the code node inside the constructor decl",
  875. "=261380<test{C.java[C~C?constructor-call(void test.C.<init>())", handle);
  876. }
  877. /*
  878. * A.aj package pack; public aspect A { pointcut p() : call( C.method before() : p() { // line 7 } }
  879. *
  880. * C.java package pack; public class C { public void method1() { method2(); // line 6 } public void method2() { } public void
  881. * method3() { method2(); // line 13 }
  882. *
  883. * }
  884. */
  885. public void testDontLoseAdviceMarkers_pr134471() {
  886. try {
  887. // see pr148027 AsmHierarchyBuilder.shouldAddUsesPointcut=false;
  888. initialiseProject("P4");
  889. build("P4");
  890. Ajc.dumpAJDEStructureModel(getModelFor("P4"), "after full build where advice is applying");
  891. // should be 4 relationship entries
  892. // In inc1 the first advised line is 'commented out'
  893. alter("P4", "inc1");
  894. build("P4");
  895. checkWasntFullBuild();
  896. Ajc.dumpAJDEStructureModel(getModelFor("P4"), "after inc build where first advised line is gone");
  897. // should now be 2 relationship entries
  898. // This will be the line 6 entry in C.java
  899. IProgramElement codeElement = findCode(checkForNode(getModelFor("P4"), "pack", "C", true));
  900. // This will be the line 7 entry in A.java
  901. IProgramElement advice = findAdvice(checkForNode(getModelFor("P4"), "pack", "A", true));
  902. IRelationshipMap asmRelMap = getModelFor("P4").getRelationshipMap();
  903. assertEquals("There should be two relationships in the relationship map", 2, asmRelMap.getEntries().size());
  904. for (Iterator<String> iter = asmRelMap.getEntries().iterator(); iter.hasNext();) {
  905. String sourceOfRelationship = (String) iter.next();
  906. IProgramElement ipe = getModelFor("P4").getHierarchy().findElementForHandle(sourceOfRelationship);
  907. assertNotNull("expected to find IProgramElement with handle " + sourceOfRelationship + " but didn't", ipe);
  908. if (ipe.getKind().equals(IProgramElement.Kind.ADVICE)) {
  909. assertEquals("expected source of relationship to be " + advice.toString() + " but found " + ipe.toString(),
  910. advice, ipe);
  911. } else if (ipe.getKind().equals(IProgramElement.Kind.CODE)) {
  912. assertEquals(
  913. "expected source of relationship to be " + codeElement.toString() + " but found " + ipe.toString(),
  914. codeElement, ipe);
  915. } else {
  916. fail("found unexpected relationship source " + ipe + " with kind " + ipe.getKind()
  917. + " when looking up handle: " + sourceOfRelationship);
  918. }
  919. List<IRelationship> relationships = asmRelMap.get(ipe);
  920. assertNotNull("expected " + ipe.getName() + " to have some " + "relationships", relationships);
  921. for (Iterator<IRelationship> iterator = relationships.iterator(); iterator.hasNext();) {
  922. Relationship rel = (Relationship) iterator.next();
  923. List<String> targets = rel.getTargets();
  924. for (Iterator<String> iterator2 = targets.iterator(); iterator2.hasNext();) {
  925. String t = (String) iterator2.next();
  926. IProgramElement link = getModelFor("P4").getHierarchy().findElementForHandle(t);
  927. if (ipe.getKind().equals(IProgramElement.Kind.ADVICE)) {
  928. assertEquals(
  929. "expected target of relationship to be " + codeElement.toString() + " but found "
  930. + link.toString(), codeElement, link);
  931. } else if (ipe.getKind().equals(IProgramElement.Kind.CODE)) {
  932. assertEquals(
  933. "expected target of relationship to be " + advice.toString() + " but found " + link.toString(),
  934. advice, link);
  935. } else {
  936. fail("found unexpected relationship source " + ipe.getName() + " with kind " + ipe.getKind());
  937. }
  938. }
  939. }
  940. }
  941. } finally {
  942. // see pr148027 AsmHierarchyBuilder.shouldAddUsesPointcut=true;
  943. // configureBuildStructureModel(false);
  944. }
  945. }
  946. public void testPr148285() {
  947. String p = "PR148285_2";
  948. initialiseProject(p); // Single source file A.aj defines A and C
  949. build(p);
  950. checkWasFullBuild();
  951. alter(p, "inc1"); // Second source introduced C.java, defines C
  952. build(p);
  953. checkWasntFullBuild();
  954. List<IMessage> msgs = getErrorMessages(p);
  955. assertEquals("error message should be 'The type C is already defined' ", "The type C is already defined",
  956. ((IMessage) msgs.get(0)).getMessage());
  957. alter("PR148285_2", "inc2"); // type C in A.aj is commented out
  958. build("PR148285_2");
  959. checkWasntFullBuild();
  960. msgs = getErrorMessages(p);
  961. assertTrue("There should be no errors reported:\n" + getErrorMessages(p), msgs.isEmpty());
  962. }
  963. public void testIncrementalAndAnnotations() {
  964. initialiseProject("Annos");
  965. build("Annos");
  966. checkWasFullBuild();
  967. checkCompileWeaveCount("Annos", 4, 4);
  968. AsmManager model = getModelFor("Annos");
  969. assertEquals("Should be 3 relationships ", 3, model.getRelationshipMap().getEntries().size());
  970. alter("Annos", "inc1"); // Comment out the annotation on Parent
  971. build("Annos");
  972. checkWasntFullBuild();
  973. assertEquals("Should be no relationships ", 0, model.getRelationshipMap().getEntries().size());
  974. checkCompileWeaveCount("Annos", 3, 3);
  975. alter("Annos", "inc2"); // Add the annotation back onto Parent
  976. build("Annos");
  977. checkWasntFullBuild();
  978. assertEquals("Should be 3 relationships ", 3, model.getRelationshipMap().getEntries().size());
  979. checkCompileWeaveCount("Annos", 3, 3);
  980. }
  981. // package a.b.c;
  982. //
  983. // public class A {
  984. // }
  985. //
  986. // aspect X {
  987. // B A.foo(C c) { return null; }
  988. // declare parents: A implements java.io.Serializable;
  989. // }
  990. //
  991. // class B {}
  992. // class C {}
  993. public void testITDFQNames_pr252702() {
  994. String p = "itdfq";
  995. AjdeInteractionTestbed.VERBOSE = true;
  996. initialiseProject(p);
  997. build(p);
  998. AsmManager model = getModelFor(p);
  999. dumptree(model.getHierarchy().getRoot(), 0);
  1000. IProgramElement root = model.getHierarchy().getRoot();
  1001. ProgramElement theITD = (ProgramElement) findElementAtLine(root, 7);
  1002. Map<String, Object> m = theITD.kvpairs;
  1003. for (Iterator<String> iterator = m.keySet().iterator(); iterator.hasNext();) {
  1004. String type = iterator.next();
  1005. System.out.println(type + " = " + m.get(type));
  1006. }
  1007. // return type of the ITD
  1008. assertEquals("a.b.c.B", theITD.getCorrespondingType(true));
  1009. List<char[]> ptypes = theITD.getParameterTypes();
  1010. for (Iterator<char[]> iterator = ptypes.iterator(); iterator.hasNext();) {
  1011. char[] object = iterator.next();
  1012. System.out.println("p = " + new String(object));
  1013. }
  1014. ProgramElement decp = (ProgramElement) findElementAtLine(root, 8);
  1015. m = decp.kvpairs;
  1016. for (Iterator<String> iterator = m.keySet().iterator(); iterator.hasNext();) {
  1017. String type = iterator.next();
  1018. System.out.println(type + " = " + m.get(type));
  1019. }
  1020. List<String> l = decp.getParentTypes();
  1021. assertEquals("java.io.Serializable", l.get(0));
  1022. ProgramElement ctorDecp = (ProgramElement) findElementAtLine(root, 16);
  1023. String ctordecphandle = ctorDecp.getHandleIdentifier();
  1024. assertEquals("=itdfq<a.b.c{A.java'XX)B.B_new)QString;", ctordecphandle); // 252702
  1025. // ,
  1026. // comment
  1027. // 7
  1028. }
  1029. public void testBrokenHandles_pr247742() {
  1030. String p = "BrokenHandles";
  1031. initialiseProject(p);
  1032. // alter(p, "inc1");
  1033. build(p);
  1034. // alter(p, "inc2");
  1035. // build(p);
  1036. AsmManager model = getModelFor(p);
  1037. dumptree(model.getHierarchy().getRoot(), 0);
  1038. IProgramElement root = model.getHierarchy().getRoot();
  1039. IProgramElement ipe = findElementAtLine(root, 4);
  1040. assertEquals("=BrokenHandles<p{GetInfo.java'GetInfo`declare warning", ipe.getHandleIdentifier());
  1041. ipe = findElementAtLine(root, 5);
  1042. assertEquals("=BrokenHandles<p{GetInfo.java'GetInfo`declare warning!2", ipe.getHandleIdentifier());
  1043. ipe = findElementAtLine(root, 6);
  1044. assertEquals("=BrokenHandles<p{GetInfo.java'GetInfo`declare parents", ipe.getHandleIdentifier());
  1045. }
  1046. public void testNPEIncremental_pr262218() {
  1047. AjdeInteractionTestbed.VERBOSE = true;
  1048. String p = "pr262218";
  1049. initialiseProject(p);
  1050. build(p);
  1051. checkWasFullBuild();
  1052. alter(p, "inc1");
  1053. build(p);
  1054. checkWasntFullBuild();
  1055. List<String> l = getCompilerErrorMessages(p);
  1056. assertEquals("Unexpected compiler error", 0, l.size());
  1057. }
  1058. public void testDeclareAnnotationNPE_298504() {
  1059. AjdeInteractionTestbed.VERBOSE = true;
  1060. String p = "pr298504";
  1061. initialiseProject(p);
  1062. build(p);
  1063. List<IMessage> l = getErrorMessages(p);
  1064. assertTrue(l.toString().indexOf("ManagedResource cannot be resolved to a type") != -1);
  1065. // checkWasFullBuild();
  1066. alter(p, "inc1");
  1067. build(p);
  1068. // checkWasntFullBuild();
  1069. List<String> compilerErrors = getCompilerErrorMessages(p);
  1070. assertTrue(compilerErrors.toString().indexOf("NullPointerException") == -1);
  1071. l = getErrorMessages(p);
  1072. assertTrue(l.toString().indexOf("ManagedResource cannot be resolved to a type") != -1);
  1073. }
  1074. public void testIncrementalAnnoStyle_pr286341() {
  1075. AjdeInteractionTestbed.VERBOSE = true;
  1076. String base = "pr286341_base";
  1077. initialiseProject(base);
  1078. build(base);
  1079. checkWasFullBuild();
  1080. String p = "pr286341";
  1081. initialiseProject(p);
  1082. configureAspectPath(p, getProjectRelativePath(base, "bin"));
  1083. addClasspathEntry(p, getProjectRelativePath(base, "bin"));
  1084. build(p);
  1085. checkWasFullBuild();
  1086. assertNoErrors(p);
  1087. alter(p, "inc1");
  1088. build(p);
  1089. checkWasntFullBuild();
  1090. assertNoErrors(p);
  1091. }
  1092. public void testImports_pr263487() {
  1093. String p2 = "importProb2";
  1094. initialiseProject(p2);
  1095. build(p2);
  1096. checkWasFullBuild();
  1097. String p = "importProb";
  1098. initialiseProject(p);
  1099. build(p);
  1100. configureAspectPath(p, getProjectRelativePath(p2, "bin"));
  1101. checkWasFullBuild();
  1102. build(p);
  1103. build(p);
  1104. build(p);
  1105. alter(p, "inc1");
  1106. addProjectSourceFileChanged(p, getProjectRelativePath(p, "src/p/Code.java"));
  1107. // addProjectSourceFileChanged(p, getProjectRelativePath(p,
  1108. // "src/q/Asp.java"));
  1109. build(p);
  1110. checkWasntFullBuild();
  1111. List<String> l = getCompilerErrorMessages(p);
  1112. assertEquals("Unexpected compiler error", 0, l.size());
  1113. }
  1114. public void testBuildingBrokenCode_pr263323() {
  1115. AjdeInteractionTestbed.VERBOSE = true;
  1116. String p = "brokenCode";
  1117. initialiseProject(p);
  1118. build(p);
  1119. checkWasFullBuild();
  1120. alter(p, "inc1"); // break the aspect
  1121. build(p);
  1122. checkWasntFullBuild();
  1123. alter(p, "inc2"); // whitespace change on affected file
  1124. build(p);
  1125. checkWasntFullBuild();
  1126. List<String> l = getCompilerErrorMessages(p);
  1127. assertEquals("Unexpected compiler error", 0, l.size());
  1128. }
  1129. /*
  1130. * public void testNPEGenericCtor_pr260944() { AjdeInteractionTestbed.VERBOSE = true; String p = "pr260944";
  1131. * initialiseProject(p); build(p); checkWasFullBuild(); alter(p, "inc1"); build(p); checkWasntFullBuild(); List l =
  1132. * getCompilerErrorMessages(p); assertEquals("Unexpected compiler error", 0, l.size()); }
  1133. */
  1134. public void testItdProb() {
  1135. AjdeInteractionTestbed.VERBOSE = true;
  1136. String p = "itdprob";
  1137. initialiseProject(p);
  1138. build(p);
  1139. checkWasFullBuild();
  1140. alter(p, "inc1");
  1141. build(p);
  1142. checkWasntFullBuild();
  1143. List<String> l = getCompilerErrorMessages(p);
  1144. assertEquals("Unexpected compiler error", 0, l.size());
  1145. }
  1146. /*
  1147. * public void testGenericITD_pr262257() throws IOException { String p = "pr262257"; initialiseProject(p); build(p);
  1148. * checkWasFullBuild();
  1149. *
  1150. * dumptree(getModelFor(p).getHierarchy().getRoot(), 0); PrintWriter pw = new PrintWriter(System.out);
  1151. * getModelFor(p).dumprels(pw); pw.flush(); }
  1152. */
  1153. public void testAnnotations_pr262154() {
  1154. String p = "pr262154";
  1155. initialiseProject(p);
  1156. build(p);
  1157. checkWasFullBuild();
  1158. alter(p, "inc1");
  1159. build(p);
  1160. List<String> l = getCompilerErrorMessages(p);
  1161. assertEquals("Unexpected compiler error", 0, l.size());
  1162. }
  1163. public void testAnnotations_pr255555() {
  1164. String p = "pr255555";
  1165. initialiseProject(p);
  1166. build(p);
  1167. checkCompileWeaveCount(p, 2, 1);
  1168. }
  1169. public void testSpacewarHandles() {
  1170. // String p = "SpaceWar";
  1171. String p = "Simpler";
  1172. initialiseProject(p);
  1173. build(p);
  1174. dumptree(getModelFor(p).getHierarchy().getRoot(), 0);
  1175. // incomplete
  1176. }
  1177. /**
  1178. * Test what is in the model for package declarations and import statements. Package Declaration nodes are new in AspectJ 1.6.4.
  1179. * Import statements are contained with an 'import references' node.
  1180. */
  1181. public void testImportHandles() {
  1182. String p = "Imports";
  1183. initialiseProject(p);
  1184. configureNonStandardCompileOptions(p, "-Xset:minimalModel=false");
  1185. build(p);
  1186. IProgramElement root = getModelFor(p).getHierarchy().getRoot();
  1187. // Looking for 'package p.q'
  1188. IProgramElement ipe = findFile(root, "Example.aj");// findElementAtLine(root, 1);
  1189. ipe = ipe.getChildren().get(0); // package decl is first entry in the type
  1190. assertEquals(IProgramElement.Kind.PACKAGE_DECLARATION, ipe.getKind());
  1191. assertEquals("package p.q;", ipe.getSourceSignature());
  1192. assertEquals("=Imports<p.q*Example.aj%p.q", ipe.getHandleIdentifier());
  1193. assertEquals(ipe.getSourceLocation().getOffset(), 8); // "package p.q" - location of p.q
  1194. // Looking for import containing containing string and integer
  1195. ipe = findElementAtLine(root, 3); // first import
  1196. ipe = ipe.getParent(); // imports container
  1197. assertEquals("=Imports<p.q*Example.aj#", ipe.getHandleIdentifier());
  1198. }
  1199. public void testAdvisingCallJoinpointsInITDS_pr253067() {
  1200. String p = "pr253067";
  1201. initialiseProject(p);
  1202. build(p);
  1203. // Check for a code node at line 5 - if there is one then we created it
  1204. // correctly when building
  1205. // the advice relationship
  1206. IProgramElement root = getModelFor(p).getHierarchy().getRoot();
  1207. IProgramElement code = findElementAtLine(root, 5);
  1208. assertEquals("=pr253067<aa*AdvisesC.aj'AdvisesC)C.nothing?method-call(int aa.C.nothing())", code.getHandleIdentifier());
  1209. // dumptree(getModelFor(p).getHierarchy().getRoot(), 0);
  1210. // Ajc.dumpAJDEStructureModel(getModelFor("pr253067"),
  1211. // "after inc build where first advised line is gone");
  1212. }
  1213. public void testHandles_DeclareAnno_pr249216_c9() {
  1214. String p = "pr249216";
  1215. initialiseProject(p);
  1216. build(p);
  1217. IProgramElement root = getModelFor(p).getHierarchy().getRoot();
  1218. IProgramElement code = findElementAtLine(root, 4);
  1219. // the @ should be escapified
  1220. assertEquals("=pr249216<{Deca.java'X`declare \\@type", code.getHandleIdentifier());
  1221. // dumptree(getModelFor(p).getHierarchy().getRoot(), 0);
  1222. // Ajc.dumpAJDEStructureModel(getModelFor(p),
  1223. // "after inc build where first advised line is gone");
  1224. }
  1225. public void testNullDelegateBrokenCode_pr251940() {
  1226. String p = "pr251940";
  1227. initialiseProject(p);
  1228. build(p);
  1229. checkForError(p, "The type F must implement the inherited");
  1230. }
  1231. public void testBeanExample() throws Exception {
  1232. String p = "BeanExample";
  1233. initialiseProject(p);
  1234. build(p);
  1235. dumptree(getModelFor(p).getHierarchy().getRoot(), 0);
  1236. PrintWriter pw = new PrintWriter(System.out);
  1237. getModelFor(p).dumprels(pw);
  1238. pw.flush();
  1239. // incomplete
  1240. }
  1241. // private void checkIfContainsFile(Set s, String filename, boolean shouldBeFound) {
  1242. // StringBuffer sb = new StringBuffer("Set of files\n");
  1243. // for (Iterator iterator = s.iterator(); iterator.hasNext();) {
  1244. // Object object = iterator.next();
  1245. // sb.append(object).append("\n");
  1246. // }
  1247. // for (Iterator iterator = s.iterator(); iterator.hasNext();) {
  1248. // File fname = (File) iterator.next();
  1249. // if (fname.getName().endsWith(filename)) {
  1250. // if (!shouldBeFound) {
  1251. // System.out.println(sb.toString());
  1252. // fail("Unexpectedly found file " + filename);
  1253. // } else {
  1254. // return;
  1255. // }
  1256. // }
  1257. // }
  1258. // if (shouldBeFound) {
  1259. // System.out.println(sb.toString());
  1260. // fail("Did not find filename " + filename);
  1261. // }
  1262. // }
  1263. // /**
  1264. // * Checking return values of the AsmManager API calls that can be invoked
  1265. // post incremental build that tell the caller which
  1266. // * files had their relationships altered. As well as the affected (woven)
  1267. // files, it is possible to query the aspects that wove
  1268. // * those files.
  1269. // */
  1270. // public void testChangesOnBuild() throws Exception {
  1271. // String p = "ChangesOnBuild";
  1272. // initialiseProject(p);
  1273. // build(p);
  1274. // // Not incremental
  1275. // checkIfContainsFile(AsmManager.getDefault().getModelChangesOnLastBuild(),
  1276. // "A.java", false);
  1277. // alter(p, "inc1");
  1278. // build(p);
  1279. // // Incremental
  1280. // checkIfContainsFile(AsmManager.getDefault().getModelChangesOnLastBuild(),
  1281. // "A.java", true);
  1282. // checkIfContainsFile(AsmManager.getDefault().
  1283. // getAspectsWeavingFilesOnLastBuild(), "X.java", true);
  1284. // checkIfContainsFile(AsmManager.getDefault().
  1285. // getAspectsWeavingFilesOnLastBuild(), "Y.java", false);
  1286. // }
  1287. public void testITDIncremental_pr192877() {
  1288. String p = "PR192877";
  1289. initialiseProject(p);
  1290. build(p);
  1291. checkWasFullBuild();
  1292. alter(p, "inc1");
  1293. build(p);
  1294. checkWasntFullBuild();
  1295. }
  1296. public void testIncrementalBuildsWithItds_pr259528() {
  1297. String p = "pr259528";
  1298. AjdeInteractionTestbed.VERBOSE = true;
  1299. initialiseProject(p);
  1300. build(p);
  1301. checkWasFullBuild();
  1302. alter(p, "inc1");
  1303. build(p);
  1304. checkWasntFullBuild();
  1305. }
  1306. public void testAdviceHandlesAreJDTCompatible() {
  1307. String p = "AdviceHandles";
  1308. initialiseProject(p);
  1309. addSourceFolderForSourceFile(p, getProjectRelativePath(p, "src/Handles.aj"), "src");
  1310. build(p);
  1311. IProgramElement root = getModelFor(p).getHierarchy().getRoot();
  1312. IProgramElement typeDecl = findElementAtLine(root, 4);
  1313. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles", typeDecl.getHandleIdentifier());
  1314. IProgramElement advice1 = findElementAtLine(root, 7);
  1315. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles&before", advice1.getHandleIdentifier());
  1316. IProgramElement advice2 = findElementAtLine(root, 11);
  1317. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles&before!2", advice2.getHandleIdentifier());
  1318. IProgramElement advice3 = findElementAtLine(root, 15);
  1319. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles&before&I", advice3.getHandleIdentifier());
  1320. IProgramElement advice4 = findElementAtLine(root, 20);
  1321. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles&before&I!2", advice4.getHandleIdentifier());
  1322. IProgramElement advice5 = findElementAtLine(root, 25);
  1323. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles&after", advice5.getHandleIdentifier());
  1324. IProgramElement advice6 = findElementAtLine(root, 30);
  1325. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles&afterReturning", advice6.getHandleIdentifier());
  1326. IProgramElement advice7 = findElementAtLine(root, 35);
  1327. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles&afterThrowing", advice7.getHandleIdentifier());
  1328. IProgramElement advice8 = findElementAtLine(root, 40);
  1329. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles&afterThrowing&I", advice8.getHandleIdentifier());
  1330. IProgramElement namedInnerClass = findElementAtLine(root, 46);
  1331. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles~x[NamedClass", namedInnerClass.getHandleIdentifier());
  1332. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles~foo[", findElementAtLine(root, 55).getHandleIdentifier());
  1333. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles~foo[!2", findElementAtLine(root, 56).getHandleIdentifier());
  1334. // From 247742: comment 3: two anon class declarations
  1335. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles~b~QString;[", findElementAtLine(root, 62)
  1336. .getHandleIdentifier());
  1337. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles~b~QString;[!2", findElementAtLine(root, 63)
  1338. .getHandleIdentifier());
  1339. // From 247742: comment 6: two diff anon class declarations
  1340. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles~c~QString;[", findElementAtLine(root, 66)
  1341. .getHandleIdentifier());
  1342. assertEquals("=AdviceHandles/src<spacewar*Handles.aj'Handles~c~QString;[!2", findElementAtLine(root, 67)
  1343. .getHandleIdentifier());
  1344. // // From 247742: comment 4
  1345. // assertEquals(
  1346. // "=AdviceHandles/src<spacewar*Handles.aj}Foo&afterReturning&QString;",
  1347. // findElementAtLine(root,
  1348. // 72).getHandleIdentifier());
  1349. // assertEquals(
  1350. // "=AdviceHandles/src<spacewar*Handles.aj}Foo&afterReturning&QString;!2"
  1351. // , findElementAtLine(root,
  1352. // 73).getHandleIdentifier());
  1353. }
  1354. // Testing code handles - should they included positional information? seems
  1355. // to be what AJDT wants but we
  1356. // only have the declaration start position in the programelement
  1357. // public void testHandlesForCodeElements() {
  1358. // String p = "CodeHandles";
  1359. // initialiseProject(p);
  1360. // addSourceFolderForSourceFile(p, getProjectRelativePath(p,
  1361. // "src/Handles.aj"), "src");
  1362. // build(p);
  1363. // IProgramElement root = AsmManager.getDefault().getHierarchy().getRoot();
  1364. // IProgramElement typeDecl = findElementAtLine(root, 3);
  1365. // assertEquals("=CodeHandles/src<spacewar*Handles.aj[C",
  1366. // typeDecl.getHandleIdentifier());
  1367. //
  1368. // IProgramElement code = findElementAtLine(root, 6);
  1369. // assertEquals(
  1370. // "=CodeHandles/src<spacewar*Handles.aj[C~m?method-call(void spacewar.C.foo(int))"
  1371. // , code.getHandleIdentifier());
  1372. // code = findElementAtLine(root, 7);
  1373. // assertEquals(
  1374. // "=CodeHandles/src<spacewar*Handles.aj[C~m?method-call(void spacewar.C.foo(int))!2"
  1375. // , code.getHandleIdentifier());
  1376. //
  1377. // }
  1378. private IProgramElement findFile(IProgramElement whereToLook, String filesubstring) {
  1379. if (whereToLook.getSourceLocation() != null && whereToLook.getKind().isSourceFile()
  1380. && whereToLook.getSourceLocation().getSourceFile().toString().indexOf(filesubstring) != -1) {
  1381. return whereToLook;
  1382. }
  1383. for (IProgramElement element : whereToLook.getChildren()) {
  1384. Kind k = element.getKind();
  1385. ISourceLocation sloc = element.getSourceLocation();
  1386. if (sloc != null && k.isSourceFile() && sloc.getSourceFile().toString().indexOf(filesubstring) != -1) {
  1387. return element;
  1388. }
  1389. if (k.isSourceFile()) {
  1390. continue; // no need to look further down
  1391. }
  1392. IProgramElement gotSomething = findFile(element, filesubstring);
  1393. if (gotSomething != null) {
  1394. return gotSomething;
  1395. }
  1396. }
  1397. return null;
  1398. }
  1399. private IProgramElement findElementAtLine(IProgramElement whereToLook, int line) {
  1400. if (whereToLook == null) {
  1401. return null;
  1402. }
  1403. if (whereToLook.getSourceLocation() != null && whereToLook.getSourceLocation().getLine() == line) {
  1404. return whereToLook;
  1405. }
  1406. for (IProgramElement object : whereToLook.getChildren()) {
  1407. if (object.getSourceLocation() != null && object.getSourceLocation().getLine() == line) {
  1408. return object;
  1409. }
  1410. IProgramElement gotSomething = findElementAtLine(object, line);
  1411. if (gotSomething != null) {
  1412. return gotSomething;
  1413. }
  1414. }
  1415. return null;
  1416. }
  1417. public void testModelWithMultipleSourceFolders() {
  1418. initialiseProject("MultiSource");
  1419. // File sourceFolderOne = getProjectRelativePath("MultiSource", "src1");
  1420. // File sourceFolderTwo = getProjectRelativePath("MultiSource", "src2");
  1421. // File sourceFolderThree = getProjectRelativePath("MultiSource",
  1422. // "src3");
  1423. // src1 source folder slashed as per 264563
  1424. addSourceFolderForSourceFile("MultiSource", getProjectRelativePath("MultiSource", "src1/CodeOne.java"), "src1/");
  1425. addSourceFolderForSourceFile("MultiSource", getProjectRelativePath("MultiSource", "src2/CodeTwo.java"), "src2");
  1426. addSourceFolderForSourceFile("MultiSource", getProjectRelativePath("MultiSource", "src3/pkg/CodeThree.java"), "src3");
  1427. build("MultiSource");
  1428. IProgramElement srcOne = getModelFor("MultiSource").getHierarchy().findElementForHandle("=MultiSource/src1");
  1429. IProgramElement CodeOneClass = getModelFor("MultiSource").getHierarchy().findElementForHandle(
  1430. "=MultiSource/src1{CodeOne.java[CodeOne");
  1431. IProgramElement srcTwoPackage = getModelFor("MultiSource").getHierarchy().findElementForHandle("=MultiSource/src2<pkg");
  1432. IProgramElement srcThreePackage = getModelFor("MultiSource").getHierarchy().findElementForHandle("=MultiSource/src3<pkg");
  1433. assertNotNull(srcOne);
  1434. assertNotNull(CodeOneClass);
  1435. assertNotNull(srcTwoPackage);
  1436. assertNotNull(srcThreePackage);
  1437. if (srcTwoPackage.equals(srcThreePackage)) {
  1438. throw new RuntimeException(
  1439. "Should not have found these package nodes to be the same, they are in different source folders");
  1440. }
  1441. // dumptree(AsmManager.getDefault().getHierarchy().getRoot(), 0);
  1442. }
  1443. // Now the source folders are more complex 'src/java/main' and
  1444. // 'src/java/tests'
  1445. public void testModelWithMultipleSourceFolders2() {
  1446. initialiseProject("MultiSource");
  1447. // File sourceFolderOne = getProjectRelativePath("MultiSource",
  1448. // "src/java/main");
  1449. // File sourceFolderTwo = getProjectRelativePath("MultiSource", "src2");
  1450. // File sourceFolderThree = getProjectRelativePath("MultiSource",
  1451. // "src3");
  1452. addSourceFolderForSourceFile("MultiSource", getProjectRelativePath("MultiSource", "src1/CodeOne.java"), "src/java/main");
  1453. addSourceFolderForSourceFile("MultiSource", getProjectRelativePath("MultiSource", "src2/CodeTwo.java"), "src/java/main");
  1454. addSourceFolderForSourceFile("MultiSource", getProjectRelativePath("MultiSource", "src3/pkg/CodeThree.java"),
  1455. "src/java/tests");
  1456. build("MultiSource");
  1457. IProgramElement srcOne = getModelFor("MultiSource").getHierarchy().findElementForHandleOrCreate(
  1458. "=MultiSource/src\\/java\\/main", false);
  1459. IProgramElement CodeOneClass = getModelFor("MultiSource").getHierarchy().findElementForHandle(
  1460. "=MultiSource/src\\/java\\/main{CodeOne.java[CodeOne");
  1461. IProgramElement srcTwoPackage = getModelFor("MultiSource").getHierarchy().findElementForHandle(
  1462. "=MultiSource/src\\/java\\/tests<pkg");
  1463. IProgramElement srcThreePackage = getModelFor("MultiSource").getHierarchy().findElementForHandle(
  1464. "=MultiSource/src\\/java\\/testssrc3<pkg");
  1465. assertNotNull(srcOne);
  1466. assertNotNull(CodeOneClass);
  1467. assertNotNull(srcTwoPackage);
  1468. assertNotNull(srcThreePackage);
  1469. if (srcTwoPackage.equals(srcThreePackage)) {
  1470. throw new RuntimeException(
  1471. "Should not have found these package nodes to be the same, they are in different source folders");
  1472. }
  1473. // dumptree(AsmManager.getDefault().getHierarchy().getRoot(), 0);
  1474. }
  1475. public void testIncrementalItdsWithMultipleAspects_pr173729() {
  1476. initialiseProject("PR173729");
  1477. build("PR173729");
  1478. checkWasFullBuild();
  1479. alter("PR173729", "inc1");
  1480. build("PR173729");
  1481. checkWasntFullBuild();
  1482. }
  1483. // Compile a single simple project
  1484. public void testTheBasics() {
  1485. initialiseProject("P1");
  1486. build("P1"); // This first build will be batch
  1487. build("P1");
  1488. checkWasntFullBuild();
  1489. checkCompileWeaveCount("P1", 0, 0);
  1490. }
  1491. // source code doesnt matter, we are checking invalid path handling
  1492. public void testInvalidAspectpath_pr121395() {
  1493. initialiseProject("P1");
  1494. File f = new File("foo.jar");
  1495. Set<File> s = new HashSet<File>();
  1496. s.add(f);
  1497. configureAspectPath("P1", s);
  1498. build("P1"); // This first build will be batch
  1499. checkForError("P1", "invalid aspectpath entry");
  1500. }
  1501. // incorrect use of '?' when it should be '*'
  1502. public void testAspectPath_pr242797_c46() {
  1503. String bug = "pr242797_1";
  1504. String bug2 = "pr242797_2";
  1505. initialiseProject(bug);
  1506. initialiseProject(bug2);
  1507. configureAspectPath(bug2, getProjectRelativePath(bug, "bin"));
  1508. build(bug);
  1509. build(bug2);
  1510. }
  1511. public void testAspectPath_pr247742_c16() throws IOException {
  1512. String bug = "AspectPathOne";
  1513. String bug2 = "AspectPathTwo";
  1514. addSourceFolderForSourceFile(bug2, getProjectRelativePath(bug2, "src/C.java"), "src");
  1515. initialiseProject(bug);
  1516. initialiseProject(bug2);
  1517. configureAspectPath(bug2, getProjectRelativePath(bug, "bin"));
  1518. build(bug);
  1519. build(bug2);
  1520. dumptree(getModelFor(bug2).getHierarchy().getRoot(), 0);
  1521. PrintWriter pw = new PrintWriter(System.out);
  1522. getModelFor(bug2).dumprels(pw);
  1523. pw.flush();
  1524. IProgramElement root = getModelFor(bug2).getHierarchy().getRoot();
  1525. assertEquals("=AspectPathTwo/binaries<pkg(Asp.class'Asp&before", findElementAtLine(root, 5).getHandleIdentifier());
  1526. assertEquals("=AspectPathTwo/binaries<(Asp2.class'Asp2&before", findElementAtLine(root, 16).getHandleIdentifier());
  1527. }
  1528. public void testAspectPath_pr274558() throws Exception {
  1529. String base = "bug274558depending";
  1530. String depending = "bug274558base";
  1531. // addSourceFolderForSourceFile(bug2, getProjectRelativePath(bug2, "src/C.java"), "src");
  1532. initialiseProject(base);
  1533. initialiseProject(depending);
  1534. configureAspectPath(depending, getProjectRelativePath(base, "bin"));
  1535. build(base);
  1536. build(depending);
  1537. printModel(depending);
  1538. IProgramElement root = getModelFor(depending).getHierarchy().getRoot();
  1539. assertEquals("=bug274558base/binaries<r(DeclaresITD.class'DeclaresITD,InterfaceForITD.x", findElementAtLine(root, 5)
  1540. .getHandleIdentifier());
  1541. // assertEquals("=AspectPathTwo/binaries<(Asp2.class}Asp2&before", findElementAtLine(root, 16).getHandleIdentifier());
  1542. }
  1543. public void testAspectPath_pr265693() throws IOException {
  1544. String bug = "AspectPath3";
  1545. String bug2 = "AspectPath4";
  1546. addSourceFolderForSourceFile(bug2, getProjectRelativePath(bug2, "src/C.java"), "src");
  1547. initialiseProject(bug);
  1548. initialiseProject(bug2);
  1549. configureAspectPath(bug2, getProjectRelativePath(bug, "bin"));
  1550. build(bug);
  1551. build(bug2);
  1552. // dumptree(getModelFor(bug2).getHierarchy().getRoot(), 0);
  1553. // PrintWriter pw = new PrintWriter(System.out);
  1554. // getModelFor(bug2).dumprels(pw);
  1555. // pw.flush();
  1556. IProgramElement root = getModelFor(bug2).getHierarchy().getRoot();
  1557. IProgramElement binariesNode = getChild(root, "binaries");
  1558. assertNotNull(binariesNode);
  1559. IProgramElement packageNode = binariesNode.getChildren().get(0);
  1560. assertEquals("a.b.c", packageNode.getName());
  1561. IProgramElement fileNode = packageNode.getChildren().get(0);
  1562. assertEquals(IProgramElement.Kind.FILE, fileNode.getKind());
  1563. }
  1564. private IProgramElement getChild(IProgramElement start, String name) {
  1565. if (start.getName().equals(name)) {
  1566. return start;
  1567. }
  1568. List<IProgramElement> kids = start.getChildren();
  1569. if (kids != null) {
  1570. for (int i = 0; i < kids.size(); i++) {
  1571. IProgramElement found = getChild((IProgramElement) kids.get(i), name);
  1572. if (found != null) {
  1573. return found;
  1574. }
  1575. }
  1576. }
  1577. return null;
  1578. }
  1579. public void testHandleQualification_pr265993() throws IOException {
  1580. String p = "pr265993";
  1581. initialiseProject(p);
  1582. configureNonStandardCompileOptions(p, "-Xset:minimalModel=false");
  1583. build(p);
  1584. IProgramElement root = getModelFor(p).getHierarchy().getRoot();
  1585. // dumptree(getModelFor(p).getHierarchy().getRoot(), 0);
  1586. // PrintWriter pw = new PrintWriter(System.out);
  1587. // getModelFor(p).dumprels(pw);
  1588. // pw.flush();
  1589. assertEquals("=pr265993<{A.java[A~m~QString;~Qjava.lang.String;", findElementAtLine(root, 3).getHandleIdentifier());
  1590. assertEquals("=pr265993<{A.java[A~m2~QList;", findElementAtLine(root, 5).getHandleIdentifier());
  1591. assertEquals("=pr265993<{A.java[A~m3~Qjava.util.ArrayList;", findElementAtLine(root, 6).getHandleIdentifier());
  1592. assertEquals("=pr265993<{A.java[A~m4~QMap\\<Qjava.lang.String;QList;>;", findElementAtLine(root, 8).getHandleIdentifier());
  1593. assertEquals("=pr265993<{A.java[A~m5~Qjava.util.Map\\<Qjava.lang.String;QList;>;", findElementAtLine(root, 9)
  1594. .getHandleIdentifier());
  1595. assertEquals("=pr265993<{A.java[A~m6~QMap\\<\\[IQList;>;", findElementAtLine(root, 10).getHandleIdentifier());
  1596. assertEquals("=pr265993<{A.java[A~m7~\\[I", findElementAtLine(root, 11).getHandleIdentifier());
  1597. assertEquals("=pr265993<{A.java[A~m8~\\[Qjava.lang.String;", findElementAtLine(root, 12).getHandleIdentifier());
  1598. assertEquals("=pr265993<{A.java[A~m9~\\[QString;", findElementAtLine(root, 13).getHandleIdentifier());
  1599. assertEquals("=pr265993<{A.java[A~m10~\\[\\[QList\\<QString;>;", findElementAtLine(root, 14).getHandleIdentifier());
  1600. assertEquals("=pr265993<{A.java[A~m11~Qjava.util.List\\<QT;>;", findElementAtLine(root, 15).getHandleIdentifier());
  1601. assertEquals("=pr265993<{A.java[A~m12~\\[QT;", findElementAtLine(root, 16).getHandleIdentifier());
  1602. assertEquals("=pr265993<{A.java[A~m13~QClass\\<QT;>;~QObject;~QString;", findElementAtLine(root, 17).getHandleIdentifier());
  1603. }
  1604. public void testHandlesForAnnotationStyle_pr269286() throws IOException {
  1605. String p = "pr269286";
  1606. initialiseProject(p);
  1607. build(p);
  1608. IProgramElement root = getModelFor(p).getHierarchy().getRoot();
  1609. dumptree(getModelFor(p).getHierarchy().getRoot(), 0);
  1610. PrintWriter pw = new PrintWriter(System.out);
  1611. getModelFor(p).dumprels(pw);
  1612. pw.flush();
  1613. assertEquals("=pr269286<{Logger.java[Logger", findElementAtLine(root, 4).getHandleIdentifier()); // type
  1614. assertEquals("=pr269286<{Logger.java[Logger~boo", findElementAtLine(root, 7).getHandleIdentifier()); // before
  1615. assertEquals("=pr269286<{Logger.java[Logger~aoo", findElementAtLine(root, 11).getHandleIdentifier()); // after
  1616. assertEquals("=pr269286<{Logger.java[Logger~aroo", findElementAtLine(root, 15).getHandleIdentifier()); // around
  1617. // pointcuts are not fixed - seems to buggy handling of them internally
  1618. assertEquals("=pr269286<{Logger.java[Logger\"ooo", findElementAtLine(root, 20).getHandleIdentifier());
  1619. // DeclareWarning
  1620. assertEquals("=pr269286<{Logger.java[Logger^message", findElementAtLine(root, 24).getHandleIdentifier());
  1621. // DeclareError
  1622. assertEquals("=pr269286<{Logger.java[Logger^message2", findElementAtLine(root, 27).getHandleIdentifier());
  1623. }
  1624. public void testHandleCountersForAdvice() throws IOException {
  1625. String p = "prx";
  1626. initialiseProject(p);
  1627. build(p);
  1628. // System.out.println("Handle Counters For Advice Output");
  1629. IProgramElement root = getModelFor(p).getHierarchy().getRoot();
  1630. // dumptree(getModelFor(p).getHierarchy().getRoot(), 0);
  1631. // PrintWriter pw = new PrintWriter(System.out);
  1632. // getModelFor(p).dumprels(pw);
  1633. // pw.flush();
  1634. IProgramElement ff = findFile(root, "ProcessAspect.aj");
  1635. assertEquals("=prx<com.kronos.aspects*ProcessAspect.aj'ProcessAspect&after&QMyProcessor;", findElementAtLine(root, 22)
  1636. .getHandleIdentifier());
  1637. assertEquals("=prx<com.kronos.aspects*ProcessAspect.aj'ProcessAspect&after&QMyProcessor;!2", findElementAtLine(root, 68)
  1638. .getHandleIdentifier());
  1639. }
  1640. /**
  1641. * A change is made to an aspect on the aspectpath (staticinitialization() advice is added) for another project.
  1642. * <p>
  1643. * Managing the aspectpath is hard. We want to do a minimal build of this project which means recognizing what kind of changes
  1644. * have occurred on the aspectpath. Was it a regular class or an aspect? Was it a structural change to that aspect?
  1645. * <p>
  1646. * The filenames for .class files created that contain aspects is stored in the AjState.aspectClassFiles field. When a change is
  1647. * detected we can see who was managing the location where the change occurred and ask them if the .class file contained an
  1648. * aspect. Right now a change detected like this will cause a full build. We might improve the detection logic here but it isn't
  1649. * trivial:
  1650. * <ul>
  1651. * <li>Around advice is inlined. Changing the body of an around advice would not normally be thought of as a structural change
  1652. * (as it does not change the signature of the class) but due to inlining it is a change we would need to pay attention to as it
  1653. * will affect types previously woven with that advice.
  1654. * <li>Annotation style aspects include pointcuts in strings. Changes to these are considered non-structural but clearly they do
  1655. * affect what might be woven.
  1656. * </ul>
  1657. */
  1658. public void testAspectPath_pr249212_c1() throws IOException {
  1659. String p1 = "AspectPathOne";
  1660. String p2 = "AspectPathTwo";
  1661. addSourceFolderForSourceFile(p2, getProjectRelativePath(p2, "src/C.java"), "src");
  1662. initialiseProject(p1);
  1663. initialiseProject(p2);
  1664. configureAspectPath(p2, getProjectRelativePath(p1, "bin"));
  1665. build(p1);
  1666. build(p2);
  1667. alter(p1, "inc1");
  1668. build(p1); // Modify the aspect Asp2 to include staticinitialization()
  1669. // advice
  1670. checkWasFullBuild();
  1671. Set<File> s = getModelFor(p1).getModelChangesOnLastBuild();
  1672. assertTrue("Should be empty as was full build:" + s, s.isEmpty());
  1673. // prod the build of the second project with some extra info to tell it
  1674. // more precisely about the change:
  1675. addClasspathEntryChanged(p2, getProjectRelativePath(p1, "bin").toString());
  1676. configureAspectPath(p2, getProjectRelativePath(p1, "bin"));
  1677. build(p2);
  1678. checkWasFullBuild();
  1679. // dumptree(AsmManager.getDefault().getHierarchy().getRoot(), 0);
  1680. // PrintWriter pw = new PrintWriter(System.out);
  1681. // AsmManager.getDefault().dumprels(pw);
  1682. // pw.flush();
  1683. // Not incremental
  1684. assertTrue("Should be empty as was full build:" + s, s.isEmpty());
  1685. // Set s = AsmManager.getDefault().getModelChangesOnLastBuild();
  1686. // checkIfContainsFile(AsmManager.getDefault().getModelChangesOnLastBuild
  1687. // (), "C.java", true);
  1688. }
  1689. // public void testAspectPath_pr242797_c41() {
  1690. // String bug = "pr242797_3";
  1691. // String bug2 = "pr242797_4";
  1692. // initialiseProject(bug);
  1693. // initialiseProject(bug2);
  1694. // configureAspectPath(bug2, getProjectRelativePath(bug, "bin"));
  1695. // build(bug);
  1696. // build(bug2);
  1697. // }
  1698. /**
  1699. * Build a project containing a resource - then mark the resource readOnly(), then do an inc-compile, it will report an error
  1700. * about write access to the resource in the output folder being denied
  1701. */
  1702. /*
  1703. * public void testProblemCopyingResources_pr138171() { initialiseProject("PR138171");
  1704. *
  1705. * File f=getProjectRelativePath("PR138171","res.txt"); Map m = new HashMap(); m.put("res.txt",f);
  1706. * AjdeInteractionTestbed.MyProjectPropertiesAdapter .getInstance().setSourcePathResources(m); build("PR138171"); File f2 =
  1707. * getProjectOutputRelativePath("PR138171","res.txt"); boolean successful = f2.setReadOnly();
  1708. *
  1709. * alter("PR138171","inc1"); AjdeInteractionTestbed.MyProjectPropertiesAdapter .getInstance().setSourcePathResources(m);
  1710. * build("PR138171"); List msgs = MyTaskListManager.getErrorMessages(); assertTrue("there should be one message but there are "
  1711. * +(msgs==null?0:msgs.size())+":\n"+msgs,msgs!=null && msgs.size()==1); IMessage msg = (IMessage)msgs.get(0); String exp =
  1712. * "unable to copy resource to output folder: 'res.txt'"; assertTrue("Expected message to include this text ["
  1713. * +exp+"] but it does not: "+msg,msg.toString().indexOf(exp)!=-1); }
  1714. */
  1715. // Make simple changes to a project, adding a class
  1716. public void testSimpleChanges() {
  1717. initialiseProject("P1");
  1718. build("P1"); // This first build will be batch
  1719. alter("P1", "inc1"); // adds a single class
  1720. build("P1");
  1721. checkCompileWeaveCount("P1", 1, -1);
  1722. build("P1");
  1723. checkCompileWeaveCount("P1", 0, -1);
  1724. }
  1725. // Make simple changes to a project, adding a class and an aspect
  1726. public void testAddingAnAspect() {
  1727. initialiseProject("P1");
  1728. build("P1"); // build 1, weave 1
  1729. alter("P1", "inc1"); // adds a class
  1730. alter("P1", "inc2"); // adds an aspect
  1731. build("P1"); // build 1,
  1732. long timeTakenForFullBuildAndWeave = getTimeTakenForBuild("P1");
  1733. checkWasFullBuild(); // it *will* be a full build under the new
  1734. // "back-to-the-source strategy
  1735. checkCompileWeaveCount("P1", 5, 3); // we compile X and A (the delta)
  1736. // find out that
  1737. // an aspect has changed, go back to the source
  1738. // and compile X,A,C, then weave the all.
  1739. build("P1");
  1740. long timeTakenForSimpleIncBuild = getTimeTakenForBuild("P1");
  1741. // I don't think this test will have timing issues as the times should
  1742. // be *RADICALLY* different
  1743. // On my config, first build time is 2093ms and the second is 30ms
  1744. assertTrue("Should not take longer for the trivial incremental build! first=" + timeTakenForFullBuildAndWeave
  1745. + "ms second=" + timeTakenForSimpleIncBuild + "ms", timeTakenForSimpleIncBuild < timeTakenForFullBuildAndWeave);
  1746. }
  1747. public void testBuildingTwoProjectsInTurns() {
  1748. initialiseProject("P1");
  1749. initialiseProject("P2");
  1750. build("P1");
  1751. build("P2");
  1752. build("P1");
  1753. checkWasntFullBuild();
  1754. build("P2");
  1755. checkWasntFullBuild();
  1756. }
  1757. public void testBuildingBrokenCode_pr240360() {
  1758. initialiseProject("pr240360");
  1759. // configureNonStandardCompileOptions("pr240360","-proceedOnError");
  1760. build("pr240360");
  1761. checkWasFullBuild();
  1762. checkCompileWeaveCount("pr240360", 5, 4);
  1763. assertTrue("There should be an error:\n" + getErrorMessages("pr240360"), !getErrorMessages("pr240360").isEmpty());
  1764. Set s = getModelFor("pr240360").getRelationshipMap().getEntries();
  1765. int relmapLength = s.size();
  1766. // Delete the erroneous type
  1767. String f = getWorkingDir().getAbsolutePath() + File.separatorChar + "pr240360" + File.separatorChar + "src"
  1768. + File.separatorChar + "test" + File.separatorChar + "Error.java";
  1769. (new File(f)).delete();
  1770. build("pr240360");
  1771. checkWasntFullBuild();
  1772. checkCompileWeaveCount("pr240360", 0, 0);
  1773. assertEquals(relmapLength, getModelFor("pr240360").getRelationshipMap().getEntries().size());
  1774. // Readd the erroneous type
  1775. alter("pr240360", "inc1");
  1776. build("pr240360");
  1777. checkWasntFullBuild();
  1778. checkCompileWeaveCount("pr240360", 1, 0);
  1779. assertEquals(relmapLength, getModelFor("pr240360").getRelationshipMap().getEntries().size());
  1780. // Change the advice
  1781. alter("pr240360", "inc2");
  1782. build("pr240360");
  1783. checkWasFullBuild();
  1784. checkCompileWeaveCount("pr240360", 6, 4);
  1785. assertEquals(relmapLength, getModelFor("pr240360").getRelationshipMap().getEntries().size());
  1786. }
  1787. public void testBrokenCodeCompilation() {
  1788. initialiseProject("pr102733_1");
  1789. // configureNonStandardCompileOptions("pr102733_1","-proceedOnError");
  1790. build("pr102733_1");
  1791. checkWasFullBuild();
  1792. checkCompileWeaveCount("pr102733_1", 1, 0);
  1793. assertTrue("There should be an error:\n" + getErrorMessages("pr102733_1"), !getErrorMessages("pr102733_1").isEmpty());
  1794. build("pr102733_1"); // incremental
  1795. checkCompileWeaveCount("pr102733_1", 0, 0);
  1796. checkWasntFullBuild();
  1797. alter("pr102733_1", "inc1"); // fix the error
  1798. build("pr102733_1");
  1799. checkWasntFullBuild();
  1800. checkCompileWeaveCount("pr102733_1", 1, 1);
  1801. assertTrue("There should be no errors:\n" + getErrorMessages("pr102733_1"), getErrorMessages("pr102733_1").isEmpty());
  1802. alter("pr102733_1", "inc2"); // break it again
  1803. build("pr102733_1");
  1804. checkWasntFullBuild();
  1805. checkCompileWeaveCount("pr102733_1", 1, 0);
  1806. assertTrue("There should be an error:\n" + getErrorMessages("pr102733_1"), !getErrorMessages("pr102733_1").isEmpty());
  1807. }
  1808. // public void testDeclareAtType_pr149293() {
  1809. // configureBuildStructureModel(true);
  1810. // initialiseProject("PR149293_1");
  1811. // build("PR149293_1");
  1812. // checkCompileWeaveCount(4,5);
  1813. // assertNoErrors();
  1814. // alter("PR149293_1","inc1");
  1815. // build("PR149293_1");
  1816. // assertNoErrors();
  1817. // }
  1818. public void testRefactoring_pr148285() {
  1819. // configureBuildStructureModel(true);
  1820. initialiseProject("PR148285");
  1821. build("PR148285");
  1822. alter("PR148285", "inc1");
  1823. build("PR148285");
  1824. }
  1825. /**
  1826. * In order for this next test to run, I had to move the weaver/world pair we keep in the AjBuildManager instance down into the
  1827. * state object - this makes perfect sense - otherwise when reusing the state for another project we'd not be switching to the
  1828. * right weaver/world for that project.
  1829. */
  1830. public void testBuildingTwoProjectsMakingSmallChanges() {
  1831. initialiseProject("P1");
  1832. initialiseProject("P2");
  1833. build("P1");
  1834. build("P2");
  1835. build("P1");
  1836. checkWasntFullBuild();
  1837. build("P2");
  1838. checkWasntFullBuild();
  1839. alter("P1", "inc1"); // adds a class
  1840. alter("P1", "inc2"); // adds an aspect
  1841. build("P1");
  1842. checkWasFullBuild(); // adding an aspect makes us go back to the source
  1843. }
  1844. public void testPr134371() {
  1845. initialiseProject("PR134371");
  1846. build("PR134371");
  1847. alter("PR134371", "inc1");
  1848. build("PR134371");
  1849. assertTrue("There should be no exceptions handled:\n" + getErrorMessages("PR134371"), getErrorMessages("PR134371")
  1850. .isEmpty());
  1851. }
  1852. /**
  1853. * This test is verifying the behaviour of the code that iterates through the type hierarchy for some type. There are two ways
  1854. * to do it - an approach that grabs all the information up front or an approach that works through iterators and only processes
  1855. * as much data as necessary to satisfy the caller. The latter approach could be much faster - especially if the matching
  1856. * process typically looks for a method in the declaring type.
  1857. */
  1858. public void xtestOptimizedMemberLookup() {
  1859. String p = "oml";
  1860. initialiseProject(p);
  1861. build(p);
  1862. AjdeCoreBuildManager buildManager = getCompilerForProjectWithName(p).getBuildManager();
  1863. AjBuildManager ajBuildManager = buildManager.getAjBuildManager();
  1864. World w = ajBuildManager.getWorld();
  1865. // Type A has no hierarchy (well, Object) and defines 3 methods
  1866. checkType(w, "com.foo.A");
  1867. // Type B extends B2. Two methods in B2, three in B
  1868. checkType(w, "com.foo.B");
  1869. // Type C implements an interface
  1870. checkType(w, "com.foo.C");
  1871. // Type CC extends a class that implements an interface
  1872. checkType(w, "com.foo.CC");
  1873. // Type CCC implements an interface that extends another interface
  1874. checkType(w, "com.foo.CCC");
  1875. // Type CCC implements an interface that extends another interface
  1876. checkType(w, "com.foo.CCC");
  1877. checkType(w, "GenericMethodInterface");
  1878. checkType(w, "GenericInterfaceChain");
  1879. // Some random classes from rt.jar that did reveal some problems:
  1880. checkType(w, "java.lang.StringBuffer");
  1881. checkType(w, "com.sun.corba.se.impl.encoding.CDRInputObject");
  1882. checkTypeHierarchy(w, "com.sun.corba.se.impl.interceptors.PIHandlerImpl$RequestInfoStack", true);
  1883. checkType(w, "com.sun.corba.se.impl.interceptors.PIHandlerImpl$RequestInfoStack");
  1884. checkType(w, "DeclareWarningAndInterfaceMethodCW");
  1885. checkType(w, "ICanGetSomething");
  1886. checkType(w, "B");
  1887. checkType(w, "C");
  1888. // checkRtJar(w); // only works if the JDK path is setup ok in checkRtJar
  1889. // speedCheck(w);
  1890. }
  1891. // private void checkRtJar(World w) {
  1892. // System.out.println("Processing everything in rt.jar: ~16000 classes");
  1893. // try {
  1894. // ZipFile zf = new ZipFile("c:/jvms/jdk1.6.0_06/jre/lib/rt.jar");
  1895. // Enumeration e = zf.entries();
  1896. // int count = 1;
  1897. // while (e.hasMoreElements()) {
  1898. // ZipEntry ze = (ZipEntry) e.nextElement();
  1899. // String n = ze.getName();
  1900. // if (n.endsWith(".class")) {
  1901. // n = n.replace('/', '.');
  1902. // n = n.substring(0, n.length() - 6);
  1903. // if ((count % 100) == 0) {
  1904. // System.out.print(count + " ");
  1905. // }
  1906. // if ((count % 1000) == 0) {
  1907. // System.out.println();
  1908. // }
  1909. // checkType(w, n);
  1910. // count++;
  1911. // }
  1912. // }
  1913. // zf.close();
  1914. // } catch (IOException t) {
  1915. // t.printStackTrace();
  1916. // fail(t.toString());
  1917. // }
  1918. // System.out.println();
  1919. // }
  1920. /**
  1921. * Compare time taken to grab them all and look at them and iterator through them all.
  1922. */
  1923. private void speedCheck(World w) {
  1924. long stime = System.currentTimeMillis();
  1925. try {
  1926. ZipFile zf = new ZipFile("c:/jvms/jdk1.6.0_06/jre/lib/rt.jar");
  1927. Enumeration<? extends ZipEntry> e = zf.entries();
  1928. while (e.hasMoreElements()) {
  1929. ZipEntry ze = (ZipEntry) e.nextElement();
  1930. String n = ze.getName();
  1931. if (n.endsWith(".class")) {
  1932. n = n.replace('/', '.');
  1933. n = n.substring(0, n.length() - 6);
  1934. ResolvedType typeA = w.resolve(n);
  1935. assertFalse(typeA.isMissing());
  1936. List<ResolvedMember> viaIteratorList = getThemAll(typeA.getMethods(true, true));
  1937. viaIteratorList = getThemAll(typeA.getMethods(false, true));
  1938. }
  1939. }
  1940. zf.close();
  1941. } catch (IOException t) {
  1942. t.printStackTrace();
  1943. fail(t.toString());
  1944. }
  1945. long etime = System.currentTimeMillis();
  1946. System.out.println("Time taken for 'iterator' approach: " + (etime - stime) + "ms");
  1947. stime = System.currentTimeMillis();
  1948. try {
  1949. ZipFile zf = new ZipFile("c:/jvms/jdk1.6.0_06/jre/lib/rt.jar");
  1950. Enumeration e = zf.entries();
  1951. while (e.hasMoreElements()) {
  1952. ZipEntry ze = (ZipEntry) e.nextElement();
  1953. String n = ze.getName();
  1954. if (n.endsWith(".class")) {
  1955. n = n.replace('/', '.');
  1956. n = n.substring(0, n.length() - 6);
  1957. ResolvedType typeA = w.resolve(n);
  1958. assertFalse(typeA.isMissing());
  1959. List<ResolvedMember> viaIteratorList = typeA.getMethodsWithoutIterator(false, true, true);
  1960. viaIteratorList = typeA.getMethodsWithoutIterator(false, true, false);
  1961. }
  1962. }
  1963. zf.close();
  1964. } catch (IOException t) {
  1965. t.printStackTrace();
  1966. fail(t.toString());
  1967. }
  1968. etime = System.currentTimeMillis();
  1969. System.out.println("Time taken for 'grab all up front' approach: " + (etime - stime) + "ms");
  1970. }
  1971. private void checkType(World w, String name) {
  1972. checkTypeHierarchy(w, name, true);
  1973. checkTypeHierarchy(w, name, false);
  1974. checkMethods(w, name, true);
  1975. checkMethods(w, name, false);
  1976. }
  1977. private void checkMethods(World w, String name, boolean wantGenerics) {
  1978. ResolvedType typeA = w.resolve(name);
  1979. assertFalse(typeA.isMissing());
  1980. List<ResolvedMember> viaIteratorList = getThemAll(typeA.getMethods(wantGenerics, true));
  1981. List<ResolvedMember> directlyList = typeA.getMethodsWithoutIterator(true, true, wantGenerics);
  1982. Collections.sort(viaIteratorList, new ResolvedMemberComparator());
  1983. Collections.sort(directlyList, new ResolvedMemberComparator());
  1984. compare(viaIteratorList, directlyList, name);
  1985. // System.out.println(toString(viaIteratorList, directlyList, genericsAware));
  1986. }
  1987. private static class ResolvedMemberComparator implements Comparator<ResolvedMember> {
  1988. public int compare(ResolvedMember o1, ResolvedMember o2) {
  1989. return o1.toString().compareTo(o2.toString());
  1990. }
  1991. }
  1992. private void checkTypeHierarchy(World w, String name, boolean wantGenerics) {
  1993. ResolvedType typeA = w.resolve(name);
  1994. assertFalse(typeA.isMissing());
  1995. List<String> viaIteratorList = exhaustTypeIterator(typeA.getHierarchy(wantGenerics, false));
  1996. List<ResolvedType> typeDirectlyList = typeA.getHierarchyWithoutIterator(true, true, wantGenerics);
  1997. assertFalse(viaIteratorList.isEmpty());
  1998. List<String> directlyList = new ArrayList<String>();
  1999. for (ResolvedType type : typeDirectlyList) {
  2000. String n = type.getName();
  2001. if (!directlyList.contains(n)) {
  2002. directlyList.add(n);
  2003. }
  2004. }
  2005. Collections.sort(viaIteratorList);
  2006. Collections.sort(directlyList);
  2007. compareTypeLists(viaIteratorList, directlyList);
  2008. // System.out.println("ShouldBeGenerics?" + wantGenerics + "\n" + typeListsToString(viaIteratorList, directlyList));
  2009. }
  2010. private void compare(List<ResolvedMember> viaIteratorList, List<ResolvedMember> directlyList, String typename) {
  2011. assertEquals(typename + "\n" + toString(directlyList), typename + "\n" + toString(viaIteratorList));
  2012. }
  2013. private void compareTypeLists(List<String> viaIteratorList, List<String> directlyList) {
  2014. assertEquals(typeListToString(directlyList), typeListToString(viaIteratorList));
  2015. }
  2016. private String toString(List<ResolvedMember> list) {
  2017. StringBuffer sb = new StringBuffer();
  2018. for (ResolvedMember m : list) {
  2019. sb.append(m).append("\n");
  2020. }
  2021. return sb.toString();
  2022. }
  2023. private String typeListToString(List<String> list) {
  2024. StringBuffer sb = new StringBuffer();
  2025. for (String m : list) {
  2026. sb.append(m).append("\n");
  2027. }
  2028. return sb.toString();
  2029. }
  2030. private String toString(List<ResolvedMember> one, List<ResolvedMember> two, boolean shouldIncludeGenerics) {
  2031. StringBuffer sb = new StringBuffer();
  2032. sb.append("Through iterator\n");
  2033. for (ResolvedMember m : one) {
  2034. sb.append(m).append("\n");
  2035. }
  2036. sb.append("Directly retrieved\n");
  2037. for (ResolvedMember m : one) {
  2038. sb.append(m).append("\n");
  2039. }
  2040. return sb.toString();
  2041. }
  2042. private String typeListsToString(List<String> one, List<String> two) {
  2043. StringBuffer sb = new StringBuffer();
  2044. sb.append("Through iterator\n");
  2045. for (String m : one) {
  2046. sb.append(">" + m).append("\n");
  2047. }
  2048. sb.append("Directly retrieved\n");
  2049. for (String m : one) {
  2050. sb.append(">" + m).append("\n");
  2051. }
  2052. return sb.toString();
  2053. }
  2054. private List<ResolvedMember> getThemAll(Iterator<ResolvedMember> methods) {
  2055. List<ResolvedMember> allOfThem = new ArrayList<ResolvedMember>();
  2056. while (methods.hasNext()) {
  2057. allOfThem.add(methods.next());
  2058. }
  2059. return allOfThem;
  2060. }
  2061. private List<String> exhaustTypeIterator(Iterator<ResolvedType> types) {
  2062. List<String> allOfThem = new ArrayList<String>();
  2063. while (types.hasNext()) {
  2064. allOfThem.add(types.next().getName());
  2065. }
  2066. return allOfThem;
  2067. }
  2068. /**
  2069. * Setup up two simple projects and build them in turn - check the structure model is right after each build
  2070. */
  2071. public void testBuildingTwoProjectsAndVerifyingModel() {
  2072. initialiseProject("P1");
  2073. initialiseProject("P2");
  2074. configureNonStandardCompileOptions("P1", "-Xset:minimalModel=false");
  2075. configureNonStandardCompileOptions("P2", "-Xset:minimalModel=false");
  2076. build("P1");
  2077. checkForNode(getModelFor("P1"), "pkg", "C", true);
  2078. build("P2");
  2079. checkForNode(getModelFor("P2"), "pkg", "C", false);
  2080. build("P1");
  2081. checkForNode(getModelFor("P1"), "pkg", "C", true);
  2082. build("P2");
  2083. checkForNode(getModelFor("P2"), "pkg", "C", false);
  2084. }
  2085. // Setup up two simple projects and build them in turn - check the
  2086. // structure model is right after each build
  2087. public void testBuildingTwoProjectsAndVerifyingStuff() {
  2088. initialiseProject("P1");
  2089. initialiseProject("P2");
  2090. configureNonStandardCompileOptions("P1", "-Xset:minimalModel=false");
  2091. configureNonStandardCompileOptions("P2", "-Xset:minimalModel=false");
  2092. build("P1");
  2093. checkForNode(getModelFor("P1"), "pkg", "C", true);
  2094. build("P2");
  2095. checkForNode(getModelFor("P2"), "pkg", "C", false);
  2096. build("P1");
  2097. checkForNode(getModelFor("P1"), "pkg", "C", true);
  2098. build("P2");
  2099. checkForNode(getModelFor("P2"), "pkg", "C", false);
  2100. }
  2101. /**
  2102. * Complex. Here we are testing that a state object records structural changes since the last full build correctly. We build a
  2103. * simple project from scratch - this will be a full build and so the structural changes since last build count should be 0. We
  2104. * then alter a class, adding a new method and check structural changes is 1.
  2105. */
  2106. public void testStateManagement1() {
  2107. File binDirectoryForP1 = new File(getFile("P1", "bin"));
  2108. initialiseProject("P1");
  2109. build("P1"); // full build
  2110. AjState ajs = IncrementalStateManager.findStateManagingOutputLocation(binDirectoryForP1);
  2111. assertTrue("There should be a state object for project P1", ajs != null);
  2112. assertTrue(
  2113. "Should be no structural changes as it was a full build but found: "
  2114. + ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  2115. ajs.getNumberOfStructuralChangesSinceLastFullBuild() == 0);
  2116. alter("P1", "inc3"); // adds a method to the class C.java
  2117. build("P1");
  2118. checkWasntFullBuild();
  2119. ajs = IncrementalStateManager.findStateManagingOutputLocation(new File(getFile("P1", "bin")));
  2120. assertTrue("There should be state for project P1", ajs != null);
  2121. checkWasntFullBuild();
  2122. assertTrue(
  2123. "Should be one structural changes as it was a full build but found: "
  2124. + ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  2125. ajs.getNumberOfStructuralChangesSinceLastFullBuild() == 1);
  2126. }
  2127. /**
  2128. * Complex. Here we are testing that a state object records structural changes since the last full build correctly. We build a
  2129. * simple project from scratch - this will be a full build and so the structural changes since last build count should be 0. We
  2130. * then alter a class, changing body of a method, not the structure and check struc changes is still 0.
  2131. */
  2132. public void testStateManagement2() {
  2133. File binDirectoryForP1 = new File(getFile("P1", "bin"));
  2134. initialiseProject("P1");
  2135. alter("P1", "inc3"); // need this change in here so 'inc4' can be
  2136. // applied without making
  2137. // it a structural change
  2138. build("P1"); // full build
  2139. AjState ajs = IncrementalStateManager.findStateManagingOutputLocation(binDirectoryForP1);
  2140. assertTrue("There should be state for project P1", ajs != null);
  2141. assertTrue("Should be no struc changes as its a full build: " + ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  2142. ajs.getNumberOfStructuralChangesSinceLastFullBuild() == 0);
  2143. alter("P1", "inc4"); // changes body of main() method but does *not*
  2144. // change the structure of C.java
  2145. build("P1");
  2146. checkWasntFullBuild();
  2147. ajs = IncrementalStateManager.findStateManagingOutputLocation(new File(getFile("P1", "bin")));
  2148. assertTrue("There should be state for project P1", ajs != null);
  2149. checkWasntFullBuild();
  2150. assertTrue("Shouldn't be any structural changes but there were " + ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  2151. ajs.getNumberOfStructuralChangesSinceLastFullBuild() == 0);
  2152. }
  2153. /**
  2154. * The C.java file modified in this test has an inner class - this means the inner class has a this$0 field and <init>(C) ctor
  2155. * to watch out for when checking for structural changes
  2156. *
  2157. */
  2158. public void testStateManagement3() {
  2159. File binDirForInterproject1 = new File(getFile("interprojectdeps1", "bin"));
  2160. initialiseProject("interprojectdeps1");
  2161. build("interprojectdeps1"); // full build
  2162. AjState ajs = IncrementalStateManager.findStateManagingOutputLocation(binDirForInterproject1);
  2163. assertTrue("There should be state for project P1", ajs != null);
  2164. assertTrue("Should be no struc changes as its a full build: " + ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  2165. ajs.getNumberOfStructuralChangesSinceLastFullBuild() == 0);
  2166. alter("interprojectdeps1", "inc1"); // adds a space to C.java
  2167. build("interprojectdeps1");
  2168. checkWasntFullBuild();
  2169. ajs = IncrementalStateManager.findStateManagingOutputLocation(new File(getFile("interprojectdeps1", "bin")));
  2170. assertTrue("There should be state for project interprojectdeps1", ajs != null);
  2171. checkWasntFullBuild();
  2172. assertTrue("Shouldn't be any structural changes but there were " + ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  2173. ajs.getNumberOfStructuralChangesSinceLastFullBuild() == 0);
  2174. }
  2175. /**
  2176. * The C.java file modified in this test has an inner class - which has two ctors - this checks how they are mangled with an
  2177. * instance of C.
  2178. *
  2179. */
  2180. public void testStateManagement4() {
  2181. File binDirForInterproject2 = new File(getFile("interprojectdeps2", "bin"));
  2182. initialiseProject("interprojectdeps2");
  2183. build("interprojectdeps2"); // full build
  2184. AjState ajs = IncrementalStateManager.findStateManagingOutputLocation(binDirForInterproject2);
  2185. assertTrue("There should be state for project interprojectdeps2", ajs != null);
  2186. assertTrue("Should be no struc changes as its a full build: " + ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  2187. ajs.getNumberOfStructuralChangesSinceLastFullBuild() == 0);
  2188. alter("interprojectdeps2", "inc1"); // minor change to C.java
  2189. build("interprojectdeps2");
  2190. checkWasntFullBuild();
  2191. ajs = IncrementalStateManager.findStateManagingOutputLocation(new File(getFile("interprojectdeps2", "bin")));
  2192. assertTrue("There should be state for project interprojectdeps1", ajs != null);
  2193. checkWasntFullBuild();
  2194. assertTrue("Shouldn't be any structural changes but there were " + ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  2195. ajs.getNumberOfStructuralChangesSinceLastFullBuild() == 0);
  2196. }
  2197. /**
  2198. * The C.java file modified in this test has an inner class - it has two ctors but also a reference to C.this in it - which will
  2199. * give rise to an accessor being created in C
  2200. *
  2201. */
  2202. public void testStateManagement5() {
  2203. File binDirForInterproject3 = new File(getFile("interprojectdeps3", "bin"));
  2204. initialiseProject("interprojectdeps3");
  2205. build("interprojectdeps3"); // full build
  2206. AjState ajs = IncrementalStateManager.findStateManagingOutputLocation(binDirForInterproject3);
  2207. assertTrue("There should be state for project interprojectdeps3", ajs != null);
  2208. assertTrue("Should be no struc changes as its a full build: " + ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  2209. ajs.getNumberOfStructuralChangesSinceLastFullBuild() == 0);
  2210. alter("interprojectdeps3", "inc1"); // minor change to C.java
  2211. build("interprojectdeps3");
  2212. checkWasntFullBuild();
  2213. ajs = IncrementalStateManager.findStateManagingOutputLocation(new File(getFile("interprojectdeps3", "bin")));
  2214. assertTrue("There should be state for project interprojectdeps1", ajs != null);
  2215. checkWasntFullBuild();
  2216. assertTrue("Shouldn't be any structural changes but there were " + ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  2217. ajs.getNumberOfStructuralChangesSinceLastFullBuild() == 0);
  2218. }
  2219. /**
  2220. * Now the most complex test. Create a dependancy between two projects. Building one may affect whether the other does an
  2221. * incremental or full build. The structural information recorded in the state object should be getting used to control whether
  2222. * a full build is necessary...
  2223. */
  2224. public void testBuildingDependantProjects() {
  2225. initialiseProject("P1");
  2226. initialiseProject("P2");
  2227. configureNewProjectDependency("P2", "P1");
  2228. build("P1");
  2229. build("P2"); // now everything is consistent and compiled
  2230. alter("P1", "inc1"); // adds a second class
  2231. build("P1");
  2232. build("P2"); // although a second class was added - P2 can't be using
  2233. // it, so we don't full build here :)
  2234. checkWasntFullBuild();
  2235. alter("P1", "inc3"); // structurally changes one of the classes
  2236. build("P1");
  2237. build("P2"); // build notices the structural change, but is incremental
  2238. // of I and J as they depend on C
  2239. checkWasntFullBuild();
  2240. alter("P1", "inc4");
  2241. build("P1");
  2242. build("P2"); // build sees a change but works out its not structural
  2243. checkWasntFullBuild();
  2244. }
  2245. public void testPr85132() {
  2246. initialiseProject("PR85132");
  2247. build("PR85132");
  2248. alter("PR85132", "inc1");
  2249. build("PR85132");
  2250. }
  2251. // parameterization of generic aspects
  2252. public void testPr125405() {
  2253. initialiseProject("PR125405");
  2254. build("PR125405");
  2255. checkCompileWeaveCount("PR125405", 1, 1);
  2256. alter("PR125405", "inc1");
  2257. build("PR125405");
  2258. // "only abstract aspects can have type parameters"
  2259. checkForError("PR125405", "only abstract aspects can have type parameters");
  2260. alter("PR125405", "inc2");
  2261. build("PR125405");
  2262. checkCompileWeaveCount("PR125405", 1, 1);
  2263. assertTrue("Should be no errors, but got " + getErrorMessages("PR125405"), getErrorMessages("PR125405").size() == 0);
  2264. }
  2265. public void testPr128618() {
  2266. initialiseProject("PR128618_1");
  2267. initialiseProject("PR128618_2");
  2268. configureNewProjectDependency("PR128618_2", "PR128618_1");
  2269. assertTrue("there should be no warning messages before we start", getWarningMessages("PR128618_1").isEmpty());
  2270. assertTrue("there should be no warning messages before we start", getWarningMessages("PR128618_2").isEmpty());
  2271. build("PR128618_1");
  2272. build("PR128618_2");
  2273. List<IMessage> l = getWarningMessages("PR128618_2");
  2274. // there should be one warning against "PR128618_2"
  2275. List<IMessage> warnings = getWarningMessages("PR128618_2");
  2276. assertTrue("Should be one warning, but there are #" + warnings.size(), warnings.size() == 1);
  2277. IMessage msg = (getWarningMessages("PR128618_2").get(0));
  2278. assertEquals("warning should be against the FFDC.aj resource", "FFDC.aj", msg.getSourceLocation().getSourceFile().getName());
  2279. alter("PR128618_2", "inc1");
  2280. build("PR128618_2");
  2281. checkWasntFullBuild();
  2282. IMessage msg2 = (getWarningMessages("PR128618_2").get(0));
  2283. assertEquals("warning should be against the FFDC.aj resource", "FFDC.aj", msg2.getSourceLocation().getSourceFile()
  2284. .getName());
  2285. assertFalse("a new warning message should have been generated", msg.equals(msg2));
  2286. }
  2287. public void testPr92837() {
  2288. initialiseProject("PR92837");
  2289. build("PR92837");
  2290. alter("PR92837", "inc1");
  2291. build("PR92837");
  2292. }
  2293. // See open generic itd bug mentioning 119570
  2294. // public void testPr119570() {
  2295. // initialiseProject("PR119570");
  2296. // build("PR119570");
  2297. // assertNoErrors("PR119570");
  2298. // }
  2299. // public void testPr119570_212783_2() {
  2300. // initialiseProject("PR119570_2");
  2301. // build("PR119570_2");
  2302. // List l = getWarningMessages("PR119570_2");
  2303. // assertTrue("Should be no warnings, but got "+l,l.size()==0);
  2304. // assertNoErrors("PR119570_2");
  2305. // }
  2306. //
  2307. // public void testPr119570_212783_3() {
  2308. // initialiseProject("pr119570_3");
  2309. // build("pr119570_3");
  2310. // List l = getWarningMessages("pr119570_3");
  2311. // assertTrue("Should be no warnings, but got "+l,l.size()==0);
  2312. // assertNoErrors("pr119570_3");
  2313. // }
  2314. // If you fiddle with the compiler options - you must manually reset the
  2315. // options at the end of the test
  2316. public void testPr117209() {
  2317. try {
  2318. initialiseProject("pr117209");
  2319. configureNonStandardCompileOptions("pr117209", "-proceedOnError");
  2320. build("pr117209");
  2321. checkCompileWeaveCount("pr117209", 6, 5);
  2322. } finally {
  2323. // MyBuildOptionsAdapter.reset();
  2324. }
  2325. }
  2326. public void testPr114875() {
  2327. // temporary problem with this on linux, think it is a filesystem
  2328. // lastmodtime issue
  2329. if (System.getProperty("os.name", "").toLowerCase().equals("linux")) {
  2330. return;
  2331. }
  2332. initialiseProject("pr114875");
  2333. build("pr114875");
  2334. alter("pr114875", "inc1");
  2335. build("pr114875");
  2336. checkWasFullBuild();
  2337. alter("pr114875", "inc2");
  2338. build("pr114875");
  2339. checkWasFullBuild(); // back to the source for an aspect change
  2340. }
  2341. public void testPr117882() {
  2342. // AjdeInteractionTestbed.VERBOSE=true;
  2343. // AjdeInteractionTestbed.configureBuildStructureModel(true);
  2344. initialiseProject("PR117882");
  2345. build("PR117882");
  2346. checkWasFullBuild();
  2347. alter("PR117882", "inc1");
  2348. build("PR117882");
  2349. // This should be an incremental build now - because of the changes
  2350. // under 259649
  2351. checkWasntFullBuild(); // back to the source for an aspect
  2352. // AjdeInteractionTestbed.VERBOSE=false;
  2353. // AjdeInteractionTestbed.configureBuildStructureModel(false);
  2354. }
  2355. public void testPr117882_2() {
  2356. // AjdeInteractionTestbed.VERBOSE=true;
  2357. // AjdeInteractionTestbed.configureBuildStructureModel(true);
  2358. initialiseProject("PR117882_2");
  2359. build("PR117882_2");
  2360. checkWasFullBuild();
  2361. alter("PR117882_2", "inc1");
  2362. build("PR117882_2");
  2363. checkWasFullBuild(); // back to the source...
  2364. // checkCompileWeaveCount(1,4);
  2365. // fullBuild("PR117882_2");
  2366. // checkWasFullBuild();
  2367. // AjdeInteractionTestbed.VERBOSE=false;
  2368. // AjdeInteractionTestbed.configureBuildStructureModel(false);
  2369. }
  2370. public void testPr115251() {
  2371. // AjdeInteractionTestbed.VERBOSE=true;
  2372. initialiseProject("PR115251");
  2373. build("PR115251");
  2374. checkWasFullBuild();
  2375. alter("PR115251", "inc1");
  2376. build("PR115251");
  2377. checkWasFullBuild(); // back to the source
  2378. }
  2379. public void testPr220255_InfiniteBuildHasMember() {
  2380. initialiseProject("pr220255");
  2381. configureNonStandardCompileOptions("pr220255", "-XhasMember");
  2382. build("pr220255");
  2383. checkWasFullBuild();
  2384. alter("pr220255", "inc1");
  2385. build("pr220255");
  2386. checkWasntFullBuild();
  2387. }
  2388. public void testPr157054() {
  2389. initialiseProject("PR157054");
  2390. configureNonStandardCompileOptions("PR157054", "-showWeaveInfo");
  2391. configureShowWeaveInfoMessages("PR157054", true);
  2392. build("PR157054");
  2393. checkWasFullBuild();
  2394. List<IMessage> weaveMessages = getWeavingMessages("PR157054");
  2395. assertTrue("Should be two weaving messages but there are " + weaveMessages.size(), weaveMessages.size() == 2);
  2396. alter("PR157054", "inc1");
  2397. build("PR157054");
  2398. weaveMessages = getWeavingMessages("PR157054");
  2399. assertTrue("Should be three weaving messages but there are " + weaveMessages.size(), weaveMessages.size() == 3);
  2400. checkWasntFullBuild();
  2401. fullBuild("PR157054");
  2402. weaveMessages = getWeavingMessages("PR157054");
  2403. assertTrue("Should be three weaving messages but there are " + weaveMessages.size(), weaveMessages.size() == 3);
  2404. }
  2405. /**
  2406. * Checks we aren't leaking mungers across compiles (accumulating multiple instances of the same one that all do the same
  2407. * thing). On the first compile the munger is added late on - so at the time we set the count it is still zero. On the
  2408. * subsequent compiles we know about this extra one.
  2409. */
  2410. public void testPr141956_IncrementallyCompilingAtAj() {
  2411. initialiseProject("PR141956");
  2412. build("PR141956");
  2413. assertTrue("Should be zero but reports " + EclipseFactory.debug_mungerCount, EclipseFactory.debug_mungerCount == 0);
  2414. alter("PR141956", "inc1");
  2415. build("PR141956");
  2416. assertTrue("Should be two but reports " + EclipseFactory.debug_mungerCount, EclipseFactory.debug_mungerCount == 2);
  2417. alter("PR141956", "inc1");
  2418. build("PR141956");
  2419. assertTrue("Should be two but reports " + EclipseFactory.debug_mungerCount, EclipseFactory.debug_mungerCount == 2);
  2420. alter("PR141956", "inc1");
  2421. build("PR141956");
  2422. assertTrue("Should be two but reports " + EclipseFactory.debug_mungerCount, EclipseFactory.debug_mungerCount == 2);
  2423. alter("PR141956", "inc1");
  2424. build("PR141956");
  2425. assertTrue("Should be two but reports " + EclipseFactory.debug_mungerCount, EclipseFactory.debug_mungerCount == 2);
  2426. }
  2427. // public void testPr124399() {
  2428. // AjdeInteractionTestbed.VERBOSE=true;
  2429. // configureBuildStructureModel(true);
  2430. // initialiseProject("PR124399");
  2431. // build("PR124399");
  2432. // checkWasFullBuild();
  2433. // alter("PR124399","inc1");
  2434. // build("PR124399");
  2435. // checkWasntFullBuild();
  2436. // }
  2437. public void testPr121384() {
  2438. // AjdeInteractionTestbed.VERBOSE=true;
  2439. // AsmManager.setReporting("c:/foo.txt",true,true,true,false);
  2440. initialiseProject("pr121384");
  2441. configureNonStandardCompileOptions("pr121384", "-showWeaveInfo");
  2442. build("pr121384");
  2443. checkWasFullBuild();
  2444. alter("pr121384", "inc1");
  2445. build("pr121384");
  2446. checkWasntFullBuild();
  2447. }
  2448. /*
  2449. * public void testPr111779() { super.VERBOSE=true; initialiseProject("PR111779"); build("PR111779"); alter("PR111779","inc1");
  2450. * build("PR111779"); }
  2451. */
  2452. public void testPr93310_1() {
  2453. initialiseProject("PR93310_1");
  2454. build("PR93310_1");
  2455. checkWasFullBuild();
  2456. String fileC2 = getWorkingDir().getAbsolutePath() + File.separatorChar + "PR93310_1" + File.separatorChar + "src"
  2457. + File.separatorChar + "pack" + File.separatorChar + "C2.java";
  2458. (new File(fileC2)).delete();
  2459. alter("PR93310_1", "inc1");
  2460. build("PR93310_1");
  2461. checkWasFullBuild();
  2462. int l = AjdeInteractionTestbed.MyStateListener.detectedDeletions.size();
  2463. assertTrue("Expected one deleted file to be noticed, but detected: " + l, l == 1);
  2464. String name = (String) AjdeInteractionTestbed.MyStateListener.detectedDeletions.get(0);
  2465. assertTrue("Should end with C2.java but is " + name, name.endsWith("C2.java"));
  2466. }
  2467. public void testPr93310_2() {
  2468. initialiseProject("PR93310_2");
  2469. build("PR93310_2");
  2470. checkWasFullBuild();
  2471. String fileC2 = getWorkingDir().getAbsolutePath() + File.separatorChar + "PR93310_2" + File.separatorChar + "src"
  2472. + File.separatorChar + "pack" + File.separatorChar + "C2.java";
  2473. (new File(fileC2)).delete();
  2474. alter("PR93310_2", "inc1");
  2475. build("PR93310_2");
  2476. checkWasFullBuild();
  2477. int l = AjdeInteractionTestbed.MyStateListener.detectedDeletions.size();
  2478. assertTrue("Expected one deleted file to be noticed, but detected: " + l, l == 1);
  2479. String name = (String) AjdeInteractionTestbed.MyStateListener.detectedDeletions.get(0);
  2480. assertTrue("Should end with C2.java but is " + name, name.endsWith("C2.java"));
  2481. }
  2482. // Stage1: Compile two files, pack.A and pack.A1 - A1 sets a protected field
  2483. // in A.
  2484. // Stage2: make the field private in class A > gives compile error
  2485. // Stage3: Add a new aspect whilst there is a compile error !
  2486. public void testPr113531() {
  2487. initialiseProject("PR113531");
  2488. build("PR113531");
  2489. assertTrue("build should have compiled ok", getErrorMessages("PR113531").isEmpty());
  2490. alter("PR113531", "inc1");
  2491. build("PR113531");
  2492. assertEquals("error message should be 'foo cannot be resolved to a variable' ", "foo cannot be resolved to a variable",
  2493. (getErrorMessages("PR113531").get(0)).getMessage());
  2494. alter("PR113531", "inc2");
  2495. build("PR113531");
  2496. assertTrue("There should be no exceptions handled:\n" + getCompilerErrorMessages("PR113531"),
  2497. getCompilerErrorMessages("PR113531").isEmpty());
  2498. assertEquals("error message should be 'foo cannot be resolved to a variable' ", "foo cannot be resolved to a variable",
  2499. (getErrorMessages("PR113531").get(0)).getMessage());
  2500. }
  2501. // Stage 1: Compile the 4 files, pack.A2 extends pack.A1 (aspects) where
  2502. // A2 uses a protected field in A1 and pack.C2 extends pack.C1 (classes)
  2503. // where C2 uses a protected field in C1
  2504. // Stage 2: make the field private in class C1 ==> compile errors in C2
  2505. // Stage 3: make the field private in aspect A1 whilst there's the compile
  2506. // error.
  2507. // There shouldn't be a BCException saying can't find delegate for pack.C2
  2508. public void testPr119882() {
  2509. initialiseProject("PR119882");
  2510. build("PR119882");
  2511. assertTrue("build should have compiled ok", getErrorMessages("PR119882").isEmpty());
  2512. alter("PR119882", "inc1");
  2513. build("PR119882");
  2514. // fullBuild("PR119882");
  2515. List<IMessage> errors = getErrorMessages("PR119882");
  2516. assertTrue("Should be at least one error, but got none", errors.size() == 1);
  2517. assertEquals("error message should be 'i cannot be resolved to a variable' ", "i cannot be resolved to a variable",
  2518. ((IMessage) errors.get(0)).getMessage());
  2519. alter("PR119882", "inc2");
  2520. build("PR119882");
  2521. assertTrue("There should be no exceptions handled:\n" + getCompilerErrorMessages("PR119882"),
  2522. getCompilerErrorMessages("PR119882").isEmpty());
  2523. assertEquals("error message should be 'i cannot be resolved to a variable' ", "i cannot be resolved to a variable",
  2524. ((IMessage) errors.get(0)).getMessage());
  2525. }
  2526. public void testPr112736() {
  2527. initialiseProject("PR112736");
  2528. build("PR112736");
  2529. checkWasFullBuild();
  2530. String fileC2 = getWorkingDir().getAbsolutePath() + File.separatorChar + "PR112736" + File.separatorChar + "src"
  2531. + File.separatorChar + "pack" + File.separatorChar + "A.java";
  2532. (new File(fileC2)).delete();
  2533. alter("PR112736", "inc1");
  2534. build("PR112736");
  2535. checkWasFullBuild();
  2536. }
  2537. /**
  2538. * We have problems with multiple rewrites of a pointcut across incremental builds.
  2539. */
  2540. public void testPr113257() {
  2541. initialiseProject("PR113257");
  2542. build("PR113257");
  2543. alter("PR113257", "inc1");
  2544. build("PR113257");
  2545. checkWasFullBuild(); // back to the source
  2546. alter("PR113257", "inc1");
  2547. build("PR113257");
  2548. }
  2549. public void testPr123612() {
  2550. initialiseProject("PR123612");
  2551. build("PR123612");
  2552. alter("PR123612", "inc1");
  2553. build("PR123612");
  2554. checkWasFullBuild(); // back to the source
  2555. }
  2556. // Bugzilla Bug 152257 - Incremental compiler doesn't handle exception
  2557. // declaration correctly
  2558. public void testPr152257() {
  2559. initialiseProject("PR152257");
  2560. configureNonStandardCompileOptions("PR152257", "-XnoInline");
  2561. build("PR152257");
  2562. List<IMessage> errors = getErrorMessages("PR152257");
  2563. assertTrue("Should be no warnings, but there are #" + errors.size(), errors.size() == 0);
  2564. checkWasFullBuild();
  2565. alter("PR152257", "inc1");
  2566. build("PR152257");
  2567. errors = getErrorMessages("PR152257");
  2568. assertTrue("Should be no warnings, but there are #" + errors.size(), errors.size() == 0);
  2569. checkWasntFullBuild();
  2570. }
  2571. public void testPr128655() {
  2572. initialiseProject("pr128655");
  2573. configureNonStandardCompileOptions("pr128655", "-showWeaveInfo");
  2574. configureShowWeaveInfoMessages("pr128655", true);
  2575. build("pr128655");
  2576. List<IMessage> firstBuildMessages = getWeavingMessages("pr128655");
  2577. assertTrue("Should be at least one message about the dec @type, but there were none", firstBuildMessages.size() > 0);
  2578. alter("pr128655", "inc1");
  2579. build("pr128655");
  2580. checkWasntFullBuild(); // back to the source
  2581. List<IMessage> secondBuildMessages = getWeavingMessages("pr128655");
  2582. // check they are the same
  2583. for (int i = 0; i < firstBuildMessages.size(); i++) {
  2584. IMessage m1 = (IMessage) firstBuildMessages.get(i);
  2585. IMessage m2 = (IMessage) secondBuildMessages.get(i);
  2586. if (!m1.toString().equals(m2.toString())) {
  2587. System.err.println("Message during first build was: " + m1);
  2588. System.err.println("Message during second build was: " + m1);
  2589. fail("The two messages should be the same, but are not: \n" + m1 + "!=" + m2);
  2590. }
  2591. }
  2592. }
  2593. // Similar to above, but now the annotation is in the default package
  2594. public void testPr128655_2() {
  2595. initialiseProject("pr128655_2");
  2596. configureNonStandardCompileOptions("pr128655_2", "-showWeaveInfo");
  2597. configureShowWeaveInfoMessages("pr128655_2", true);
  2598. build("pr128655_2");
  2599. List<IMessage> firstBuildMessages = getWeavingMessages("pr128655_2");
  2600. assertTrue("Should be at least one message about the dec @type, but there were none", firstBuildMessages.size() > 0);
  2601. alter("pr128655_2", "inc1");
  2602. build("pr128655_2");
  2603. checkWasntFullBuild(); // back to the source
  2604. List<IMessage> secondBuildMessages = getWeavingMessages("pr128655_2");
  2605. // check they are the same
  2606. for (int i = 0; i < firstBuildMessages.size(); i++) {
  2607. IMessage m1 = (IMessage) firstBuildMessages.get(i);
  2608. IMessage m2 = (IMessage) secondBuildMessages.get(i);
  2609. if (!m1.toString().equals(m2.toString())) {
  2610. System.err.println("Message during first build was: " + m1);
  2611. System.err.println("Message during second build was: " + m1);
  2612. fail("The two messages should be the same, but are not: \n" + m1 + "!=" + m2);
  2613. }
  2614. }
  2615. }
  2616. // test for comment #31 - NPE
  2617. public void testPr129163() {
  2618. initialiseProject("PR129613");
  2619. build("PR129613");
  2620. alter("PR129613", "inc1");
  2621. build("PR129613");
  2622. assertTrue("There should be no exceptions handled:\n" + getCompilerErrorMessages("PR129613"),
  2623. getCompilerErrorMessages("PR129613").isEmpty());
  2624. assertEquals("warning message should be 'no match for this type name: File [Xlint:invalidAbsoluteTypeName]' ",
  2625. "no match for this type name: File [Xlint:invalidAbsoluteTypeName]",
  2626. (getWarningMessages("PR129613").get(0)).getMessage());
  2627. }
  2628. // test for comment #0 - adding a comment to a class file shouldn't
  2629. // cause us to go back to source and recompile everything. To force this
  2630. // to behave like AJDT we need to include the aspect in 'inc1' so that
  2631. // when AjState looks at its timestamp it thinks the aspect has been
  2632. // modified.
  2633. // The logic within CrosscuttingMembers should then work out correctly
  2634. // that there haven't really been any changes within the aspect and so
  2635. // we shouldn't go back to source.
  2636. public void testPr129163_2() {
  2637. // want to behave like AJDT
  2638. initialiseProject("pr129163_2");
  2639. build("pr129163_2");
  2640. checkWasFullBuild();
  2641. alter("pr129163_2", "inc1");
  2642. build("pr129163_2");
  2643. checkWasntFullBuild(); // shouldn't be a full build because the
  2644. // aspect hasn't changed
  2645. }
  2646. public void testIncrementalIntelligence_Scenario01() {
  2647. AjdeInteractionTestbed.VERBOSE = true;
  2648. initialiseProject("Project1");
  2649. initialiseProject("Project2");
  2650. configureNewProjectDependency("Project2", "Project1");
  2651. build("Project1");
  2652. build("Project2");
  2653. alter("Project1", "inc1"); // white space change to ClassA - no impact
  2654. build("Project1");
  2655. build("Project2");
  2656. checkWasntFullBuild(); // not a structural change so ignored
  2657. alter("Project1", "inc2"); // structural change to ClassB - new method!
  2658. build("Project1");
  2659. build("Project2");
  2660. checkWasntFullBuild(); // not a type that Project2 depends on so ignored
  2661. alter("Project1", "inc3"); // structural change to ClassA
  2662. build("Project1");
  2663. setNextChangeResponse("Project2", ICompilerConfiguration.EVERYTHING); // See
  2664. // pr245566
  2665. // comment
  2666. // 3
  2667. build("Project2");
  2668. checkWasntFullBuild(); // Just need to recompile ClassAExtender
  2669. checkCompileWeaveCount("Project2", 1, 1);
  2670. checkCompiled("Project2", "ClassAExtender");
  2671. alter("Project2", "inc1"); // New type that depends on ClassAExtender
  2672. build("Project1");
  2673. build("Project2");
  2674. checkWasntFullBuild(); // Just build ClassAExtenderExtender
  2675. alter("Project1", "inc4"); // another structural change to ClassA
  2676. build("Project1");
  2677. setNextChangeResponse("Project2", ICompilerConfiguration.EVERYTHING); // See
  2678. // pr245566
  2679. // comment
  2680. // 3
  2681. build("Project2");
  2682. checkWasntFullBuild(); // Should rebuild ClassAExtender and
  2683. // ClassAExtenderExtender
  2684. checkCompileWeaveCount("Project2", 2, 2);
  2685. checkCompiled("Project2", "ClassAExtenderExtender");
  2686. }
  2687. private void checkCompiled(String projectName, String typeNameSubstring) {
  2688. List<String> files = getCompiledFiles(projectName);
  2689. boolean found = false;
  2690. for (String object: files) {
  2691. if (object.indexOf(typeNameSubstring) != -1) {
  2692. found = true;
  2693. }
  2694. }
  2695. assertTrue("Did not find '" + typeNameSubstring + "' in list of compiled files", found);
  2696. }
  2697. // Case001: renaming a private field in a type
  2698. /*
  2699. * public void testPrReducingDependentBuilds_001_221427() { AjdeInteractionTestbed.VERBOSE=true;
  2700. * IncrementalStateManager.debugIncrementalStates=true; initialiseProject("P221427_1"); initialiseProject("P221427_2");
  2701. * configureNewProjectDependency("P221427_2","P221427_1");
  2702. *
  2703. * build("P221427_1"); build("P221427_2"); alter("P221427_1","inc1"); // rename private class in super project
  2704. * MyStateListener.reset(); build("P221427_1"); build("P221427_2");
  2705. *
  2706. * AjState ajs = IncrementalStateManager.findStateManagingOutputLocation(new File(getFile("P221427_1","bin")));
  2707. * assertTrue("There should be state for project P221427_1",ajs!=null);
  2708. * //System.out.println(MyStateListener.getInstance().getDecisions()); checkWasntFullBuild();
  2709. * assertTrue("Should be one structural change but there were "+ ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  2710. * ajs.getNumberOfStructuralChangesSinceLastFullBuild()==1);
  2711. *
  2712. * }
  2713. *
  2714. * // Case002: changing a class to final that is extended in a dependent project public void
  2715. * testPrReducingDependentBuilds_002_221427() { AjdeInteractionTestbed.VERBOSE=true;
  2716. * IncrementalStateManager.debugIncrementalStates=true; initialiseProject("P221427_3"); initialiseProject("P221427_4");
  2717. * configureNewProjectDependency("P221427_4","P221427_3");
  2718. *
  2719. * build("P221427_3"); build("P221427_4"); // build OK, type in super project is non-final alter("P221427_3","inc1"); // change
  2720. * class declaration in super-project to final MyStateListener.reset(); build("P221427_3"); build("P221427_4"); // build FAIL,
  2721. * type in super project is now final
  2722. *
  2723. * AjState ajs = IncrementalStateManager.findStateManagingOutputLocation(new File(getFile("P221427_3","bin")));
  2724. * assertTrue("There should be state for project P221427_3",ajs!=null);
  2725. * System.out.println(MyStateListener.getInstance().getDecisions());
  2726. *
  2727. * List errors = getErrorMessages("P221427_4"); if (errors.size()!=1) { if (errors.size()==0)
  2728. * fail("Expected error about not being able to extend final class"); for (Iterator iterator = errors.iterator();
  2729. * iterator.hasNext();) { Object object = (Object) iterator.next(); System.out.println(object); }
  2730. * fail("Expected 1 error but got "+errors.size()); } // assertTrue("Shouldn't be one structural change but there were "+ //
  2731. * ajs.getNumberOfStructuralChangesSinceLastFullBuild(), // ajs.getNumberOfStructuralChangesSinceLastFullBuild()==1);
  2732. *
  2733. * }
  2734. */
  2735. // test for comment #6 - simulates AJDT core builder test testBug99133a -
  2736. // changing the contents of a method within a class shouldn't force a
  2737. // full build of a dependant project. To force this to behave like AJDT
  2738. // 'inc1' of the dependant project should just be a copy of 'base' so that
  2739. // AjState thinks somethings changed within the dependant project and
  2740. // we do a build. Similarly, 'inc1' of the project depended on should
  2741. // include the aspect even though nothing's changed within it. This causes
  2742. // AjState to think that the aspect has changed. Together its then up to
  2743. // logic within CrosscuttingMembers and various equals methods to decide
  2744. // correctly that we don't have to go back to source.
  2745. public void testPr129163_3() {
  2746. initialiseProject("PR129163_4");
  2747. build("PR129163_4");
  2748. checkWasFullBuild(); // should be a full build because initializing
  2749. // project
  2750. initialiseProject("PR129163_3");
  2751. configureNewProjectDependency("PR129163_3", "PR129163_4");
  2752. build("PR129163_3");
  2753. checkWasFullBuild(); // should be a full build because initializing
  2754. // project
  2755. alter("PR129163_4", "inc1");
  2756. build("PR129163_4");
  2757. checkWasntFullBuild(); // should be an incremental build because
  2758. // although
  2759. // "inc1" includes the aspect A1.aj, it actually hasn't
  2760. // changed so we shouldn't go back to source
  2761. alter("PR129163_3", "inc1");
  2762. build("PR129163_3");
  2763. checkWasntFullBuild(); // should be an incremental build because nothing
  2764. // has
  2765. // changed within the class and no aspects have changed
  2766. // within the running of the test
  2767. }
  2768. public void testPr133117() {
  2769. // System.gc();
  2770. // System.exit();
  2771. initialiseProject("PR133117");
  2772. configureNonStandardCompileOptions("PR133117", "-Xlint:warning");
  2773. build("PR133117");
  2774. assertTrue("There should only be one xlint warning message reported:\n" + getWarningMessages("PR133117"),
  2775. getWarningMessages("PR133117").size() == 1);
  2776. alter("PR133117", "inc1");
  2777. build("PR133117");
  2778. List<IMessage> warnings = getWarningMessages("PR133117");
  2779. List<IMessage> noGuardWarnings = new ArrayList<>();
  2780. for (IMessage warning: warnings) {
  2781. if (warning.getMessage().indexOf("Xlint:noGuardForLazyTjp") != -1) {
  2782. noGuardWarnings.add(warning);
  2783. }
  2784. }
  2785. assertTrue("There should only be two Xlint:noGuardForLazyTjp warning message reported:\n" + noGuardWarnings,
  2786. noGuardWarnings.size() == 2);
  2787. }
  2788. public void testPr131505() {
  2789. initialiseProject("PR131505");
  2790. configureNonStandardCompileOptions("PR131505", "-outxml");
  2791. build("PR131505");
  2792. checkWasFullBuild();
  2793. String outputDir = getWorkingDir().getAbsolutePath() + File.separatorChar + "PR131505" + File.separatorChar + "bin";
  2794. // aop.xml file shouldn't contain any aspects
  2795. checkXMLAspectCount("PR131505", "", 0, outputDir);
  2796. // add a new aspect A which should be included in the aop.xml file
  2797. alter("PR131505", "inc1");
  2798. build("PR131505");
  2799. checkWasFullBuild();
  2800. checkXMLAspectCount("PR131505", "", 1, outputDir);
  2801. checkXMLAspectCount("PR131505", "A", 1, outputDir);
  2802. // make changes to the class file which shouldn't affect the contents
  2803. // of the aop.xml file
  2804. alter("PR131505", "inc2");
  2805. build("PR131505");
  2806. checkWasntFullBuild();
  2807. checkXMLAspectCount("PR131505", "", 1, outputDir);
  2808. checkXMLAspectCount("PR131505", "A", 1, outputDir);
  2809. // add another new aspect A1 which should also be included in the
  2810. // aop.xml file
  2811. // ...there should be no duplicate entries in the file
  2812. alter("PR131505", "inc3");
  2813. build("PR131505");
  2814. checkWasFullBuild();
  2815. checkXMLAspectCount("PR131505", "", 2, outputDir);
  2816. checkXMLAspectCount("PR131505", "A1", 1, outputDir);
  2817. checkXMLAspectCount("PR131505", "A", 1, outputDir);
  2818. // delete aspect A1 which meanss that aop.xml file should only contain A
  2819. File a1 = new File(getWorkingDir().getAbsolutePath() + File.separatorChar + "PR131505" + File.separatorChar + "A1.aj");
  2820. a1.delete();
  2821. build("PR131505");
  2822. checkWasFullBuild();
  2823. checkXMLAspectCount("PR131505", "", 1, outputDir);
  2824. checkXMLAspectCount("PR131505", "A1", 0, outputDir);
  2825. checkXMLAspectCount("PR131505", "A", 1, outputDir);
  2826. // add another aspect called A which is in a different package, both A
  2827. // and pkg.A should be included in the aop.xml file
  2828. alter("PR131505", "inc4");
  2829. build("PR131505");
  2830. checkWasFullBuild();
  2831. checkXMLAspectCount("PR131505", "", 2, outputDir);
  2832. checkXMLAspectCount("PR131505", "A", 1, outputDir);
  2833. checkXMLAspectCount("PR131505", "pkg.A", 1, outputDir);
  2834. }
  2835. public void testPr136585() {
  2836. initialiseProject("PR136585");
  2837. build("PR136585");
  2838. alter("PR136585", "inc1");
  2839. build("PR136585");
  2840. assertTrue("There should be no errors reported:\n" + getErrorMessages("PR136585"), getErrorMessages("PR136585").isEmpty());
  2841. }
  2842. public void testPr133532() {
  2843. initialiseProject("PR133532");
  2844. build("PR133532");
  2845. alter("PR133532", "inc1");
  2846. build("PR133532");
  2847. alter("PR133532", "inc2");
  2848. build("PR133532");
  2849. assertTrue("There should be no errors reported:\n" + getErrorMessages("PR133532"), getErrorMessages("PR133532").isEmpty());
  2850. }
  2851. public void testPr133532_2() {
  2852. initialiseProject("pr133532_2");
  2853. build("pr133532_2");
  2854. alter("pr133532_2", "inc2");
  2855. build("pr133532_2");
  2856. assertTrue("There should be no errors reported:\n" + getErrorMessages("pr133532_2"), getErrorMessages("pr133532_2")
  2857. .isEmpty());
  2858. String decisions = AjdeInteractionTestbed.MyStateListener.getDecisions();
  2859. String expect = "Need to recompile 'A.aj'";
  2860. assertTrue("Couldn't find build decision: '" + expect + "' in the list of decisions made:\n" + decisions,
  2861. decisions.indexOf(expect) != -1);
  2862. }
  2863. public void testPr133532_3() {
  2864. initialiseProject("PR133532_3");
  2865. build("PR133532_3");
  2866. alter("PR133532_3", "inc1");
  2867. build("PR133532_3");
  2868. assertTrue("There should be no errors reported:\n" + getErrorMessages("PR133532_3"), getErrorMessages("PR133532_3")
  2869. .isEmpty());
  2870. }
  2871. public void testPr134541() {
  2872. initialiseProject("PR134541");
  2873. build("PR134541");
  2874. assertEquals("[Xlint:adviceDidNotMatch] should be associated with line 5", 5, (getWarningMessages("PR134541").get(0))
  2875. .getSourceLocation().getLine());
  2876. alter("PR134541", "inc1");
  2877. build("PR134541");
  2878. // if (getModelFor("PR134541").getHandleProvider().dependsOnLocation())
  2879. // checkWasFullBuild(); // the line number has changed... but nothing
  2880. // // structural about the code
  2881. // else
  2882. checkWasntFullBuild(); // the line number has changed... but nothing
  2883. // structural about the code
  2884. assertEquals("[Xlint:adviceDidNotMatch] should now be associated with line 7", 7, (getWarningMessages("PR134541").get(0))
  2885. .getSourceLocation().getLine());
  2886. }
  2887. public void testJDTLikeHandleProviderWithLstFile_pr141730() {
  2888. // IElementHandleProvider handleProvider =
  2889. // AsmManager.getDefault().getHandleProvider();
  2890. // AsmManager.getDefault().setHandleProvider(new
  2891. // JDTLikeHandleProvider());
  2892. // try {
  2893. // The JDTLike-handles should start with the name
  2894. // of the buildconfig file
  2895. initialiseProject("JDTLikeHandleProvider");
  2896. build("JDTLikeHandleProvider");
  2897. IHierarchy top = getModelFor("JDTLikeHandleProvider").getHierarchy();
  2898. IProgramElement pe = top.findElementForType("pkg", "A");
  2899. String expectedHandle = "=JDTLikeHandleProvider<pkg*A.aj'A";
  2900. assertEquals("expected handle to be " + expectedHandle + ", but found " + pe.getHandleIdentifier(), expectedHandle,
  2901. pe.getHandleIdentifier());
  2902. // } finally {
  2903. // AsmManager.getDefault().setHandleProvider(handleProvider);
  2904. // }
  2905. }
  2906. public void testMovingAdviceDoesntChangeHandles_pr141730() {
  2907. // IElementHandleProvider handleProvider =
  2908. // AsmManager.getDefault().getHandleProvider();
  2909. // AsmManager.getDefault().setHandleProvider(new
  2910. // JDTLikeHandleProvider());
  2911. // try {
  2912. initialiseProject("JDTLikeHandleProvider");
  2913. build("JDTLikeHandleProvider");
  2914. checkWasFullBuild();
  2915. IHierarchy top = getModelFor("JDTLikeHandleProvider").getHierarchy();
  2916. IProgramElement pe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.ADVICE, "before(): <anonymous pointcut>");
  2917. // add a line which shouldn't change the handle
  2918. alter("JDTLikeHandleProvider", "inc1");
  2919. build("JDTLikeHandleProvider");
  2920. checkWasntFullBuild();
  2921. IHierarchy top2 = getModelFor("JDTLikeHandleProvider").getHierarchy();
  2922. IProgramElement pe2 = top
  2923. .findElementForLabel(top2.getRoot(), IProgramElement.Kind.ADVICE, "before(): <anonymous pointcut>");
  2924. assertEquals("expected advice to be on line " + pe.getSourceLocation().getLine() + 1 + " but was on "
  2925. + pe2.getSourceLocation().getLine(), pe.getSourceLocation().getLine() + 1, pe2.getSourceLocation().getLine());
  2926. assertEquals(
  2927. "expected advice to have handle " + pe.getHandleIdentifier() + " but found handle " + pe2.getHandleIdentifier(),
  2928. pe.getHandleIdentifier(), pe2.getHandleIdentifier());
  2929. // } finally {
  2930. // AsmManager.getDefault().setHandleProvider(handleProvider);
  2931. // }
  2932. }
  2933. public void testSwappingAdviceAndHandles_pr141730() {
  2934. // IElementHandleProvider handleProvider =
  2935. // AsmManager.getDefault().getHandleProvider();
  2936. // AsmManager.getDefault().setHandleProvider(new
  2937. // JDTLikeHandleProvider());
  2938. // try {
  2939. initialiseProject("JDTLikeHandleProvider");
  2940. build("JDTLikeHandleProvider");
  2941. IHierarchy top = getModelFor("JDTLikeHandleProvider").getHierarchy();
  2942. IProgramElement call = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.ADVICE, "after(): callPCD..");
  2943. IProgramElement exec = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.ADVICE, "after(): execPCD..");
  2944. // swap the two after advice statements over. This forces
  2945. // a full build which means 'after(): callPCD..' will now
  2946. // be the second after advice in the file and have the same
  2947. // handle as 'after(): execPCD..' originally did.
  2948. alter("JDTLikeHandleProvider", "inc2");
  2949. build("JDTLikeHandleProvider");
  2950. checkWasFullBuild();
  2951. IHierarchy top2 = getModelFor("JDTLikeHandleProvider").getHierarchy();
  2952. IProgramElement newCall = top2.findElementForLabel(top2.getRoot(), IProgramElement.Kind.ADVICE, "after(): callPCD..");
  2953. IProgramElement newExec = top2.findElementForLabel(top2.getRoot(), IProgramElement.Kind.ADVICE, "after(): execPCD..");
  2954. assertEquals("after swapping places, expected 'after(): callPCD..' " + "to be on line "
  2955. + newExec.getSourceLocation().getLine() + " but was on line " + call.getSourceLocation().getLine(), newExec
  2956. .getSourceLocation().getLine(), call.getSourceLocation().getLine());
  2957. assertEquals("after swapping places, expected 'after(): callPCD..' " + "to have handle " + exec.getHandleIdentifier()
  2958. + " (because was full build) but had " + newCall.getHandleIdentifier(), exec.getHandleIdentifier(),
  2959. newCall.getHandleIdentifier());
  2960. // } finally {
  2961. // AsmManager.getDefault().setHandleProvider(handleProvider);
  2962. // }
  2963. }
  2964. public void testInitializerCountForJDTLikeHandleProvider_pr141730() {
  2965. // IElementHandleProvider handleProvider =
  2966. // AsmManager.getDefault().getHandleProvider();
  2967. // AsmManager.getDefault().setHandleProvider(new
  2968. // JDTLikeHandleProvider());
  2969. // try {
  2970. initialiseProject("JDTLikeHandleProvider");
  2971. build("JDTLikeHandleProvider");
  2972. String expected = "=JDTLikeHandleProvider<pkg*A.aj[C|1";
  2973. IHierarchy top = getModelFor("JDTLikeHandleProvider").getHierarchy();
  2974. IProgramElement init = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.INITIALIZER, "...");
  2975. assertEquals("expected initializers handle to be " + expected + "," + " but found " + init.getHandleIdentifier(true),
  2976. expected, init.getHandleIdentifier(true));
  2977. alter("JDTLikeHandleProvider", "inc2");
  2978. build("JDTLikeHandleProvider");
  2979. checkWasFullBuild();
  2980. IHierarchy top2 = getModelFor("JDTLikeHandleProvider").getHierarchy();
  2981. IProgramElement init2 = top2.findElementForLabel(top2.getRoot(), IProgramElement.Kind.INITIALIZER, "...");
  2982. assertEquals(
  2983. "expected initializers handle to still be " + expected + "," + " but found " + init2.getHandleIdentifier(true),
  2984. expected, init2.getHandleIdentifier(true));
  2985. // } finally {
  2986. // AsmManager.getDefault().setHandleProvider(handleProvider);
  2987. // }
  2988. }
  2989. // 134471 related tests perform incremental compilation and verify features
  2990. // of the structure model post compile
  2991. public void testPr134471_IncrementalCompilationAndModelUpdates() {
  2992. try {
  2993. // see pr148027 AsmHierarchyBuilder.shouldAddUsesPointcut=false;
  2994. // Step1. Build the code, simple advice from aspect A onto class C
  2995. initialiseProject("PR134471");
  2996. configureNonStandardCompileOptions("PR134471", "-showWeaveInfo -emacssym");
  2997. configureShowWeaveInfoMessages("PR134471", true);
  2998. build("PR134471");
  2999. AsmManager model = getModelFor("PR134471");
  3000. // Step2. Quick check that the advice points to something...
  3001. IProgramElement nodeForTypeA = checkForNode(model, "pkg", "A", true);
  3002. IProgramElement nodeForAdvice = findAdvice(nodeForTypeA);
  3003. List<String> relatedElements = getRelatedElements(model, nodeForAdvice, 1);
  3004. // Step3. Check the advice applying at the first 'code' join point
  3005. // in pkg.C is from aspect pkg.A, line 7
  3006. IProgramElement programElement = getFirstRelatedElement(model, findCode(checkForNode(model, "pkg", "C", true)));
  3007. int line = programElement.getSourceLocation().getLine();
  3008. assertTrue("advice should be at line 7 - but is at line " + line, line == 7);
  3009. // Step4. Simulate the aspect being saved but with no change at all
  3010. // in it
  3011. alter("PR134471", "inc1");
  3012. build("PR134471");
  3013. model = getModelFor("PR134471");
  3014. // Step5. Quick check that the advice points to something...
  3015. nodeForTypeA = checkForNode(model, "pkg", "A", true);
  3016. nodeForAdvice = findAdvice(nodeForTypeA);
  3017. relatedElements = getRelatedElements(model, nodeForAdvice, 1);
  3018. // Step6. Check the advice applying at the first 'code' join point
  3019. // in pkg.C is from aspect pkg.A, line 7
  3020. programElement = getFirstRelatedElement(model, findCode(checkForNode(model, "pkg", "C", true)));
  3021. line = programElement.getSourceLocation().getLine();
  3022. assertTrue("advice should be at line 7 - but is at line " + line, line == 7);
  3023. } finally {
  3024. // see pr148027 AsmHierarchyBuilder.shouldAddUsesPointcut=true;
  3025. }
  3026. }
  3027. // now the advice moves down a few lines - hopefully the model will
  3028. // notice... see discussion in 134471
  3029. public void testPr134471_MovingAdvice() {
  3030. // Step1. build the project
  3031. initialiseProject("PR134471_2");
  3032. configureNonStandardCompileOptions("PR134471_2", "-showWeaveInfo -emacssym");
  3033. configureShowWeaveInfoMessages("PR134471_2", true);
  3034. build("PR134471_2");
  3035. AsmManager model = getModelFor("PR134471_2");
  3036. // Step2. confirm advice is from correct location
  3037. IProgramElement programElement = getFirstRelatedElement(model, findCode(checkForNode(model, "pkg", "C", true)));
  3038. int line = programElement.getSourceLocation().getLine();
  3039. assertTrue("advice should be at line 7 - but is at line " + line, line == 7);
  3040. // Step3. No structural change to the aspect but the advice has moved
  3041. // down a few lines... (change in source location)
  3042. alter("PR134471_2", "inc1");
  3043. build("PR134471_2");
  3044. model = getModelFor("PR134471_2");
  3045. checkWasntFullBuild(); // the line number has changed... but nothing
  3046. // structural about the code
  3047. // checkWasFullBuild(); // this is true whilst we consider
  3048. // sourcelocation in the type/shadow munger equals() method - have
  3049. // to until the handles are independent of location
  3050. // Step4. Check we have correctly realised the advice moved to line 11
  3051. programElement = getFirstRelatedElement(model, findCode(checkForNode(model, "pkg", "C", true)));
  3052. line = programElement.getSourceLocation().getLine();
  3053. assertTrue("advice should be at line 11 - but is at line " + line, line == 11);
  3054. }
  3055. public void testAddingAndRemovingDecwWithStructureModel() {
  3056. initialiseProject("P3");
  3057. build("P3");
  3058. alter("P3", "inc1");
  3059. build("P3");
  3060. assertTrue("There should be no exceptions handled:\n" + getCompilerErrorMessages("P3"), getCompilerErrorMessages("P3")
  3061. .isEmpty());
  3062. alter("P3", "inc2");
  3063. build("P3");
  3064. assertTrue("There should be no exceptions handled:\n" + getCompilerErrorMessages("P3"), getCompilerErrorMessages("P3")
  3065. .isEmpty());
  3066. }
  3067. // same as first test with an extra stage that asks for C to be recompiled,
  3068. // it should still be advised...
  3069. public void testPr134471_IncrementallyRecompilingTheAffectedClass() {
  3070. try {
  3071. // see pr148027 AsmHierarchyBuilder.shouldAddUsesPointcut=false;
  3072. // Step1. build the project
  3073. initialiseProject("PR134471");
  3074. configureNonStandardCompileOptions("PR134471", "-showWeaveInfo -emacssym");
  3075. configureShowWeaveInfoMessages("PR134471", true);
  3076. build("PR134471");
  3077. AsmManager model = getModelFor("PR134471");
  3078. // Step2. confirm advice is from correct location
  3079. IProgramElement programElement = getFirstRelatedElement(model, findCode(checkForNode(model, "pkg", "C", true)));
  3080. int line = programElement.getSourceLocation().getLine();
  3081. assertTrue("advice should be at line 7 - but is at line " + line, line == 7);
  3082. // Step3. No change to the aspect at all
  3083. alter("PR134471", "inc1");
  3084. build("PR134471");
  3085. model = getModelFor("PR134471");
  3086. // Step4. Quick check that the advice points to something...
  3087. IProgramElement nodeForTypeA = checkForNode(model, "pkg", "A", true);
  3088. IProgramElement nodeForAdvice = findAdvice(nodeForTypeA);
  3089. List<String> relatedElements = getRelatedElements(model, nodeForAdvice, 1);
  3090. // Step5. No change to the file C but it should still be advised
  3091. // afterwards
  3092. alter("PR134471", "inc2");
  3093. build("PR134471");
  3094. checkWasntFullBuild();
  3095. model = getModelFor("PR134471");
  3096. // Step6. confirm advice is from correct location
  3097. programElement = getFirstRelatedElement(model, findCode(checkForNode(model, "pkg", "C", true)));
  3098. line = programElement.getSourceLocation().getLine();
  3099. assertTrue("advice should be at line 7 - but is at line " + line, line == 7);
  3100. } finally {
  3101. // see pr148027 AsmHierarchyBuilder.shouldAddUsesPointcut=true;
  3102. }
  3103. }
  3104. // similar to previous test but with 'declare warning' as well as advice
  3105. public void testPr134471_IncrementallyRecompilingAspectContainingDeclare() {
  3106. // Step1. build the project
  3107. initialiseProject("PR134471_3");
  3108. configureNonStandardCompileOptions("PR134471_3", "-showWeaveInfo -emacssym");
  3109. configureShowWeaveInfoMessages("PR134471_3", true);
  3110. build("PR134471_3");
  3111. checkWasFullBuild();
  3112. AsmManager model = getModelFor("PR134471_3");
  3113. // Step2. confirm declare warning is from correct location, decw matches
  3114. // line 7 in pkg.C
  3115. IProgramElement programElement = getFirstRelatedElement(model, findCode(checkForNode(model, "pkg", "C", true), 7));
  3116. int line = programElement.getSourceLocation().getLine();
  3117. assertTrue("declare warning should be at line 10 - but is at line " + line, line == 10);
  3118. // Step3. confirm advice is from correct location, advice matches line 6
  3119. // in pkg.C
  3120. programElement = getFirstRelatedElement(model, findCode(checkForNode(model, "pkg", "C", true), 6));
  3121. line = programElement.getSourceLocation().getLine();
  3122. assertTrue("advice should be at line 7 - but is at line " + line, line == 7);
  3123. // Step4. Move declare warning in the aspect
  3124. alter("PR134471_3", "inc1");
  3125. build("PR134471_3");
  3126. model = getModelFor("PR134471_3");
  3127. checkWasntFullBuild(); // the line number has changed... but nothing
  3128. // structural about the code
  3129. // checkWasFullBuild();
  3130. // Step5. confirm declare warning is from correct location, decw (now at
  3131. // line 12) in pkg.A matches line 7 in pkg.C
  3132. programElement = getFirstRelatedElement(model, findCode(checkForNode(model, "pkg", "C", true), 7));
  3133. line = programElement.getSourceLocation().getLine();
  3134. assertTrue("declare warning should be at line 12 - but is at line " + line, line == 12);
  3135. // Step6. Now just simulate 'resave' of the aspect, nothing has changed
  3136. alter("PR134471_3", "inc2");
  3137. build("PR134471_3");
  3138. checkWasntFullBuild();
  3139. model = getModelFor("PR134471_3");
  3140. // Step7. confirm declare warning is from correct location, decw (now at
  3141. // line 12) in pkg.A matches line 7 in pkg.C
  3142. programElement = getFirstRelatedElement(model, findCode(checkForNode(model, "pkg", "C", true), 7));
  3143. line = programElement.getSourceLocation().getLine();
  3144. assertTrue("declare warning should be at line 12 - but is at line " + line, line == 12);
  3145. }
  3146. // similar to previous test but with 'declare warning' as well as advice
  3147. public void testPr134471_IncrementallyRecompilingTheClassAffectedByDeclare() {
  3148. // Step1. build the project
  3149. initialiseProject("PR134471_3");
  3150. configureNonStandardCompileOptions("PR134471_3", "-showWeaveInfo -emacssym");
  3151. configureShowWeaveInfoMessages("PR134471_3", true);
  3152. build("PR134471_3");
  3153. checkWasFullBuild();
  3154. AsmManager model = getModelFor("PR134471_3");
  3155. // Step2. confirm declare warning is from correct location, decw matches
  3156. // line 7 in pkg.C
  3157. IProgramElement programElement = getFirstRelatedElement(model, findCode(checkForNode(model, "pkg", "C", true), 7));
  3158. int line = programElement.getSourceLocation().getLine();
  3159. assertTrue("declare warning should be at line 10 - but is at line " + line, line == 10);
  3160. // Step3. confirm advice is from correct location, advice matches line 6
  3161. // in pkg.C
  3162. programElement = getFirstRelatedElement(model, findCode(checkForNode(model, "pkg", "C", true), 6));
  3163. line = programElement.getSourceLocation().getLine();
  3164. assertTrue("advice should be at line 7 - but is at line " + line, line == 7);
  3165. // Step4. Move declare warning in the aspect
  3166. alter("PR134471_3", "inc1");
  3167. build("PR134471_3");
  3168. model = getModelFor("PR134471_3");
  3169. checkWasntFullBuild(); // the line number has changed... but nothing
  3170. // structural about the code
  3171. // checkWasFullBuild();
  3172. // Step5. confirm declare warning is from correct location, decw (now at
  3173. // line 12) in pkg.A matches line 7 in pkg.C
  3174. programElement = getFirstRelatedElement(model, findCode(checkForNode(model, "pkg", "C", true), 7));
  3175. line = programElement.getSourceLocation().getLine();
  3176. assertTrue("declare warning should be at line 12 - but is at line " + line, line == 12);
  3177. // Step6. Now just simulate 'resave' of the aspect, nothing has changed
  3178. alter("PR134471_3", "inc2");
  3179. build("PR134471_3");
  3180. checkWasntFullBuild();
  3181. model = getModelFor("PR134471_3");
  3182. // Step7. confirm declare warning is from correct location, decw (now at
  3183. // line 12) in pkg.A matches line 7 in pkg.C
  3184. programElement = getFirstRelatedElement(model, findCode(checkForNode(model, "pkg", "C", true), 7));
  3185. line = programElement.getSourceLocation().getLine();
  3186. assertTrue("declare warning should be at line 12 - but is at line " + line, line == 12);
  3187. // Step8. Now just simulate resave of the pkg.C type - no change at
  3188. // all... are relationships gonna be repaired OK?
  3189. alter("PR134471_3", "inc3");
  3190. build("PR134471_3");
  3191. checkWasntFullBuild();
  3192. // Step9. confirm declare warning is from correct location, decw (now at
  3193. // line 12) in pkg.A matches line 7 in pkg.C
  3194. programElement = getFirstRelatedElement(model, findCode(checkForNode(model, "pkg", "C", true), 7));
  3195. line = programElement.getSourceLocation().getLine();
  3196. assertTrue("declare warning should be at line 12 - but is at line " + line, line == 12);
  3197. }
  3198. public void testDontLoseXlintWarnings_pr141556() {
  3199. initialiseProject("PR141556");
  3200. configureNonStandardCompileOptions("PR141556", "-Xlint:warning");
  3201. build("PR141556");
  3202. checkWasFullBuild();
  3203. String warningMessage = "can not build thisJoinPoint " + "lazily for this advice since it has no suitable guard "
  3204. + "[Xlint:noGuardForLazyTjp]";
  3205. assertEquals("warning message should be '" + warningMessage + "'", warningMessage,
  3206. (getWarningMessages("PR141556").get(0)).getMessage());
  3207. // add a space to the Aspect but dont do a build
  3208. alter("PR141556", "inc1");
  3209. // remove the space so that the Aspect is exactly as it was
  3210. alter("PR141556", "inc2");
  3211. // build the project and we should not have lost the xlint warning
  3212. build("PR141556");
  3213. checkWasntFullBuild();
  3214. assertTrue("there should still be a warning message ", !getWarningMessages("PR141556").isEmpty());
  3215. assertEquals("warning message should be '" + warningMessage + "'", warningMessage,
  3216. (getWarningMessages("PR141556").get(0)).getMessage());
  3217. }
  3218. public void testAdviceDidNotMatch_pr152589() {
  3219. initialiseProject("PR152589");
  3220. build("PR152589");
  3221. List<IMessage> warnings = getWarningMessages("PR152589");
  3222. assertTrue("There should be no warnings:\n" + warnings, warnings.isEmpty());
  3223. alter("PR152589", "inc1");
  3224. build("PR152589");
  3225. checkWasntFullBuild(); // the line number has changed... but nothing
  3226. // structural about the code
  3227. // checkWasFullBuild();
  3228. warnings = getWarningMessages("PR152589");
  3229. assertTrue("There should be no warnings after adding a whitespace:\n" + warnings, warnings.isEmpty());
  3230. }
  3231. // see comment #11 of bug 154054
  3232. public void testNoFullBuildOnChangeInSysOutInAdviceBody_pr154054() {
  3233. initialiseProject("PR154054");
  3234. build("PR154054");
  3235. alter("PR154054", "inc1");
  3236. build("PR154054");
  3237. checkWasntFullBuild();
  3238. }
  3239. public void testIncrementalBuildAdviceChange_456801() throws Exception {
  3240. initialiseProject("456801");
  3241. build("456801");
  3242. String output = runMethod("456801", "Code", "run");
  3243. assertEquals("advice runnning\nrun() running\n",output);
  3244. alter("456801", "inc1");
  3245. build("456801");
  3246. output = runMethod("456801", "Code", "run");
  3247. assertEquals("advice running\nrun() running\n",output);
  3248. checkCompileWeaveCount("456801", 1, 1);
  3249. checkWasntFullBuild();
  3250. }
  3251. // change exception type in around advice, does it notice?
  3252. public void testShouldFullBuildOnExceptionChange_pr154054() {
  3253. initialiseProject("PR154054_2");
  3254. build("PR154054_2");
  3255. alter("PR154054_2", "inc1");
  3256. build("PR154054_2");
  3257. checkWasFullBuild();
  3258. }
  3259. public void testPR158573() {
  3260. // IElementHandleProvider handleProvider =
  3261. // AsmManager.getDefault().getHandleProvider();
  3262. // AsmManager.getDefault().setHandleProvider(new
  3263. // JDTLikeHandleProvider());
  3264. initialiseProject("PR158573");
  3265. build("PR158573");
  3266. List warnings = getWarningMessages("PR158573");
  3267. assertTrue("There should be no warnings:\n" + warnings, warnings.isEmpty());
  3268. alter("PR158573", "inc1");
  3269. build("PR158573");
  3270. checkWasntFullBuild();
  3271. warnings = getWarningMessages("PR158573");
  3272. assertTrue("There should be no warnings after changing the value of a " + "variable:\n" + warnings, warnings.isEmpty());
  3273. // AsmManager.getDefault().setHandleProvider(handleProvider);
  3274. }
  3275. /**
  3276. * If the user has specified that they want Java 6 compliance and kept the default classfile and source file level settings
  3277. * (also 6.0) then expect an error saying that we don't support java 6.
  3278. */
  3279. public void testPR164384_1() {
  3280. initialiseProject("PR164384");
  3281. Hashtable<String, String> javaOptions = new Hashtable<String, String>();
  3282. javaOptions.put("org.eclipse.jdt.core.compiler.compliance", "1.6");
  3283. javaOptions.put("org.eclipse.jdt.core.compiler.codegen.targetPlatform", "1.6");
  3284. javaOptions.put("org.eclipse.jdt.core.compiler.source", "1.6");
  3285. configureJavaOptionsMap("PR164384", javaOptions);
  3286. build("PR164384");
  3287. List<IMessage> errors = getErrorMessages("PR164384");
  3288. if (getCompilerForProjectWithName("PR164384").isJava6Compatible()) {
  3289. assertTrue("There should be no errors:\n" + errors, errors.isEmpty());
  3290. } else {
  3291. String expectedError = "Java 6.0 compliance level is unsupported";
  3292. String found = ((IMessage) errors.get(0)).getMessage();
  3293. assertEquals("Expected 'Java 6.0 compliance level is unsupported'" + " error message but found " + found,
  3294. expectedError, found);
  3295. // This is because the 'Java 6.0 compliance' error is an 'error'
  3296. // rather than an 'abort'. Aborts are really for compiler
  3297. // exceptions.
  3298. assertTrue("expected there to be more than the one compliance level" + " error but only found that one",
  3299. errors.size() > 1);
  3300. }
  3301. }
  3302. /**
  3303. * If the user has specified that they want Java 6 compliance and selected classfile and source file level settings to be 5.0
  3304. * then expect an error saying that we don't support java 6.
  3305. */
  3306. public void testPR164384_2() {
  3307. initialiseProject("PR164384");
  3308. Hashtable<String, String> javaOptions = new Hashtable<String, String>();
  3309. javaOptions.put("org.eclipse.jdt.core.compiler.compliance", "1.6");
  3310. javaOptions.put("org.eclipse.jdt.core.compiler.codegen.targetPlatform", "1.5");
  3311. javaOptions.put("org.eclipse.jdt.core.compiler.source", "1.5");
  3312. configureJavaOptionsMap("PR164384", javaOptions);
  3313. build("PR164384");
  3314. List<IMessage> errors = getErrorMessages("PR164384");
  3315. if (getCompilerForProjectWithName("PR164384").isJava6Compatible()) {
  3316. assertTrue("There should be no errors:\n" + errors, errors.isEmpty());
  3317. } else {
  3318. String expectedError = "Java 6.0 compliance level is unsupported";
  3319. String found = ((IMessage) errors.get(0)).getMessage();
  3320. assertEquals("Expected 'Java 6.0 compliance level is unsupported'" + " error message but found " + found,
  3321. expectedError, found);
  3322. // This is because the 'Java 6.0 compliance' error is an 'error'
  3323. // rather than an 'abort'. Aborts are really for compiler
  3324. // exceptions.
  3325. assertTrue("expected there to be more than the one compliance level" + " error but only found that one",
  3326. errors.size() > 1);
  3327. }
  3328. }
  3329. /**
  3330. * If the user has specified that they want Java 6 compliance and set the classfile level to be 6.0 and source file level to be
  3331. * 5.0 then expect an error saying that we don't support java 6.
  3332. */
  3333. public void testPR164384_3() {
  3334. initialiseProject("PR164384");
  3335. Hashtable<String, String> javaOptions = new Hashtable<String, String>();
  3336. javaOptions.put("org.eclipse.jdt.core.compiler.compliance", "1.6");
  3337. javaOptions.put("org.eclipse.jdt.core.compiler.codegen.targetPlatform", "1.6");
  3338. javaOptions.put("org.eclipse.jdt.core.compiler.source", "1.5");
  3339. configureJavaOptionsMap("PR164384", javaOptions);
  3340. build("PR164384");
  3341. List<IMessage> errors = getErrorMessages("PR164384");
  3342. if (getCompilerForProjectWithName("PR164384").isJava6Compatible()) {
  3343. assertTrue("There should be no errros:\n" + errors, errors.isEmpty());
  3344. } else {
  3345. String expectedError = "Java 6.0 compliance level is unsupported";
  3346. String found = ((IMessage) errors.get(0)).getMessage();
  3347. assertEquals("Expected 'Java 6.0 compliance level is unsupported'" + " error message but found " + found,
  3348. expectedError, found);
  3349. // This is because the 'Java 6.0 compliance' error is an 'error'
  3350. // rather than an 'abort'. Aborts are really for compiler
  3351. // exceptions.
  3352. assertTrue("expected there to be more than the one compliance level" + " error but only found that one",
  3353. errors.size() > 1);
  3354. }
  3355. }
  3356. public void testPr168840() throws Exception {
  3357. initialiseProject("inpathTesting");
  3358. String inpathTestingDir = getWorkingDir() + File.separator + "inpathTesting";
  3359. String inpathDir = inpathTestingDir + File.separator + "injarBin" + File.separator + "pkg";
  3360. String expectedOutputDir = inpathTestingDir + File.separator + "bin";
  3361. // set up the inpath to have the directory on it's path
  3362. File f = new File(inpathDir);
  3363. Set<File> s = new HashSet<File>();
  3364. s.add(f);
  3365. configureInPath("inpathTesting", s);
  3366. build("inpathTesting");
  3367. // the declare warning matches one place so expect one warning message
  3368. List<IMessage> warnings = getWarningMessages("inpathTesting");
  3369. assertTrue("Expected there to be one warning message but found " + warnings.size() + ": " + warnings, warnings.size() == 1);
  3370. // copy over the updated version of the inpath class file
  3371. File from = new File(testdataSrcDir + File.separatorChar + "inpathTesting" + File.separatorChar + "newInpathClass"
  3372. + File.separatorChar + "InpathClass.class");
  3373. File destination = new File(inpathDir + File.separatorChar + "InpathClass.class");
  3374. FileUtil.copyFile(from, destination);
  3375. build("inpathTesting");
  3376. checkWasntFullBuild();
  3377. // the newly copied inpath class means the declare warning now matches
  3378. // two
  3379. // places, therefore expect two warning messages
  3380. warnings = getWarningMessages("inpathTesting");
  3381. assertTrue("Expected there to be two warning message but found " + warnings.size() + ": " + warnings, warnings.size() == 2);
  3382. }
  3383. // warning about cant change parents of Object is fine
  3384. public void testInpathHandles_271201() throws Exception {
  3385. AjdeInteractionTestbed.VERBOSE = true;
  3386. String p = "inpathHandles";
  3387. initialiseProject(p);
  3388. String inpathTestingDir = getWorkingDir() + File.separator + "inpathHandles";
  3389. String inpathDir = inpathTestingDir + File.separator + "binpath";
  3390. // set up the inpath to have the directory on it's path
  3391. System.out.println(inpathDir);
  3392. File f = new File(inpathDir);
  3393. Set<File> s = new HashSet<File>();
  3394. s.add(f);
  3395. configureInPath(p, s);
  3396. build(p);
  3397. IProgramElement root = getModelFor(p).getHierarchy().getRoot();
  3398. // alter(p,"inc1");
  3399. // build(p);
  3400. dumptree(root, 0);
  3401. PrintWriter pw = new PrintWriter(System.out);
  3402. try {
  3403. getModelFor(p).dumprels(pw);
  3404. pw.flush();
  3405. } catch (Exception e) {
  3406. }
  3407. List<IRelationship> l = getModelFor(p).getRelationshipMap().get("=inpathHandles/;<codep(Code.class[Code");
  3408. assertNotNull(l);
  3409. }
  3410. // warning about cant change parents of Object is fine
  3411. public void testInpathHandles_IncrementalCompilation_271201() throws Exception {
  3412. AjdeInteractionTestbed.VERBOSE = true;
  3413. String p = "inpathHandles";
  3414. initialiseProject(p);
  3415. String inpathTestingDir = getWorkingDir() + File.separator + "inpathHandles";
  3416. String inpathDir = inpathTestingDir + File.separator + "binpath";
  3417. // set up the inpath to have the directory on it's path
  3418. File f = new File(inpathDir);
  3419. Set<File> s = new HashSet<File>();
  3420. s.add(f);
  3421. configureInPath(p, s);
  3422. // This build will weave a declare parents into the inpath class codep.Code
  3423. build(p);
  3424. assertNotNull(getModelFor(p).getRelationshipMap().get("=inpathHandles/;<codep(Code.class[Code"));
  3425. IProgramElement root = getModelFor(p).getHierarchy().getRoot();
  3426. // This alteration introduces a new source file B.java, the build should not
  3427. // damage phantom handle based relationships
  3428. alter(p, "inc1");
  3429. build(p);
  3430. assertNotNull(getModelFor(p).getRelationshipMap().get("=inpathHandles/;<codep(Code.class[Code"));
  3431. assertNotNull(getModelFor(p).getRelationshipMap().get("=inpathHandles<p{B.java[B"));
  3432. // This alteration removes B.java, the build should not damage phantom handle based relationships
  3433. String fileB = getWorkingDir().getAbsolutePath() + File.separatorChar + "inpathHandles" + File.separatorChar + "src"
  3434. + File.separatorChar + "p" + File.separatorChar + "B.java";
  3435. (new File(fileB)).delete();
  3436. build(p);
  3437. assertNotNull(getModelFor(p).getRelationshipMap().get("=inpathHandles/;<codep(Code.class[Code"));
  3438. assertNull(getModelFor(p).getRelationshipMap().get("=inpathHandles<p{B.java[B"));
  3439. }
  3440. public void testInpathHandles_WithInpathMap_271201() throws Exception {
  3441. AjdeInteractionTestbed.VERBOSE = true;
  3442. String p = "inpathHandles";
  3443. initialiseProject(p);
  3444. String inpathTestingDir = getWorkingDir() + File.separator + "inpathHandles";
  3445. String inpathDir = inpathTestingDir + File.separator + "binpath";// + File.separator+ "codep";
  3446. // String expectedOutputDir = inpathTestingDir + File.separator + "bin";
  3447. // set up the inpath to have the directory on it's path
  3448. System.out.println(inpathDir);
  3449. File f = new File(inpathDir);
  3450. Set<File> s = new HashSet<File>();
  3451. s.add(f);
  3452. Map<File, String> m = new HashMap<File, String>();
  3453. m.put(f, "wibble");
  3454. configureOutputLocationManager(p, new TestOutputLocationManager(getProjectRelativePath(p, ".").toString(), m));
  3455. configureInPath(p, s);
  3456. build(p);
  3457. IProgramElement root = getModelFor(p).getHierarchy().getRoot();
  3458. // alter(p,"inc1");
  3459. // build(p);
  3460. dumptree(root, 0);
  3461. PrintWriter pw = new PrintWriter(System.out);
  3462. try {
  3463. getModelFor(p).dumprels(pw);
  3464. pw.flush();
  3465. } catch (Exception e) {
  3466. }
  3467. List<IRelationship> l = getModelFor(p).getRelationshipMap().get("=inpathHandles/;wibble<codep(Code.class[Code");
  3468. assertNotNull(l);
  3469. }
  3470. private void printModelAndRelationships(String p) {
  3471. IProgramElement root = getModelFor(p).getHierarchy().getRoot();
  3472. dumptree(root, 0);
  3473. PrintWriter pw = new PrintWriter(System.out);
  3474. try {
  3475. getModelFor(p).dumprels(pw);
  3476. pw.flush();
  3477. } catch (Exception e) {
  3478. }
  3479. }
  3480. public void testInpathHandles_IncrementalCompilation_RemovingInpathEntries_271201() throws Exception {
  3481. AjdeInteractionTestbed.VERBOSE = true;
  3482. String p = "inpathHandles2";
  3483. initialiseProject(p);
  3484. String inpathDir = getWorkingDir() + File.separator + "inpathHandles2" + File.separator + "binpath";
  3485. // set up the inpath to have the directory on it's path
  3486. File f = new File(inpathDir);
  3487. configureInPath(p, f);
  3488. // This build will weave a declare parents into the inpath class codep.A and codep.B
  3489. build(p);
  3490. assertNotNull(getModelFor(p).getRelationshipMap().get("=inpathHandles2/;<codep(A.class[A"));
  3491. // Not let us delete one of the inpath .class files
  3492. assertTrue(new File(inpathDir, "codep" + File.separator + "A.class").delete());
  3493. setNextChangeResponse(p, ICompilerConfiguration.EVERYTHING);
  3494. build(p);
  3495. // printModelAndRelationships(p);
  3496. }
  3497. // warning about cant change parents of Object is fine
  3498. // public void testInpathJars_271201() throws Exception {
  3499. // AjdeInteractionTestbed.VERBOSE = true;
  3500. // String p = "inpathJars";
  3501. // initialiseProject(p);
  3502. //
  3503. // String inpathTestingDir = getWorkingDir() + File.separator + "inpathJars";
  3504. // String inpathDir = inpathTestingDir + File.separator + "code.jar";
  3505. // // String expectedOutputDir = inpathTestingDir + File.separator + "bin";
  3506. //
  3507. // // set up the inpath to have the directory on it's path
  3508. // File f = new File(inpathDir);
  3509. // Set s = new HashSet();
  3510. // s.add(f);
  3511. // Map m = new HashMap();
  3512. // m.put(f, "Gibble");
  3513. // configureOutputLocationManager(p, new TestOutputLocationManager(getProjectRelativePath(p, ".").toString(), m));
  3514. // configureInPath(p, s);
  3515. // build(p);
  3516. //
  3517. // // alter(p,"inc1");
  3518. // // build(p);
  3519. // List l = getModelFor(p).getRelationshipMap().get("=inpathJars/,Gibble<codep(Code.class[Code");
  3520. // assertNotNull(l);
  3521. // }
  3522. // --- helper code ---
  3523. /**
  3524. * Retrieve program elements related to this one regardless of the relationship. A JUnit assertion is made that the number that
  3525. * the 'expected' number are found.
  3526. *
  3527. * @param programElement Program element whose related elements are to be found
  3528. * @param expected the number of expected related elements
  3529. */
  3530. private List<String> getRelatedElements(AsmManager model, IProgramElement programElement, int expected) {
  3531. List<String> relatedElements = getRelatedElements(model, programElement);
  3532. StringBuffer debugString = new StringBuffer();
  3533. if (relatedElements != null) {
  3534. for (String element : relatedElements) {
  3535. debugString.append(model.getHierarchy().findElementForHandle(element).toLabelString()).append("\n");
  3536. }
  3537. }
  3538. assertTrue("Should be " + expected + " element" + (expected > 1 ? "s" : "") + " related to this one '" + programElement
  3539. + "' but found :\n " + debugString, relatedElements != null && relatedElements.size() == 1);
  3540. return relatedElements;
  3541. }
  3542. private IProgramElement getFirstRelatedElement(AsmManager model, IProgramElement programElement) {
  3543. List<String> rels = getRelatedElements(model, programElement, 1);
  3544. return model.getHierarchy().findElementForHandle((String) rels.get(0));
  3545. }
  3546. private List<String> getRelatedElements(AsmManager model, IProgramElement advice) {
  3547. List<String> output = null;
  3548. IRelationshipMap map = model.getRelationshipMap();
  3549. List<IRelationship> rels = map.get(advice);
  3550. if (rels == null) {
  3551. fail("Did not find any related elements!");
  3552. }
  3553. for (Iterator<IRelationship> iter = rels.iterator(); iter.hasNext();) {
  3554. IRelationship element = iter.next();
  3555. List<String> targets = element.getTargets();
  3556. if (output == null) {
  3557. output = new ArrayList<String>();
  3558. }
  3559. output.addAll(targets);
  3560. }
  3561. return output;
  3562. }
  3563. private IProgramElement findAdvice(IProgramElement ipe) {
  3564. return findAdvice(ipe, 1);
  3565. }
  3566. private IProgramElement findAdvice(IProgramElement ipe, int whichOne) {
  3567. if (ipe.getKind() == IProgramElement.Kind.ADVICE) {
  3568. whichOne = whichOne - 1;
  3569. if (whichOne == 0) {
  3570. return ipe;
  3571. }
  3572. }
  3573. List<IProgramElement> kids = ipe.getChildren();
  3574. for (IProgramElement kid: kids) {
  3575. IProgramElement found = findAdvice(kid, whichOne);
  3576. if (found != null) {
  3577. return found;
  3578. }
  3579. }
  3580. return null;
  3581. }
  3582. /**
  3583. * Finds the first 'code' program element below the element supplied - will return null if there aren't any
  3584. */
  3585. private IProgramElement findCode(IProgramElement ipe) {
  3586. return findCode(ipe, -1);
  3587. }
  3588. /**
  3589. * Searches a hierarchy of program elements for a 'code' element at the specified line number, a line number of -1 means just
  3590. * return the first one you find
  3591. */
  3592. private IProgramElement findCode(IProgramElement ipe, int linenumber) {
  3593. if (ipe.getKind() == IProgramElement.Kind.CODE) {
  3594. if (linenumber == -1 || ipe.getSourceLocation().getLine() == linenumber) {
  3595. return ipe;
  3596. }
  3597. }
  3598. List<IProgramElement> kids = ipe.getChildren();
  3599. for (IProgramElement kid: kids) {
  3600. IProgramElement found = findCode(kid, linenumber);
  3601. if (found != null) {
  3602. return found;
  3603. }
  3604. }
  3605. return null;
  3606. }
  3607. // other possible tests:
  3608. // - memory usage (freemem calls?)
  3609. // - relationship map
  3610. // --------------------------------------------------------------------------
  3611. // -------------------------
  3612. private IProgramElement checkForNode(AsmManager model, String packageName, String typeName, boolean shouldBeFound) {
  3613. IProgramElement ipe = model.getHierarchy().findElementForType(packageName, typeName);
  3614. if (shouldBeFound) {
  3615. if (ipe == null) {
  3616. printModel(model);
  3617. }
  3618. assertTrue("Should have been able to find '" + packageName + "." + typeName + "' in the asm", ipe != null);
  3619. } else {
  3620. if (ipe != null) {
  3621. printModel(model);
  3622. }
  3623. assertTrue("Should have NOT been able to find '" + packageName + "." + typeName + "' in the asm", ipe == null);
  3624. }
  3625. return ipe;
  3626. }
  3627. private void printModel(AsmManager model) {
  3628. try {
  3629. AsmManager.dumptree(model.getHierarchy().getRoot(), 0);
  3630. } catch (IOException e) {
  3631. e.printStackTrace();
  3632. }
  3633. }
  3634. private static void log(String msg) {
  3635. if (VERBOSE) {
  3636. System.out.println(msg);
  3637. }
  3638. }
  3639. }