Hi Brian -
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
hmm - what should happen?
I can't find a JLS reference to what should happen in Java when a method
declared in an interface is annotated.
If the method is in a class, then everything works as expected in Java
and when declared in an aspect using AspectJ:
- when the method is inherited, the annotation is visible
- when the inherited method is overridden, the annotation is n/a
(i.e., annotation not inherited)
But in Java if the method is declared in an interface, then it's like
the override case for classes. I think that's how JLS mavens would
read it.
For ajc, we *implement* methods declared on interfaces by stuffing
them into all top-level classes implementating that interface, but I
don't think that should determine the semantics of declaring
annotations on interface method implementations in AspectJ.
instead tried replacing it with the following, to no avail:
declare @method : void TestInterface+.x() : @TestAnnotation;
This works for me. I tried it when ST is any supertype
(class or interface) and x() is declared in the supertype or
the subclass:
declare @method : void ST+.x() : @TestAnnotation;
It works even when ST does not declare x(). However, it does not
work when the method is declared in an aspect - bug? I should note
that a similar locution does pick out the aspect-declared method:
declare error: execution(void ST+.x()): "ST";
So that could be a bug in the implementation of declare @method
(or some subtle difference in the meaning of the typepattern
in declare @method that I'm not aware of).
Fixing the bug might enable you to work around the semantics
question by asserting that you do want the annotation. As I read it,
though, using declare @method would mean *all* implementations of
that method would be annotated, not just the topmost. So if you
override the aspect-declared implementation with one of your own,
that would be annotated as well.
So: should annotating a method declared on an interface in an aspect
result in the annotations being on all the top-level implementations?
Given that we allow the ITD, I'd say yes, but I'm not sure what the
implications might be for other implementations of AspectJ.
Hope this helps - or at least didn't hurt too much!
Wes
------------Original Message------------
From: Brian Ericson <bme@xxxxxxxx>
To: aspectj-users@xxxxxxxxxxx
Date: Sun, Mar-19-2006 7:18 PM
Subject: [aspectj-users] Introduction advice & annotations
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;
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users