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 method return 30 * @modules jdk.compiler/com.sun.tools.classfile 31 * @compile -g Driver.java ReferenceInfoUtil.java MethodReturns.java 32 * @run main Driver MethodReturns 33 */ 34 public class MethodReturns { 35 36 // Method returns 37 @TADescription(annotation = "TA", type = METHOD_RETURN) 38 public String methodReturnAsPrimitive() { 39 return "@TA int test() { return 0; }"; 40 } 41 42 @TADescription(annotation = "TA", type = METHOD_RETURN) 43 public String methodReturnAsObject() { 44 return "@TA Object test() { return null; }"; 45 } 46 47 @TADescription(annotation = "TA", type = METHOD_RETURN) 48 @TADescription(annotation = "TB", type = METHOD_RETURN, 49 genericLocation = { 3, 0 }) 50 @TADescription(annotation = "TC", type = METHOD_RETURN, 51 genericLocation = { 3, 1 }) 52 @TADescription(annotation = "TD", type = METHOD_RETURN, 53 genericLocation = { 3, 1, 3, 0 }) 54 public String methodReturnAsParametrized() { 55 return "@TA Map<@TB String, @TC List<@TD String>> test() { return null; }"; 56 } 57 58 @TADescription(annotation = "TA", type = METHOD_RETURN) 59 @TADescription(annotation = "TB", type = METHOD_RETURN, 60 genericLocation = { 0, 0 }) 61 @TADescription(annotation = "TC", type = METHOD_RETURN, 62 genericLocation = { 0, 0, 0, 0 }) 63 public String methodReturnAsArray() { 64 return "@TC String @TA [] @TB [] test() { return null; }"; 65 } 66 67 @TADescription(annotation = "TA", type = METHOD_RETURN) 68 @TADescription(annotation = "TB", type = METHOD_RETURN, 69 genericLocation = { 0, 0 }) 70 @TADescription(annotation = "TC", type = METHOD_RETURN, 71 genericLocation = { 0, 0, 0, 0 }) 72 public String methodReturnAsArrayOld() { 73 return "@TC String test() @TA [] @TB [] { return null; }"; 74 } 75 76 @TADescriptions({}) 77 public String methodWithDeclarationAnnotation() { 78 return "@Decl String test() { return null; }"; 79 } 80 81 @TADescriptions({}) 82 public String methodWithNoTargetAnno() { 83 return "@A String test() { return null; }"; 84 } 85 86 // Smoke tests 87 @TADescription(annotation = "TA", type = METHOD_RETURN) 88 public String interfaceMethodReturnAsObject() { 89 return "interface %TEST_CLASS_NAME% { @TA Object test(); }"; 90 } 91 92 @TADescription(annotation = "TA", type = METHOD_RETURN) 93 public String abstractMethodReturnAsObject() { 94 return "abstract class %TEST_CLASS_NAME% { abstract @TA Object test(); }"; 95 } 96 97 98 @TADescription(annotation = "TA", type = METHOD_RETURN) 99 @TADescription(annotation = "TB", type = METHOD_RETURN, 100 genericLocation = { 3, 0 }) 101 @TADescription(annotation = "TC", type = METHOD_RETURN, 102 genericLocation = { 3, 1 }) 103 @TADescription(annotation = "TD", type = METHOD_RETURN, 104 genericLocation = { 3, 1, 3, 0 }) 105 public String interfaceMethodReturnAsParametrized() { 106 return "interface %TEST_CLASS_NAME% { @TA Map<@TB String, @TC List<@TD String>> test(); }"; 107 } 108 109 @TADescription(annotation = "TA", type = METHOD_RETURN, 110 genericLocation = { 3, 0 }) 111 @TADescription(annotation = "TB", type = METHOD_RETURN, 112 genericLocation = { 3, 0, 2, 0 }) 113 @TADescription(annotation = "TC", type = METHOD_RETURN, 114 genericLocation = { 3, 0, 2, 0, 1, 0 }) 115 @TADescription(annotation = "TD", type = METHOD_RETURN, 116 genericLocation = { 3, 0, 2, 0, 1, 0, 3, 0 }) 117 @TADescription(annotation = "TE", type = METHOD_RETURN, 118 genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1 }) 119 @TADescription(annotation = "TF", type = METHOD_RETURN, 120 genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1, 2, 0 }) 121 public String methodReturnAsNestedWildcard() { 122 return "Set<@TA ? extends @TB GOuter<String, String>. @TC GInner<@TD String, @TE ? super @TF Object>> entrySet() { return null; }"; 123 } 124 125 @TADescription(annotation = "TA", type = METHOD_RETURN, 126 genericLocation = { 3, 0, 1, 0, 3, 0 }) 127 @TADescription(annotation = "TB", type = METHOD_RETURN, 128 genericLocation = { 3, 0, 1, 0, 3, 1 }) 129 @TADescription(annotation = "TC", type = METHOD_RETURN, 130 genericLocation = { 3, 0, 1, 0, 3, 1, 2, 0 }) 131 public String methodReturnAsNestedWildcard2() { 132 return "class GOuter<X, Y> { class GInner<X, Y> {} } " + 133 "class %TEST_CLASS_NAME%<K> { Set<GOuter<String, String>.GInner<@TA K, @TB ? extends @TC Object>> entrySet() { return null; } }"; 134 } 135 136 @TADescription(annotation = "TB", type = METHOD_RETURN, 137 genericLocation = { 3, 0, 2, 0 }) 138 @TADescription(annotation = "TC", type = METHOD_RETURN, 139 genericLocation = { 3, 0, 2, 0, 1, 0 }) 140 public String methodReturnAsNestedWildcard3() { 141 return "Set<? extends @TB GOuter<String, String>. @TC GInner<String, Object>> entrySet() { return null; }"; 142 } 143 144 @TADescription(annotation = "TC", type = METHOD_RETURN, 145 genericLocation = { 3, 0, 2, 0, 1, 0 }) 146 public String methodReturnAsNestedWildcard4() { 147 return "Set<? extends GOuter<String, String>. @TC GInner<String, Object>> entrySet() { return null; }"; 148 } 149 150 @TADescription(annotation = "TB", type = METHOD_RETURN, 151 genericLocation = { 3, 0, 2, 0 }) 152 @TADescription(annotation = "TC", type = METHOD_RETURN, 153 genericLocation = { 3, 0, 2, 0, 1, 0 }) 154 public String methodReturnAsNestedWildcard5() { 155 return "Set<? extends @TB Outer. @TC Inner> entrySet() { return null; }"; 156 } 157 158 @TADescription(annotation = "TA", type = METHOD_RETURN, 159 genericLocation = { 3, 0, 2, 0, 1, 0, 3, 0 }) 160 @TADescription(annotation = "TB", type = METHOD_RETURN, 161 genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1 }) 162 @TADescription(annotation = "TC", type = METHOD_RETURN, 163 genericLocation = { 3, 0, 2, 0, 1, 0 }) 164 public String methodReturnAsNestedWildcard6() { 165 return "Set<? extends GOuter<String, String>. @TC GInner<@TA String, @TB Object>> entrySet() { return null; }"; 166 } 167 168 @TADescription(annotation = "RTAs", type = METHOD_RETURN) 169 public String methodReturnAsPrimitiveRepeatableAnnotation() { 170 return "@RTA @RTA int test() { return 0; }"; 171 } 172 173 @TADescription(annotation = "RTAs", type = METHOD_RETURN) 174 public String methodReturnAsObjectRepeatableAnnotation() { 175 return "@RTA @RTA Object test() { return null; }"; 176 } 177 178 @TADescription(annotation = "RTAs", type = METHOD_RETURN) 179 @TADescription(annotation = "RTBs", type = METHOD_RETURN, 180 genericLocation = { 3, 0 }) 181 @TADescription(annotation = "RTCs", type = METHOD_RETURN, 182 genericLocation = { 3, 1 }) 183 @TADescription(annotation = "RTDs", type = METHOD_RETURN, 184 genericLocation = { 3, 1, 3, 0 }) 185 public String methodReturnAsParametrizedRepeatableAnnotation() { 186 return "@RTA @RTA Map<@RTB @RTB String, @RTC @RTC List<@RTD @RTD String>> test() { return null; }"; 187 } 188 189 @TADescription(annotation = "RTAs", type = METHOD_RETURN) 190 @TADescription(annotation = "RTBs", type = METHOD_RETURN, 191 genericLocation = { 0, 0 }) 192 @TADescription(annotation = "RTCs", type = METHOD_RETURN, 193 genericLocation = { 0, 0, 0, 0 }) 194 public String methodReturnAsArrayRepeatableAnnotation() { 195 return "@RTC @RTC String @RTA @RTA [] @RTB @RTB [] test() { return null; }"; 196 } 197 198 @TADescription(annotation = "RTAs", type = METHOD_RETURN) 199 @TADescription(annotation = "RTBs", type = METHOD_RETURN, 200 genericLocation = { 0, 0 }) 201 @TADescription(annotation = "RTCs", type = METHOD_RETURN, 202 genericLocation = { 0, 0, 0, 0 }) 203 public String methodReturnAsArrayOldRepeatableAnnotation() { 204 return "@RTC @RTC String test() @RTA @RTA [] @RTB @RTB [] { return null; }"; 205 } 206 207 // Smoke tests 208 @TADescription(annotation = "RTAs", type = METHOD_RETURN) 209 public String interfaceMethodReturnAsObjectRepeatableAnnotation() { 210 return "interface %TEST_CLASS_NAME% { @RTA @RTA Object test(); }"; 211 } 212 213 @TADescription(annotation = "RTAs", type = METHOD_RETURN) 214 public String abstractMethodReturnAsObjectRepeatableAnnotation() { 215 return "abstract class %TEST_CLASS_NAME% { abstract @RTA @RTA Object test(); }"; 216 } 217 218 219 @TADescription(annotation = "RTAs", type = METHOD_RETURN) 220 @TADescription(annotation = "RTBs", type = METHOD_RETURN, 221 genericLocation = { 3, 0 }) 222 @TADescription(annotation = "RTCs", type = METHOD_RETURN, 223 genericLocation = { 3, 1 }) 224 @TADescription(annotation = "RTDs", type = METHOD_RETURN, 225 genericLocation = { 3, 1, 3, 0 }) 226 public String interfaceMethodReturnAsParametrizedRepeatableAnnotation() { 227 return "interface %TEST_CLASS_NAME% { @RTA @RTA Map<@RTB @RTB String, @RTC @RTC List<@RTD @RTD String>> test(); }"; 228 } 229 230 @TADescription(annotation = "RTAs", type = METHOD_RETURN, 231 genericLocation = { 3, 0 }) 232 @TADescription(annotation = "RTBs", type = METHOD_RETURN, 233 genericLocation = { 3, 0, 2, 0 }) 234 @TADescription(annotation = "RTCs", type = METHOD_RETURN, 235 genericLocation = { 3, 0, 2, 0, 1, 0 }) 236 @TADescription(annotation = "RTDs", type = METHOD_RETURN, 237 genericLocation = { 3, 0, 2, 0, 1, 0, 3, 0 }) 238 @TADescription(annotation = "RTEs", type = METHOD_RETURN, 239 genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1 }) 240 @TADescription(annotation = "RTFs", type = METHOD_RETURN, 241 genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1, 2, 0 }) 242 public String methodReturnAsNestedWildcardRepeatableAnnotation() { 243 return "Set<@RTA @RTA ? extends @RTB @RTB GOuter<String, String>. @RTC @RTC GInner<@RTD @RTD String," + 244 " @RTE @RTE ? super @RTF @RTF Object>> entrySet() { return null; }"; 245 } 246 247 @TADescription(annotation = "RTAs", type = METHOD_RETURN, 248 genericLocation = { 3, 0, 1, 0, 3, 0 }) 249 @TADescription(annotation = "RTBs", type = METHOD_RETURN, 250 genericLocation = { 3, 0, 1, 0, 3, 1 }) 251 @TADescription(annotation = "RTCs", type = METHOD_RETURN, 252 genericLocation = { 3, 0, 1, 0, 3, 1, 2, 0 }) 253 public String methodReturnAsNestedWildcardRepeatableAnnotation2() { 254 return "class GOuter<X, Y> { class GInner<X, Y> {} } " + 255 "class %TEST_CLASS_NAME%<K> { Set<GOuter<String, String>.GInner<@RTA @RTA K," + 256 " @RTB @RTB ? extends @RTC @RTC Object>> entrySet() { return null; } }"; 257 } 258 259 @TADescription(annotation = "RTBs", type = METHOD_RETURN, 260 genericLocation = { 3, 0, 2, 0 }) 261 @TADescription(annotation = "RTCs", type = METHOD_RETURN, 262 genericLocation = { 3, 0, 2, 0, 1, 0 }) 263 public String methodReturnAsNestedWildcardRepeatableAnnotation3() { 264 return "Set<? extends @RTB @RTB GOuter<String, String>. @RTC @RTC GInner<String, Object>> entrySet() { return null; }"; 265 } 266 267 @TADescription(annotation = "RTCs", type = METHOD_RETURN, 268 genericLocation = { 3, 0, 2, 0, 1, 0 }) 269 public String methodReturnAsNestedWildcardRepeatableAnnotation4() { 270 return "Set<? extends GOuter<String, String>. @RTC @RTC GInner<String, Object>> entrySet() { return null; }"; 271 } 272 273 @TADescription(annotation = "RTBs", type = METHOD_RETURN, 274 genericLocation = { 3, 0, 2, 0 }) 275 @TADescription(annotation = "RTCs", type = METHOD_RETURN, 276 genericLocation = { 3, 0, 2, 0, 1, 0 }) 277 public String methodReturnAsNestedWildcardRepeatableAnnotation5() { 278 return "Set<? extends @RTB @RTB Outer. @RTC @RTC Inner> entrySet() { return null; }"; 279 } 280 281 @TADescription(annotation = "RTAs", type = METHOD_RETURN, 282 genericLocation = { 3, 0, 2, 0, 1, 0, 3, 0 }) 283 @TADescription(annotation = "RTBs", type = METHOD_RETURN, 284 genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1 }) 285 @TADescription(annotation = "RTCs", type = METHOD_RETURN, 286 genericLocation = { 3, 0, 2, 0, 1, 0 }) 287 public String methodReturnAsNestedWildcardRepeatableAnnotation6() { 288 return "Set<? extends GOuter<String, String>. @RTC @RTC GInner<@RTA @RTA String," + 289 " @RTB @RTB Object>> entrySet() { return null; }"; 290 } 291 }