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