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

Tue, 12 Mar 2013 17:39:34 +0100

author
jfranck
date
Tue, 12 Mar 2013 17:39:34 +0100
changeset 1629
f427043f8c65
parent 1563
bc456436c613
child 1755
ddb4a2bfcd82
permissions
-rw-r--r--

7196531: Duplicate error messages on repeating annotations
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 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 /*
    25  * @test
    26  * @bug 8008077
    27  * @summary Test population of reference info for lambda expressions
    28  * @compile -g Driver.java ReferenceInfoUtil.java Lambda.java
    29  * @run main Driver Lambda
    30  * @author Werner Dietl
    31  */
    33 import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
    35 public class Lambda {
    37     @TADescriptions({
    38         @TADescription(annotation = "TA", type = METHOD_REFERENCE,
    39                 offset = ReferenceInfoUtil.IGNORE_VALUE),
    40         @TADescription(annotation = "TB", type = METHOD_REFERENCE,
    41                 offset = ReferenceInfoUtil.IGNORE_VALUE)
    42     })
    43     public String returnMethodRef1() {
    44         return
    45                 "class Lambda {" +
    46                 "  public String getName() { return \"Lambda!\"; }" +
    47                 "}" +
    49                 "class Test {" +
    50                 "  java.util.function.Function<Lambda, String> lambda() {" +
    51                 "    return @TA @TB Lambda::getName;" +
    52                 "  }" +
    53                 "}";
    54     }
    56     @TADescriptions({
    57         @TADescription(annotation = "TA", type = METHOD_REFERENCE,
    58                 offset = ReferenceInfoUtil.IGNORE_VALUE),
    59         @TADescription(annotation = "TB", type = METHOD_REFERENCE,
    60                 offset = ReferenceInfoUtil.IGNORE_VALUE,
    61                 genericLocation = { 3, 0 }),
    62         @TADescription(annotation = "TC", type = METHOD_REFERENCE,
    63                 offset = ReferenceInfoUtil.IGNORE_VALUE,
    64                 genericLocation = { 3, 0 }),
    65         @TADescription(annotation = "TD", type = METHOD_REFERENCE,
    66                 offset = ReferenceInfoUtil.IGNORE_VALUE,
    67                 genericLocation = { 3, 1 }),
    68         @TADescription(annotation = "TE", type = METHOD_REFERENCE,
    69                 offset = ReferenceInfoUtil.IGNORE_VALUE,
    70                 genericLocation = { 3, 1 })
    71     })
    72     public String returnMethodRef2() {
    73         return
    74                 "class Lambda<S, T> {" +
    75                 "  public String getName() { return \"Lambda!\"; }" +
    76                 "}" +
    78                 "class Test {" +
    79                 "  java.util.function.Function<Lambda<Integer, Float>, String> lambda() {" +
    80                 "    return @TA Lambda<@TB @TC Integer, @TD @TE Float>::getName;" +
    81                 "  }" +
    82                 "}";
    83     }
    85     @TADescriptions({
    86         @TADescription(annotation = "CTA", type = METHOD_REFERENCE,
    87                 offset = ReferenceInfoUtil.IGNORE_VALUE),
    88         @TADescription(annotation = "CTB", type = METHOD_REFERENCE,
    89                 offset = ReferenceInfoUtil.IGNORE_VALUE,
    90                 genericLocation = { 3, 0 }),
    91         @TADescription(annotation = "CTC", type = METHOD_REFERENCE,
    92                 offset = ReferenceInfoUtil.IGNORE_VALUE,
    93                 genericLocation = { 3, 1 })
    94     })
    95     public String returnMethodRef3() {
    96         return
    97                 "class Lambda<S, T> {" +
    98                 "  public String getName() { return \"Lambda!\"; }" +
    99                 "}" +
   101                 "@Target(ElementType.TYPE_USE)" +
   102                 "@interface CTA {" +
   103                 "  String value();" +
   104                 "}" +
   106                 "@Target(ElementType.TYPE_USE)" +
   107                 "@interface CTB {" +
   108                 "  int age();" +
   109                 "}" +
   111                 "@Target(ElementType.TYPE_USE)" +
   112                 "@interface CTC {" +
   113                 "  String name();" +
   114                 "}" +
   116                 "class Test {" +
   117                 "  java.util.function.Function<Lambda<Integer, Float>, String> lambda() {" +
   118                 "    return @CTA(\"x\") Lambda<@CTB(age = 5) Integer, @CTC(name = \"y\") Float>::getName;" +
   119                 "  }" +
   120                 "}";
   121     }
   124     @TADescriptions({
   125         @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE,
   126                 offset = ReferenceInfoUtil.IGNORE_VALUE),
   127         @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE,
   128                 offset = ReferenceInfoUtil.IGNORE_VALUE)
   129     })
   130     public String returnConstructorRef1() {
   131         return
   132                 "class Lambda {" +
   133                 "  Lambda() { }" +
   134                 "}" +
   136                 "class Test {" +
   137                 "  Runnable lambda() {" +
   138                 "    return @TA @TB Lambda::new;" +
   139                 "  }" +
   140                 "}";
   141     }
   143     @TADescriptions({
   144         @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE,
   145                 offset = ReferenceInfoUtil.IGNORE_VALUE),
   146         @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE,
   147                 offset = ReferenceInfoUtil.IGNORE_VALUE,
   148                 genericLocation = { 3, 0 }),
   149         @TADescription(annotation = "TC", type = CONSTRUCTOR_REFERENCE,
   150                 offset = ReferenceInfoUtil.IGNORE_VALUE,
   151                 genericLocation = { 3, 0 }),
   152         @TADescription(annotation = "TD", type = CONSTRUCTOR_REFERENCE,
   153                 offset = ReferenceInfoUtil.IGNORE_VALUE,
   154                 genericLocation = { 3, 1 }),
   155         @TADescription(annotation = "TE", type = CONSTRUCTOR_REFERENCE,
   156                 offset = ReferenceInfoUtil.IGNORE_VALUE,
   157                 genericLocation = { 3, 1 })
   158     })
   159     public String returnConstructorRef2() {
   160         return
   161                 "class Lambda<S, T> {" +
   162                 "  Lambda() { }" +
   163                 "}" +
   165                 "class Test {" +
   166                 "  Runnable lambda() {" +
   167                 "    return @TA Lambda<@TB @TC Integer, @TD @TE Float>::new;" +
   168                 "  }" +
   169                 "}";
   170     }
   172     @TADescriptions({
   173         @TADescription(annotation = "CTA", type = CONSTRUCTOR_REFERENCE,
   174                 offset = ReferenceInfoUtil.IGNORE_VALUE),
   175         @TADescription(annotation = "CTB", type = CONSTRUCTOR_REFERENCE,
   176                 offset = ReferenceInfoUtil.IGNORE_VALUE,
   177                 genericLocation = { 3, 0 }),
   178         @TADescription(annotation = "CTC", type = CONSTRUCTOR_REFERENCE,
   179                 offset = ReferenceInfoUtil.IGNORE_VALUE,
   180                 genericLocation = { 3, 1 })
   181     })
   182     public String returnConstructorRef3() {
   183         return
   184                 "class Lambda<S, T> {" +
   185                 "  Lambda() { }" +
   186                 "}" +
   188                 "@Target(ElementType.TYPE_USE)" +
   189                 "@interface CTA {" +
   190                 "  String value();" +
   191                 "}" +
   193                 "@Target(ElementType.TYPE_USE)" +
   194                 "@interface CTB {" +
   195                 "  int age();" +
   196                 "}" +
   198                 "@Target(ElementType.TYPE_USE)" +
   199                 "@interface CTC {" +
   200                 "  String name();" +
   201                 "}" +
   203                 "class Test {" +
   204                 "  Runnable lambda() {" +
   205                 "    return @CTA(\"x\") Lambda<@CTB(age = 5) Integer, @CTC(name = \"y\") Float>::new;" +
   206                 "  }" +
   207                 "}";
   208     }
   211     @TADescriptions({
   212         @TADescription(annotation = "TA", type = METHOD_REFERENCE_TYPE_ARGUMENT,
   213                  offset = ReferenceInfoUtil.IGNORE_VALUE,
   214                  typeIndex = 0),
   215         @TADescription(annotation = "TB", type = METHOD_REFERENCE_TYPE_ARGUMENT,
   216                  offset = ReferenceInfoUtil.IGNORE_VALUE,
   217                  typeIndex = 1)
   218     })
   219     public String returnMethodRefTA1() {
   220         return
   221                 "interface Lambda {" +
   222                 "  <S, T> void generic(S p1, T p2);" +
   223                 "}" +
   225                 "class LambdaImpl implements Lambda {" +
   226                 "  public <S, T> void generic(S p1, T p2) {}" +
   227                 "}" +
   229                 "class Test {" +
   230                 "  Lambda lambda(LambdaImpl r) {" +
   231                 "    return r::<@TA Object, @TB Object>generic;" +
   232                 "  }" +
   233                 "}";
   234     }
   236     @TADescriptions({
   237         @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT,
   238                  offset = ReferenceInfoUtil.IGNORE_VALUE,
   239                  typeIndex = 0),
   240         @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT,
   241                  offset = ReferenceInfoUtil.IGNORE_VALUE,
   242                  typeIndex = 1)
   243     })
   244     public String returnConstructorRefTA2() {
   245         return
   246                 "interface Lambda {" +
   247                 "  <S, T> void generic(S p1, T p2);" +
   248                 "}" +
   250                 "class LambdaImpl implements Lambda {" +
   251                 "  <S, T> LambdaImpl(S p1, T p2) {}" +
   252                 "  public <S, T> void generic(S p1, T p2) {}" +
   253                 "}" +
   255                 "class Test {" +
   256                 "  Lambda lambda() {" +
   257                 "    return LambdaImpl::<@TA Object, @TB Object>new;" +
   258                 "  }" +
   259                 "}";
   260     }
   262 }

mercurial