aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoraclement <aclement>2006-06-06 08:38:28 +0000
committeraclement <aclement>2006-06-06 08:38:28 +0000
commit5e74f35fa0ac6002b0a291259b88c1b0017fbf40 (patch)
tree4058bc2e6745d73742c7faeea0d0130addf04879 /tests
parentd1dbf827ea64012890fd2de97d684722f81f3226 (diff)
downloadaspectj-5e74f35fa0ac6002b0a291259b88c1b0017fbf40.tar.gz
aspectj-5e74f35fa0ac6002b0a291259b88c1b0017fbf40.zip
some code for 141730 - store type signatures in program elements rather than processed type names.
Diffstat (limited to 'tests')
-rw-r--r--tests/bugs152/pr141730.aj46
-rw-r--r--tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java6
-rw-r--r--tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java104
-rw-r--r--tests/src/org/aspectj/systemtest/ajc152/ajc152.xml4
4 files changed, 157 insertions, 3 deletions
diff --git a/tests/bugs152/pr141730.aj b/tests/bugs152/pr141730.aj
new file mode 100644
index 000000000..65b90d37a
--- /dev/null
+++ b/tests/bugs152/pr141730.aj
@@ -0,0 +1,46 @@
+import java.util.List;
+
+aspect A {
+
+ pointcut p() : execution(* *.*(..));
+
+ before() : p() {}
+
+ public void MyClass.method() {}
+
+ public MyClass.new() {super();}
+}
+
+class C {
+
+ public C() {}
+
+ public void method() {}
+
+ public void intMethod(int i) {}
+
+ public void stringMethod(String s) {}
+
+ public void myClassMethod(MyClass s) {}
+
+ public void genericMethod(List<String> l) {}
+
+ public void twoArgsMethod(int i, String s) {}
+
+ public void genericMethod2(MyGenericClass<String,MyClass> m) {}
+
+ public static void main(String[] args) {}
+
+ public void multiMethod(String[][] s) {}
+
+ public void intArray(int[] i) {}
+
+}
+
+class MyClass {
+
+ public MyClass(String s) {}
+
+}
+
+class MyGenericClass<X,Y> {}
diff --git a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
index 3f9896ab4..8e9d48fe8 100644
--- a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
+++ b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
@@ -109,7 +109,7 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
IProgramElement pe2 = top.findElementForType("pkg","printParameters");
assertNotNull("Couldn't find 'printParameters' element in the tree",pe2);
// the argument is org.aspectj.lang.JoinPoint, check that this is added
- assertFalse("printParameters method should have arguments",pe2.getParameterTypes().isEmpty());
+ assertFalse("printParameters method should have arguments",pe2.getParameterSignatures().isEmpty());
}
public void testParameterizedEnum_pr126316() {
@@ -156,8 +156,8 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
IProgramElement.Kind.INTER_TYPE_FIELD,"Bar.children");
assertNotNull("Couldn't find 'Bar.children' element in the tree",field);
IProgramElement constructor = top.findElementForLabel(top.getRoot(),
- IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR,"Foo.Foo(List<T>)");
- assertNotNull("Couldn't find 'Foo.Foo(List<T>)' element in the tree",constructor);
+ IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR,"Foo.Foo(java.util.List<T>)");
+ assertNotNull("Couldn't find 'Foo.Foo(java.util.List<T>)' element in the tree",constructor);
// check that the relationship map has 'itd method declared on bar'
List matches = AsmManager.getDefault().getRelationshipMap().get(method);
diff --git a/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java b/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java
index e27efeffa..0500cf757 100644
--- a/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java
+++ b/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java
@@ -11,6 +11,7 @@
package org.aspectj.systemtest.ajc152;
import java.io.File;
+import java.util.ArrayList;
import java.util.List;
import junit.framework.Test;
@@ -128,6 +129,60 @@ public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
public void testJarChecking_pr137235_2() { runTest("directory with .jar extension"); }
public void testMakePreMethodNPE_pr136393() { runTest("NPE in makePreMethod");}
+ public void testGetParameterHandles_pr141730() {
+ runTest("new IProgramElement handle methods");
+
+ checkParametersForIPE("intMethod(int)",IProgramElement.Kind.METHOD,"I",true);
+ checkParametersForIPE("stringMethod(java.lang.String)",IProgramElement.Kind.METHOD,"Ljava/lang/String;",true);
+ checkParametersForIPE("myClassMethod(MyClass)",IProgramElement.Kind.METHOD,"LMyClass;",true);
+ checkParametersForIPE("genericMethod(java.util.List<java.lang.String>)",IProgramElement.Kind.METHOD,"Pjava/util/List<Ljava/lang/String;>;",true);
+ checkParametersForIPE("genericMethod2(MyGenericClass<java.lang.String,MyClass>)",IProgramElement.Kind.METHOD,"PMyGenericClass<Ljava/lang/String;LMyClass;>;",true);
+ checkParametersForIPE("main(java.lang.String[])",IProgramElement.Kind.METHOD,"[Ljava/lang/String;",true);
+ checkParametersForIPE("multiMethod(java.lang.String[][])",IProgramElement.Kind.METHOD,"[[Ljava/lang/String;",true);
+ checkParametersForIPE("intArray(int[])",IProgramElement.Kind.METHOD,"[I",true);
+
+ IHierarchy top = AsmManager.getDefault().getHierarchy();
+ IProgramElement twoArgsMethod = top.findElementForLabel(
+ top.getRoot(),IProgramElement.Kind.METHOD,"twoArgsMethod(int,java.lang.String)");
+ assertNotNull("Couldn't find 'twoArgsMethod(int,java.lang.String)' element in the tree",twoArgsMethod);
+ List l = twoArgsMethod.getParameterSignatures();
+ assertEquals("",((char[])l.get(0))[0],'I');
+ boolean eq = equals(((char[])l.get(1)),"Ljava/lang/String;".toCharArray());
+ assertTrue("expected parameter to be 'Ljava/lang/String;' but found '" +
+ new String(((char[])l.get(1))) + "'",eq);
+ }
+
+ public void testGetParameterTypes_pr141730() {
+ runTest("new IProgramElement handle methods");
+
+ checkParametersForIPE("intMethod(int)",IProgramElement.Kind.METHOD,"int",false);
+ checkParametersForIPE("stringMethod(java.lang.String)",IProgramElement.Kind.METHOD,"java.lang.String",false);
+ checkParametersForIPE("myClassMethod(MyClass)",IProgramElement.Kind.METHOD,"MyClass",false);
+ checkParametersForIPE("genericMethod(java.util.List<java.lang.String>)",IProgramElement.Kind.METHOD,"java.util.List<java.lang.String>",false);
+ checkParametersForIPE("genericMethod2(MyGenericClass<java.lang.String,MyClass>)",IProgramElement.Kind.METHOD,"MyGenericClass<java.lang.String,MyClass>",false);
+ checkParametersForIPE("main(java.lang.String[])",IProgramElement.Kind.METHOD,"java.lang.String[]",false);
+ checkParametersForIPE("multiMethod(java.lang.String[][])",IProgramElement.Kind.METHOD,"java.lang.String[][]",false);
+ checkParametersForIPE("intArray(int[])",IProgramElement.Kind.METHOD,"int[]",false);
+ }
+
+ public void testToSignatureString_pr141730() {
+ runTest("new IProgramElement handle methods");
+
+ checkSignatureOfIPE("main(java.lang.String[])",IProgramElement.Kind.METHOD);
+ checkSignatureOfIPE("C",IProgramElement.Kind.CLASS);
+ checkSignatureOfIPE("C()",IProgramElement.Kind.CONSTRUCTOR);
+ checkSignatureOfIPE("method()",IProgramElement.Kind.METHOD);
+ checkSignatureOfIPE("p()",IProgramElement.Kind.POINTCUT);
+ checkSignatureOfIPE("before(): p..",IProgramElement.Kind.ADVICE,"before()");
+ checkSignatureOfIPE("MyClass.method()",IProgramElement.Kind.INTER_TYPE_METHOD);
+ checkSignatureOfIPE("multiMethod(java.lang.String[][])",IProgramElement.Kind.METHOD);
+ checkSignatureOfIPE("intArray(int[])",IProgramElement.Kind.METHOD);
+ checkSignatureOfIPE("MyClass.MyClass()",IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR);
+ }
+
+
+
+
// public void testFunkyGenericErrorWithITDs_pr126355_2() {
// runTest("bizarre generic error with itds - 2");
// // public class Pair<F,S> affected by pertarget aspect
@@ -143,6 +198,55 @@ public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
// Not valid whilst the ajc compiler forces debug on (ignores -g:none) - it will be green but is invalid, trust me
// public void testLongWindedMessages_pr129408() { runTest("long winded ataj messages");}
+
+ // ---------------- helper methods ---------------
+
+ /**
+ * taken from CharOperation
+ */
+ private final boolean equals(char[] first, char[] second) {
+ if (first == second)
+ return true;
+ if (first == null || second == null)
+ return false;
+ if (first.length != second.length)
+ return false;
+
+ for (int i = first.length; --i >= 0;)
+ if (first[i] != second[i])
+ return false;
+ return true;
+ }
+
+ private void checkParametersForIPE(String ipeLabel, IProgramElement.Kind kind, String expectedParm, boolean getHandles) {
+ IHierarchy top = AsmManager.getDefault().getHierarchy();
+ IProgramElement ipe = top.findElementForLabel(top.getRoot(),kind,ipeLabel);
+ assertNotNull("Couldn't find '" + ipeLabel + "' element in the tree",ipe);
+ List l = new ArrayList();
+ if (getHandles) {
+ l = ipe.getParameterSignatures();
+ } else {
+ l = ipe.getParameterTypes();
+ }
+ boolean eq = equals(((char[])l.get(0)),expectedParm.toCharArray());
+ assertTrue("expected parameter to be '" + expectedParm + "' but found '" +
+ new String(((char[])l.get(0))) + "'",eq);
+ }
+
+ private void checkSignatureOfIPE(String ipeLabel, IProgramElement.Kind kind) {
+ checkSignatureOfIPE(ipeLabel,kind,ipeLabel);
+ }
+
+ private void checkSignatureOfIPE(String ipeLabel, IProgramElement.Kind kind, String expectedSig) {
+ IHierarchy top = AsmManager.getDefault().getHierarchy();
+ IProgramElement ipe = top.findElementForLabel(
+ top.getRoot(),kind,ipeLabel);
+ assertNotNull("Couldn't find '" + ipeLabel + "' element in the tree",ipe);
+ assertEquals("expected signature to be '"+ expectedSig + "' but was " +
+ ipe.toSignatureString(true),expectedSig,ipe.toSignatureString(true));
+
+ }
+
/////////////////////////////////////////
public static Test suite() {
return XMLBasedAjcTestCase.loadSuite(Ajc152Tests.class);
diff --git a/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml b/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml
index dbdbdeda4..54718c6c5 100644
--- a/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml
+++ b/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml
@@ -602,6 +602,10 @@
<compile files="Covariance.java" options="-1.5"/>
</ajc-test>
+ <ajc-test dir="bugs152" title="new IProgramElement handle methods">
+ <compile files="pr141730.aj" options="-emacssym -1.5"/>
+ </ajc-test>
+
<ajc-test dir="bugs152" title="declare @method relationship">
<compile files="pr143924.aj" options="-1.5 -showWeaveInfo -emacssym">
<message kind="weave" text="'public void BankAccount.debit(String,long)' (pr143924.aj:7) is annotated with @Secured"/>