1 /* 2 * Copyright (c) 2009, 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 type casts 29 * @compile -g Driver.java ReferenceInfoUtil.java TypeCasts.java 30 * @run main Driver TypeCasts 31 */ 32 public class TypeCasts { 33 34 @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE) 35 public String returnObject() { 36 return "Object returnObject() { return (@TA String)null; }"; 37 } 38 39 @TADescriptions({ 40 @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 41 @TADescription(annotation = "TB", type = CAST, 42 genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE), 43 @TADescription(annotation = "TC", type = CAST, 44 genericLocation = { 0, 0, 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 45 }) 46 public String returnObjectArray() { 47 return "Object returnObjectArray() { return (@TC String @TA [] @TB [])null; }"; 48 } 49 50 @TADescriptions({ 51 @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 52 @TADescription(annotation = "TB", type = CAST, 53 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 54 }) 55 public String returnObjectGeneric() { 56 return "Object returnObjectGeneric() { return (@TA List<@TB String>)null; }"; 57 } 58 59 @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE) 60 public String returnPrim() { 61 return "Object returnPrim() { return (@TA int)0; }"; 62 } 63 64 @TADescriptions({ 65 @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 66 @TADescription(annotation = "TB", type = CAST, 67 genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 68 }) 69 public String returnPrimArray() { 70 return "Object returnPrimArray() { return (@TB int @TA [])null; }"; 71 } 72 73 @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE) 74 public String initObject() { 75 return "void initObject() { Object a = (@TA String)null; }"; 76 } 77 78 @TADescriptions({ 79 @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 80 @TADescription(annotation = "TB", type = CAST, 81 genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 82 }) 83 public String initObjectArray() { 84 return "void initObjectArray() { Object a = (@TB String @TA [])null; }"; 85 } 86 87 @TADescriptions({ 88 @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 89 @TADescription(annotation = "TB", type = CAST, 90 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 91 }) 92 public String initObjectGeneric() { 93 return "void initObjectGeneric() { Object a = (@TA List<@TB String>)null; }"; 94 } 95 96 @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE) 97 public String initPrim() { 98 return "void initPrim() { Object a = (@TA int)0; }"; 99 } 100 101 @TADescriptions({ 102 @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 103 @TADescription(annotation = "TB", type = CAST, 104 genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 105 }) 106 public String initPrimArray() { 107 return "void initPrimArray() { Object a = (@TB int @TA [])null; }"; 108 } 109 110 @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE) 111 public String eqtestObject() { 112 return "void eqtestObject() { if (null == (@TA String)null); }"; 113 } 114 115 @TADescriptions({ 116 @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 117 @TADescription(annotation = "TB", type = CAST, 118 genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 119 }) 120 public String eqtestObjectArray() { 121 return "void eqtestObjectArray() { if (null == (@TB String @TA [])null); }"; 122 } 123 124 @TADescriptions({ 125 @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 126 @TADescription(annotation = "TB", type = CAST, 127 genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 128 }) 129 public String eqtestObjectGeneric() { 130 return "void eqtestObjectGeneric() { if (null == (@TA List<@TB String >)null); }"; 131 } 132 133 @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE) 134 // compiler optimizes away compile time constants casts 135 public String eqtestPrim() { 136 return "void eqtestPrim(int a) { if (0 == (@TA int)a); }"; 137 } 138 139 @TADescriptions({ 140 @TADescription(annotation = "TA", type = CAST, offset = ReferenceInfoUtil.IGNORE_VALUE), 141 @TADescription(annotation = "TB", type = CAST, 142 genericLocation = { 0, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE) 143 }) 144 public String eqtestPrimArray() { 145 return "void eqtestPrimArray() { if (null == (@TB int @TA [])null); }"; 146 } 147 148 }