]> source.dussan.org Git - aspectj.git/commitdiff
some abstract generic aspect tests, not yet linked into main suite
authoracolyer <acolyer>
Wed, 5 Oct 2005 14:35:24 +0000 (14:35 +0000)
committeracolyer <acolyer>
Wed, 5 Oct 2005 14:35:24 +0000 (14:35 +0000)
tests/java5/generics/genericaspects/GenericAspectPointcuts.aj [new file with mode: 0644]
tests/java5/generics/genericaspects/GenericAspectRuntimePointcuts.aj [new file with mode: 0644]
tests/java5/generics/genericaspects/testplan.txt [new file with mode: 0644]

diff --git a/tests/java5/generics/genericaspects/GenericAspectPointcuts.aj b/tests/java5/generics/genericaspects/GenericAspectPointcuts.aj
new file mode 100644 (file)
index 0000000..0ca1bbc
--- /dev/null
@@ -0,0 +1,72 @@
+abstract aspect GenericAspectPointcuts<S,T,E> {
+       
+       /** 
+         test declare warning with :
+                   - KindedPointcut
+                      all parts of Signature pattern
+                   - HandlerPointcut
+                   - ReferencePointcut
+                   - WithincodePointcut
+                   - WithinPointcut
+                   - And
+                   - Or
+                   - Not
+       */
+       
+       pointcut kindedWithReturning() : execution(T *(..));
+       pointcut kindedWithDeclaring() : call(* S.*(..));
+       pointcut kindedWithParams() : execution(* *(T));
+       pointcut kindedWithThrows() : execution(* *(..) throws E);
+       
+       pointcut p1() : execution(* T.*(..));
+       pointcut p2() : execution(S *(..));
+       pointcut p3() : set(S a);
+       pointcut p4() : get(* T.*);
+       pointcut p5() : within(S || T);
+       
+       pointcut handlerPC() : handler(E);
+       
+       declare warning : kindedWithReturning() : "kinded-returning-ok";
+       declare warning : kindedWithDeclaring() : "kinded-declaring-ok";
+       declare warning : kindedWithParams() : "kinded-params-ok";
+       declare warning : kindedWithThrows() : "kinded-throws-ok";
+       
+       declare warning : p1() && p2() : "and-ok";
+       declare warning : p3() || p4() : "or-ok";
+       declare warning : staticinitialization(*) && !p5() : "not-ok";
+       
+       declare warning : within(T) && staticinitialization(*) : "within-ok";
+       declare warning : withincode(S T.*(..)) : "withincode-ok";
+}
+
+aspect Sub extends GenericAspectPointcuts<A,B,Z> {
+       
+       declare warning : handlerPC() : "handler-ok";  // also tests ref to super pointcut
+}
+
+
+
+class A {
+       void bar(B b) {
+               try {
+                       t();
+               } catch( Z z) { System.out.println("z");}
+       }
+       
+       void t() throws Z {}
+}
+
+class B {
+    A a = new A();
+       
+       B newB() { return new B(); }
+       
+       A newA() { return a; }
+       
+       void foo() {
+               a.bar(this);
+       }
+       
+}
+
+class Z extends Exception {}
\ No newline at end of file
diff --git a/tests/java5/generics/genericaspects/GenericAspectRuntimePointcuts.aj b/tests/java5/generics/genericaspects/GenericAspectRuntimePointcuts.aj
new file mode 100644 (file)
index 0000000..8436e71
--- /dev/null
@@ -0,0 +1,99 @@
+import java.lang.annotation.*;
+
+abstract aspect GA<P,Q,A extends Annotation> {
+       
+       /*
+               * test before advice with
+           - CflowPointcut
+           - annotation
+           - args annotation
+           - args
+           - this
+           - target
+           - @this
+           - @target
+           - @within
+           - @withincode
+           - parameter binding
+        */
+       
+       before(P p, Q q) : cflow(execution(* P.*(..)) && this(p)) && set(Q q) {
+               System.out.println("cflow-ok " + p + " " + q);
+       }
+       
+       before(A a) : execution(* *(..)) && @annotation(a) {
+               System.out.println("@annotation-ok " + a);
+       }
+       
+       before(A a) : @args(a) {
+               System.out.println("@args-ok " + a);
+       }
+       
+       before(P p) : args(..,p) {
+               System.out.println("args-ok " + p);
+       }
+       
+       before(Q q) : this(q) && execution(* *(..)) {
+               System.out.println("this-ok " + q);
+       }
+       
+       before(P p) : target(p) && call(* *(..)) {
+               System.out.println("target-ok " + p);
+       }
+       
+       before(A a) : @this(a) && execution(* *(..)) {
+               System.out.println("@this-ok " + a);
+       }
+       
+       before(A a) : @target(a) && call(* *(..)) {
+               System.out.println("@target-ok " + a);
+       }
+       
+       before(A a) : @within(a) && execution(* *(..)) {
+               System.out.println("@within-ok " + a);
+       }
+       
+       before(A a) : @withincode(a) && get(* *) {
+               System.out.println("@withincode-ok " + a);
+       }
+}
+
+aspect GenericAspectRuntimePointcuts extends GA<X,Y,MyAnnotation> {
+       
+       public static void main(String[] s) {
+               X x = new X();
+               Y y = new Y();
+               x.foo();
+               x.bar();
+               y.foo(x);
+               y.bar();
+       }
+}
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface MyAnnotation {
+       String value() default "my-value";
+}
+
+@MyAnnotation
+class X {
+       Y y;
+       
+       void foo() {
+               this.y = new Y();
+       }
+       
+       @MyAnnotation("bar")
+       void bar() {}
+       
+}
+
+@MyAnnotation("on Y")
+class Y {
+       X x;
+       
+       void foo(X x) {}
+       
+       @MyAnnotation
+       X bar() { return this.x; }
+}
\ No newline at end of file
diff --git a/tests/java5/generics/genericaspects/testplan.txt b/tests/java5/generics/genericaspects/testplan.txt
new file mode 100644 (file)
index 0000000..2d4c2a9
--- /dev/null
@@ -0,0 +1,74 @@
+Test plan for abstract aspects:
+
+Coverage:
+  * all pointcut types
+  * all declare types
+  * all annotation pattern nodes
+  * all type pattern nodes
+  * type variables as type parameters
+  
+  * Binary weaving!!!
+  
+Pointcut types:
+
+  * test declare warning with :                DONE
+    - KindedPointcut
+       all parts of Signature pattern
+    - HandlerPointcut
+    - ReferencePointcut
+    - WithincodePointcut
+    - WithinPointcut
+    - And
+    - Or
+    - Not
+    
+  * test before advice with
+    - CflowPointcut
+    - annotation
+    - args annotation
+    - args
+    - this
+    - target
+    - @this
+    - @target
+    - @within
+    - @withincode
+    - parameter binding
+    
+  * pointcut in abstract class
+    - ref with parameterized type
+    - ref without parameterized type (error)
+    
+Declares:
+
+  * declare warning / error (covered above)
+  * declare parents
+  * declare soft
+  * declare precedence
+  * declare @type
+  * declare @field / method / cons
+  
+AnnotationPatternNodes:
+
+  * And
+  * Or
+  * Not
+  * Exact 
+  * Wild
+
+Type pattern Nodes:
+
+  * And
+  * AnyWithAnnotation
+  * Or
+  * Not
+  * HasMember
+  * Exact
+  * Wild
+  * type variables as type parameters
+
+Multi-level hierarchy:
+
+  * test 3-deep with partial parameterization in middle
+  
+  
\ No newline at end of file