|
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 new object creations |
|
29 * @compile -g Driver.java ReferenceInfoUtil.java NewObjects.java |
|
30 * @run main Driver NewObjects |
|
31 */ |
|
32 public class NewObjects { |
|
33 |
|
34 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
35 public String returnObject() { |
|
36 return "Object returnObject() { return new @TA String(); }"; |
|
37 } |
|
38 |
|
39 @TADescriptions({ |
|
40 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), |
|
41 @TADescription(annotation = "TB", type = NEW, |
|
42 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
43 }) |
|
44 public String returnObjectGeneric() { |
|
45 return "Object returnObjectGeneric() { return new @TA ArrayList<@TB String>(); }"; |
|
46 } |
|
47 |
|
48 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
49 public String initObject() { |
|
50 return "void initObject() { Object a = new @TA String(); }"; |
|
51 } |
|
52 |
|
53 @TADescriptions({ |
|
54 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), |
|
55 @TADescription(annotation = "TB", type = NEW, |
|
56 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), |
|
57 @TADescription(annotation = "TC", type = NEW, |
|
58 genericLocation = { 3, 1 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
59 }) |
|
60 public String initObjectGeneric() { |
|
61 return "void initObjectGeneric() { Object a = new @TA HashMap<@TB String, @TC String>(); }"; |
|
62 } |
|
63 |
|
64 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
65 public String eqtestObject() { |
|
66 return "void eqtestObject() { if (null == new @TA String()); }"; |
|
67 } |
|
68 |
|
69 @TADescriptions({ |
|
70 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), |
|
71 @TADescription(annotation = "TB", type = NEW, |
|
72 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
73 }) |
|
74 public String eqtestObjectGeneric() { |
|
75 return "void eqtestObjectGeneric() { if (null == new @TA ArrayList<@TB String >()); }"; |
|
76 } |
|
77 |
|
78 @TADescriptions({ |
|
79 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
80 genericLocation = {0, 0}), |
|
81 @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) |
|
82 }) |
|
83 public String returnNewArray1() { |
|
84 return "Object returnNewArray1() { return new @TA String @TB[1]; }"; |
|
85 } |
|
86 |
|
87 @TADescriptions({ |
|
88 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
89 genericLocation = {0, 0, 0, 0}), |
|
90 @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), |
|
91 @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
92 genericLocation = {0, 0}), |
|
93 }) |
|
94 public String returnNewArray2() { |
|
95 return "Object returnNewArray2() { return new @TA String @TB [1] @TC [2]; }"; |
|
96 } |
|
97 |
|
98 @TADescriptions({ |
|
99 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
100 genericLocation = {0, 0, 0, 0}), |
|
101 @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
102 genericLocation = {0, 0, 0, 0, 1, 0}), |
|
103 @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), |
|
104 @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
105 genericLocation = {0, 0}), |
|
106 }) |
|
107 public String returnNewArray3() { |
|
108 return "Object returnNewArray3() { return new @TA Outer. @TB Inner @TC [1] @TD [2]; }"; |
|
109 } |
|
110 |
|
111 @TADescriptions({ |
|
112 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
113 genericLocation = {0, 0, 0, 0}), |
|
114 @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
115 genericLocation = {0, 0, 0, 0, 1, 0}), |
|
116 @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
117 genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}), |
|
118 @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), |
|
119 @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
120 genericLocation = {0, 0}), |
|
121 }) |
|
122 public String returnNewArray4() { |
|
123 return "Object returnNewArray4() { return new @TA Outer. @TB Middle. @TC MInner @TD [1] @TE [2]; }"; |
|
124 } |
|
125 |
|
126 @TADescriptions({ |
|
127 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), |
|
128 @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
129 genericLocation = {3, 0, 0, 0, 0, 0}), |
|
130 @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
131 genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}), |
|
132 @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
133 genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}), |
|
134 @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
135 genericLocation = {3, 0}), |
|
136 @TADescription(annotation = "TF", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
137 genericLocation = {3, 0, 0, 0}), |
|
138 }) |
|
139 public String returnNewArray5() { |
|
140 return "Object returnNewArray5() { return new @TA ArrayList<@TB Outer. @TC Middle. @TD MInner @TE [] @TF []>(); }"; |
|
141 } |
|
142 |
|
143 @TADescriptions({ |
|
144 @TADescription(annotation = "TA", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
145 genericLocation = {0, 0, 0, 0}), |
|
146 @TADescription(annotation = "TB", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
147 genericLocation = {0, 0, 0, 0, 1, 0}), |
|
148 @TADescription(annotation = "TC", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE), |
|
149 @TADescription(annotation = "TD", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, |
|
150 genericLocation = {0, 0}), |
|
151 }) |
|
152 public String arrayField() { |
|
153 return "@TA Outer. @TB Inner @TC [] @TD [] f;"; |
|
154 } |
|
155 } |