Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Introduction advice & annotations

this problem of doubly annotating something via declare is now fixed in AJ.

On 21/03/06, Brian Ericson <bme@xxxxxxxx > wrote:
Thanks!  I'll take a look at these.  Meanwhile...  It does not appear to be possible to multiply annotate a method/field.  Something like (assuming the implementing class implements the method rather than getting it "free" from advice):
    declare @method : void TestInterface+.x() : @TestAnnotation;
    declare @method : void TestInterface+.x() : @TestAnnotation2;

You'll get one of the two annotations, but not both.

Andy Clement wrote:
See these two bugs:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=98901
https://bugs.eclipse.org/bugs/show_bug.cgi?id=114005

as they are related to this (as Wes says, the one Ramnivas is pointing to concerns types, not methods).

Andy.


On 21/03/06, Brian Ericson <bme@xxxxxxxx> wrote:
The behavior is inconsistent today.  Whether annotations get applied
(or, even, can be applied) is determined by whether you choose to have
advice implement the method.  I'd both like the annotation to
automatically be there if the method to be introduced by advice is
annotated (that is, not the interface's declared method, but the actual
implementing method -- I agree it makes little sense to do anything at
all about advice on the interface methods themselves) or if I choose to
use the @method syntax.

I'll also note that if you use the @Aspect notation and annotate the
method in the "Impl" class, the result is that the annotation is copied
to the class ultimately receiving advice (in fact, AspectJ even goes so
far as to noisily state the advice is being copied).  It seems wrong to
conclude annotations should not be possible in the "classic" style
(period, but especially in light of the fact that the @Aspect style goes
through pains to copy them).

Wes Isberg wrote:

>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
>
>
>
_______________________________________________
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

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top