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 
24 import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
25 
26 /*
27  * @test
28  * @bug 8042451
29  * @summary Test population of reference info for class literals
30  * @modules jdk.jdeps/com.sun.tools.classfile
31  * @compile -g Driver.java ReferenceInfoUtil.java TypeTests.java
32  * @run main Driver TypeTests
33  */
34 public class TypeTests {
35 
36     @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
returnObject()37     public String returnObject() {
38         return "Object returnObject() { return null instanceof @TA String; }";
39     }
40 
41     @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
42     @TADescription(annotation = "TB", type = INSTANCEOF,
43             genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
44     @TADescription(annotation = "TC", type = INSTANCEOF,
45             genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
returnObjectArray()46     public String returnObjectArray() {
47         return "Object returnObjectArray() { return null instanceof @TC String @TA [] @TB []; }";
48     }
49 
50     // no type test for primitives
51 
52     @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
53     @TADescription(annotation = "TB", type = INSTANCEOF,
54             genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
55     @TADescription(annotation = "TC", type = INSTANCEOF,
56             genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
returnPrimArray()57     public String returnPrimArray() {
58         return "Object returnPrimArray() { return null instanceof @TC int @TA [] @TB []; }";
59     }
60 
61     // no void
62     // no void array
63 
64     @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
initObject()65     public String initObject() {
66         return "void initObject() { Object a =  null instanceof @TA String; }";
67     }
68 
69     @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
70     @TADescription(annotation = "TB", type = INSTANCEOF,
71             genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
72     @TADescription(annotation = "TC", type = INSTANCEOF,
73             genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
initObjectArray()74     public String initObjectArray() {
75         return "void initObjectArray() { Object a = null instanceof @TC String @TA [] @TB []; }";
76     }
77 
78     // no primitive instanceof
79 
80     @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
81     @TADescription(annotation = "TB", type = INSTANCEOF,
82             genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
83     @TADescription(annotation = "TC", type = INSTANCEOF,
84             genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
initPrimArray()85     public String initPrimArray() {
86         return "void initPrimArray() { Object a = null instanceof @TC int @TA [] @TB []; }";
87     }
88 
89     // no void
90     // no void array
91 
92     @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
eqtestObject()93     public String eqtestObject() {
94         return "void eqtestObject() { if (true == (null instanceof @TA String)); }";
95     }
96 
97     @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
98     @TADescription(annotation = "TB", type = INSTANCEOF,
99             genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
100     @TADescription(annotation = "TC", type = INSTANCEOF,
101             genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
eqtestObjectArray()102     public String eqtestObjectArray() {
103         return "void eqtestObjectArray() { if (true == (null instanceof @TC String @TA [] @TB [])); }";
104     }
105 
106     // no primitives
107 
108     @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
109     @TADescription(annotation = "TB", type = INSTANCEOF,
110             genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
111     @TADescription(annotation = "TC", type = INSTANCEOF,
112             genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
eqtestPrimArray()113     public String eqtestPrimArray() {
114         return "void eqtestPrimArray() { if (true == (null instanceof @TC int @TA [] @TB [])); }";
115     }
116 
117     // no void
118     // no void array
119 
120     @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
returnObjectRepeatableAnnotation()121     public String returnObjectRepeatableAnnotation() {
122         return "Object returnObject() { return null instanceof @RTA @RTA String; }";
123     }
124 
125     @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
126     @TADescription(annotation = "RTBs", type = INSTANCEOF,
127             genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
128     @TADescription(annotation = "RTCs", type = INSTANCEOF,
129             genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
returnObjectArrayRepeatableAnnotation()130     public String returnObjectArrayRepeatableAnnotation() {
131         return "Object returnObjectArray() { return null instanceof @RTC @RTC String @RTA @RTA [] @RTB @RTB []; }";
132     }
133 
134     @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
135     @TADescription(annotation = "RTBs", type = INSTANCEOF,
136             genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
137     @TADescription(annotation = "RTCs", type = INSTANCEOF,
138             genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
returnPrimArrayRepeatableAnnotation()139     public String returnPrimArrayRepeatableAnnotation() {
140         return "Object returnPrimArrayRepeatableAnnotation() { return null instanceof @RTC @RTC int @RTA @RTA [] @RTB @RTB []; }";
141     }
142 
143     @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
initObjectRepeatableAnnotation()144     public String initObjectRepeatableAnnotation() {
145         return "void initObject() { Object a =  null instanceof @RTA @RTA String; }";
146     }
147 
148     @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
149     @TADescription(annotation = "RTBs", type = INSTANCEOF,
150             genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
151     @TADescription(annotation = "RTCs", type = INSTANCEOF,
152             genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
initObjectArrayRepeatableAnnotation()153     public String initObjectArrayRepeatableAnnotation() {
154         return "void initObjectArray() { Object a = null instanceof @RTC @RTC String @RTA @RTA [] @RTB @RTB []; }";
155     }
156 
157     @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
158     @TADescription(annotation = "RTBs", type = INSTANCEOF,
159             genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
160     @TADescription(annotation = "RTCs", type = INSTANCEOF,
161             genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
initPrimArrayRepeatableAnnotation()162     public String initPrimArrayRepeatableAnnotation() {
163         return "void initPrimArray() { Object a = null instanceof @RTC @RTC int @RTA @RTA [] @RTB @RTB []; }";
164     }
165 
166     @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
eqtestObjectRepeatableAnnotation()167     public String eqtestObjectRepeatableAnnotation() {
168         return "void eqtestObject() { if (true == (null instanceof @RTA @RTA String)); }";
169     }
170 
171     @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
172     @TADescription(annotation = "RTBs", type = INSTANCEOF,
173             genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
174     @TADescription(annotation = "RTCs", type = INSTANCEOF,
175             genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
eqtestObjectArrayRepeatableAnnotation()176     public String eqtestObjectArrayRepeatableAnnotation() {
177         return "void eqtestObjectArray() { if (true == (null instanceof @RTC @RTC String @RTA @RTA [] @RTB @RTB [])); }";
178     }
179 
180     @TADescription(annotation = "RTAs", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
181     @TADescription(annotation = "RTBs", type = INSTANCEOF,
182             genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
183     @TADescription(annotation = "RTCs", type = INSTANCEOF,
184             genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
eqtestPrimArrayRepeatableAnnotation()185     public String eqtestPrimArrayRepeatableAnnotation() {
186         return "void eqtestPrimArray() { if (true == (null instanceof @RTC @RTC int @RTA @RTA [] @RTB @RTB [])); }";
187     }
188 }
189