aboutsummaryrefslogtreecommitdiffstats
path: root/tests/java5/annotations/itds/AtItd3.aj
blob: c3412cf56361a3eb3acb6a2a2d28d3be73ec0dd6 (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
import java.lang.annotation.*;
import java.lang.reflect.*;

@Retention(RetentionPolicy.RUNTIME)
@interface Ann {
  String id() default "hello";
  int anInt() default 5;
}

aspect X {
  @Ann(id="goodbye",anInt=4) public void AtItd3.m() {}
}

public class AtItd3 {
  public static void main(String []argv) {
    try {
      Method m = AtItd3.class.getDeclaredMethod("m",null);
      System.err.println("Method is "+m);
      Annotation[] as = m.getDeclaredAnnotations();
      System.err.println("Number of annotations "+
        (as==null?"0":new Integer(as.length).toString()));
      Annotation aa = m.getAnnotation(Ann.class);
      System.err.println("Ann.class retrieved is: "+aa);

      if (!aa.toString().equals("@Ann(id=goodbye, anInt=4)")) // < Java8 order
          if (!aa.toString().equals("@Ann(anInt=4, id=goodbye)")) // Java8 order
        throw new RuntimeException("Incorrect output, expected:"+
          "@Ann(id=goodbye, anInt=4) but got "+aa.toString());
 
      if (as.length==0) 
        throw new RuntimeException("Couldn't find annotation on member!");
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
  }
  
}