23 |
23 |
24 import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; |
24 import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; |
25 |
25 |
26 /* |
26 /* |
27 * @test |
27 * @test |
28 * @bug 8013852 |
28 * @bug 8013852 8042451 |
29 * @summary Test population of reference info for instance and class initializers |
29 * @summary Test population of reference info for instance and class initializers |
30 * @author Werner Dietl |
30 * @author Werner Dietl |
31 * @compile -g Driver.java ReferenceInfoUtil.java Initializers.java |
31 * @compile -g Driver.java ReferenceInfoUtil.java Initializers.java |
32 * @run main Driver Initializers |
32 * @run main Driver Initializers |
33 */ |
33 */ |
34 public class Initializers { |
34 public class Initializers { |
35 |
35 |
36 @TADescriptions({ |
36 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
37 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), |
37 @TADescription(annotation = "TB", type = NEW, |
38 @TADescription(annotation = "TB", type = NEW, |
|
39 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
38 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
40 }) |
39 public String instanceInit1() { |
41 public String instanceInit1() { |
40 return "class %TEST_CLASS_NAME% { { Object o = new @TA ArrayList<@TB String>(); } }"; |
42 return "class Test { { Object o = new @TA ArrayList<@TB String>(); } }"; |
|
43 } |
41 } |
44 |
42 |
45 @TADescriptions({ |
43 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
46 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), |
44 @TADescription(annotation = "TB", type = NEW, |
47 @TADescription(annotation = "TB", type = NEW, |
|
48 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), |
|
49 @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), |
|
50 @TADescription(annotation = "TD", type = NEW, |
|
51 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
45 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
52 }) |
46 @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
53 public String instanceInit2() { |
47 @TADescription(annotation = "TD", type = NEW, |
54 return "class Test { Object f = new @TA ArrayList<@TB String>(); " + |
48 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
49 public String instanceInit2() { |
|
50 return "class %TEST_CLASS_NAME% { Object f = new @TA ArrayList<@TB String>(); " + |
55 " { Object o = new @TC ArrayList<@TD String>(); } }"; |
51 " { Object o = new @TC ArrayList<@TD String>(); } }"; |
56 } |
52 } |
57 |
53 |
58 @TADescriptions({ |
54 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
59 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), |
55 @TADescription(annotation = "TB", type = NEW, |
60 @TADescription(annotation = "TB", type = NEW, |
|
61 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
56 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
62 }) |
57 public String staticInit1() { |
63 public String staticInit1() { |
58 return "class %TEST_CLASS_NAME% { static { Object o = new @TA ArrayList<@TB String>(); } }"; |
64 return "class Test { static { Object o = new @TA ArrayList<@TB String>(); } }"; |
|
65 } |
59 } |
66 |
60 |
67 @TADescriptions({ |
61 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
68 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), |
62 @TADescription(annotation = "TB", type = NEW, |
69 @TADescription(annotation = "TB", type = NEW, |
|
70 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), |
|
71 @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), |
|
72 @TADescription(annotation = "TD", type = NEW, |
|
73 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), |
|
74 @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), |
|
75 @TADescription(annotation = "TF", type = NEW, |
|
76 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
63 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
77 }) |
64 @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
78 public String staticInit2() { |
65 @TADescription(annotation = "TD", type = NEW, |
79 return "class Test { Object f = new @TA ArrayList<@TB String>(); " + |
66 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
67 @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
68 @TADescription(annotation = "TF", type = NEW, |
|
69 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
70 public String staticInit2() { |
|
71 return "class %TEST_CLASS_NAME% { Object f = new @TA ArrayList<@TB String>(); " + |
80 " static Object g = new @TC ArrayList<@TD String>(); " + |
72 " static Object g = new @TC ArrayList<@TD String>(); " + |
81 " static { Object o = new @TE ArrayList<@TF String>(); } }"; |
73 " static { Object o = new @TE ArrayList<@TF String>(); } }"; |
82 } |
74 } |
83 |
75 |
84 // TODO: test interaction with several constructors, especially non-initial constuctors. |
76 @TADescription(annotation = "TA", type = CAST, |
|
77 typeIndex = 0, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
78 public String lazyConstantCast1() { |
|
79 return "class %TEST_CLASS_NAME% { public static final Object o = (@TA Object) null; }"; |
|
80 } |
|
81 |
|
82 @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
83 @TADescription(annotation = "RTBs", type = NEW, |
|
84 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
85 public String instanceInitRepeatableAnnotation1() { |
|
86 return "class %TEST_CLASS_NAME% { { Object o = new @RTA @RTA ArrayList<@RTB @RTB String>(); } }"; |
|
87 } |
|
88 |
|
89 @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
90 @TADescription(annotation = "RTBs", type = NEW, |
|
91 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
92 @TADescription(annotation = "RTCs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
93 @TADescription(annotation = "RTDs", type = NEW, |
|
94 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
95 public String instanceInitRepeatableAnnotation2() { |
|
96 return "class %TEST_CLASS_NAME% { Object f = new @RTA @RTA ArrayList<@RTB @RTB String>(); " + |
|
97 " { Object o = new @RTC @RTC ArrayList<@RTD @RTD String>(); } }"; |
|
98 } |
|
99 |
|
100 @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
101 @TADescription(annotation = "RTBs", type = NEW, |
|
102 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
103 public String staticInitRepeatableAnnotation1() { |
|
104 return "class %TEST_CLASS_NAME% { static { Object o = new @RTA @RTA ArrayList<@RTB @RTB String>(); } }"; |
|
105 } |
|
106 |
|
107 @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
108 @TADescription(annotation = "RTBs", type = NEW, |
|
109 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
110 @TADescription(annotation = "RTCs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
111 @TADescription(annotation = "RTDs", type = NEW, |
|
112 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
113 @TADescription(annotation = "RTEs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
114 @TADescription(annotation = "RTFs", type = NEW, |
|
115 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
116 public String staticInitRepeatableAnnotation2() { |
|
117 return "class %TEST_CLASS_NAME% { Object f = new @RTA @RTA ArrayList<@RTB @RTB String>(); " + |
|
118 " static Object g = new @RTC @RTC ArrayList<@RTD @RTD String>(); " + |
|
119 " static { Object o = new @RTE @RTE ArrayList<@RTF @RTF String>(); } }"; |
|
120 } |
|
121 |
|
122 // TODO: test interaction with several constructors, especially non-initial constructors. |
85 // I don't think this kind of test is possible here. |
123 // I don't think this kind of test is possible here. |
86 |
124 |
87 @TADescriptions({ |
125 @TADescription(annotation = "RTAs", type = CAST, |
88 @TADescription(annotation = "TA", type = CAST, |
126 typeIndex = 0, offset = ReferenceInfoUtil.IGNORE_VALUE) |
89 typeIndex = 0, offset = ReferenceInfoUtil.IGNORE_VALUE), |
127 public String lazyConstantCastRepeatableAnnotation1() { |
90 }) |
128 return "class %TEST_CLASS_NAME% { public static final Object o = (@RTA @RTA Object) null; }"; |
91 public String lazyConstantCast1() { |
|
92 return "class Test { public static final Object o = (@TA Object) null; }"; |
|
93 } |
129 } |
94 |
|
95 } |
130 } |