]> source.dussan.org Git - aspectj.git/commitdiff
generic aspect testcases - woohoo!
authoracolyer <acolyer>
Thu, 11 Aug 2005 15:30:37 +0000 (15:30 +0000)
committeracolyer <acolyer>
Thu, 11 Aug 2005 15:30:37 +0000 (15:30 +0000)
tests/java5/generics/genericaspects/AnonymousPointcutInGenericAspect.aj [new file with mode: 0644]
tests/java5/generics/genericaspects/DeclareParentsWithTypeVars.aj [new file with mode: 0644]
tests/java5/generics/genericaspects/DeclareWarningInGenericAspect.aj [new file with mode: 0644]
tests/java5/generics/genericaspects/ExecutionAdviceInGenericAspect.aj [new file with mode: 0644]

diff --git a/tests/java5/generics/genericaspects/AnonymousPointcutInGenericAspect.aj b/tests/java5/generics/genericaspects/AnonymousPointcutInGenericAspect.aj
new file mode 100644 (file)
index 0000000..d8dabf7
--- /dev/null
@@ -0,0 +1,28 @@
+abstract aspect SuperAspect<T> {
+       
+       before() : execution(* *(T)) {
+               System.out.println("I matched at " + thisJoinPointStaticPart);
+       }
+       
+}
+
+public aspect AnonymousPointcutInGenericAspect extends SuperAspect<String> {
+       
+       public static void main(String[] args) {
+               C c = new C();
+               c.foo("well i never");
+               c.bar(5);
+       }
+       
+}
+
+class C {
+       
+       // should be matched
+       public void foo(String s) {}
+       
+       // should not be matched
+       public void bar(Number n)  {}
+       
+       
+}
\ No newline at end of file
diff --git a/tests/java5/generics/genericaspects/DeclareParentsWithTypeVars.aj b/tests/java5/generics/genericaspects/DeclareParentsWithTypeVars.aj
new file mode 100644 (file)
index 0000000..48b729b
--- /dev/null
@@ -0,0 +1,37 @@
+import java.lang.reflect.*;
+
+abstract aspect GiveMeFoo<T> {
+       
+       declare parents : C implements I<T>;
+       
+}
+
+public aspect DeclareParentsWithTypeVars extends GiveMeFoo<String> {
+       
+       public static void main(String[] args) {
+               C c = new C();
+               if (! (c instanceof I)) throw new RuntimeException("C should implement I");
+               Type[] superinterfaces = C.class.getGenericInterfaces();
+               if (! (superinterfaces[0] instanceof ParameterizedType)) throw new RuntimeException("Expected to get parameterized interface but found " + superinterfaces[0]);
+               ParameterizedType pt = (ParameterizedType) superinterfaces[0];
+               Type[] typeArguments = pt.getActualTypeArguments();
+               if (typeArguments[0] != String.class) throw new RuntimeException("Expecting String parameter but found " + typeArguments[0]);
+       }
+       
+}
+
+class C {
+       
+//     public Object identity(Object o) { return o; }
+       
+       public String identity(String aString) {
+               return aString;
+       }
+       
+}
+
+interface I<E> {
+       
+       E identity(E anE);
+       
+}
diff --git a/tests/java5/generics/genericaspects/DeclareWarningInGenericAspect.aj b/tests/java5/generics/genericaspects/DeclareWarningInGenericAspect.aj
new file mode 100644 (file)
index 0000000..b0cc510
--- /dev/null
@@ -0,0 +1,22 @@
+abstract aspect SuperAspect<T> {
+       
+       pointcut takesAT() : execution(* *(T));
+
+       declare warning : takesAT() : "this method takes a T!";
+}
+
+
+public aspect DeclareWarningInGenericAspect extends SuperAspect<String> {
+       
+}
+
+class C {
+       
+       // should be matched
+       public void foo(String s) {}
+       
+       // should not be matched
+       public void bar(Number n)  {}
+       
+       
+}
\ No newline at end of file
diff --git a/tests/java5/generics/genericaspects/ExecutionAdviceInGenericAspect.aj b/tests/java5/generics/genericaspects/ExecutionAdviceInGenericAspect.aj
new file mode 100644 (file)
index 0000000..27624bc
--- /dev/null
@@ -0,0 +1,31 @@
+abstract aspect SuperAspect<T> {
+       
+       pointcut takesAT() : execution(* *(T));
+
+       before() : takesAT() {
+               System.out.println("I matched at " + thisJoinPointStaticPart);
+       }
+       
+}
+
+
+public aspect ExecutionAdviceInGenericAspect extends SuperAspect<String> {
+       
+       public static void main(String[] args) {
+               C c = new C();
+               c.foo("well i never");
+               c.bar(5);
+       }
+       
+}
+
+class C {
+       
+       // should be matched
+       public void foo(String s) {}
+       
+       // should not be matched
+       public void bar(Number n)  {}
+       
+       
+}
\ No newline at end of file