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 method parameters 29 * @compile -g Driver.java ReferenceInfoUtil.java MethodParameters.java 30 * @run main Driver MethodParameters 31 */ 32 public class MethodParameters { 33 34 @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) 35 public String methodParamAsPrimitive() { 36 return "void test(@TA int a) { }"; 37 } 38 39 @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1) 40 public String methodParamAsObject() { 41 return "void test(Object b, @TA Object a) { }"; 42 } 43 44 @TADescriptions({ 45 @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0), 46 @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, 47 genericLocation = { 3, 0 }, paramIndex = 0), 48 @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, 49 genericLocation = { 3, 1 }, paramIndex = 0), 50 @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, 51 genericLocation = { 3, 1, 3, 0 }, paramIndex = 0) 52 }) 53 public String methodParamAsParametrized() { 54 return "void test(@TA Map<@TB String, @TC List<@TD String>> a) { }"; 55 } 56 57 @TADescriptions({ 58 @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0), 59 @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, 60 genericLocation = { 3, 0 }, paramIndex = 0), 61 @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, 62 genericLocation = { 3, 0, 2, 0 }, paramIndex = 0), 63 @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, 64 genericLocation = { 3, 1 }, paramIndex = 0), 65 @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, 66 genericLocation = { 3, 1, 3, 0 }, paramIndex = 0), 67 @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, 68 genericLocation = { 3, 1, 3, 0, 2, 0 }, paramIndex = 0), 69 @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER, 70 genericLocation = { 3, 1, 3, 0, 2, 0, 3, 0 }, paramIndex = 0), 71 @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER, 72 genericLocation = { 3, 1, 3, 0, 2, 0, 3, 0, 2, 0 }, paramIndex = 0), 73 @TADescription(annotation = "TI", type = METHOD_FORMAL_PARAMETER, 74 genericLocation = { 3, 1, 3, 0, 2, 0, 3, 1 }, paramIndex = 0), 75 @TADescription(annotation = "TJ", type = METHOD_FORMAL_PARAMETER, 76 genericLocation = { 3, 1, 3, 0, 2, 0, 3, 1, 2, 0 }, paramIndex = 0) 77 }) 78 public String methodParamAsWildcard() { 79 return "void test(@TA Map<@TB ? extends @TC String," + 80 " @TD List<@TE ? extends @TF Map<@TG ? super @TH String," + 81 " @TI ? extends @TJ Object>>> a) { }"; 82 } 83 84 @TADescriptions({ 85 @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1), 86 @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, 87 genericLocation = { 0, 0 }, paramIndex = 1), 88 @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, 89 genericLocation = { 0, 0, 0, 0 }, paramIndex = 1) 90 }) 91 public String methodParamAsArray() { 92 return "void test(Object b, @TC String @TA [] @TB [] a) { }"; 93 } 94 95 @TADescriptions({ 96 @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1), 97 @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, 98 genericLocation = { 0, 0 }, paramIndex = 1), 99 @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, 100 genericLocation = { 0, 0, 0, 0 }, paramIndex = 1) 101 }) 102 public String methodParamAsVararg() { 103 return "void test(Object b, @TC String @TA [] @TB ... a) { }"; 104 } 105 106 @TADescriptions({ 107 @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1), 108 @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, 109 genericLocation = { 0, 0 }, paramIndex = 1), 110 @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, 111 genericLocation = { 0, 0, 0, 0 }, paramIndex = 1) 112 }) 113 public String methodParamAsFQVararg() { 114 return "void test(Object b, java.lang.@TC String @TA [] @TB ... a) { }"; 115 } 116 117 @TADescriptions({}) 118 public String methodWithDeclarationAnnotatin() { 119 return "void test(@Decl String a) { }"; 120 } 121 122 @TADescriptions({}) 123 public String methodWithNoTargetAnno() { 124 return "void test(@A String a) { }"; 125 } 126 127 // Smoke tests 128 @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) 129 public String interfacemethodParamAsObject() { 130 return "interface Test { void test(@TA Object a); }"; 131 } 132 133 @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 2) 134 public String abstractmethodParamAsObject() { 135 return "abstract class Test { abstract void test(Object b, Object c, @TA Object a); }"; 136 } 137 138 @TADescriptions({ 139 @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0), 140 @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, 141 genericLocation = { 3, 0 }, paramIndex = 0), 142 @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, 143 genericLocation = { 3, 1 }, paramIndex = 0), 144 @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER, 145 genericLocation = { 3, 1, 3, 0 }, paramIndex = 0) 146 }) 147 public String interfacemethodParamAsParametrized() { 148 return "interface Test { void test(@TA Map<@TB String, @TC List<@TD String>> a); }"; 149 } 150 151 }