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.

JDTLikeHandleProviderTests.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /********************************************************************
  2. * Copyright (c) 2006 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: IBM Corporation - initial API and implementation
  9. * Helen Hawkins - initial version
  10. *******************************************************************/
  11. package org.aspectj.systemtest.ajc153;
  12. import java.io.IOException;
  13. import java.net.URL;
  14. import java.util.Iterator;
  15. import java.util.List;
  16. import org.aspectj.asm.AsmManager;
  17. import org.aspectj.asm.IHierarchy;
  18. import org.aspectj.asm.IProgramElement;
  19. import org.aspectj.testing.XMLBasedAjcTestCase;
  20. import junit.framework.Test;
  21. public class JDTLikeHandleProviderTests extends XMLBasedAjcTestCase {
  22. // IElementHandleProvider handleProvider;
  23. protected void setUp() throws Exception {
  24. super.setUp();
  25. // handleProvider = AsmManager.getDefault().getHandleProvider();
  26. // AsmManager.getDefault().setHandleProvider(new JDTLikeHandleProvider());
  27. }
  28. protected void tearDown() throws Exception {
  29. super.tearDown();
  30. // AsmManager.getDefault().setHandleProvider(handleProvider);
  31. }
  32. public void testMoreThanOneNamedPointcut() {
  33. runTest("More than one named pointcut");
  34. }
  35. public void testAspectHandle() {
  36. runTest("aspect handle");
  37. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  38. IProgramElement pe = top.findElementForType("pkg", "A1");
  39. String expected = "<pkg*A1.aj'A1";
  40. String found = pe.getHandleIdentifier();
  41. assertEquals("handleIdentifier - expected " + expected + ", but found " + found, expected, found);
  42. }
  43. public void testAdviceHandle() {
  44. runTest("advice handle");
  45. compareHandles(IProgramElement.Kind.ADVICE, "before(): <anonymous pointcut>", "<pkg*A2.aj'A2&before");
  46. }
  47. public void testPointcutHandle() {
  48. runTest("pointcut handle");
  49. compareHandles(IProgramElement.Kind.POINTCUT, "p()", "<pkg*A4.aj'A4\"p");
  50. }
  51. public void testGetIPEWithAspectHandle() {
  52. runTest("get IProgramElement with aspect handle");
  53. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  54. String handle = "<pkg*A1.aj'A1";
  55. IProgramElement ipe = top.getElement(handle);
  56. assertNotNull("should have found ipe with handle " + handle, ipe);
  57. IProgramElement ipe2 = top.getElement(handle);
  58. assertEquals("should be the same IPE", ipe, ipe2);
  59. }
  60. public void testAdviceHandleWithCrossCutting() {
  61. runTest("advice handle with crosscutting");
  62. compareHandles(IProgramElement.Kind.ADVICE, "before(): <anonymous pointcut>", "<pkg*A3.aj'A3&before");
  63. }
  64. public void testPointcutHandleWithArgs() {
  65. runTest("pointcut handle with args");
  66. compareHandles(IProgramElement.Kind.POINTCUT, "p(java.lang.Integer)", "<*A6.aj'A6\"p\"QInteger;");
  67. }
  68. public void testAdviceHandleWithArgs() {
  69. runTest("advice handle with args");
  70. compareHandles(IProgramElement.Kind.ADVICE, "afterReturning(java.lang.Integer): p..",
  71. "<pkg*A8.aj'A8&afterReturning&QInteger;");
  72. }
  73. public void testFieldITD() {
  74. runTest("field itd handle");
  75. compareHandles(IProgramElement.Kind.INTER_TYPE_FIELD, "C.x", "<pkg*A9.aj'A9,C.x");
  76. }
  77. public void testMethodITD() {
  78. runTest("method itd handle");
  79. compareHandles(IProgramElement.Kind.INTER_TYPE_METHOD, "C.method()", "<pkg*A9.aj'A9)C.method");
  80. }
  81. public void testMethodITDWithArgs() {
  82. runTest("method itd with args handle");
  83. compareHandles(IProgramElement.Kind.INTER_TYPE_METHOD, "C.methodWithArgs(int)", "<pkg*A9.aj'A9)C.methodWithArgs)I");
  84. }
  85. public void testConstructorITDWithArgs() {
  86. runTest("constructor itd with args");
  87. compareHandles(IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR, "C.C(int,java.lang.String)",
  88. "<pkg*A13.aj'A13)C.C_new)I)QString;");
  89. }
  90. public void testDeclareParentsHandle() {
  91. runTest("declare parents handle");
  92. compareHandles(IProgramElement.Kind.DECLARE_PARENTS, "declare parents: implements C2", "<pkg*A7.aj'A7`declare parents");
  93. }
  94. public void testTwoDeclareParents() {
  95. runTest("two declare parents in same file");
  96. compareHandles(IProgramElement.Kind.DECLARE_PARENTS, "declare parents: extends C5", "<pkg*A7.aj'A7`declare parents!2");
  97. }
  98. public void testMethodCallHandle() {
  99. runTest("method call handle");
  100. compareHandles(IProgramElement.Kind.CODE, "method-call(void pkg.C.m2())", "<pkg*A10.aj[C~m1?method-call(void pkg.C.m2())");
  101. }
  102. public void testDeclareAtType() {
  103. // AJDT: =AJHandleProject/src<pkg*A.aj}A`declare \@type
  104. runTest("declare @type");
  105. compareHandles(IProgramElement.Kind.DECLARE_ANNOTATION_AT_TYPE, "declare @type: pkg.C : @MyAnnotation",
  106. "<pkg*A12.aj'A`declare \\@type");
  107. }
  108. public void testDeclareAtField() {
  109. // AJDT: =AJHandleProject/src<pkg*A.aj}A`declare \@field
  110. runTest("declare @field");
  111. compareHandles(IProgramElement.Kind.DECLARE_ANNOTATION_AT_FIELD, "declare @field: int pkg.C.someField : @MyAnnotation",
  112. "<pkg*A12.aj'A`declare \\@field");
  113. }
  114. public void testDeclareAtMethod() {
  115. // AJDT: =AJHandleProject/src<pkg*A.aj}A`declare \@method
  116. runTest("declare @method");
  117. compareHandles(IProgramElement.Kind.DECLARE_ANNOTATION_AT_METHOD,
  118. "declare @method: public void pkg.C.method1() : @MyAnnotation", "<pkg*A12.aj'A`declare \\@method");
  119. }
  120. public void testDeclareAtConstructor() {
  121. // AJDT: =AJHandleProject/src<pkg*A.aj}A`declare \@constructor
  122. runTest("declare @constructor");
  123. compareHandles(IProgramElement.Kind.DECLARE_ANNOTATION_AT_CONSTRUCTOR, "declare @constructor: pkg.C.new() : @MyAnnotation",
  124. "<pkg*A12.aj'A`declare \\@constructor");
  125. }
  126. // what about 2 pieces of before advice with the same
  127. // signature and the same pointcut
  128. public void testTwoPiecesOfAdviceWithSameSignatureAndPointcut() {
  129. runTest("two pieces of advice with the same signature and pointcut");
  130. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  131. IProgramElement parent = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.ASPECT, "A5");
  132. List children = parent.getChildren();
  133. String handle1 = null;
  134. String handle2 = null;
  135. for (Object child : children) {
  136. IProgramElement element = (IProgramElement) child;
  137. if (element.getKind().equals(IProgramElement.Kind.ADVICE)) {
  138. if (handle1 == null) {
  139. handle1 = element.getHandleIdentifier();
  140. } else {
  141. handle2 = element.getHandleIdentifier();
  142. }
  143. }
  144. }
  145. String expected1 = "<pkg*A5.aj'A5&before";
  146. String expected2 = "<pkg*A5.aj'A5&before!2";
  147. boolean b = expected1.equals(handle1);
  148. if (b) {
  149. assertEquals("handleIdentifier - expected " + expected2 + ", but found " + handle2, expected2, handle2);
  150. } else {
  151. assertEquals("handleIdentifier - expected " + expected1 + ", but found " + handle2, expected1, handle2);
  152. assertEquals("handleIdentifier - expected " + expected2 + ", but found " + handle1, expected2, handle1);
  153. }
  154. }
  155. public void testDeclareWarningHandle() {
  156. runTest("declare warning handle");
  157. compareHandles(IProgramElement.Kind.DECLARE_WARNING, "declare warning: \"Illegal call.\"",
  158. "<pkg*A11.aj'A11`declare warning");
  159. }
  160. public void testTwoDeclareWarningHandles() {
  161. runTest("two declare warning handles");
  162. compareHandles(IProgramElement.Kind.DECLARE_WARNING, "declare warning: \"blah\"", "<pkg*A11.aj'A11`declare warning!2");
  163. }
  164. // this is to ensure the logic for not including '1' in the count
  165. // works correctly. We don't want a decw ipe with count 1 but we do
  166. // want one with count 10.
  167. public void testTenDeclareWarningHandles() {
  168. runTest("ten declare warning handles");
  169. compareHandles(IProgramElement.Kind.DECLARE_WARNING, "declare warning: \"warning 1\"",
  170. "<*DeclareWarnings.aj'DeclareWarnings`declare warning");
  171. compareHandles(IProgramElement.Kind.DECLARE_WARNING, "declare warning: \"warning 10\"",
  172. "<*DeclareWarnings.aj'DeclareWarnings`declare warning!10");
  173. }
  174. // these two handles are the same unless we have added a counter
  175. // on the end
  176. public void testIPEsWithSameNameHaveUniqueHandles_methodCall() {
  177. runTest("ipes with same name have unique handles - method-call");
  178. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  179. String handle1 = "<*TwoMethodCalls.aj[Main~main~\\[QString;?method-call("
  180. + "void java.io.PrintStream.println(java.lang.String))";
  181. assertNotNull("expected to find node with handle " + handle1 + ", but did not", top.getElement(handle1));
  182. String handle2 = "<*TwoMethodCalls.aj[Main~main~\\[QString;?method-call("
  183. + "void java.io.PrintStream.println(java.lang.String))!2";
  184. assertNotNull("expected to find node with handle " + handle2 + ", but did not", top.getElement(handle2));
  185. String handle3 = "<*TwoMethodCalls.aj[Main~main~\\[QString;?method-call("
  186. + "void java.io.PrintStream.println(java.lang.String))!3";
  187. assertNull("expected not to find node with handle " + handle3 + ", but found one", top.getElement(handle3));
  188. }
  189. // these two handles should be different anyway so second one
  190. // shouldn't have the "2"
  191. public void testIPEsWithDiffNamesDontHaveCounter_methodCall() {
  192. runTest("ipes with different names do not have counter - method-call");
  193. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  194. String handle1 = "<*TwoDiffMethodCalls.aj[Main~main~\\[QString;?method-call("
  195. + "void java.io.PrintStream.println(java.lang.String))";
  196. assertNotNull("expected to find node with handle " + handle1 + ", but did not", top.getElement(handle1));
  197. String handle2 = "<*TwoDiffMethodCalls.aj[Main~method~\\[QString;?method-call("
  198. + "void java.io.PrintStream.println(java.lang.String))";
  199. assertNotNull("expected to find node with handle " + handle2 + ", but did not", top.getElement(handle2));
  200. }
  201. public void testIPEsWithSameNameHaveUniqueHandles_handler() {
  202. runTest("ipes with same name have unique handles - handler");
  203. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  204. String handle1 = "<*Handler.aj[C~method?exception-handler(void C." + "<catch>(java.io.FileNotFoundException))";
  205. assertNotNull("expected to find node with handle " + handle1 + ", but did not", top.getElement(handle1));
  206. String handle2 = "<*Handler.aj[C~method?exception-handler(void C." + "<catch>(java.io.FileNotFoundException))!2";
  207. assertNotNull("expected to find node with handle " + handle2 + ", but did not", top.getElement(handle2));
  208. }
  209. public void testIPEsWithSameNameHaveUniqueHandles_get() {
  210. runTest("ipes with same name have unique handles - get");
  211. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  212. String handle1 = "<*Get.aj[C1~method1?field-get(int C1.x)";
  213. assertNotNull("expected to find node with handle " + handle1 + ", but did not", top.getElement(handle1));
  214. String handle2 = "<*Get.aj[C1~method1?field-get(int C1.x)!2";
  215. assertNotNull("expected to find node with handle " + handle2 + ", but did not", top.getElement(handle2));
  216. }
  217. public void testIPEsWithSameNameHaveUniqueHandles_set() {
  218. runTest("ipes with same name have unique handles - set");
  219. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  220. String handle1 = "<*Set.aj[C1~method?field-set(int C1.x)";
  221. assertNotNull("expected to find node with handle " + handle1 + ", but did not", top.getElement(handle1));
  222. String handle2 = "<*Set.aj[C1~method?field-set(int C1.x)!2";
  223. assertNotNull("expected to find node with handle " + handle2 + ", but did not", top.getElement(handle2));
  224. }
  225. public void testTwoPiecesOfBeforeAdviceInInjarAspectHaveUniqueHandles_pr159896() {
  226. runTest("advice with same name in injar aspect should have unique handles");
  227. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  228. String handle1 = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.ADVICE, "before(): p..").getHandleIdentifier();
  229. String handle2 = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.ADVICE, "before(): exec..")
  230. .getHandleIdentifier();
  231. assertFalse("expected the two advice nodes to have unique handles but" + " did not", handle1.equals(handle2));
  232. try {
  233. AsmManager.lastActiveStructureModel.dumptree(AsmManager.lastActiveStructureModel.getHierarchy().getRoot(), 0);
  234. } catch (IOException e) {
  235. // TODO Auto-generated catch block
  236. e.printStackTrace();
  237. }
  238. }
  239. public void testTwoDeclareWarningsInInjarAspectHaveUniqueHandles_pr159896() {
  240. runTest("declare warnings in injar aspect should have unique handles");
  241. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  242. String handle1 = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_WARNING, "declare warning: \"blah\"")
  243. .getHandleIdentifier();
  244. String handle2 = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_WARNING, "declare warning: \"blah2\"")
  245. .getHandleIdentifier();
  246. assertFalse("expected the two declare warning nodes to have unique handles but" + " did not", handle1.equals(handle2));
  247. }
  248. // if have one declare warning and one declare error statement within an
  249. // injar
  250. // aspect, neither of them should have a counter (i.e. "!2") at the end of
  251. // their handle
  252. public void testOnlyIncrementSameDeclareTypeFromInjar_pr159896() {
  253. runTest("dont increment counter for different declares");
  254. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  255. String warning = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_WARNING,
  256. "declare warning: \"warning\"").getHandleIdentifier();
  257. assertTrue("shouldn't have incremented counter for declare warning handle " + "because only one declare warning statement",
  258. !warning.contains("!0") && !warning.contains("!2"));
  259. String error = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ERROR, "declare error: \"error\"")
  260. .getHandleIdentifier();
  261. assertTrue("shouldn't have incremented counter for declare error handle " + "because only one declare error statement",
  262. !error.contains("!0") && !error.contains("!2"));
  263. }
  264. // public void testOnlyIncrementSameAdviceKindFromInjar_pr159896() {
  265. // runTest("dont increment counter for different advice kinds");
  266. // IHierarchy top = AsmManager.getDefault().getHierarchy();
  267. // String before = top.findElementForLabel(top.getRoot(),
  268. // IProgramElement.Kind.ADVICE, "before(): p..")
  269. // .getHandleIdentifier();
  270. // assertTrue("shouldn't have incremented counter for before handle "
  271. // + "because only one before advice", before.indexOf("!0") == -1
  272. // && before.indexOf("!2") == -1 && before.indexOf("!3") == -1);
  273. // String after = top.findElementForLabel(top.getRoot(),
  274. // IProgramElement.Kind.ADVICE, "after(): p..")
  275. // .getHandleIdentifier();
  276. // assertTrue("shouldn't have incremented counter for after handle "
  277. // + "because only one after advice", after.indexOf("!0") == -1
  278. // && after.indexOf("!2") == -1 && after.indexOf("!3") == -1);
  279. // String around = top.findElementForLabel(top.getRoot(),
  280. // IProgramElement.Kind.ADVICE, "around(): p1..")
  281. // .getHandleIdentifier();
  282. // assertTrue("shouldn't have incremented counter for around handle "
  283. // + "because only one around advice", around.indexOf("!0") == -1
  284. // && around.indexOf("!2") == -1 && around.indexOf("!3") == -1);
  285. //
  286. // }
  287. // ---------- following tests ensure we produce the same handles as jdt
  288. // -----//
  289. // ---------- (apart from the prefix)
  290. // NOTES: there is no ipe equivalent to a package fragment root or
  291. //
  292. public void testCompilationUnitSameAsJDT() {
  293. // JDT: =TJP Example/src<tjp{Demo.java
  294. runTest("compilation unit same as jdt");
  295. compareHandles(IProgramElement.Kind.FILE_JAVA, "Demo.java", "<tjp{Demo.java");
  296. }
  297. public void testClassSameAsJDT() {
  298. // JDT: =Java5 Handles/src<pkg{C.java[C
  299. runTest("class same as jdt");
  300. compareHandles(IProgramElement.Kind.CLASS, "C", "<pkg{C.java[C");
  301. }
  302. public void testInterfaceSameAsJDT() {
  303. // JDT: =Java5 Handles/src<pkg{C.java[MyInterface
  304. runTest("interface same as jdt");
  305. compareHandles(IProgramElement.Kind.INTERFACE, "MyInterface", "<pkg{C.java[MyInterface");
  306. }
  307. public void testConstructorSameAsJDT() {
  308. // JDT: =Java5 Handles/src<pkg{C.java[C~C
  309. runTest("constructor same as jdt");
  310. compareHandles(IProgramElement.Kind.CONSTRUCTOR, "C()", "<pkg{C.java[C~C");
  311. }
  312. public void testConstructorWithArgsSameAsJDT() {
  313. // JDT: =Java5 Handles/src<pkg{C.java[C~C~QString;
  314. runTest("constructor with args same as jdt");
  315. compareHandles(IProgramElement.Kind.CONSTRUCTOR, "C(java.lang.String)", "<pkg{C.java[C~C~QString;");
  316. }
  317. // public void testPackageDeclarationSameAsJDT() {
  318. // // JDT: =TJP Example/src<tjp{Demo.java%tjp
  319. // fail("package declaration isn't the same");
  320. // runTest("package declaration same as jdt");
  321. // compareHandles(IProgramElement.Kind.PACKAGE,
  322. // "tjp",
  323. // "<tjp{Demo.java%tjp");
  324. // }
  325. public void testImportDeclarationSameAsJDT() {
  326. // JDT: =TJP Example/src<tjp{Demo.java#java.io.*
  327. runTest("import declaration same as jdt");
  328. compareHandles(IProgramElement.Kind.IMPORT_REFERENCE, "java.io.*", "<tjp{Demo.java#java.io.*");
  329. }
  330. public void testTypeSameAsJDT() {
  331. // JDT: =TJP Example/src<tjp{Demo.java[Demo
  332. runTest("type same as jdt");
  333. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  334. IProgramElement pe = top.findElementForType("tjp", "Demo");
  335. String expected = "<tjp{Demo.java[Demo";
  336. String found = pe.getHandleIdentifier();
  337. assertEquals("handleIdentifier - expected " + expected + ", but found " + found, expected, found);
  338. }
  339. public void testFieldSameAsJDT() {
  340. // JDT: =TJP Example/src<tjp{Demo.java[Demo^d
  341. runTest("field same as jdt");
  342. compareHandles(IProgramElement.Kind.FIELD, "d", "<tjp{Demo.java[Demo^d");
  343. }
  344. public void testInitializationSameAsJDT() {
  345. // JDT: =TJP Example/src<tjp{Demo.java[Demo|1
  346. // and =TJP Example/src<tjp{Demo.java[Demo|2
  347. runTest("initialization same as jdt");
  348. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  349. IProgramElement parent = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.CLASS, "Demo");
  350. List children = parent.getChildren();
  351. String handle1 = null;
  352. String handle2 = null;
  353. for (Object child : children) {
  354. IProgramElement element = (IProgramElement) child;
  355. if (element.getKind().equals(IProgramElement.Kind.INITIALIZER)) {
  356. if (handle1 == null) {
  357. handle1 = element.getHandleIdentifier();
  358. } else {
  359. handle2 = element.getHandleIdentifier();
  360. }
  361. }
  362. }
  363. String expected1 = "<tjp{Demo.java[Demo|1";
  364. String expected2 = "<tjp{Demo.java[Demo|2";
  365. boolean b = expected1.equals(handle1);
  366. System.err.println("actual: " + handle1);
  367. System.err.println("actual: " + handle2);
  368. if (b) {
  369. assertEquals("handleIdentifier - expected " + expected2 + ", but found " + handle2, expected2, handle2);
  370. } else {
  371. assertEquals("handleIdentifier - expected " + expected1 + ", but found " + handle2, expected1, handle2);
  372. assertEquals("handleIdentifier - expected " + expected2 + ", but found " + handle1, expected2, handle1);
  373. }
  374. }
  375. public void testMethodWithStringArrayArgsSameAsJDT() {
  376. // JDT: =TJP Example/src<tjp{Demo.java[Demo~main~\[QString;
  377. runTest("method with string array as argument same as jdt");
  378. compareHandles(IProgramElement.Kind.METHOD, "main(java.lang.String[])", "<tjp{Demo.java[Demo~main~\\[QString;");
  379. }
  380. public void testMethodWithIntArrayArgsSameAsJDT() {
  381. // JDT: =TJP Example/src<tjp{Demo.java[Demo~m~\[I
  382. runTest("method with int array as argument same as jdt");
  383. compareHandles(IProgramElement.Kind.METHOD, "m(int[])", "<tjp{Demo.java[Demo~m~\\[I");
  384. }
  385. public void testMethodWithNoArgsSameAsJDT() {
  386. // JDT: =TJP Example/src<tjp{Demo.java[Demo~go
  387. runTest("method with no args same as jdt");
  388. compareHandles(IProgramElement.Kind.METHOD, "go()", "<tjp{Demo.java[Demo~go");
  389. }
  390. public void testMethodWithTwoArgsSameAsJDT() {
  391. // JDT: =TJP Example/src<tjp{Demo.java[Demo~foo~I~QObject;
  392. runTest("method with two args same as jdt");
  393. compareHandles(IProgramElement.Kind.METHOD, "foo(int,java.lang.Object)", "<tjp{Demo.java[Demo~foo~I~QObject;");
  394. }
  395. public void testMethodWithTwoStringArgsSameAsJDT() {
  396. // JDT: =TJP Example/src<tjp{Demo.java[Demo~m2~QString;~QString;
  397. runTest("method with two string args same as jdt");
  398. compareHandles(IProgramElement.Kind.METHOD, "m2(java.lang.String,java.lang.String)",
  399. "<tjp{Demo.java[Demo~m2~QString;~QString;");
  400. }
  401. public void testEnumSameAsJDT() {
  402. // JDT: =Java5 Handles/src<pkg{E.java[E
  403. runTest("enum same as jdt");
  404. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  405. IProgramElement pe = top.findElementForType("pkg", "E");
  406. String expected = "<pkg{E.java[E";
  407. String found = pe.getHandleIdentifier();
  408. assertEquals("handleIdentifier - expected " + expected + ", but found " + found, expected, found);
  409. }
  410. public void testEnumValueSameAsJDT() {
  411. // JDT: =Java5 Handles/src<pkg{E.java[E^A
  412. runTest("enum value same as jdt");
  413. compareHandles(IProgramElement.Kind.ENUM_VALUE, "A", "<pkg{E.java[E^A");
  414. }
  415. public void testAnnotationSameAsJDT() {
  416. // JDT: =Java5 Handles/src<pkg{MyAnnotation.java[MyAnnotation
  417. runTest("annotation same as jdt");
  418. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  419. IProgramElement pe = top.findElementForType("pkg", "MyAnnotation");
  420. String expected = "<pkg{MyAnnotation.java[MyAnnotation";
  421. String found = pe.getHandleIdentifier();
  422. assertEquals("handleIdentifier - expected " + expected + ", but found " + found, expected, found);
  423. }
  424. public void testMethodWithListArgSameAsJDT() {
  425. // JDT: =Java5 Handles/src<pkg{Java5Class.java[Java5Class~method2~QList;
  426. runTest("method with list arg same as jdt");
  427. compareHandles(IProgramElement.Kind.METHOD, "method2(java.util.List)", "<pkg{Java5Class.java[Java5Class~method2~QList;");
  428. }
  429. public void testMethodWithGenericArgSameAsJDT() {
  430. // JDT: =Java5 Handles/src<pkg{Java5Class.java[Java5Class
  431. // ~genericMethod1~QList\<QString;>;
  432. runTest("method with generic arg same as jdt");
  433. compareHandles(IProgramElement.Kind.METHOD, "genericMethod1(java.util.List<java.lang.String>)",
  434. "<pkg{Java5Class.java[Java5Class~genericMethod1~QList\\<QString;>;");
  435. }
  436. public void testMethodWithTwoGenericArgsSameAsJDT() {
  437. // JDT: =Java5 Handles/src<pkg{Java5Class.java[Java5Class
  438. // ~genericMethod2~QList\<QString;>;~QMyGenericClass\<QInteger;>;
  439. runTest("method with two generic args same as jdt");
  440. compareHandles(IProgramElement.Kind.METHOD, "genericMethod2(java.util.List<java.lang.String>,"
  441. + "pkg.MyGenericClass<java.lang.Integer>)", "<pkg{Java5Class.java[Java5Class~genericMethod2~QList"
  442. + "\\<QString;>;~QMyGenericClass\\<QInteger;>;");
  443. }
  444. public void testMethodWithTwoTypeParametersSameAsJDT() {
  445. // JDT: =Java5 Handles/src<pkg{Java5Class.java[Java5Class~genericMethod4
  446. // ~QMyGenericClass2\<QString;QInteger;>;
  447. runTest("method with two type parameters same as jdt");
  448. compareHandles(IProgramElement.Kind.METHOD, "genericMethod4(pkg.MyGenericClass2<java.lang.String,java.lang.Integer>)",
  449. "<pkg{Java5Class.java[Java5Class~genericMethod4" + "~QMyGenericClass2\\<QString;QInteger;>;");
  450. }
  451. public void testMethodWithTwoArgsSameAsJDT_2() {
  452. // JDT: =Java5 Handles/src<pkg{Java5Class.java[Java5Class
  453. // ~genericMethod3~I~QList\<QString;>;
  454. runTest("method with two args one of which is generic same as jdt");
  455. compareHandles(IProgramElement.Kind.METHOD, "genericMethod3(int,java.util.List<java.lang.String>)",
  456. "<pkg{Java5Class.java[Java5Class~genericMethod3~I~QList\\<QString;>;");
  457. }
  458. /*
  459. * Still to do; PROJECT, PACKAGE, FILE, FILE_ASPECTJ, FILE_LST, DECLARE_ERROR, DECLARE_SOFT, DECLARE_PRECEDENCE,
  460. */
  461. // ----------- helper methods ---------------
  462. private void compareHandles(IProgramElement.Kind kind, String ipeName, String expectedHandle) {
  463. IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy();
  464. IProgramElement pe = top.findElementForLabel(top.getRoot(), kind, ipeName);
  465. String found = pe.getHandleIdentifier();
  466. System.err.println("expected: " + expectedHandle);
  467. System.err.println("actual: " + found);
  468. assertEquals("handleIdentifier - expected " + expectedHandle + ", but found " + found, expectedHandle, found);
  469. }
  470. // ///////////////////////////////////////
  471. public static Test suite() {
  472. return XMLBasedAjcTestCase.loadSuite(JDTLikeHandleProviderTests.class);
  473. }
  474. protected URL getSpecFile() {
  475. return getClassResource("jdtlikehandleprovider.xml");
  476. }
  477. }