Browse Source

annotation tests for this and target

tags/Root_AspectJ5_Development
acolyer 19 years ago
parent
commit
592467e8a3

BIN
tests/java5/annotations/thisOrtarget/TestingAnnotations.jar View File


+ 51
- 0
tests/java5/annotations/thisOrtarget/TestingAnnotations.java View File

@@ -0,0 +1,51 @@
public class TestingAnnotations {

public static void main(String[] args) {

A a = new A();
B b = new B();
C c = new C();
D d = new D();
A reallyB = new B();
C reallyD = new D();

a.doSomething();
b.doSomething();
c.doSomething();
d.doSomething();
reallyB.doSomething();
reallyD.doSomething();
}

}

@MyClassRetentionAnnotation
class A {
public void doSomething() {}
}


@MyAnnotation
class B extends A {
public void doSomething() {}
}

@MyInheritableAnnotation
@MyAnnotation
class C {
public void doSomething() {}
}

class D extends C {
public void doSomething() {}
}


@interface MyClassRetentionAnnotation {}

@java.lang.annotation.Retention(value=java.lang.annotation.RetentionPolicy.RUNTIME)
@interface MyAnnotation {}

@java.lang.annotation.Retention(value=java.lang.annotation.RetentionPolicy.RUNTIME)
@java.lang.annotation.Inherited
@interface MyInheritableAnnotation {}

+ 50
- 0
tests/java5/annotations/thisOrtarget/ThisOrTargetTests.aj View File

@@ -0,0 +1,50 @@
import java.util.List;
public aspect ThisOrTargetTests {
pointcut doSomethingExecution() : execution(* doSomething());
pointcut doSomethingCall() : call(* doSomething());
before() : doSomethingExecution() && @this(@MyAnnotation) {
// should match:
// b.doSomething(), reallyB.doSomething() [with test],
// c.doSomething()
System.out.println("@this(@MyAnnotation): " + thisJoinPointStaticPart);
}
before() : doSomethingExecution() && @this(@MyClassRetentionAnnotation) {
// should be compile-time error!
}
before() : doSomethingExecution() && @this(@MyInheritableAnnotation) {
// should match:
// c.doSomething()
// d.doSomething()
// reallyD.doSomething()
System.out.println("@this(@MyInheritableAnnotation): " + thisJoinPointStaticPart);
}
after() returning : doSomthingCall() && @target(@MyAnnotation) {
// should match:
// b.doSomething(), reallyB.doSomething() [with test],
// c.doSomething()
System.out.println("@target(@MyAnnotation): " + thisJoinPointStaticPart);
}
after() returning : doSomethingCall() && @target(@MyClassRetentionAnnotation) {
// should be compile-time error!
}
after() returning : doSomethingCall() && @target(@MyInheritableAnnotation) {
// should match:
// c.doSomething()
// d.doSomething()
// reallyD.doSomething()
System.out.println("@target(@MyInheritableAnnotation): " + thisJoinPointStaticPart);
}
after(MyAnnotation ann) returning : @target(ann) {
// should be compile time error (limitation)
}
}

Loading…
Cancel
Save