[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-dev] @annotation - more news.

Following on from yesterdays post, I've now uploaded a dev
build of AspectJ where @annotation can be used for binding with
*any* of the kinded PCDs.  (yesterday it was just call/execution)

The dev build is here:


You can now write this kind of thing, which uses annotations
on field-set join points:

import java.lang.annotation.*;

@interface Colored {String value();}

public class A {

  @Colored("red") static int i;

  public static void main(String[] argv) {
    i = 5;

  static aspect X {
    before(Colored c): set(* *) && @annotation(c) {
      if (c.value().equals("red"))
      System.err.println("The red field is being set!!");


You can even write this:

  before(Colored c): @annotation(c) { }

which will bind to Colored annotations at any of the join points
encountered.  Here is a useful table from the developers
notebook - it tells you what the subject for each join point kind.
It is the subject which we attempt annotation matching on for that
join point:

Join Point Kind        Subject
Method call            The method picked out by Java as the static target of the method call.
Method execution       The method that is executing.
Constructor call       The constructor being called.
Constructor execution  The constructor executing.
Field get              The field being accessed.
Field set              The field being set.
Pre-initialization     The first constructor executing in this constructor chain.
Initialization         The first constructor executing in this constructor chain.
Static initialization  The type being initialized.
Handler                The declared type of the exception being handled.Advice executionThe advice being executed.

Two pieces of annotation binding work remain, @this() and @args().  

Any feedback is welcomed - an AJDT containing this feature will be
available shortly.

Andy Clement.
AspectJ Development