I'm using introductions to provide default implementations of interface
methods. I'd like those methods to be annotated, but AspectJ is
dropping the annotations (in both the 1.5 release and in the latest
development release) as demonstrated below. Is it possible to retain
the annotation?
TestAnnotation.java:
===================
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
public @interface TestAnnotation {}
TestInterface.java:
==================
public interface TestInterface {
void x();
public static aspect IMPL {
@TestAnnotation
public void TestInterface.x() { }
@TestAnnotation
Object TestInterface.field;
}
}
TestClass.java:
==============
import java.lang.annotation.*;
import java.lang.reflect.*;
public class TestClass implements TestInterface {
public static void main(String[] args) throws Exception {
Annotation[] annotations = TestClass.class.getMethod("x",
null).getAnnotations();
System.out.println("Found "+annotations.length+" annotations on
method x():");
for (int i = 0; i < annotations.length; i++)
System.out.println(" "+annotations[i]);
Field field = TestClass.class.getDeclaredFields()[1];
annotations = field.getAnnotations();
System.out.println("Found "+annotations.length+" annotations on
field "+field+":");
for (int i = 0; i < annotations.length; i++)
System.out.println(" "+annotations[i]);
}
}
I've also removed the annotation (necessary to avoid a compilation
error) and instead tried replacing it with the following, to no avail:
declare @method : void TestInterface+.x() : @TestAnnotation;
|