summaryrefslogtreecommitdiffstats
path: root/tests/java5/annotations/binding/AtArgs5.aj
blob: b2b51885a24007f4e26f17ddfe75604980db2739 (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
29
30
31
32
33
34
35
36
37
38
39
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 {}
@Colored(color="green") @Fruit("apple") class GA {}
@Colored(color="red") @Fruit("tomato") class RT {}

public class AtArgs5 {
  public static void main(String[]argv) {
    m(new YB(),new GA(),new RT());
  }

  public static void m(Object a,Object b,Object c) { }

}

aspect X {
  static int count = 0;

  before(Colored c1,Fruit f,Colored c2): execution(* m(..)) && !within(X) && @args(c1,f,c2) {
    System.err.println("Two colors:"+c1.color()+","+c2.color());
    System.err.println("Fruit is:"+f.value());
    count++;
    if (!c1.color().equals("yellow")) 
      throw new RuntimeException("Color1 should be yellow");
    if (!f.value().equals("apple")) 
      throw new RuntimeException("Fruit should be apple");
    if (!c2.color().equals("red")) 
      throw new RuntimeException("Color2 should be red");
    
  }

   public static void verify() {
    if (count!=3) throw new Error("Should be 3 runs: "+count);
   }
}