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 parameters
  30  * @modules jdk.jdeps/com.sun.tools.classfile
  31  * @compile -g Driver.java ReferenceInfoUtil.java MethodParameters.java
  32  * @run main Driver MethodParameters
  33  */
  34 public class MethodParameters {
  35 
  36     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
  37     public String methodParamAsPrimitive() {
  38         return "void test(@TA int a) { }";
  39     }
  40 
  41     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1)
  42     public String methodParamAsObject() {
  43         return "void test(Object b, @TA Object a) { }";
  44     }
  45 
  46     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
  47     @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
  48                 genericLocation = { 3, 0 }, paramIndex = 0)
  49     @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER,
  50                 genericLocation = { 3, 1 }, paramIndex = 0)
  51     @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER,
  52                 genericLocation = { 3, 1, 3, 0 }, paramIndex = 0)
  53     public String methodParamAsParametrized() {
  54         return "void test(@TA Map<@TB String, @TC List<@TD String>> a) { }";
  55     }
  56 
  57     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
  58     @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
  59                 genericLocation = { 3, 0 }, paramIndex = 0)
  60     @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER,
  61                 genericLocation = { 3, 0, 2, 0 }, paramIndex = 0)
  62     @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER,
  63                 genericLocation = { 3, 1 }, paramIndex = 0)
  64     @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER,
  65                 genericLocation = { 3, 1, 3, 0 }, paramIndex = 0)
  66     @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER,
  67                 genericLocation = { 3, 1, 3, 0, 2, 0 }, paramIndex = 0)
  68     @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER,
  69                 genericLocation = { 3, 1, 3, 0, 2, 0, 3, 0 }, paramIndex = 0)
  70     @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER,
  71                 genericLocation = { 3, 1, 3, 0, 2, 0, 3, 0, 2, 0 }, paramIndex = 0)
  72     @TADescription(annotation = "TI", type = METHOD_FORMAL_PARAMETER,
  73                 genericLocation = { 3, 1, 3, 0, 2, 0, 3, 1 }, paramIndex = 0)
  74     @TADescription(annotation = "TJ", type = METHOD_FORMAL_PARAMETER,
  75                 genericLocation = { 3, 1, 3, 0, 2, 0, 3, 1, 2, 0 }, paramIndex = 0)
  76     public String methodParamAsWildcard() {
  77         return "void test(@TA Map<@TB ? extends @TC String," +
  78                 "                 @TD List<@TE ? extends @TF Map<@TG ? super @TH String," +
  79                 "                                                @TI ? extends @TJ Object>>> a) { }";
  80     }
  81 
  82     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1)
  83     @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
  84                 genericLocation = { 0, 0 }, paramIndex = 1)
  85     @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER,
  86                 genericLocation = { 0, 0, 0, 0 }, paramIndex = 1)
  87     public String methodParamAsArray() {
  88         return "void test(Object b, @TC String @TA [] @TB [] a) { }";
  89     }
  90 
  91     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER,
  92                 genericLocation = { 0, 0 }, paramIndex = 1)
  93     @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
  94                 genericLocation = { 0, 0 }, paramIndex = 1)
  95     public String methodParamAsArray2() {
  96         return "void test(Object b, @TA @TB String [] a) { }";
  97     }
  98 
  99     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER,
 100                 genericLocation = { 0, 0 }, paramIndex = 1)
 101     @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
 102                 genericLocation = { 0, 0 }, paramIndex = 1)
 103     @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER,
 104                 genericLocation = { 0, 0 }, paramIndex = 1)
 105     public String methodParamAsArray3() {
 106         return "void test(Object b, @TA @TB @TC String [] a) { }";
 107     }
 108 
 109     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1)
 110     @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
 111                 genericLocation = { 0, 0 }, paramIndex = 1)
 112     @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER,
 113                 genericLocation = { 0, 0, 0, 0 }, paramIndex = 1)
 114     public String methodParamAsVararg() {
 115         return "void test(Object b, @TC String @TA [] @TB ... a) { }";
 116     }
 117 
 118     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1)
 119     @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
 120                 genericLocation = { 0, 0 }, paramIndex = 1)
 121     @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER,
 122                 genericLocation = { 0, 0, 0, 0 }, paramIndex = 1)
 123     public String methodParamAsFQVararg() {
 124         return "void test(Object b, java.lang.@TC String @TA [] @TB ... a) { }";
 125     }
 126 
 127     @TADescriptions({})
 128     public String methodWithDeclarationAnnotatin() {
 129         return "void test(@Decl String a) { }";
 130     }
 131 
 132     @TADescriptions({})
 133     public String methodWithNoTargetAnno() {
 134         return "void test(@A String a) { }";
 135     }
 136 
 137     // Smoke tests
 138     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
 139     public String interfaceMethodParamAsObject() {
 140         return "interface %TEST_CLASS_NAME% { void test(@TA Object a); }";
 141     }
 142 
 143     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 2)
 144     public String abstractMethodParamAsObject() {
 145         return "abstract class %TEST_CLASS_NAME% { abstract void test(Object b, Object c, @TA Object a); }";
 146     }
 147 
 148     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
 149     @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
 150                 genericLocation = { 3, 0 }, paramIndex = 0)
 151     @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER,
 152                 genericLocation = { 3, 1 }, paramIndex = 0)
 153     @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER,
 154                 genericLocation = { 3, 1, 3, 0 }, paramIndex = 0)
 155     public String interfaceMethodParamAsParametrized() {
 156         return "interface %TEST_CLASS_NAME% { void test(@TA Map<@TB String, @TC List<@TD String>> a); }";
 157     }
 158 
 159     @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
 160     public String methodParamAsPrimitiveRepeatableAnnotation() {
 161         return "void test(@RTA @RTA int a) { }";
 162     }
 163 
 164     @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 1)
 165     public String methodParamAsObjectRepeatableAnnotation() {
 166         return "void test(Object b, @RTA @RTA Object a) { }";
 167     }
 168 
 169     @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
 170     @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER,
 171             genericLocation = { 3, 0 }, paramIndex = 0)
 172     @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER,
 173             genericLocation = { 3, 1 }, paramIndex = 0)
 174     @TADescription(annotation = "RTDs", type = METHOD_FORMAL_PARAMETER,
 175             genericLocation = { 3, 1, 3, 0 }, paramIndex = 0)
 176     public String methodParamAsParametrizedRepeatableAnnotation() {
 177         return "void test(@RTA @RTA Map<@RTB @RTB String, @RTC @RTC List<@RTD @RTD String>> a) { }";
 178     }
 179 
 180     @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
 181     @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER,
 182             genericLocation = { 3, 0 }, paramIndex = 0)
 183     @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER,
 184             genericLocation = { 3, 0, 2, 0 }, paramIndex = 0)
 185     @TADescription(annotation = "RTDs", type = METHOD_FORMAL_PARAMETER,
 186             genericLocation = { 3, 1 }, paramIndex = 0)
 187     @TADescription(annotation = "RTEs", type = METHOD_FORMAL_PARAMETER,
 188             genericLocation = { 3, 1, 3, 0 }, paramIndex = 0)
 189     @TADescription(annotation = "RTFs", type = METHOD_FORMAL_PARAMETER,
 190             genericLocation = { 3, 1, 3, 0, 2, 0 }, paramIndex = 0)
 191     public String methodParamAsWildcardRepeatableAnnotation() {
 192         return "void test(@RTA @RTA Map<@RTB @RTB ? extends @RTC @RTC String," +
 193                 "                 @RTD @RTD List<@RTE @RTE ? super @RTF @RTF String>> a) { }";
 194     }
 195 
 196     @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 1)
 197     @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER,
 198             genericLocation = { 0, 0 }, paramIndex = 1)
 199     @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER,
 200             genericLocation = { 0, 0, 0, 0 }, paramIndex = 1)
 201     public String methodParamAsArrayRepeatableAnnotation() {
 202         return "void test(Object b, @RTC @RTC String @RTA @RTA [] @RTB @RTB [] a) { }";
 203     }
 204 
 205     @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER,
 206             genericLocation = { 0, 0 }, paramIndex = 1)
 207     @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER,
 208             genericLocation = { 0, 0 }, paramIndex = 1)
 209     public String methodParamAsArrayRepeatableAnnotation2() {
 210         return "void test(Object b, @RTA @RTA @RTB @RTB String [] a) { }";
 211     }
 212 
 213     @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER,
 214             genericLocation = { 0, 0 }, paramIndex = 1)
 215     @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER,
 216             genericLocation = { 0, 0 }, paramIndex = 1)
 217     public String methodParamAsArrayRepeatableAnnotation3() {
 218         return "void test(Object b, @RTA @RTA @RTB @RTB String [] a) { }";
 219     }
 220 
 221     @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 1)
 222     @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER,
 223             genericLocation = { 0, 0 }, paramIndex = 1)
 224     @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER,
 225             genericLocation = { 0, 0, 0, 0 }, paramIndex = 1)
 226     public String methodParamAsVarargRepeatableAnnotation() {
 227         return "void test(Object b, @RTC @RTC String @RTA @RTA [] @RTB @RTB ... a) { }";
 228     }
 229 
 230     @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 1)
 231     @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER,
 232             genericLocation = { 0, 0 }, paramIndex = 1)
 233     @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER,
 234             genericLocation = { 0, 0, 0, 0 }, paramIndex = 1)
 235     public String methodParamAsFQVarargRepeatableAnnotation() {
 236         return "void test(Object b, java.lang.@RTC @RTC String @RTA @RTA [] @RTB @RTB ... a) { }";
 237     }
 238 
 239     // Smoke tests
 240     @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
 241     public String interfaceMethodParamAsObjectRepeatableAnnotation() {
 242         return "interface %TEST_CLASS_NAME% { void test(@RTA @RTA Object a); }";
 243     }
 244 
 245     @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 2)
 246     public String abstractMethodParamAsObjectRepeatableAnnotation() {
 247         return "abstract class %TEST_CLASS_NAME% { abstract void test(Object b, Object c, @RTA @RTA Object a); }";
 248     }
 249 
 250     @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
 251     @TADescription(annotation = "RTBs", type = METHOD_FORMAL_PARAMETER,
 252             genericLocation = { 3, 0 }, paramIndex = 0)
 253     @TADescription(annotation = "RTCs", type = METHOD_FORMAL_PARAMETER,
 254             genericLocation = { 3, 1 }, paramIndex = 0)
 255     @TADescription(annotation = "RTDs", type = METHOD_FORMAL_PARAMETER,
 256             genericLocation = { 3, 1, 3, 0 }, paramIndex = 0)
 257     public String interfaceMethodParamAsParametrizedRepeatableAnnotation() {
 258         return "interface %TEST_CLASS_NAME% { void test(@RTA @RTA Map<@RTB @RTB String, @RTC @RTC List<@RTD @RTD String>> a); }";
 259     }
 260 }