From: acolyer Date: Thu, 9 Dec 2004 14:02:47 +0000 (+0000) Subject: annotation tests for this and target X-Git-Tag: Root_AspectJ5_Development~168 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=592467e8a30dac18931ffed58a27e2b0835fbd9b;p=aspectj.git annotation tests for this and target --- diff --git a/tests/java5/annotations/thisOrtarget/TestingAnnotations.jar b/tests/java5/annotations/thisOrtarget/TestingAnnotations.jar new file mode 100644 index 000000000..d5dbd0b5e Binary files /dev/null and b/tests/java5/annotations/thisOrtarget/TestingAnnotations.jar differ diff --git a/tests/java5/annotations/thisOrtarget/TestingAnnotations.java b/tests/java5/annotations/thisOrtarget/TestingAnnotations.java new file mode 100644 index 000000000..67ad612a6 --- /dev/null +++ b/tests/java5/annotations/thisOrtarget/TestingAnnotations.java @@ -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 {} \ No newline at end of file diff --git a/tests/java5/annotations/thisOrtarget/ThisOrTargetTests.aj b/tests/java5/annotations/thisOrtarget/ThisOrTargetTests.aj new file mode 100644 index 000000000..c642da9aa --- /dev/null +++ b/tests/java5/annotations/thisOrtarget/ThisOrTargetTests.aj @@ -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) + } + +} \ No newline at end of file