Fields.java revision 2942:08092deced3f
1/*
2 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
25
26/*
27 * @test
28 * @bug 8042451
29 * @summary Test population of reference info for field
30 * @modules jdk.jdeps/com.sun.tools.classfile
31 * @compile -g Driver.java ReferenceInfoUtil.java Fields.java
32 * @run main Driver Fields
33 */
34public class Fields {
35    // field types
36    @TADescription(annotation = "TA", type = FIELD)
37    public String fieldAsPrimitive() {
38        return "@TA int test;";
39    }
40
41    @TADescription(annotation = "TA", type = FIELD)
42    public String fieldAsObject() {
43        return "@TA Object test;";
44    }
45
46    @TADescription(annotation = "TA", type = FIELD)
47    @TADescription(annotation = "TB", type = FIELD,
48            genericLocation = { 3, 0 })
49    @TADescription(annotation = "TC", type = FIELD,
50            genericLocation = { 3, 1 })
51    @TADescription(annotation = "TD", type = FIELD,
52            genericLocation = { 3, 1, 3, 0 })
53    public String fieldAsParametrized() {
54        return "@TA Map<@TB String, @TC List<@TD String>> test;";
55    }
56
57    @TADescription(annotation = "TA", type = FIELD)
58    @TADescription(annotation = "TB", type = FIELD,
59            genericLocation = { 0, 0 })
60    @TADescription(annotation = "TC", type = FIELD,
61            genericLocation = { 0, 0, 0, 0 })
62    public String fieldAsArray() {
63        return "@TC String @TA [] @TB [] test;";
64    }
65
66    @TADescription(annotation = "TA", type = FIELD)
67    @TADescription(annotation = "TB", type = FIELD,
68            genericLocation = { 0, 0 })
69    @TADescription(annotation = "TC", type = FIELD,
70            genericLocation = { 0, 0, 0, 0 })
71    public String fieldAsArrayOld() {
72        return "@TC String test @TA [] @TB [];";
73    }
74
75    @TADescriptions({})
76    public String fieldWithDeclarationAnnotatin() {
77        return "@Decl String test;";
78    }
79
80    @TADescriptions({})
81    public String fieldWithNoTargetAnno() {
82        return "@A String test;";
83    }
84
85    // Smoke tests
86    @TADescription(annotation = "TA", type = FIELD)
87    public String interfaceFieldAsObject() {
88        return "interface %TEST_CLASS_NAME% { @TA String test = null; }";
89    }
90
91    @TADescription(annotation = "TA", type = FIELD)
92    public String abstractFieldAsObject() {
93        return "abstract class %TEST_CLASS_NAME% { @TA String test; }";
94    }
95
96    @TADescription(annotation = "TA", type = FIELD)
97    @TADescription(annotation = "TB", type = FIELD,
98            genericLocation = { 3, 0 })
99    @TADescription(annotation = "TC", type = FIELD,
100            genericLocation = { 3, 1 })
101    @TADescription(annotation = "TD", type = FIELD,
102            genericLocation = { 3, 1, 3, 0 })
103    public String interfaceFieldAsParametrized() {
104        return "interface %TEST_CLASS_NAME% { @TA Map<@TB String, @TC List<@TD String>> test = null; }";
105    }
106
107
108    @TADescription(annotation = "TA", type = FIELD)
109    @TADescription(annotation = "TB", type = FIELD,
110            genericLocation = { 3, 0 })
111    @TADescription(annotation = "TC", type = FIELD,
112            genericLocation = { 3, 1 })
113    @TADescription(annotation = "TD", type = FIELD,
114            genericLocation = { 3, 1, 3, 0 })
115    public String staticFieldAsParametrized() {
116        return "static @TA Map<@TB String, @TC List<@TD String>> test;";
117    }
118
119    @TADescription(annotation = "RTAs", type = FIELD)
120    public String fieldAsPrimitiveRepeatableAnnotation() {
121        return "@RTA @RTA int test;";
122    }
123
124    @TADescription(annotation = "RTAs", type = FIELD)
125    public String fieldAsObjectRepeatableAnnotation() {
126        return "@RTA @RTA Object test;";
127    }
128
129    @TADescription(annotation = "RTAs", type = FIELD)
130    @TADescription(annotation = "RTBs", type = FIELD,
131            genericLocation = { 3, 0 })
132    @TADescription(annotation = "RTCs", type = FIELD,
133            genericLocation = { 3, 1 })
134    @TADescription(annotation = "RTDs", type = FIELD,
135            genericLocation = { 3, 1, 3, 0 })
136    public String fieldAsParametrizedRepeatableAnnotation() {
137        return "@RTA @RTA Map<@RTB @RTB String, @RTC @RTC List<@RTD @RTD String>> test;";
138    }
139
140    @TADescription(annotation = "RTAs", type = FIELD)
141    @TADescription(annotation = "RTBs", type = FIELD,
142            genericLocation = { 0, 0 })
143    @TADescription(annotation = "RTCs", type = FIELD,
144            genericLocation = { 0, 0, 0, 0 })
145    public String fieldAsArrayRepeatableAnnotation() {
146        return "@RTC @RTC String @RTA @RTA [] @RTB @RTB [] test;";
147    }
148
149    @TADescription(annotation = "RTAs", type = FIELD)
150    @TADescription(annotation = "RTBs", type = FIELD,
151           genericLocation = { 0, 0 })
152    @TADescription(annotation = "RTCs", type = FIELD,
153            genericLocation = { 0, 0, 0, 0 })
154    public String fieldAsArrayOldRepeatableAnnotation() {
155        return "@RTC @RTC String test @RTA @RTA [] @RTB @RTB [];";
156    }
157
158    // Smoke tests
159    @TADescription(annotation = "RTAs", type = FIELD)
160    public String interfaceFieldAsObjectRepeatableAnnotation() {
161        return "interface %TEST_CLASS_NAME% { @RTA @RTA String test = null; }";
162    }
163
164    @TADescription(annotation = "RTAs", type = FIELD)
165    public String abstractFieldAsObjectRepeatableAnnotation() {
166        return "abstract class %TEST_CLASS_NAME% { @RTA @RTA String test; }";
167    }
168
169    @TADescription(annotation = "RTAs", type = FIELD)
170    @TADescription(annotation = "RTBs", type = FIELD,
171            genericLocation = { 3, 0 })
172    @TADescription(annotation = "RTCs", type = FIELD,
173            genericLocation = { 3, 1 })
174    @TADescription(annotation = "RTDs", type = FIELD,
175            genericLocation = { 3, 1, 3, 0 })
176    public String interfaceFieldAsParametrizedRepeatableAnnotation() {
177        return "interface %TEST_CLASS_NAME% { @RTA @RTA Map<@RTB @RTB String, @RTC @RTC List<@RTD @RTD String>> test = null; }";
178    }
179
180
181    @TADescription(annotation = "RTAs", type = FIELD)
182    @TADescription(annotation = "RTBs", type = FIELD,
183            genericLocation = { 3, 0 })
184    @TADescription(annotation = "RTCs", type = FIELD,
185            genericLocation = { 3, 1 })
186    @TADescription(annotation = "RTDs", type = FIELD,
187            genericLocation = { 3, 1, 3, 0 })
188    public String staticFieldAsParametrizedRepeatableAnnotation() {
189        return "static @RTA @RTA Map<@RTB @RTB String, @RTC @RTC List<@RTD @RTD String>> test;";
190    }
191}
192