1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/NewObjects.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,155 @@ 1.4 +/* 1.5 + * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; 1.28 + 1.29 +/* 1.30 + * @test 1.31 + * @summary Test population of reference info for new object creations 1.32 + * @compile -g Driver.java ReferenceInfoUtil.java NewObjects.java 1.33 + * @run main Driver NewObjects 1.34 + */ 1.35 +public class NewObjects { 1.36 + 1.37 + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 1.38 + public String returnObject() { 1.39 + return "Object returnObject() { return new @TA String(); }"; 1.40 + } 1.41 + 1.42 + @TADescriptions({ 1.43 + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), 1.44 + @TADescription(annotation = "TB", type = NEW, 1.45 + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 1.46 + }) 1.47 + public String returnObjectGeneric() { 1.48 + return "Object returnObjectGeneric() { return new @TA ArrayList<@TB String>(); }"; 1.49 + } 1.50 + 1.51 + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 1.52 + public String initObject() { 1.53 + return "void initObject() { Object a = new @TA String(); }"; 1.54 + } 1.55 + 1.56 + @TADescriptions({ 1.57 + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), 1.58 + @TADescription(annotation = "TB", type = NEW, 1.59 + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), 1.60 + @TADescription(annotation = "TC", type = NEW, 1.61 + genericLocation = { 3, 1 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 1.62 + }) 1.63 + public String initObjectGeneric() { 1.64 + return "void initObjectGeneric() { Object a = new @TA HashMap<@TB String, @TC String>(); }"; 1.65 + } 1.66 + 1.67 + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 1.68 + public String eqtestObject() { 1.69 + return "void eqtestObject() { if (null == new @TA String()); }"; 1.70 + } 1.71 + 1.72 + @TADescriptions({ 1.73 + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), 1.74 + @TADescription(annotation = "TB", type = NEW, 1.75 + genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 1.76 + }) 1.77 + public String eqtestObjectGeneric() { 1.78 + return "void eqtestObjectGeneric() { if (null == new @TA ArrayList<@TB String >()); }"; 1.79 + } 1.80 + 1.81 + @TADescriptions({ 1.82 + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.83 + genericLocation = {0, 0}), 1.84 + @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE) 1.85 + }) 1.86 + public String returnNewArray1() { 1.87 + return "Object returnNewArray1() { return new @TA String @TB[1]; }"; 1.88 + } 1.89 + 1.90 + @TADescriptions({ 1.91 + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.92 + genericLocation = {0, 0, 0, 0}), 1.93 + @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), 1.94 + @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.95 + genericLocation = {0, 0}), 1.96 + }) 1.97 + public String returnNewArray2() { 1.98 + return "Object returnNewArray2() { return new @TA String @TB [1] @TC [2]; }"; 1.99 + } 1.100 + 1.101 + @TADescriptions({ 1.102 + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.103 + genericLocation = {0, 0, 0, 0}), 1.104 + @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.105 + genericLocation = {0, 0, 0, 0, 1, 0}), 1.106 + @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), 1.107 + @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.108 + genericLocation = {0, 0}), 1.109 + }) 1.110 + public String returnNewArray3() { 1.111 + return "Object returnNewArray3() { return new @TA Outer. @TB Inner @TC [1] @TD [2]; }"; 1.112 + } 1.113 + 1.114 + @TADescriptions({ 1.115 + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.116 + genericLocation = {0, 0, 0, 0}), 1.117 + @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.118 + genericLocation = {0, 0, 0, 0, 1, 0}), 1.119 + @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.120 + genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}), 1.121 + @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), 1.122 + @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.123 + genericLocation = {0, 0}), 1.124 + }) 1.125 + public String returnNewArray4() { 1.126 + return "Object returnNewArray4() { return new @TA Outer. @TB Middle. @TC MInner @TD [1] @TE [2]; }"; 1.127 + } 1.128 + 1.129 + @TADescriptions({ 1.130 + @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE), 1.131 + @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.132 + genericLocation = {3, 0, 0, 0, 0, 0}), 1.133 + @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.134 + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}), 1.135 + @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.136 + genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}), 1.137 + @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.138 + genericLocation = {3, 0}), 1.139 + @TADescription(annotation = "TF", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.140 + genericLocation = {3, 0, 0, 0}), 1.141 + }) 1.142 + public String returnNewArray5() { 1.143 + return "Object returnNewArray5() { return new @TA ArrayList<@TB Outer. @TC Middle. @TD MInner @TE [] @TF []>(); }"; 1.144 + } 1.145 + 1.146 + @TADescriptions({ 1.147 + @TADescription(annotation = "TA", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.148 + genericLocation = {0, 0, 0, 0}), 1.149 + @TADescription(annotation = "TB", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.150 + genericLocation = {0, 0, 0, 0, 1, 0}), 1.151 + @TADescription(annotation = "TC", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE), 1.152 + @TADescription(annotation = "TD", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE, 1.153 + genericLocation = {0, 0}), 1.154 + }) 1.155 + public String arrayField() { 1.156 + return "@TA Outer. @TB Inner @TC [] @TD [] f;"; 1.157 + } 1.158 +}