-public aspect NotRuntimeRetention {
-
- pointcut doSomethingExecution() : execution(* doSomething());
- pointcut doSomethingCall() : call(* doSomething());
-
- // CE L7
- before() : doSomethingExecution() && @this(MyClassRetentionAnnotation) {
- // should be compile-time error!
- System.out.println("How did I get here?");
- }
-
- // CE L13
- after() returning : doSomethingCall() && @target(MyClassRetentionAnnotation) {
- // should be compile-time error!
- System.out.println("How did I get here?");
- }
-
-}
\ No newline at end of file
+//"must have runtime retention"
+
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface MyRuntimeAnnotation {}
+
+@Retention(RetentionPolicy.SOURCE)
+@interface MySourceAnnotation {}
+
+@Retention(RetentionPolicy.CLASS)
+@interface MyClassAnnotation {}
+
+@interface MyAnnotation {}
+
+aspect X {
+ @MyRuntimeAnnotation @MySourceAnnotation @MyClassAnnotation @MyAnnotation
+ void a(){}
+ before(MyRuntimeAnnotation a): execution(* *(..)) && @annotation(a) {} // no error
+ before(MySourceAnnotation a): execution(* *(..)) && @annotation(a) {} // error expected
+ before(MyClassAnnotation a): execution(* *(..)) && @annotation(a) {} // error expected
+ before(MyAnnotation a): execution(* *(..)) && @annotation(a) {} // error expected
+}
</ajc-test>
<ajc-test dir="java5/annotations/thisOrtarget" vm="1.5" title="must have runtime retention">
- <compile options="-1.5" files="TestingAnnotations.java,NotRuntimeRetention.aj">
- <message kind="error" line="7" text="Annotation type MyClassRetentionAnnotation does not have runtime retention"/>
- <message kind="error" line="13" text="Annotation type MyClassRetentionAnnotation does not have runtime retention"/>
+ <compile options="-1.5" files="NotRuntimeRetention.aj">
+ <message kind="error" line="20" text="Annotation type MySourceAnnotation does not have runtime retention"/>
+ <message kind="error" line="21" text="Annotation type MyClassAnnotation does not have runtime retention"/>
+ <message kind="error" line="22" text="Annotation type MyAnnotation does not have runtime retention"/>
</compile>
</ajc-test>
world.getMessageHandler().handleMessage(m);
resolved = false;
}
- if (!annotationType.hasAnnotation(TypeX.AT_RETENTION)) {
+ if (!annotationType.isAnnotationWithRuntimeRetention(world)) { // default is class visibility
// default is class visibility
IMessage m = MessageUtil.error(
WeaverMessages.format(WeaverMessages.BINDING_NON_RUNTIME_RETENTION_ANNOTATION,annotationType.getName()),
getSourceLocation());
world.getMessageHandler().handleMessage(m);
resolved = false;
- } else {
- // Get the retention policy annotation, and check the value is RetentionPolicy.RUNTIME;
- // FIXME asc invention required, implement this !
-// if (!annotationType.hasRuntimeRetention()) {
-// ResolvedTypeX[] allAs = annotationType.getAnnotationTypes();
-// for (int i = 0; i < allAs.length; i++) {
-// ResolvedTypeX ann = allAs[i];
-// if ()
-// }
}
}