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

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