1 /*
2  * Copyright (c) 2009, 2013, 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  * @summary Test population of reference info for class literals
29  * @compile -g Driver.java ReferenceInfoUtil.java TypeTests.java
30  * @run main Driver TypeTests
31  */
32 public class TypeTests {
33 
34     @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
returnObject()35     public String returnObject() {
36         return "Object returnObject() { return null instanceof @TA String; }";
37     }
38 
39     @TADescriptions({
40         @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE),
41         @TADescription(annotation = "TB", type = INSTANCEOF,
42                 genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
43         @TADescription(annotation = "TC", type = INSTANCEOF,
44                 genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
45     })
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     @TADescriptions({
53         @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE),
54         @TADescription(annotation = "TB", type = INSTANCEOF,
55                 genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
56         @TADescription(annotation = "TC", type = INSTANCEOF,
57                 genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
58     })
returnPrimArray()59     public String returnPrimArray() {
60         return "Object returnPrimArray() { return null instanceof @TC int @TA [] @TB []; }";
61     }
62 
63     // no void
64     // no void array
65 
66     @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
initObject()67     public String initObject() {
68         return "void initObject() { Object a =  null instanceof @TA String; }";
69     }
70 
71     @TADescriptions({
72         @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE),
73         @TADescription(annotation = "TB", type = INSTANCEOF,
74                 genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
75         @TADescription(annotation = "TC", type = INSTANCEOF,
76                 genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
77     })
initObjectArray()78     public String initObjectArray() {
79         return "void initObjectArray() { Object a = null instanceof @TC String @TA [] @TB []; }";
80     }
81 
82     // no primitive instanceof
83 
84     @TADescriptions({
85         @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE),
86         @TADescription(annotation = "TB", type = INSTANCEOF,
87                 genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
88         @TADescription(annotation = "TC", type = INSTANCEOF,
89                 genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
90     })
initPrimArray()91     public String initPrimArray() {
92         return "void initPrimArray() { Object a = null instanceof @TC int @TA [] @TB []; }";
93     }
94 
95     // no void
96     // no void array
97 
98     @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE)
eqtestObject()99     public String eqtestObject() {
100         return "void eqtestObject() { if (true == (null instanceof @TA String)); }";
101     }
102 
103     @TADescriptions({
104         @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE),
105         @TADescription(annotation = "TB", type = INSTANCEOF,
106                 genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
107         @TADescription(annotation = "TC", type = INSTANCEOF,
108                 genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
109     })
eqtestObjectArray()110     public String eqtestObjectArray() {
111         return "void eqtestObjectArray() { if (true == (null instanceof @TC String @TA [] @TB [])); }";
112     }
113 
114     // no primitives
115 
116     @TADescriptions({
117         @TADescription(annotation = "TA", type = INSTANCEOF, offset = ReferenceInfoUtil.IGNORE_VALUE),
118         @TADescription(annotation = "TB", type = INSTANCEOF,
119                 genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
120         @TADescription(annotation = "TC", type = INSTANCEOF,
121                 genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
122     })
eqtestPrimArray()123     public String eqtestPrimArray() {
124         return "void eqtestPrimArray() { if (true == (null instanceof @TC int @TA [] @TB [])); }";
125     }
126 
127     // no void
128     // no void array
129 
130 }
131