1 /* 2 * Copyright (c) 2009, 2024, 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 java.lang.classfile.TypeAnnotation.TargetType.*; 25 26 /* 27 * @test 28 * @bug 8042451 29 * @summary Test population of reference info for new object creations 30 * @compile -g Driver.java ReferenceInfoUtil.java NewObjects.java 31 * @run main Driver NewObjects 32 */ 33 public class NewObjects { 34 35 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 36 public String returnObject() { 37 return "Object returnObject() { return new @TA String(); }"; 38 } 39 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 public String returnObjectGeneric() { 44 return "Object returnObjectGeneric() { return new @TA ArrayList<@TB String>(); }"; 45 } 46 47 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 48 public String initObject() { 49 return "void initObject() { Object a = new @TA String(); }"; 50 } 51 52 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 53 @TADescription(annotation = "TB", type = NEW, 54 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 55 @TADescription(annotation = "TC", type = NEW, 56 genericLocation = { 3, 1 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 57 public String initObjectGeneric() { 58 return "void initObjectGeneric() { Object a = new @TA HashMap<@TB String, @TC String>(); }"; 59 } 60 61 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 62 public String eqtestObject() { 63 return "void eqtestObject(String s) { if (s == new @TA String()); }"; 64 } 65 66 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 67 @TADescription(annotation = "TB", type = NEW, 68 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 69 public String eqtestObjectGeneric() { 70 return "void eqtestObjectGeneric(ArrayList<String> as) { if (as == new @TA ArrayList<@TB String >()); }"; 71 } 72 73 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 74 genericLocation = {0, 0}) 75 @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 76 public String returnNewArray1() { 77 return "Object returnNewArray1() { return new @TA String @TB[1]; }"; 78 } 79 80 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 81 genericLocation = {0, 0, 0, 0}) 82 @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 83 @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 84 genericLocation = {0, 0}) 85 public String returnNewArray2() { 86 return "Object returnNewArray2() { return new @TA String @TB [1] @TC [2]; }"; 87 } 88 89 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 90 genericLocation = {0, 0, 0, 0}) 91 @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 92 genericLocation = {0, 0, 0, 0, 1, 0}) 93 @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 94 @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 95 genericLocation = {0, 0}) 96 public String returnNewArray3() { 97 return "Object returnNewArray3() { return new @TA Outer. @TB Inner @TC [1] @TD [2]; }"; 98 } 99 100 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 101 genericLocation = {0, 0, 0, 0}) 102 @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 103 genericLocation = {0, 0, 0, 0, 1, 0}) 104 @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 105 genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}) 106 @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 107 @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 108 genericLocation = {0, 0}) 109 public String returnNewArray4() { 110 return "Object returnNewArray4() { return new @TA Outer. @TB Middle. @TC MInner @TD [1] @TE [2]; }"; 111 } 112 113 @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 114 @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 115 genericLocation = {3, 0, 0, 0, 0, 0}) 116 @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 117 genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}) 118 @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 119 genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}) 120 @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 121 genericLocation = {3, 0}) 122 @TADescription(annotation = "TF", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 123 genericLocation = {3, 0, 0, 0}) 124 public String returnNewArray5() { 125 return "Object returnNewArray5() { return new @TA ArrayList<@TB Outer. @TC Middle. @TD MInner @TE [] @TF []>(); }"; 126 } 127 128 @TADescription(annotation = "TA", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, 129 genericLocation = {0, 0, 0, 0}) 130 @TADescription(annotation = "TB", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, 131 genericLocation = {0, 0, 0, 0, 1, 0}) 132 @TADescription(annotation = "TC", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE) 133 @TADescription(annotation = "TD", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, 134 genericLocation = {0, 0}) 135 public String arrayField() { 136 return "@TA Outer. @TB Inner @TC [] @TD [] f;"; 137 } 138 139 @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 140 public String returnObjectRepeatableAnnotation() { 141 return "Object returnObject() { return new @RTA @RTA String(); }"; 142 } 143 144 @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 145 @TADescription(annotation = "RTBs", type = NEW, 146 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 147 public String returnObjectGenericRepeatableAnnotation() { 148 return "Object returnObjectGeneric() { return new @RTA @RTA ArrayList<@RTB @RTB String>(); }"; 149 } 150 151 @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 152 public String initObjectRepeatableAnnotation() { 153 return "void initObject() { Object a = new @RTA @RTA String(); }"; 154 } 155 156 @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 157 @TADescription(annotation = "RTBs", type = NEW, 158 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 159 @TADescription(annotation = "RTCs", type = NEW, 160 genericLocation = { 3, 1 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 161 public String initObjectGenericRepeatableAnnotation() { 162 return "void initObjectGeneric() { Object a = new @RTA @RTA HashMap<@RTB @RTB String, @RTC @RTC String>(); }"; 163 } 164 165 @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 166 public String eqtestObjectRepeatableAnnotation() { 167 return "void eqtestObject(String s) { if (s == new @RTA @RTA String()); }"; 168 } 169 170 @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 171 @TADescription(annotation = "RTBs", type = NEW, 172 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 173 public String eqtestObjectGenericRepeatableAnnotation() { 174 return "void eqtestObjectGeneric(ArrayList<String> as) { if (as == new @RTA @RTA ArrayList<@RTB @RTB String >()); }"; 175 } 176 177 @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 178 genericLocation = {0, 0}) 179 @TADescription(annotation = "RTBs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 180 public String returnNewArrayRepeatableAnnotation1() { 181 return "Object returnNewArray1() { return new @RTA @RTA String @RTB @RTB[1]; }"; 182 } 183 184 @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 185 genericLocation = {0, 0, 0, 0}) 186 @TADescription(annotation = "RTBs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 187 @TADescription(annotation = "RTCs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 188 genericLocation = {0, 0}) 189 public String returnNewArrayRepeatableAnnotation2() { 190 return "Object returnNewArray2() { return new @RTA @RTA String @RTB @RTB [1] @RTC @RTC [2]; }"; 191 } 192 193 @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 194 genericLocation = {0, 0, 0, 0}) 195 @TADescription(annotation = "RTBs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 196 genericLocation = {0, 0, 0, 0, 1, 0}) 197 @TADescription(annotation = "RTCs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 198 @TADescription(annotation = "RTDs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 199 genericLocation = {0, 0}) 200 public String returnNewArrayRepeatableAnnotation3() { 201 return "Object returnNewArray3() { return new @RTA @RTA Outer. @RTB @RTB Inner @RTC @RTC [1] @RTD @RTD [2]; }"; 202 } 203 204 @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 205 genericLocation = {0, 0, 0, 0}) 206 @TADescription(annotation = "RTBs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 207 genericLocation = {0, 0, 0, 0, 1, 0}) 208 @TADescription(annotation = "RTCs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 209 genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}) 210 @TADescription(annotation = "RTDs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 211 @TADescription(annotation = "RTEs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 212 genericLocation = {0, 0}) 213 public String returnNewArrayRepeatableAnnotation4() { 214 return "Object returnNewArray4() { return new @RTA @RTA Outer." + 215 " @RTB @RTB Middle. @RTC @RTC MInner @RTD @RTD [1] @RTE @RTE [2]; }"; 216 } 217 218 @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 219 @TADescription(annotation = "RTBs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 220 genericLocation = {3, 0, 0, 0, 0, 0}) 221 @TADescription(annotation = "RTCs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 222 genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}) 223 @TADescription(annotation = "RTDs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 224 genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}) 225 @TADescription(annotation = "RTEs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 226 genericLocation = {3, 0}) 227 @TADescription(annotation = "RTFs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 228 genericLocation = {3, 0, 0, 0}) 229 public String returnNewArrayRepeatableAnnotation5() { 230 return "Object returnNewArray5() { return new @RTA @RTA ArrayList<@RTB @RTB Outer." + 231 " @RTC @RTC Middle. @RTD @RTD MInner @RTE @RTE [] @RTF @RTF []>(); }"; 232 } 233 234 @TADescription(annotation = "RTAs", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, 235 genericLocation = {0, 0, 0, 0}) 236 @TADescription(annotation = "RTBs", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, 237 genericLocation = {0, 0, 0, 0, 1, 0}) 238 @TADescription(annotation = "RTCs", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE) 239 @TADescription(annotation = "RTDs", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, 240 genericLocation = {0, 0}) 241 public String arrayFieldRepeatableAnnotation() { 242 return "@RTA @RTA Outer. @RTB @RTB Inner @RTC @RTC [] @RTD @RTD [] f;"; 243 } 244 }