test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodParameters.java

Tue, 24 Dec 2013 09:17:37 -0800

author
ksrini
date
Tue, 24 Dec 2013 09:17:37 -0800
changeset 2227
998b10c43157
parent 1563
bc456436c613
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8029230: Update copyright year to match last edit in jdk8 langtools repository for 2013
Reviewed-by: ksrini
Contributed-by: steve.sides@oracle.com

     1 /*
     2  * Copyright (c) 2009, 2013, 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  */
    24 import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
    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 {
    34     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
    35     public String methodParamAsPrimitive() {
    36         return "void test(@TA int a) { }";
    37     }
    39     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1)
    40     public String methodParamAsObject() {
    41         return "void test(Object b, @TA Object a) { }";
    42     }
    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     }
    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     }
    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     }
    95     @TADescriptions({
    96         @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER,
    97                 genericLocation = { 0, 0 }, paramIndex = 1),
    98         @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
    99                 genericLocation = { 0, 0 }, paramIndex = 1)
   100     })
   101     public String methodParamAsArray2() {
   102         return "void test(Object b, @TA @TB String [] a) { }";
   103     }
   105     @TADescriptions({
   106         @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER,
   107                 genericLocation = { 0, 0 }, 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 }, paramIndex = 1)
   112     })
   113     public String methodParamAsArray3() {
   114         return "void test(Object b, @TA @TB @TC String [] a) { }";
   115     }
   117     @TADescriptions({
   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     })
   124     public String methodParamAsVararg() {
   125         return "void test(Object b, @TC String @TA [] @TB ... a) { }";
   126     }
   128     @TADescriptions({
   129         @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 1),
   130         @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
   131                 genericLocation = { 0, 0 }, paramIndex = 1),
   132         @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER,
   133                 genericLocation = { 0, 0, 0, 0 }, paramIndex = 1)
   134     })
   135     public String methodParamAsFQVararg() {
   136         return "void test(Object b, java.lang.@TC String @TA [] @TB ... a) { }";
   137     }
   139     @TADescriptions({})
   140     public String methodWithDeclarationAnnotatin() {
   141         return "void test(@Decl String a) { }";
   142     }
   144     @TADescriptions({})
   145     public String methodWithNoTargetAnno() {
   146         return "void test(@A String a) { }";
   147     }
   149     // Smoke tests
   150     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
   151     public String interfacemethodParamAsObject() {
   152         return "interface Test { void test(@TA Object a); }";
   153     }
   155     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 2)
   156     public String abstractmethodParamAsObject() {
   157         return "abstract class Test { abstract void test(Object b, Object c, @TA Object a); }";
   158     }
   160     @TADescriptions({
   161         @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0),
   162         @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
   163                 genericLocation = { 3, 0 }, paramIndex = 0),
   164         @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER,
   165                 genericLocation = { 3, 1 }, paramIndex = 0),
   166         @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER,
   167                 genericLocation = { 3, 1, 3, 0 }, paramIndex = 0)
   168     })
   169     public String interfacemethodParamAsParametrized() {
   170         return "interface Test { void test(@TA Map<@TB String, @TC List<@TD String>> a); }";
   171     }
   173 }

mercurial