Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Annotation Binding - progress.



The first parts of annotation binding are available from the latest
dev build:

http://download.eclipse.org/technology/ajdt/dev/aspectj-DEVELOPMENT.jar

@target is working

@annotation works when used with call() or execution() - it *will not*
work with the other kinded PCDs (so field-set, field-get don't work).

Support for the other PCDs will follow later this week I hope.
I wanted to release something for users to try so we can iron out
the bugs before putting out 1.5.0 M2.

The developers notebook has much more detail on binding of annotations:

http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/ajdk15notebook/annotations-pointcuts-and-advice.html#d0e1169


Here is a simple example:

-----------8<---------------8<-----------------

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
@interface Colored {String value();}

public class A {
  public static void main(String[] argv) {
    m1();
    m2();
  }
  @Colored("red") static void m1() { System.err.println("m1 running"); }
  @Colored("blue") static void m2() { System.err.println("m2 running"); }

  static aspect X {
    before(Colored c): call(* m*(..)) && @annotation(c) {
      System.err.println("Color at "+thisJoinPoint+" is "+c.value());
    }
  }
}

-----------8<---------------8<-----------------

$ java A
Color at call(void A.m1()) is red
m1 running
Color at call(void A.m2()) is blue
m2 running

---
Andy.
AspectJ
clemas@xxxxxxxxxx



Back to the top