Initializers.java revision 2942:08092deced3f
1193323Sed/* 2193323Sed * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 3193323Sed * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4193323Sed * 5193323Sed * This code is free software; you can redistribute it and/or modify it 6193323Sed * under the terms of the GNU General Public License version 2 only, as 7193323Sed * published by the Free Software Foundation. 8193323Sed * 9193323Sed * This code is distributed in the hope that it will be useful, but WITHOUT 10193323Sed * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11193323Sed * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12193323Sed * version 2 for more details (a copy is included in the LICENSE file that 13193323Sed * accompanied this code). 14193323Sed * 15193323Sed * You should have received a copy of the GNU General Public License version 16193323Sed * 2 along with this work; if not, write to the Free Software Foundation, 17193323Sed * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18193323Sed * 19193323Sed * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20193323Sed * or visit www.oracle.com if you need additional information or have any 21193323Sed * questions. 22193323Sed */ 23193323Sed 24193323Sedimport static com.sun.tools.classfile.TypeAnnotation.TargetType.*; 25193323Sed 26193323Sed/* 27193323Sed * @test 28193323Sed * @bug 8013852 8042451 29193323Sed * @summary Test population of reference info for instance and class initializers 30193323Sed * @author Werner Dietl 31193323Sed * @modules jdk.jdeps/com.sun.tools.classfile 32193323Sed * @compile -g Driver.java ReferenceInfoUtil.java Initializers.java 33193323Sed * @run main Driver Initializers 34193323Sed */ 35193323Sedpublic class Initializers { 36193323Sed 37193323Sed @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 38193323Sed @TADescription(annotation = "TB", type = NEW, 39193323Sed genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 40234353Sdim public String instanceInit1() { 41193323Sed return "class %TEST_CLASS_NAME% { { Object o = new @TA ArrayList<@TB String>(); } }"; 42193323Sed } 43193323Sed 44193323Sed @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 45193323Sed @TADescription(annotation = "TB", type = NEW, 46193323Sed genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 47193323Sed @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 48193323Sed @TADescription(annotation = "TD", type = NEW, 49193323Sed genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 50193323Sed public String instanceInit2() { 51193323Sed return "class %TEST_CLASS_NAME% { Object f = new @TA ArrayList<@TB String>(); " + 52193323Sed " { Object o = new @TC ArrayList<@TD String>(); } }"; 53193323Sed } 54193323Sed 55193323Sed @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 56193323Sed @TADescription(annotation = "TB", type = NEW, 57193323Sed genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 58193323Sed public String staticInit1() { 59193323Sed return "class %TEST_CLASS_NAME% { static { Object o = new @TA ArrayList<@TB String>(); } }"; 60193323Sed } 61193323Sed 62193323Sed @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 63193323Sed @TADescription(annotation = "TB", type = NEW, 64193323Sed genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 65193323Sed @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 66193323Sed @TADescription(annotation = "TD", type = NEW, 67193323Sed genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 68239462Sdim @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 69239462Sdim @TADescription(annotation = "TF", type = NEW, 70239462Sdim genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 71239462Sdim public String staticInit2() { 72239462Sdim return "class %TEST_CLASS_NAME% { Object f = new @TA ArrayList<@TB String>(); " + 73239462Sdim " static Object g = new @TC ArrayList<@TD String>(); " + 74239462Sdim " static { Object o = new @TE ArrayList<@TF String>(); } }"; 75239462Sdim } 76193323Sed 77193323Sed @TADescription(annotation = "TA", type = CAST, 78193323Sed typeIndex = 0, offset = ReferenceInfoUtil.IGNORE_VALUE) 79193323Sed public String lazyConstantCast1() { 80193323Sed return "class %TEST_CLASS_NAME% { public static final Object o = (@TA Object) null; }"; 81193323Sed } 82193323Sed 83193323Sed @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 84193323Sed @TADescription(annotation = "RTBs", type = NEW, 85193323Sed genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 86193323Sed public String instanceInitRepeatableAnnotation1() { 87193323Sed return "class %TEST_CLASS_NAME% { { Object o = new @RTA @RTA ArrayList<@RTB @RTB String>(); } }"; 88193323Sed } 89193323Sed 90193323Sed @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 91193323Sed @TADescription(annotation = "RTBs", type = NEW, 92193323Sed genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 93234353Sdim @TADescription(annotation = "RTCs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 94234353Sdim @TADescription(annotation = "RTDs", type = NEW, 95234353Sdim genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 96193323Sed public String instanceInitRepeatableAnnotation2() { 97193323Sed return "class %TEST_CLASS_NAME% { Object f = new @RTA @RTA ArrayList<@RTB @RTB String>(); " + 98193323Sed " { Object o = new @RTC @RTC ArrayList<@RTD @RTD String>(); } }"; 99193323Sed } 100193323Sed 101193323Sed @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 102193323Sed @TADescription(annotation = "RTBs", type = NEW, 103193323Sed genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 104193323Sed public String staticInitRepeatableAnnotation1() { 105193323Sed return "class %TEST_CLASS_NAME% { static { Object o = new @RTA @RTA ArrayList<@RTB @RTB String>(); } }"; 106193323Sed } 107193323Sed 108193323Sed @TADescription(annotation = "RTAs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 109193323Sed @TADescription(annotation = "RTBs", type = NEW, 110193323Sed genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 111193323Sed @TADescription(annotation = "RTCs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 112193323Sed @TADescription(annotation = "RTDs", type = NEW, 113193323Sed genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 114193323Sed @TADescription(annotation = "RTEs", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 115193323Sed @TADescription(annotation = "RTFs", type = NEW, 116193323Sed genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 117234353Sdim public String staticInitRepeatableAnnotation2() { 118234353Sdim return "class %TEST_CLASS_NAME% { Object f = new @RTA @RTA ArrayList<@RTB @RTB String>(); " + 119234353Sdim " static Object g = new @RTC @RTC ArrayList<@RTD @RTD String>(); " + 120234353Sdim " static { Object o = new @RTE @RTE ArrayList<@RTF @RTF String>(); } }"; 121234353Sdim } 122193323Sed 123193323Sed // TODO: test interaction with several constructors, especially non-initial constructors. 124193323Sed // I don't think this kind of test is possible here. 125193323Sed 126193323Sed @TADescription(annotation = "RTAs", type = CAST, 127193323Sed typeIndex = 0, offset = ReferenceInfoUtil.IGNORE_VALUE) 128193323Sed public String lazyConstantCastRepeatableAnnotation1() { 129193323Sed return "class %TEST_CLASS_NAME% { public static final Object o = (@RTA @RTA Object) null; }"; 130193323Sed } 131193323Sed} 132193323Sed