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.

Ajc150Tests.java 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*******************************************************************************
  2. * Copyright (c) 2004 IBM
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Common Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/cpl-v10.html
  7. *
  8. * Contributors:
  9. * Andy Clement - initial API and implementation
  10. *******************************************************************************/
  11. package org.aspectj.systemtest.ajc150;
  12. import java.io.ByteArrayOutputStream;
  13. import java.io.File;
  14. import java.io.IOException;
  15. import java.io.PrintWriter;
  16. import java.util.Iterator;
  17. import java.util.List;
  18. import junit.framework.Test;
  19. import org.aspectj.apache.bcel.classfile.JavaClass;
  20. import org.aspectj.apache.bcel.classfile.Method;
  21. import org.aspectj.apache.bcel.classfile.Signature;
  22. import org.aspectj.apache.bcel.util.ClassPath;
  23. import org.aspectj.apache.bcel.util.SyntheticRepository;
  24. import org.aspectj.asm.AsmManager;
  25. import org.aspectj.asm.IHierarchy;
  26. import org.aspectj.asm.IProgramElement;
  27. import org.aspectj.asm.IRelationship;
  28. import org.aspectj.asm.internal.Relationship;
  29. import org.aspectj.testing.XMLBasedAjcTestCase;
  30. import org.aspectj.util.LangUtil;
  31. public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
  32. public static Test suite() {
  33. return XMLBasedAjcTestCase.loadSuite(Ajc150Tests.class);
  34. }
  35. protected File getSpecFile() {
  36. return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
  37. }
  38. public void testCantCallSuperMethods_pr90143() { runTest("cant call super methods");}
  39. /*
  40. public void testBrokenDispatchByITD_pr72834() { runTest("broken dispatch");}
  41. public void testMissingAccessor_pr73856() { runTest("missing accessor");}
  42. public void testCunningDeclareParents_pr92311() { runTest("cunning declare parents");}
  43. public void testGenericITDsAndAbstractMethodError_pr102357() { runTest("generic itds and abstract method error");}
  44. public void testITDCtor_pr112783() { runTest("Problem with constructor ITDs");}
  45. */
  46. public void testPossibleStaticImports_pr113066() { runTest("possible static imports bug");}
  47. public void testBrokenDecp_pr112476() { runTest("binary weaving decp broken");}
  48. public void testUnboundFormal_pr112027() { runTest("unexpected error unboundFormalInPC");}
  49. public void testNPEScopeSetup_pr115038() { runTest("NPE in ensureScopeSetup");}
  50. public void testCCEGenerics_pr113445() { runTest("Generics ClassCastException");}
  51. public void testMatthewsAspect_pr113947_1() { runTest("maws generic aspect - 1");}
  52. public void testMatthewsAspect_pr113947_2() { runTest("maws generic aspect - 2");}
  53. public void testFieldGet_pr114343() { runTest("field-get, generics and around advice");}
  54. public void testFieldGet_pr114343_2() { runTest("field-get, generics and around advice - 2");}
  55. public void testFieldGet_pr114343_3() { runTest("field-get, generics and around advice - 3");}
  56. public void testCaptureBinding_pr114744() { runTest("capturebinding wildcard problem");}
  57. public void testBadDecp_pr110788_1() { runTest("bad generic decp - 1");}
  58. public void testBadDecp_pr110788_2() { runTest("bad generic decp - 2");}
  59. public void testBadDecp_pr110788_3() { runTest("bad generic decp - 3");}
  60. public void testBadDecp_pr110788_4() { runTest("bad generic decp - 4");}
  61. public void testVarargsITD_pr110906() { runTest("ITD varargs problem");}
  62. public void testBadRenderer_pr86903() { runTest("bcelrenderer bad");}
  63. public void testIncompatibleClassChangeError_pr113630_1() {runTest("IncompatibleClassChangeError - errorscenario");}
  64. public void testIncompatibleClassChangeError_pr113630_2() {runTest("IncompatibleClassChangeError - workingscenario");}
  65. public void testFieldGetProblemWithGenericField_pr113861() {runTest("field-get problems with generic field");}
  66. public void testDeclareAnnotationOnNonExistentType_pr99191_1() { runTest("declare annotation on non existent type - 1");}
  67. public void testDeclareAnnotationOnNonExistentType_pr99191_2() { runTest("declare annotation on non existent type - 2");}
  68. public void testDeclareAnnotationOnNonExistentType_pr99191_3() { runTest("declare annotation on non existent type - 3");}
  69. public void testDeclareAnnotationOnNonExistentType_pr99191_4() { runTest("declare annotation on non existent type - 4");}
  70. public void testDeclareAnnotationOnNonExistentType_pr99191_5() { runTest("declare annotation on non existent type - 5");}
  71. public void testBadGenericSigAttribute_pr110927() {
  72. runTest("cant create signature attribute");
  73. Signature sig = GenericsTests.getClassSignature(ajc,"I");
  74. if (sig==null) fail("Couldn't find signature attribute for type I");
  75. String sigString = sig.getSignature();
  76. if (!(sigString.equals("Ljava/lang/Object;LIE2;LIE1<Ljava/lang/String;>;") ||
  77. sigString.equals("Ljava/lang/Object;LIE1<Ljava/lang/String;>;LIE2;"))) {
  78. fail("Signature was "+sigString+" when should have been something like Ljava/lang/Object;LIE1<Ljava/lang/String;>;LIE2;");
  79. }
  80. }
  81. public void test_typeProcessingOrderWhenDeclareParents() {
  82. runTest("Order of types passed to compiler determines weaving behavior");
  83. }
  84. public void test_aroundMethod() {
  85. runTest("method called around in class");
  86. }
  87. public void test_aroundMethodAspect() {
  88. runTest("method called around in aspect");
  89. }
  90. public void test_ambiguousBindingsDetection() {
  91. runTest("Various kinds of ambiguous bindings");
  92. }
  93. public void test_ambiguousArgsDetection() {
  94. runTest("ambiguous args");
  95. }
  96. public void testIncorrectExceptionTableWhenBreakInMethod_pr78021() {
  97. runTest("Injecting exception into while loop with break statement causes catch block to be ignored");
  98. }
  99. public void testIncorrectExceptionTableWhenReturnInMethod_pr79554() {
  100. runTest("Return in try-block disables catch-block if final-block is present");
  101. }
  102. public void testMissingDebugInfoForGeneratedMethods_pr82570() throws ClassNotFoundException {
  103. runTest("Weaved code does not include debug lines");
  104. boolean f = false;
  105. JavaClass jc = getClassFrom(ajc.getSandboxDirectory(),"PR82570_1");
  106. Method[] meths = jc.getMethods();
  107. for (int i = 0; i < meths.length; i++) {
  108. Method method = meths[i];
  109. if (f) System.err.println("Line number table for "+method.getName()+method.getSignature()+" = "+method.getLineNumberTable());
  110. assertTrue("Didn't find a line number table for method "+method.getName()+method.getSignature(),
  111. method.getLineNumberTable()!=null);
  112. }
  113. // This test would determine the info isn't there if you pass -g:none ...
  114. // cR = ajc(baseDir,new String[]{"PR82570_1.java","-g:none"});
  115. // assertTrue("Expected no compile problem:"+cR,!cR.hasErrorMessages());
  116. // System.err.println(cR.getStandardError());
  117. // jc = getClassFrom(ajc.getSandboxDirectory(),"PR82570_1");
  118. // meths = jc.getMethods();
  119. // for (int i = 0; i < meths.length; i++) {
  120. // Method method = meths[i];
  121. // assertTrue("Found a line number table for method "+method.getName(),
  122. // method.getLineNumberTable()==null);
  123. // }
  124. }
  125. public void testCanOverrideProtectedMethodsViaITDandDecp_pr83303() {
  126. runTest("compiler error when mixing inheritance, overriding and polymorphism");
  127. }
  128. public void testPerTypeWithin_pr106554() {runTest("Problem in staticinitialization with pertypewithin aspect");}
  129. public void testPerTypeWithinMissesNamedInnerTypes() {
  130. runTest("pertypewithin() handing of inner classes (1)");
  131. }
  132. public void testPerTypeWithinMissesAnonymousInnerTypes() {
  133. runTest("pertypewithin() handing of inner classes (2)");
  134. }
  135. public void testPerTypeWithinIncorrectlyMatchingInterfaces() {
  136. runTest("pertypewithin({interface}) illegal field modifier");
  137. }
  138. public void test051_arrayCloningInJava5() {
  139. runTest("AJC possible bug with static nested classes");
  140. }
  141. public void testBadASMforEnums() throws IOException {
  142. runTest("bad asm for enums");
  143. if (LangUtil.is15VMOrGreater()) {
  144. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  145. PrintWriter pw = new PrintWriter(baos);
  146. AsmManager.dumptree(pw,AsmManager.getDefault().getHierarchy().getRoot(),0);
  147. pw.flush();
  148. String tree = baos.toString();
  149. assertTrue("Expected 'Red [enumvalue]' somewhere in here:"+tree,tree.indexOf("Red [enumvalue]")!=-1);
  150. }
  151. }
  152. public void npeOnTypeNotFound() {
  153. runTest("structure model npe on type not found");
  154. }
  155. public void testNoRuntimeExceptionSoftening() {
  156. runTest("declare soft of runtime exception");
  157. }
  158. public void testRuntimeNoSoftenWithHandler() {
  159. runTest("declare soft w. catch block");
  160. }
  161. public void testSyntaxError() {
  162. runTest("invalid cons syntax");
  163. }
  164. public void testVarargsInConsBug() {
  165. runTest("varargs in constructor sig");
  166. }
  167. public void testAspectpathdirs() {
  168. runTest("dirs on aspectpath");
  169. }
  170. public void testIntroSample() {
  171. runTest("introduction sample");
  172. }
  173. public void testPTWInterface() {
  174. runTest("pertypewithin({interface}) illegal field modifier");
  175. }
  176. public void testEnumCalledEnumEtc() {
  177. runTest("enum called Enum, annotation called Annotation, etc");
  178. }
  179. public void testInternalCompilerError_pr86832() {
  180. runTest("Internal compiler error");
  181. }
  182. public void testCloneMethod_pr83311() {
  183. runTest("overriding/polymorphism error on interface method introduction");
  184. }
  185. // IfPointcut.findResidueInternal() was modified to make this test complete in a short amount
  186. // of time - if you see it hanging, someone has messed with the optimization.
  187. public void testIfEvaluationExplosion_pr94086() {
  188. runTest("Exploding compile time with if() statements in pointcut");
  189. }
  190. public void testReflectNPE_pr94167() {runTest("NPE in reflect implementation");}
  191. public void testStaticImports_pr84260() {runTest("static import failures");}
  192. public void testGenerics_pr99089() {runTest("ArrayIndexOutOfBoundsException - Generics in privileged aspects");}
  193. public void testGenerics_pr95993() {runTest("NPE at ClassScope.java:660 when compiling generic class");}
  194. public void testItdGenerics_pr99228() {runTest("ITD of a field into a generic class");}
  195. public void testItdGenerics_pr98320() {runTest("intertype with nested generic type");}
  196. public void testItdGenerics_pr100227() {runTest("inner class with generic enclosing class");}
  197. public void testItdGenerics_pr100260() {runTest("methods inherited from a generic parent");}
  198. public void testSyntaxErrorNPE_pr103266() {runTest("NPE on syntax error");}
  199. public void testFinalAbstractClass_pr109486() { runTest("Internal compiler error (ClassParser.java:242)");}
  200. public void testComplexBinding_pr102210() { runTest("NullPointerException trying to compile");}
  201. public void testIllegalStateExceptionOnNestedParameterizedType_pr106634() {
  202. runTest("IllegalStateException unpacking signature of nested parameterized type");
  203. }
  204. public void testParseErrorOnAnnotationStarPlusPattern() {
  205. runTest("(@Foo *)+ type pattern parse error");
  206. }
  207. public void test_pr106130_tooManyLocals() {
  208. runTest("test weaving with > 256 locals");
  209. }
  210. public void testMissingNamePattern_pr106461() { runTest("missing name pattern"); }
  211. public void testMissingNamePattern_pr107059() {
  212. runTest("parser crashes on call(void (@a *)(..)");
  213. }
  214. public void testIntermediateAnnotationMatching() {
  215. runTest("intermediate annotation matching");
  216. }
  217. public void testBadRuntimeTestGeneration() {
  218. runTest("target(@Foo *)");
  219. }
  220. public void testErrorMessageOnITDWithTypePatterns() {
  221. runTest("clear error message on itd with type pattern");
  222. }
  223. public void testAjKeywordsAsIdentifiers() {
  224. runTest("before and after are valid identifiers in classes");
  225. }
  226. public void testAjKeywordsAsIdentifiers2() {
  227. runTest("before and after are valid identifiers in classes, part 2");
  228. }
  229. public void testNoBeforeReturningAdvice() {
  230. runTest("before returning advice not allowed!");
  231. }
  232. public void testDetectVoidFieldType() {
  233. runTest("void field type in pointcut expression");
  234. }
  235. public void testPointcutOverriding() {
  236. runTest("overriding final pointcut from super-aspect");
  237. }
  238. public void testAtSuppressWarnings() {
  239. runTest("@SuppressWarnings should suppress");
  240. }
  241. public void testDEOWWithBindingPointcut() {
  242. runTest("declare warning : foo(str) : ...;");
  243. }
  244. public void testAroundAdviceAndInterfaceInitializer() {
  245. runTest("around advice on interface initializer");
  246. }
  247. public void testGoodErrorMessageOnUnmatchedMemberSyntax() {
  248. runTest("good error message for unmatched member syntax");
  249. }
  250. public void testITDWithNoExceptionAndIntermediary() {
  251. runTest("itd override with no exception clause");
  252. }
  253. public void testAnonymousInnerClasses() {
  254. runTest("anonymous inner classes");
  255. }
  256. public void testMultipleAnonymousInnerClasses() {
  257. runTest("multiple anonymous inner classes");
  258. }
  259. public void testPrivilegedMethodAccessorsGetRightExceptions_pr82989() {
  260. runTest("Compiler error due to a wrong exception check in try blocks");
  261. }
  262. public void testAnonymousInnerClassWithMethodReturningTypeParameter_pr107898() {
  263. runTest("anonymous inner class with method returning type parameter");
  264. }
  265. public void testMatchingOfObjectArray() {
  266. runTest("matching against Object[]");
  267. }
  268. public void testMultipleAnonymousInnerClasses_pr108104() {
  269. runTest("multiple anonymous inner classes 2");
  270. }
  271. public void testSignatureMatchingInMultipleOverrideScenario() {
  272. runTest("signature matching in override scenario");
  273. }
  274. public void testWildcardAnnotationMatching_pr108245() {
  275. runTest("wildcard annotation matching - pr108245");
  276. }
  277. public void testInnerTypesAndTypeVariables() {
  278. runTest("inner types and type variables");
  279. }
  280. public void testAtAfterThrowingWithNoFormal() {
  281. runTest("@AfterThrowing with no formal specified");
  282. }
  283. public void testParameterizedVarArgsMatch() {
  284. runTest("varargs with type variable");
  285. }
  286. public void testFieldAccessInsideITDM() {
  287. runTest("itd field access inside itd method");
  288. }
  289. public void testTypeVarWithTypeVarBound() {
  290. runTest("type variable with type variable bound");
  291. }
  292. public void testEnumSwitchInITD() {
  293. runTest("switch on enum inside ITD method");
  294. }
  295. public void testInnerTypeOfGeneric() {
  296. runTest("inner type of generic interface reference from parameterized type");
  297. }
  298. public void testDeclareParentsIntroducingCovariantReturnType() {
  299. runTest("declare parents introducing override with covariance");
  300. }
  301. public void testInnerClassPassedToVarargs() {
  302. runTest("inner class passed as argument to varargs method");
  303. }
  304. public void testInlinedFieldAccessInProceedCall() {
  305. runTest("inlined field access in proceed call");
  306. }
  307. public void testVisibiltyInSignatureMatchingWithOverridesPart1() {
  308. runTest("visibility in signature matching with overrides - 1");
  309. }
  310. public void testVisibiltyInSignatureMatchingWithOverridesPart2() {
  311. runTest("visibility in signature matching with overrides - 2");
  312. }
  313. public void testVisibiltyInSignatureMatchingWithOverridesPart3() {
  314. runTest("visibility in signature matching with overrides - 3");
  315. }
  316. public void testArgsGeneratedCorrectlyForAdviceExecution() {
  317. runTest("args generated correctly for advice execution join point");
  318. }
  319. public void testNoUnusedWarningsOnAspectTypes() {
  320. runTest("no unused warnings on aspect types");
  321. }
  322. public void testSyntheticArgumentsOnITDConstructorsNotUsedInMatching() {
  323. runTest("synthetic arguments on itd cons are not used in matching");
  324. }
  325. public void testParsingOfGenericTypeSignature() {
  326. runTest("parse generic type signature with parameterized type in interface");
  327. }
  328. public void testOverrideAndCovarianceWithDecPRuntime() {
  329. runTest("override and covariance with decp - runtime");
  330. }
  331. public void testOverrideAndCovarianceWithDecPRuntimeMultiFiles() {
  332. runTest("override and covariance with decp - runtime separate files");
  333. }
  334. public void testOverrideAndCovarianceWithDecPRuntimeMultiFilesBinaryWeaving() {
  335. runTest("override and covariance with decp - binary weaving");
  336. }
  337. public void testAbstractSynchronizedITDMethods() {
  338. runTest("abstract synchronized itdms not detected");
  339. }
  340. public void testSynchronizedITDInterfaceMethods() {
  341. runTest("synchronized itd interface methods");
  342. }
  343. public void testNoWarningOnUnusedPointcut() {
  344. runTest("unused private pointcuts");
  345. }
  346. public void testITDOnInterfaceWithExistingMember() {
  347. runTest("itd interface method already existing on interface");
  348. }
  349. public void testFinalITDMOnInterface() {
  350. runTest("final itd methods on interfaces");
  351. }
  352. public void testPrivatePointcutOverriding() {
  353. runTest("can't override private pointcut in abstract aspect");
  354. }
  355. public void testAdviceOnCflow() {
  356. runTest("advising cflow advice execution");
  357. }
  358. public void testNoTypeMismatchOnSameGenericTypes() {
  359. runTest("no type mismatch on generic types in itds");
  360. }
  361. public void testSuperCallInITD() {
  362. runTest("super call in ITD");
  363. }
  364. public void testSuperCallInITDPart2() {
  365. runTest("super call in ITD - part 2");
  366. }
  367. public void testAtAnnotationBadTest_pr103740() {
  368. runTest("Compiler failure on at_annotation");
  369. }
  370. public void testNoUnusedParameterWarningsForSyntheticAdviceArgs() {
  371. runTest("no unused parameter warnings for synthetic advice args");
  372. }
  373. public void testNoVerifyErrorWithSetOnInnerType() {
  374. runTest("no verify error with set on inner type");
  375. }
  376. public void testCantFindTypeErrorWithGenericReturnTypeOrParameter() {
  377. runTest("cant find type error with generic return type or parameter");
  378. }
  379. public void testNoVerifyErrorOnGenericCollectionMemberAccess() {
  380. runTest("no verify error on generic collection member access");
  381. }
  382. public void testRawAndGenericTypeConversionITDCons() {
  383. runTest("raw and generic type conversion with itd cons");
  384. }
  385. public void testAtAnnotationBindingWithAround() {
  386. runTest("@annotation binding with around advice");
  387. }
  388. public void testUnableToBuildShadows_pr109728() { runTest("Unable to build shadows");}
  389. public void testMessageOnMissingTypeInDecP() {
  390. runTest("declare parents on a missing type");
  391. }
  392. public void testParameterizedGenericMethods() {
  393. runTest("parameterized generic methods");
  394. }
  395. public void testIllegalChangeToPointcutDeclaration_pr111915() {
  396. runTest("test illegal change to pointcut declaration");
  397. }
  398. public void testCantProvideDefaultImplViaITD_pr110307_1() {runTest("Cant provide default implementation via ITD - 1");}
  399. public void testCantProvideDefaultImplViaITD_pr110307_2() {runTest("Cant provide default implementation via ITD - 2");}
  400. public void testCantProvideDefaultImplViaITD_pr110307_3() {runTest("Cant provide default implementation via ITD - 3");}
  401. public void testCantProvideDefaultImplViaITD_pr110307_4() {runTest("Cant provide default implementation via ITD - 4");}
  402. public void testCantProvideDefaultImplViaITD_pr110307_5() {runTest("Cant provide default implementation via ITD - 5");}
  403. // Needs a change in the compiler so that getType() can be overridden in the intertype scope - thats
  404. // where we can police whether a type variable has been used without being specified appropriately.
  405. //public void testCantProvideDefaultImplViaITD_pr110307_6() {runTest("Cant provide default implementation via ITD - 6");}
  406. public void testCantProvideDefaultImplViaITD_pr110307_7() {runTest("Cant provide default implementation via ITD - 7");}
  407. public void testCallJoinPointsInAnonymousInnerClasses() {
  408. runTest("call join points in anonymous inner classes");
  409. }
  410. public void testNoRequirementForUnwovenTypesToBeExposedToWeaver() {
  411. runTest("default impl of Runnable");
  412. }
  413. public void testArrayCloneCallJoinPoints() {
  414. runTest("array clone call join points in 1.4 vs 1.3");
  415. }
  416. public void testDebugInfoForAroundAdvice() {
  417. runTest("debug info in around advice inlining");
  418. }
  419. public void testCCEWithGenericWildcard_pr112602() {
  420. runTest("ClassCastException with generic wildcard");
  421. }
  422. public void testAdviceInStructureModelWithAnonymousInnerClass_pr77269() {
  423. //AsmManager.setReporting("c:/debug.txt",true,true,true,true);
  424. runTest("advice in structure model with anonymous inner class");
  425. IHierarchy top = AsmManager.getDefault().getHierarchy();
  426. // checking that the run() method inside anonymous inner class is in
  427. // the structure model
  428. IProgramElement anonRunMethodIPE = top.findElementForLabel(top.getRoot(),
  429. IProgramElement.Kind.METHOD,"run()");
  430. assertNotNull("Couldn't find 'run()' element in the tree",anonRunMethodIPE);
  431. List l = AsmManager.getDefault().getRelationshipMap().get(anonRunMethodIPE);
  432. assertNotNull("Should have some relationships but does not",l);
  433. assertTrue("Should have one relationship but has " + l.size(),l.size()==1);
  434. Relationship rel = (Relationship)l.get(0);
  435. List targets = rel.getTargets();
  436. assertTrue("Should have one target but has" + targets.size(),
  437. targets.size()==1);
  438. IProgramElement target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)targets.get(0));
  439. assertEquals("target of relationship should be 'before(): p..' but is "
  440. + target.toLabelString(),"before(): p..",target.toLabelString());
  441. IProgramElement adviceIPE = top.findElementForLabel(top.getRoot(),
  442. IProgramElement.Kind.ADVICE,"before(): p..");
  443. assertNotNull("Couldn't find 'before(): p..' element in the tree",adviceIPE);
  444. l = AsmManager.getDefault().getRelationshipMap().get(adviceIPE);
  445. assertNotNull("Should have some relationships but does not",l);
  446. assertTrue("Should have a relationship but does not ",l.size()>0);
  447. for (Iterator iter = l.iterator(); iter.hasNext();) {
  448. IRelationship element = (IRelationship) iter.next();
  449. if (element.getName().equals("advises")) {
  450. rel = (Relationship) element;
  451. break;
  452. }
  453. }
  454. targets = rel.getTargets();
  455. assertTrue("Should have one target but has" + targets.size(),
  456. targets.size()==1);
  457. target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)targets.get(0));
  458. assertEquals("target of relationship should be 'run()' but is "
  459. + target.toLabelString(),"run()",target.toLabelString());
  460. }
  461. public void testAdviceInStructureModelWithNamedInnerClass_pr77269() {
  462. //AsmManager.setReporting("c:/debug.txt",true,true,true,true);
  463. runTest("advice in structure model with named inner class");
  464. IHierarchy top = AsmManager.getDefault().getHierarchy();
  465. // checking that the m() method inside named inner class is in
  466. // the structure model
  467. IProgramElement namedMethodIPE = top.findElementForLabel(top.getRoot(),
  468. IProgramElement.Kind.METHOD,"m()");
  469. assertNotNull("Couldn't find 'm()' element in the tree",namedMethodIPE);
  470. List l = AsmManager.getDefault().getRelationshipMap().get(namedMethodIPE);
  471. assertNotNull("Should have some relationships but does not",l);
  472. assertTrue("Should have one relationship but has " + l.size(),l.size()==1);
  473. Relationship rel = (Relationship)l.get(0);
  474. List targets = rel.getTargets();
  475. assertTrue("Should have one target but has" + targets.size(),
  476. targets.size()==1);
  477. IProgramElement target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)targets.get(0));
  478. assertEquals("target of relationship should be 'before(): p..' but is "
  479. + target.toLabelString(),"before(): p..",target.toLabelString());
  480. IProgramElement adviceIPE = top.findElementForLabel(top.getRoot(),
  481. IProgramElement.Kind.ADVICE,"before(): p..");
  482. assertNotNull("Couldn't find 'before(): p..' element in the tree",adviceIPE);
  483. l = AsmManager.getDefault().getRelationshipMap().get(adviceIPE);
  484. assertNotNull("Should have some relationships but does not",l);
  485. assertTrue("Should have a relationship but does not ",l.size()>0);
  486. for (Iterator iter = l.iterator(); iter.hasNext();) {
  487. IRelationship element = (IRelationship) iter.next();
  488. if (element.getName().equals("advises")) {
  489. rel = (Relationship) element;
  490. break;
  491. }
  492. }
  493. targets = rel.getTargets();
  494. assertTrue("Should have one target but has" + targets.size(),
  495. targets.size()==1);
  496. target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)targets.get(0));
  497. assertEquals("target of relationship should be 'm()' but is "
  498. + target.toLabelString(),"m()",target.toLabelString());
  499. }
  500. public void testDWInStructureModelWithAnonymousInnerClass_pr77269() {
  501. // AsmManager.setReporting("c:/debug.txt",true,true,true,true);
  502. runTest("declare warning in structure model with anonymous inner class");
  503. IHierarchy top = AsmManager.getDefault().getHierarchy();
  504. IProgramElement pe = top.findElementForLabel(top.getRoot(),
  505. IProgramElement.Kind.CODE,"method-call(void pack.Test.someMethod())");
  506. assertNotNull("Couldn't find 'method-call(void pack.Test.someMethod())' element in the tree",pe);
  507. }
  508. public void testVarArgsIITDInConstructor() {
  509. runTest("ITD varargs in constructor");
  510. }
  511. public void testWeaveInfoMessageForDeclareAtMethodOnITDdMethod() {
  512. runTest("weaveinfo message for declare at method on an ITDd method");
  513. }
  514. public void testNoVerifyErrorWithTwoThisPCDs_pr113447() {
  515. runTest("no verify error with two this pcds");
  516. }
  517. public void testITDCWithNoExplicitConsCall() {
  518. runTest("ITDC with no explicit cons call");
  519. }
  520. public void testJava5SpecificFeaturesUsedAtJava14OrLower() {
  521. runTest("java 5 pointcuts and declares at pre-java 5 compliance levels");
  522. }
  523. public void testAnonymousTypes() {
  524. runTest("Anonymous types and nome matching");
  525. }
  526. // helper methods.....
  527. public SyntheticRepository createRepos(File cpentry) {
  528. ClassPath cp = new ClassPath(cpentry+File.pathSeparator+System.getProperty("java.class.path"));
  529. return SyntheticRepository.getInstance(cp);
  530. }
  531. protected JavaClass getClassFrom(File where,String clazzname) throws ClassNotFoundException {
  532. SyntheticRepository repos = createRepos(where);
  533. return repos.loadClass(clazzname);
  534. }
  535. }