summaryrefslogtreecommitdiffstats
path: root/tests/java5/annotations/binding/AtArgs2.aj
blob: ed46d61865f34eb1af3a2e10c5251b50f3c03fff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.lang.annotation.*;

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

@Colored(color="yellow") @Fruit("banana") class YB {}

public class AtArgs2 {
  public static void main(String[]argv) {
    m(new YB());
    if (!X.run) throw new Error("Advice should have run");
  }

  public static void m(Object a) {}

}

aspect X {
  public static boolean run = false;
  before(Colored c): call(* m(..)) && !within(X) && @args(c) {
    System.err.println("Color is "+c.color());
    run = true;
    if (!c.color().equals("yellow")) 
      throw new RuntimeException("Color should be yellow: "+c.color());
  }

}