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

jjg@1563 1 /*
jjg@1563 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
jjg@1563 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@1563 4 *
jjg@1563 5 * This code is free software; you can redistribute it and/or modify it
jjg@1563 6 * under the terms of the GNU General Public License version 2 only, as
jjg@1563 7 * published by the Free Software Foundation.
jjg@1563 8 *
jjg@1563 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@1563 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@1563 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@1563 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@1563 13 * accompanied this code).
jjg@1563 14 *
jjg@1563 15 * You should have received a copy of the GNU General Public License version
jjg@1563 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@1563 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@1563 18 *
jjg@1563 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jjg@1563 20 * or visit www.oracle.com if you need additional information or have any
jjg@1563 21 * questions.
jjg@1563 22 */
jjg@1563 23
jjg@1563 24 /*
jjg@1563 25 * @test
jjg@1563 26 * @bug 8008077
jjg@1563 27 * @summary Test population of reference info for lambda expressions
jjg@1563 28 * @compile -g Driver.java ReferenceInfoUtil.java Lambda.java
jjg@1563 29 * @run main Driver Lambda
jjg@1563 30 * @author Werner Dietl
jjg@1563 31 */
jjg@1563 32
jjg@1563 33 import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
jjg@1563 34
jjg@1563 35 public class Lambda {
jjg@1563 36
jjg@1563 37 @TADescriptions({
jjg@1563 38 @TADescription(annotation = "TA", type = METHOD_REFERENCE,
jjg@1563 39 offset = ReferenceInfoUtil.IGNORE_VALUE),
jjg@1563 40 @TADescription(annotation = "TB", type = METHOD_REFERENCE,
jjg@1563 41 offset = ReferenceInfoUtil.IGNORE_VALUE)
jjg@1563 42 })
jjg@1563 43 public String returnMethodRef1() {
jjg@1563 44 return
jjg@1563 45 "class Lambda {" +
jjg@1563 46 " public String getName() { return \"Lambda!\"; }" +
jjg@1563 47 "}" +
jjg@1563 48
jjg@1563 49 "class Test {" +
jjg@1563 50 " java.util.function.Function<Lambda, String> lambda() {" +
jjg@1563 51 " return @TA @TB Lambda::getName;" +
jjg@1563 52 " }" +
jjg@1563 53 "}";
jjg@1563 54 }
jjg@1563 55
jjg@1563 56 @TADescriptions({
jjg@1563 57 @TADescription(annotation = "TA", type = METHOD_REFERENCE,
jjg@1563 58 offset = ReferenceInfoUtil.IGNORE_VALUE),
jjg@1563 59 @TADescription(annotation = "TB", type = METHOD_REFERENCE,
jjg@1563 60 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 61 genericLocation = { 3, 0 }),
jjg@1563 62 @TADescription(annotation = "TC", type = METHOD_REFERENCE,
jjg@1563 63 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 64 genericLocation = { 3, 0 }),
jjg@1563 65 @TADescription(annotation = "TD", type = METHOD_REFERENCE,
jjg@1563 66 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 67 genericLocation = { 3, 1 }),
jjg@1563 68 @TADescription(annotation = "TE", type = METHOD_REFERENCE,
jjg@1563 69 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 70 genericLocation = { 3, 1 })
jjg@1563 71 })
jjg@1563 72 public String returnMethodRef2() {
jjg@1563 73 return
jjg@1563 74 "class Lambda<S, T> {" +
jjg@1563 75 " public String getName() { return \"Lambda!\"; }" +
jjg@1563 76 "}" +
jjg@1563 77
jjg@1563 78 "class Test {" +
jjg@1563 79 " java.util.function.Function<Lambda<Integer, Float>, String> lambda() {" +
jjg@1563 80 " return @TA Lambda<@TB @TC Integer, @TD @TE Float>::getName;" +
jjg@1563 81 " }" +
jjg@1563 82 "}";
jjg@1563 83 }
jjg@1563 84
jjg@1563 85 @TADescriptions({
jjg@1563 86 @TADescription(annotation = "CTA", type = METHOD_REFERENCE,
jjg@1563 87 offset = ReferenceInfoUtil.IGNORE_VALUE),
jjg@1563 88 @TADescription(annotation = "CTB", type = METHOD_REFERENCE,
jjg@1563 89 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 90 genericLocation = { 3, 0 }),
jjg@1563 91 @TADescription(annotation = "CTC", type = METHOD_REFERENCE,
jjg@1563 92 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 93 genericLocation = { 3, 1 })
jjg@1563 94 })
jjg@1563 95 public String returnMethodRef3() {
jjg@1563 96 return
jjg@1563 97 "class Lambda<S, T> {" +
jjg@1563 98 " public String getName() { return \"Lambda!\"; }" +
jjg@1563 99 "}" +
jjg@1563 100
jjg@1563 101 "@Target(ElementType.TYPE_USE)" +
jjg@1563 102 "@interface CTA {" +
jjg@1563 103 " String value();" +
jjg@1563 104 "}" +
jjg@1563 105
jjg@1563 106 "@Target(ElementType.TYPE_USE)" +
jjg@1563 107 "@interface CTB {" +
jjg@1563 108 " int age();" +
jjg@1563 109 "}" +
jjg@1563 110
jjg@1563 111 "@Target(ElementType.TYPE_USE)" +
jjg@1563 112 "@interface CTC {" +
jjg@1563 113 " String name();" +
jjg@1563 114 "}" +
jjg@1563 115
jjg@1563 116 "class Test {" +
jjg@1563 117 " java.util.function.Function<Lambda<Integer, Float>, String> lambda() {" +
jjg@1563 118 " return @CTA(\"x\") Lambda<@CTB(age = 5) Integer, @CTC(name = \"y\") Float>::getName;" +
jjg@1563 119 " }" +
jjg@1563 120 "}";
jjg@1563 121 }
jjg@1563 122
jjg@1563 123
jjg@1563 124 @TADescriptions({
jjg@1563 125 @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE,
jjg@1563 126 offset = ReferenceInfoUtil.IGNORE_VALUE),
jjg@1563 127 @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE,
jjg@1563 128 offset = ReferenceInfoUtil.IGNORE_VALUE)
jjg@1563 129 })
jjg@1563 130 public String returnConstructorRef1() {
jjg@1563 131 return
jjg@1563 132 "class Lambda {" +
jjg@1563 133 " Lambda() { }" +
jjg@1563 134 "}" +
jjg@1563 135
jjg@1563 136 "class Test {" +
jjg@1563 137 " Runnable lambda() {" +
jjg@1563 138 " return @TA @TB Lambda::new;" +
jjg@1563 139 " }" +
jjg@1563 140 "}";
jjg@1563 141 }
jjg@1563 142
jjg@1563 143 @TADescriptions({
jjg@1563 144 @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE,
jjg@1563 145 offset = ReferenceInfoUtil.IGNORE_VALUE),
jjg@1563 146 @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE,
jjg@1563 147 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 148 genericLocation = { 3, 0 }),
jjg@1563 149 @TADescription(annotation = "TC", type = CONSTRUCTOR_REFERENCE,
jjg@1563 150 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 151 genericLocation = { 3, 0 }),
jjg@1563 152 @TADescription(annotation = "TD", type = CONSTRUCTOR_REFERENCE,
jjg@1563 153 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 154 genericLocation = { 3, 1 }),
jjg@1563 155 @TADescription(annotation = "TE", type = CONSTRUCTOR_REFERENCE,
jjg@1563 156 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 157 genericLocation = { 3, 1 })
jjg@1563 158 })
jjg@1563 159 public String returnConstructorRef2() {
jjg@1563 160 return
jjg@1563 161 "class Lambda<S, T> {" +
jjg@1563 162 " Lambda() { }" +
jjg@1563 163 "}" +
jjg@1563 164
jjg@1563 165 "class Test {" +
jjg@1563 166 " Runnable lambda() {" +
jjg@1563 167 " return @TA Lambda<@TB @TC Integer, @TD @TE Float>::new;" +
jjg@1563 168 " }" +
jjg@1563 169 "}";
jjg@1563 170 }
jjg@1563 171
jjg@1563 172 @TADescriptions({
jjg@1563 173 @TADescription(annotation = "CTA", type = CONSTRUCTOR_REFERENCE,
jjg@1563 174 offset = ReferenceInfoUtil.IGNORE_VALUE),
jjg@1563 175 @TADescription(annotation = "CTB", type = CONSTRUCTOR_REFERENCE,
jjg@1563 176 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 177 genericLocation = { 3, 0 }),
jjg@1563 178 @TADescription(annotation = "CTC", type = CONSTRUCTOR_REFERENCE,
jjg@1563 179 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 180 genericLocation = { 3, 1 })
jjg@1563 181 })
jjg@1563 182 public String returnConstructorRef3() {
jjg@1563 183 return
jjg@1563 184 "class Lambda<S, T> {" +
jjg@1563 185 " Lambda() { }" +
jjg@1563 186 "}" +
jjg@1563 187
jjg@1563 188 "@Target(ElementType.TYPE_USE)" +
jjg@1563 189 "@interface CTA {" +
jjg@1563 190 " String value();" +
jjg@1563 191 "}" +
jjg@1563 192
jjg@1563 193 "@Target(ElementType.TYPE_USE)" +
jjg@1563 194 "@interface CTB {" +
jjg@1563 195 " int age();" +
jjg@1563 196 "}" +
jjg@1563 197
jjg@1563 198 "@Target(ElementType.TYPE_USE)" +
jjg@1563 199 "@interface CTC {" +
jjg@1563 200 " String name();" +
jjg@1563 201 "}" +
jjg@1563 202
jjg@1563 203 "class Test {" +
jjg@1563 204 " Runnable lambda() {" +
jjg@1563 205 " return @CTA(\"x\") Lambda<@CTB(age = 5) Integer, @CTC(name = \"y\") Float>::new;" +
jjg@1563 206 " }" +
jjg@1563 207 "}";
jjg@1563 208 }
jjg@1563 209
jjg@1563 210
jjg@1563 211 @TADescriptions({
jjg@1563 212 @TADescription(annotation = "TA", type = METHOD_REFERENCE_TYPE_ARGUMENT,
jjg@1563 213 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 214 typeIndex = 0),
jjg@1563 215 @TADescription(annotation = "TB", type = METHOD_REFERENCE_TYPE_ARGUMENT,
jjg@1563 216 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 217 typeIndex = 1)
jjg@1563 218 })
jjg@1563 219 public String returnMethodRefTA1() {
jjg@1563 220 return
jjg@1563 221 "interface Lambda {" +
jjg@1563 222 " <S, T> void generic(S p1, T p2);" +
jjg@1563 223 "}" +
jjg@1563 224
jjg@1563 225 "class LambdaImpl implements Lambda {" +
jjg@1563 226 " public <S, T> void generic(S p1, T p2) {}" +
jjg@1563 227 "}" +
jjg@1563 228
jjg@1563 229 "class Test {" +
jjg@1563 230 " Lambda lambda(LambdaImpl r) {" +
jjg@1563 231 " return r::<@TA Object, @TB Object>generic;" +
jjg@1563 232 " }" +
jjg@1563 233 "}";
jjg@1563 234 }
jjg@1563 235
jjg@1563 236 @TADescriptions({
jjg@1563 237 @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT,
jjg@1563 238 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 239 typeIndex = 0),
jjg@1563 240 @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT,
jjg@1563 241 offset = ReferenceInfoUtil.IGNORE_VALUE,
jjg@1563 242 typeIndex = 1)
jjg@1563 243 })
jjg@1563 244 public String returnConstructorRefTA2() {
jjg@1563 245 return
jjg@1563 246 "interface Lambda {" +
jjg@1563 247 " <S, T> void generic(S p1, T p2);" +
jjg@1563 248 "}" +
jjg@1563 249
jjg@1563 250 "class LambdaImpl implements Lambda {" +
jjg@1563 251 " <S, T> LambdaImpl(S p1, T p2) {}" +
jjg@1563 252 " public <S, T> void generic(S p1, T p2) {}" +
jjg@1563 253 "}" +
jjg@1563 254
jjg@1563 255 "class Test {" +
jjg@1563 256 " Lambda lambda() {" +
jjg@1563 257 " return LambdaImpl::<@TA Object, @TB Object>new;" +
jjg@1563 258 " }" +
jjg@1563 259 "}";
jjg@1563 260 }
jjg@1563 261
jjg@1563 262 }

mercurial