aoqi@0: /* aoqi@0: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test aoqi@0: * @bug 8008077 8029721 aoqi@0: * @summary Test population of reference info for lambda expressions aoqi@0: * javac crash for annotated parameter type of lambda in a field aoqi@0: * @compile -g Driver.java ReferenceInfoUtil.java Lambda.java aoqi@0: * @run main Driver Lambda aoqi@0: * @author Werner Dietl aoqi@0: */ aoqi@0: aoqi@0: import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; aoqi@0: aoqi@0: public class Lambda { aoqi@0: aoqi@0: @TADescriptions({ aoqi@0: @TADescription(annotation = "TA", type = METHOD_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE), aoqi@0: @TADescription(annotation = "TB", type = METHOD_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE) aoqi@0: }) aoqi@0: public String returnMethodRef1() { aoqi@0: return aoqi@0: "class Lambda {" + aoqi@0: " public String getName() { return \"Lambda!\"; }" + aoqi@0: "}" + aoqi@0: aoqi@0: "class Test {" + aoqi@0: " java.util.function.Function lambda() {" + aoqi@0: " return @TA @TB Lambda::getName;" + aoqi@0: " }" + aoqi@0: "}"; aoqi@0: } aoqi@0: aoqi@0: @TADescriptions({ aoqi@0: @TADescription(annotation = "TA", type = METHOD_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE), aoqi@0: @TADescription(annotation = "TB", type = METHOD_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: genericLocation = { 3, 0 }), aoqi@0: @TADescription(annotation = "TC", type = METHOD_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: genericLocation = { 3, 0 }), aoqi@0: @TADescription(annotation = "TD", type = METHOD_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: genericLocation = { 3, 1 }), aoqi@0: @TADescription(annotation = "TE", type = METHOD_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: genericLocation = { 3, 1 }) aoqi@0: }) aoqi@0: public String returnMethodRef2() { aoqi@0: return aoqi@0: "class Lambda {" + aoqi@0: " public String getName() { return \"Lambda!\"; }" + aoqi@0: "}" + aoqi@0: aoqi@0: "class Test {" + aoqi@0: " java.util.function.Function, String> lambda() {" + aoqi@0: " return @TA Lambda<@TB @TC Integer, @TD @TE Float>::getName;" + aoqi@0: " }" + aoqi@0: "}"; aoqi@0: } aoqi@0: aoqi@0: @TADescriptions({ aoqi@0: @TADescription(annotation = "CTA", type = METHOD_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE), aoqi@0: @TADescription(annotation = "CTB", type = METHOD_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: genericLocation = { 3, 0 }), aoqi@0: @TADescription(annotation = "CTC", type = METHOD_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: genericLocation = { 3, 1 }) aoqi@0: }) aoqi@0: public String returnMethodRef3() { aoqi@0: return aoqi@0: "class Lambda {" + aoqi@0: " public String getName() { return \"Lambda!\"; }" + aoqi@0: "}" + aoqi@0: aoqi@0: "@Target(ElementType.TYPE_USE)" + aoqi@0: "@interface CTA {" + aoqi@0: " String value();" + aoqi@0: "}" + aoqi@0: aoqi@0: "@Target(ElementType.TYPE_USE)" + aoqi@0: "@interface CTB {" + aoqi@0: " int age();" + aoqi@0: "}" + aoqi@0: aoqi@0: "@Target(ElementType.TYPE_USE)" + aoqi@0: "@interface CTC {" + aoqi@0: " String name();" + aoqi@0: "}" + aoqi@0: aoqi@0: "class Test {" + aoqi@0: " java.util.function.Function, String> lambda() {" + aoqi@0: " return @CTA(\"x\") Lambda<@CTB(age = 5) Integer, @CTC(name = \"y\") Float>::getName;" + aoqi@0: " }" + aoqi@0: "}"; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: @TADescriptions({ aoqi@0: @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE), aoqi@0: @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE) aoqi@0: }) aoqi@0: public String returnConstructorRef1() { aoqi@0: return aoqi@0: "class Lambda {" + aoqi@0: " Lambda() { }" + aoqi@0: "}" + aoqi@0: aoqi@0: "class Test {" + aoqi@0: " Runnable lambda() {" + aoqi@0: " return @TA @TB Lambda::new;" + aoqi@0: " }" + aoqi@0: "}"; aoqi@0: } aoqi@0: aoqi@0: @TADescriptions({ aoqi@0: @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE), aoqi@0: @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: genericLocation = { 3, 0 }), aoqi@0: @TADescription(annotation = "TC", type = CONSTRUCTOR_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: genericLocation = { 3, 0 }), aoqi@0: @TADescription(annotation = "TD", type = CONSTRUCTOR_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: genericLocation = { 3, 1 }), aoqi@0: @TADescription(annotation = "TE", type = CONSTRUCTOR_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: genericLocation = { 3, 1 }) aoqi@0: }) aoqi@0: public String returnConstructorRef2() { aoqi@0: return aoqi@0: "class Lambda {" + aoqi@0: " Lambda() { }" + aoqi@0: "}" + aoqi@0: aoqi@0: "class Test {" + aoqi@0: " Runnable lambda() {" + aoqi@0: " return @TA Lambda<@TB @TC Integer, @TD @TE Float>::new;" + aoqi@0: " }" + aoqi@0: "}"; aoqi@0: } aoqi@0: aoqi@0: @TADescriptions({ aoqi@0: @TADescription(annotation = "CTA", type = CONSTRUCTOR_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE), aoqi@0: @TADescription(annotation = "CTB", type = CONSTRUCTOR_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: genericLocation = { 3, 0 }), aoqi@0: @TADescription(annotation = "CTC", type = CONSTRUCTOR_REFERENCE, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: genericLocation = { 3, 1 }) aoqi@0: }) aoqi@0: public String returnConstructorRef3() { aoqi@0: return aoqi@0: "class Lambda {" + aoqi@0: " Lambda() { }" + aoqi@0: "}" + aoqi@0: aoqi@0: "@Target(ElementType.TYPE_USE)" + aoqi@0: "@interface CTA {" + aoqi@0: " String value();" + aoqi@0: "}" + aoqi@0: aoqi@0: "@Target(ElementType.TYPE_USE)" + aoqi@0: "@interface CTB {" + aoqi@0: " int age();" + aoqi@0: "}" + aoqi@0: aoqi@0: "@Target(ElementType.TYPE_USE)" + aoqi@0: "@interface CTC {" + aoqi@0: " String name();" + aoqi@0: "}" + aoqi@0: aoqi@0: "class Test {" + aoqi@0: " Runnable lambda() {" + aoqi@0: " return @CTA(\"x\") Lambda<@CTB(age = 5) Integer, @CTC(name = \"y\") Float>::new;" + aoqi@0: " }" + aoqi@0: "}"; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: @TADescriptions({ aoqi@0: @TADescription(annotation = "TA", type = METHOD_REFERENCE_TYPE_ARGUMENT, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: typeIndex = 0), aoqi@0: @TADescription(annotation = "TB", type = METHOD_REFERENCE_TYPE_ARGUMENT, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: typeIndex = 1) aoqi@0: }) aoqi@0: public String returnMethodRefTA1() { aoqi@0: return aoqi@0: "interface Lambda {" + aoqi@0: " void generic(S p1, T p2);" + aoqi@0: "}" + aoqi@0: aoqi@0: "class LambdaImpl implements Lambda {" + aoqi@0: " public void generic(S p1, T p2) {}" + aoqi@0: "}" + aoqi@0: aoqi@0: "class Test {" + aoqi@0: " Lambda lambda(LambdaImpl r) {" + aoqi@0: " return r::<@TA Object, @TB Object>generic;" + aoqi@0: " }" + aoqi@0: "}"; aoqi@0: } aoqi@0: aoqi@0: @TADescriptions({ aoqi@0: @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: typeIndex = 0), aoqi@0: @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: typeIndex = 1) aoqi@0: }) aoqi@0: public String returnConstructorRefTA2() { aoqi@0: return aoqi@0: "interface Lambda {" + aoqi@0: " void generic(S p1, T p2);" + aoqi@0: "}" + aoqi@0: aoqi@0: "class LambdaImpl implements Lambda {" + aoqi@0: " LambdaImpl(S p1, T p2) {}" + aoqi@0: " public void generic(S p1, T p2) {}" + aoqi@0: "}" + aoqi@0: aoqi@0: "class Test {" + aoqi@0: " Lambda lambda() {" + aoqi@0: " return LambdaImpl::<@TA Object, @TB Object>new;" + aoqi@0: " }" + aoqi@0: "}"; aoqi@0: } aoqi@0: aoqi@0: @TADescriptions({ aoqi@0: @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, aoqi@0: paramIndex = 0), aoqi@0: @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER, aoqi@0: paramIndex = 1), aoqi@0: @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, aoqi@0: paramIndex = 1, genericLocation = { 3, 0 }), aoqi@0: @TADescription(annotation = "TD", type = LOCAL_VARIABLE, aoqi@0: lvarOffset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: lvarLength = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: lvarIndex = ReferenceInfoUtil.IGNORE_VALUE), aoqi@0: @TADescription(annotation = "TE", type = CAST, aoqi@0: offset = ReferenceInfoUtil.IGNORE_VALUE, aoqi@0: typeIndex = 0) aoqi@0: }) aoqi@0: public String returnLambdaExpr1() { aoqi@0: return aoqi@0: "interface LambdaInt {" + aoqi@0: " void lambda(Object p1, List p2);" + aoqi@0: "}" + aoqi@0: "class Test {" + aoqi@0: " LambdaInt getLambda() {" + aoqi@0: " return (@TA Object x, @TB List<@TC Object> y) -> { @TD Object l = null; System.out.println((@TE Object) l); };" + aoqi@0: " }" + aoqi@0: "}"; aoqi@0: } aoqi@0: aoqi@0: @TADescriptions({ aoqi@0: @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, aoqi@0: paramIndex = 0)}) aoqi@0: public String lambdaField1() { aoqi@0: return aoqi@0: "class Test {" + aoqi@0: " java.util.function.IntUnaryOperator field = (@TA int y) -> 1;" + aoqi@0: "}"; aoqi@0: } aoqi@0: aoqi@0: @TADescriptions({ aoqi@0: @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, aoqi@0: paramIndex = 0)}) aoqi@0: public String lambdaField2() { aoqi@0: return aoqi@0: "class Test {" + aoqi@0: " static java.util.function.IntUnaryOperator field = (@TA int y) -> 1;" + aoqi@0: "}"; aoqi@0: } aoqi@0: }