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