changeset 1130:fff19d71854a

Initial check-in of test code for lambda and method references Reviewed-by: mcimadamore Contributed-by: Sue Wye <sue.wei@oracle.com>
author jjh
date Mon, 11 Jul 2011 13:39:22 -0700
parents 777491a7c4e1
children 397b7ba6e0b9
files test/tools/javac/lambda/sqe/lambdaExpression/AbstractClass_neg.java test/tools/javac/lambda/sqe/lambdaExpression/AbstractClass_neg.out test/tools/javac/lambda/sqe/lambdaExpression/AccessNonStatic_neg.java test/tools/javac/lambda/sqe/lambdaExpression/AccessNonStatic_neg.out test/tools/javac/lambda/sqe/lambdaExpression/EffectivelyFinal_neg.java test/tools/javac/lambda/sqe/lambdaExpression/EffectivelyFinal_neg.out test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression1.java test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression1.out test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression3.java test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression3.out test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression4.java test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression4.out test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression5.java test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression5.out test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression6.java test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression6.out test/tools/javac/lambda/sqe/lambdaExpression/LambdaTest1.java test/tools/javac/lambda/sqe/lambdaExpression/LambdaTest2.java test/tools/javac/lambda/sqe/lambdaExpression/LambdaTest3.java test/tools/javac/lambda/sqe/lambdaExpression/LambdaTest4.java test/tools/javac/lambda/sqe/lambdaExpression/LambdaTest5.java test/tools/javac/lambda/sqe/lambdaExpression/LambdaTest6.java test/tools/javac/lambda/sqe/methodReference/MethodRef1.java test/tools/javac/lambda/sqe/methodReference/MethodRef2.java test/tools/javac/lambda/sqe/methodReference/MethodRef3.java test/tools/javac/lambda/sqe/methodReference/MethodRef4.java test/tools/javac/lambda/sqe/methodReference/MethodRef5.java test/tools/javac/lambda/sqe/methodReference/MethodRef6.java test/tools/javac/lambda/sqe/methodReference/MethodRef7.java test/tools/javac/lambda/sqe/methodReference/MethodRef_neg.java test/tools/javac/lambda/sqe/methodReference/MethodRef_neg.out
diffstat 31 files changed, 1288 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/AbstractClass_neg.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,16 @@
+/**
+ * @test     /nodynamiccopyright/
+ * @summary  Test that lambda conversion is only for SAM interface, not abstract class
+ * @compile/fail/ref=AbstractClass_neg.out -XDrawDiagnostics AbstractClass_neg.java
+ */
+
+public class AbstractClass_neg {
+
+    abstract class SAM {
+        abstract int m();
+    }
+
+    void test() {
+        SAM s = #{ 6 };
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/AbstractClass_neg.out	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,2 @@
+AbstractClass_neg.java:14:17: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.target.for.lambda.conv.must.be.interface: null, kindname.class, AbstractClass_neg.SAM)), compiler.misc.type.lambda, AbstractClass_neg.SAM
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/AccessNonStatic_neg.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,28 @@
+/**
+ * @test     /nodynamiccopyright/
+ * @summary  Test accessing non-static variable from lambda expressions in static context
+ * @compile/fail/ref=AccessNonStatic_neg.out -XDrawDiagnostics AccessNonStatic_neg.java
+ */
+
+public class AccessNonStatic_neg {
+
+    private int n = 0;
+
+    static {
+        ((Runnable)
+            #{
+                System.out.println(this);
+                System.out.println(n);
+            }
+        ).run();
+    }
+
+    public static void test() {
+        ((Runnable)
+            #{
+                Object o = this;
+                n++;
+            }
+        ).run();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/AccessNonStatic_neg.out	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,5 @@
+AccessNonStatic_neg.java:14:36: compiler.err.non-static.cant.be.ref: kindname.variable, this
+AccessNonStatic_neg.java:15:36: compiler.err.non-static.cant.be.ref: kindname.variable, n
+AccessNonStatic_neg.java:23:28: compiler.err.non-static.cant.be.ref: kindname.variable, this
+AccessNonStatic_neg.java:24:17: compiler.err.non-static.cant.be.ref: kindname.variable, n
+4 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/EffectivelyFinal_neg.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,23 @@
+/**
+ * @test     /nodynamiccopyright/
+ * @summary  Negative test of capture of "effectively final" local variable in lambda expressions
+ * @compile/fail/ref=EffectivelyFinal_neg.out -XDrawDiagnostics EffectivelyFinal_neg.java
+ */
+
+public class EffectivelyFinal_neg {
+
+    void test() {
+        String s = "a";
+        String s2 = "a";
+        int n = 1;
+        ((Runnable)
+            #{
+                s2 = "b"; //re-assign illegal here
+                System.out.println(n);
+                System.out.println(s);
+                s = "b"; // not effectively final
+            }
+        ).run();
+        n = 2; // not effectively final
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/EffectivelyFinal_neg.out	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,5 @@
+EffectivelyFinal_neg.java:15:17: compiler.err.cant.ref.non.effectively.final.var: s2
+EffectivelyFinal_neg.java:16:36: compiler.err.cant.ref.non.effectively.final.var: n
+EffectivelyFinal_neg.java:17:36: compiler.err.cant.ref.non.effectively.final.var: s
+EffectivelyFinal_neg.java:18:17: compiler.err.cant.ref.non.effectively.final.var: s
+4 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression1.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,15 @@
+/**
+ * @test     /nodynamiccopyright/
+ * @summary  Test invalid lambda expressions
+ * @compile/fail/ref=InvalidExpression1.out -XDrawDiagnostics InvalidExpression1.java
+ */
+
+import java.util.Comparator;
+
+public class InvalidExpression1 {
+
+    void test() {
+        Comparator<Number> c = #{ Number n1, Number n2 -> 42; }; //not a statement
+        Comparator<Number> c = #{ Number n1, Number n2 -> return 42 }; //";" expected
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression1.out	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,3 @@
+InvalidExpression1.java:12:59: compiler.err.not.stmt
+InvalidExpression1.java:13:68: compiler.err.expected: ';'
+2 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression3.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,14 @@
+/**
+ * @test     /nodynamiccopyright/
+ * @summary  Test invalid lambda expressions
+ * @compile/fail/ref=InvalidExpression3.out -XDrawDiagnostics InvalidExpression3.java
+ */
+
+import java.util.Comparator;
+
+public class InvalidExpression3 {
+
+    void test() {
+        Comparator<Integer> c2 = #{ Integer i1, Integer i2 -> return "0"; }; //return type need to match
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression3.out	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,2 @@
+InvalidExpression3.java:12:34: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.infer.incompatible.ret.types.in.lambda: java.lang.String)), compiler.misc.type.lambda, java.util.Comparator<java.lang.Integer>
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression4.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,16 @@
+/**
+ * @test     /nodynamiccopyright/
+ * @summary  Test invalid lambda expressions
+ * @compile/fail/ref=InvalidExpression4.out -XDrawDiagnostics InvalidExpression4.java
+ */
+
+public class InvalidExpression4 {
+
+    interface SAM {
+        void m(int i);
+    }
+
+    void test() {
+        SAM s = #{ Integer i -> }; //parameters not match, boxing not allowed here
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression4.out	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,2 @@
+InvalidExpression4.java:14:17: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.infer.incompatible.arg.types.in.lambda)), compiler.misc.type.lambda, InvalidExpression4.SAM
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression5.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,12 @@
+/**
+ * @test     /nodynamiccopyright/
+ * @summary  Test invalid lambda expressions
+ * @compile/fail/ref=InvalidExpression5.out -XDrawDiagnostics InvalidExpression5.java
+ */
+
+public class InvalidExpression5 {
+
+    void test() {
+        Object o = #{ int n -> }; // Invalid target type
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression5.out	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,2 @@
+InvalidExpression5.java:10:20: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.target.for.lambda.conv.must.be.interface: null, kindname.class, java.lang.Object)), compiler.misc.type.lambda, java.lang.Object
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression6.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,17 @@
+/**
+ * @test     /nodynamiccopyright/
+ * @summary  Test invalid lambda expressions
+ * @compile/fail/ref=InvalidExpression6.out -XDrawDiagnostics InvalidExpression6.java
+ */
+
+public class InvalidExpression6 {
+
+    interface SAM {
+        void m(int i);
+    }
+
+    void test() {
+        SAM s = #{ int n -> break;}; //break not allowed
+        s = #{ n -> continue;}; //continue not allowed
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/InvalidExpression6.out	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,3 @@
+InvalidExpression6.java:14:29: compiler.err.break.inside.lambda
+InvalidExpression6.java:15:21: compiler.err.cont.inside.lambda
+2 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/LambdaTest1.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary  Test lambda expressions for existing SAM interfaces like Runnable and Comparator<T>
+ * @compile LambdaTest1.java
+ * @run main LambdaTest1
+ */
+
+import java.util.Collections;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Date;
+
+public class LambdaTest1 {
+
+    private static String assertionStr = "";
+
+    private static void assertTrue(boolean b) {
+        if(!b)
+            throw new AssertionError();
+    }
+
+    private static void test1(Runnable r) {
+        r.run();
+    }
+
+    void test2(Object o) {
+        if(o instanceof Runnable)
+            ((Runnable)o).run();
+    }
+
+    Runnable test3() {
+        return #{assertionStr += "Runnable6";};
+    }
+
+    public static void main(String[] args) {
+
+        //lambda expressions for SAM interface Runnable:
+        //assign:
+        Runnable r = #{assertionStr += "Runnable1 ";};
+        r.run();
+
+        //cast:
+        ((Runnable)#{assertionStr += "Runnable2 ";}).run();
+
+        Object o = (Runnable)#{};
+
+        o = (Runnable)#{
+                switch (assertionStr) {
+                    case "Runnable1 Runnable2 ":
+                        assertionStr += "Runnable3 ";
+                        break;
+                    default:
+                        throw new AssertionError();
+                }
+                return;
+            };
+
+        //method parameter:
+        test1(#{assertionStr += "Runnable4 "; return;});
+
+        LambdaTest1 test = new LambdaTest1();
+        test.test2((Runnable)#{assertionStr += "Runnable5 ";});
+
+        //return type:
+        r = test.test3();
+        r.run();
+
+        assertTrue(assertionStr.equals("Runnable1 Runnable2 Runnable4 Runnable5 Runnable6"));
+
+        //lambda expressions for SAM interface Comparator<T>:
+        List<Integer> list = new ArrayList<Integer>();
+        list.add(4);
+        list.add(10);
+        list.add(-5);
+        list.add(100);
+        list.add(9);
+        Collections.sort(list, #{Integer i1, Integer i2 -> i2 - i1});
+        String result = "";
+        for(int i : list)
+            result += i + " ";
+        assertTrue(result.equals("100 10 9 4 -5 "));
+
+        Collections.sort(list,
+            #{i1, i2 ->
+                String s1 = i1.toString();
+                String s2 = i2.toString();
+                return s1.length() - s2.length();
+             });
+        result = "";
+        for(int i : list)
+            result += i + " ";
+        assertTrue(result.equals("9 4 10 -5 100 "));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/LambdaTest2.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary  Test lambda expressions for different method signatures (parameter and return type)
+ * @compile LambdaTest2.java
+ * @run main LambdaTest2
+ */
+
+public class LambdaTest2 {
+
+    private static int count = 0;
+
+    private static void assertTrue(boolean b) {
+        if(!b)
+            throw new AssertionError();
+    }
+
+    public static void main(String[] args) {
+        LambdaTest2 test = new LambdaTest2();
+
+        test.method2(#{ int n -> ; });
+        test.method2(#{ n -> ; }); // "int" is optional here
+        test.method2(#{ n -> }); // ";" is optional here
+        test.method2(#{ int n -> return;}); // ";" is mandatory here
+        test.method2(#{ int n -> count += n; });
+        assertTrue(count == 10);
+
+        VoidInt vi = #{int i ->
+                            switch (i) {
+                                case 0:
+                                    System.out.println("normal");
+                                    break;
+                                default:
+                                    System.out.println("invalid");
+                            }
+                       };
+
+        test.method3(#{ count++; });
+        test.method3(#{});
+        assertTrue(count == 11);
+
+        VoidVoid vv = #{ while(true)
+                            if(false)
+                                break;
+                            else
+                                continue;
+                       };
+
+        IntVoid iv1 = #{ 42 };
+        IntVoid iv2 = #{ return 43; };//";" is mandatory here
+        IntVoid iv3 = #{ -> 44 }; // "->" is optional here
+        IntVoid iv4 = #{ -> return 45; }; // "->" is optional here
+        assertTrue(iv1.ivMethod() == 42);
+        assertTrue(iv2.ivMethod() == 43);
+        assertTrue(iv3.ivMethod() == 44);
+        assertTrue(iv4.ivMethod() == 45);
+
+        IntInt ii1 = #{ int n -> n+1 };
+        IntInt ii2 = #{ n -> 42 };
+        IntInt ii3 = #{ n -> return 43; };
+        IntInt ii4 =
+            #{
+                int n ->{ //"{" optional here
+                if(n > 0)
+                    return n+1;
+                else
+                    return n-1;}//"}" optional here
+            };
+        assertTrue(ii1.iiMethod(1) == 2);
+        assertTrue(ii2.iiMethod(1) == 42);
+        assertTrue(ii3.iiMethod(1) == 43);
+        assertTrue(ii4.iiMethod(-1) == -2);
+    }
+
+    void method2(VoidInt a) {
+        a.viMethod(10);
+    }
+
+    void method3(VoidVoid a) {
+        a.vvMethod();
+    }
+
+    //SAM type interfaces
+    interface VoidInt {
+        void viMethod(int n);
+    }
+
+    interface VoidVoid {
+        void vvMethod();
+    }
+
+    interface IntVoid {
+        int ivMethod();
+    }
+
+    interface IntInt {
+        int iiMethod(int n);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/LambdaTest3.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary  Test capture of "effectively final" local variable in lambda expressions
+ * @compile LambdaTest3.java
+ * @run main LambdaTest3
+ */
+
+public class LambdaTest3 {
+
+    private static int count = 0;
+
+    private static void assertTrue(boolean b) {
+        if(!b)
+            throw new AssertionError();
+    }
+
+    public static void main(String[] args) {
+        final int N = 100;
+        int n = 2; //effectively final variable
+
+        Runnable r = ((Runnable)
+            #{
+                count += N;
+                count += n;
+            }
+        );
+        assertTrue(count == 0);
+        r.run();
+        assertTrue(count == 102);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/LambdaTest4.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary  Test accessing "this" in lambda expressions
+ * @compile LambdaTest4.java
+ * @run main LambdaTest4
+ */
+
+public class LambdaTest4 {
+
+    {
+        ((Runnable)
+            #{
+                this.init();
+                assertTrue(this.toString().equals(thisStr));
+                count++;
+            }
+        ).run();
+    }
+
+    private String thisStr;
+    private static int count = 0;
+
+    private static void assertTrue(boolean b) {
+        if(!b)
+            throw new AssertionError();
+    }
+
+    private void init() {
+        thisStr = this.toString();
+    }
+
+    private void m() {
+        String s1 = this.toString();
+        ((Runnable)
+            #{
+                assertTrue(this.toString().equals(thisStr));
+                assertTrue(this.toString().equals(s1));
+            }
+        ).run();
+    }
+
+    public static void main(String[] args) {
+        LambdaTest4 test = new LambdaTest4();
+        assertTrue(count == 1);
+        test.m();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/LambdaTest5.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary  Test lambda expressions inside lambda expressions
+ * @compile LambdaTest5.java
+ * @run main LambdaTest5
+ */
+
+public class LambdaTest5 {
+
+    interface A {
+        int m();
+    }
+
+    interface B {
+        int make (int i);
+    }
+
+    private static int count = 0;
+
+    private static void assertTrue(boolean b) {
+        if(!b)
+            throw new AssertionError();
+    }
+
+    public static void main(String[] args) {
+        B b = #{ int i -> ((A)#{ 5 }).m() };
+        assertTrue(b.make(0) == 5);
+
+        A a = #{ ((A)#{ return 6; }).m() }; //self reference
+        assertTrue(a.m() == 6);
+
+        A a2 = #{
+                  A an = #{ return 7; }; //self reference
+                  return an.m();
+                };
+        assertTrue(a2.m() == 7);
+
+        A a3 = #{ a3.m() }; //self reference
+        try {
+            a3.m();
+        } catch(StackOverflowError e) {
+            count++;
+        }
+        assertTrue(count==1);
+
+        A a4 = #{ ((B)#{ int i -> ((A)#{ 9 }).m() }).make(0) };
+        assertTrue(a4.m() == 9);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/lambdaExpression/LambdaTest6.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary  Test bridge methods for certain SAM convertions
+ * @compile LambdaTest6.java
+ * @run main LambdaTest6
+ */
+
+import java.lang.reflect.Method;
+
+public class LambdaTest6<T> {
+
+    interface H {Object m();}
+
+    interface K<U> {void m(U element);}
+
+    interface L extends K<String> {} //generic substitution
+
+    interface M {void m(String s);}
+
+    interface KM extends K<String>, M{} //generic substitution
+
+    interface N extends H {String m();} //covariant return
+
+    private static void assertTrue(boolean b) {
+        if(!b)
+            throw new AssertionError();
+    }
+
+    private void test1()
+    {
+        L la = #{ s -> };
+        la.m("hi");
+        Class<? extends L> c1 = la.getClass();
+        Method[] methods = c1.getDeclaredMethods();
+        String parameters = "";
+        for(Method m : methods) {
+            assertTrue(m.getName().equals("m"));
+            Class[] parameterTypes = m.getParameterTypes();
+            assertTrue(parameterTypes.length == 1);
+            parameters += parameterTypes[0].getName() + " ";
+        }
+        assertTrue(parameters.equals("java.lang.String java.lang.Object "));
+    }
+
+    private void test2()
+    {
+        KM km = #{ s -> };
+        //km.m("hi");
+        Class<? extends KM> c2 = km.getClass();
+        Method[] methods = c2.getDeclaredMethods();
+        String parameters = "";
+        for(Method m : methods) {
+            assertTrue(m.getName().equals("m"));
+            Class[] parameterTypes = m.getParameterTypes();
+            assertTrue(parameterTypes.length == 1);
+            parameters += parameterTypes[0].getName() + " ";
+        }
+        assertTrue(parameters.equals("java.lang.String java.lang.Object "));
+    }
+
+    private void test3()
+    {
+        N na = #{ "hi" };
+        assertTrue( na.m().equals("hi") );
+        assertTrue( ((H)na).m().equals("hi") );
+        Class<? extends N> c3 = na.getClass();
+        Method[] methods = c3.getDeclaredMethods();
+        String returnTypes = "";
+        for(Method m : methods) {
+            assertTrue(m.getName().equals("m"));
+            Class returnType = m.getReturnType();
+            returnTypes += returnType.getName() + " ";
+        }
+        assertTrue(returnTypes.equals("java.lang.String java.lang.Object "));
+    }
+
+
+    public static void main(String[] args) {
+        LambdaTest6 test = new LambdaTest6();
+        test.test1();
+        test.test2();
+        test.test3();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/methodReference/MethodRef1.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary  Test static method reference
+ * @compile MethodRef1.java
+ * @run main MethodRef1
+ */
+
+public class MethodRef1 {
+
+    static interface A {void m();}
+
+    static interface B {void m(int i);}
+
+    static interface C {String m(String s);}
+
+    private static void assertTrue(boolean cond) {
+        if (!cond)
+            throw new AssertionError();
+    }
+
+    static void foo(int x) {
+        System.out.println("MethodRef1.foo(int) " + x);
+    }
+
+    static void bar() {
+        System.out.println("MethodRef1.bar()");
+    }
+
+    static void bar(int x) {
+        System.out.println("MethodRef1.bar(int) " + x);
+    }
+
+    static String bar(String s) {
+        return "MethodRef1.bar(String) " + s;
+    }
+
+    public static void main(String[] args) {
+
+        A a = MethodRef1#bar(); //static reference to bar()
+        a.m();
+
+        B b = MethodRef1#foo; //static reference to foo(int), (int) omitted because method foo is not overloaded
+        b.m(1);
+
+        b = MethodRef1#foo(int); //static reference to foo(int)
+        b.m(1);
+
+        b = new MethodRef1()#foo; //instance reference to static methods, supported for now
+        b.m(1);
+
+        b = MethodRef1#bar(int); //static reference to bar(int)
+        b.m(2);
+
+        C c = MethodRef1#bar(String); //static reference to bar(String)
+        assertTrue( c.m("hi").equals("MethodRef1.bar(String) hi") );
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/methodReference/MethodRef2.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary  Test instance method reference
+ * @compile MethodRef2.java
+ * @run main MethodRef2
+ */
+
+public class MethodRef2 {
+
+    static interface A {String m();}
+
+    static interface B {String m(int i);}
+
+    private static void assertTrue(boolean cond) {
+        if (!cond)
+            throw new AssertionError();
+    }
+
+    String moo() {
+        return "moo";
+    }
+
+    String wahoo() {
+        return "wahoo";
+    }
+
+    String wahoo(int x) {
+        return "wahoo " + x;
+    }
+
+    public static void main(String[] args) {
+
+        MethodRef2 mr = new MethodRef2();
+
+        A a = mr#moo; //instance reference to moo()
+        assertTrue( a.m().equals("moo") );
+
+        a = new MethodRef2()#wahoo(); //instance reference to wahoo()
+        assertTrue( a.m().equals("wahoo") );
+
+        B b = mr#wahoo(int); //instance reference to wahoo(int)
+        assertTrue( b.m(4).equals("wahoo 4") );
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/methodReference/MethodRef3.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary  Test unbound method reference
+ * @compile MethodRef3.java
+ * @run main MethodRef3
+ */
+
+public class MethodRef3 {
+
+    static interface A { String m(MethodRef3 mr); }
+
+    static interface B { String m(MethodRef3 mr, String s); }
+
+    private static void assertTrue(boolean cond) {
+        if (!cond)
+            throw new AssertionError();
+    }
+
+    String moo() {
+        return "moo";
+    }
+
+    String wahoo(String s) {
+        return "wahoo " + s;
+    }
+
+    public static void main(String[] args) {
+
+        MethodRef3 mr = new MethodRef3();
+        A a = MethodRef3#moo; //unbound reference to moo()
+        assertTrue( a.m(mr).equals("moo") );
+        B b = MethodRef3#wahoo; //unbound reference to wahoo()
+        assertTrue( b.m(mr, "hi").equals("wahoo hi") );
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/methodReference/MethodRef4.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary  Test constructor reference
+ * @compile MethodRef4.java
+ * @run main MethodRef4
+ */
+
+public class MethodRef4 {
+
+    static interface A {Fee<String> m();}
+
+    static interface B {Fee<String> m(String s);}
+
+    static interface C {Object m();}
+
+    static class Fee<T> {
+
+        private T t;
+
+        public Fee() {
+            System.out.println("Fee<T> instantiated");
+        }
+
+        public Fee(T t) {
+            this.t = t;
+            System.out.println("Fee<T> instantiated: " + t);
+        }
+
+        public void make() {
+            System.out.println(this + ": make()");
+        }
+    }
+
+    private static void assertTrue(boolean cond) {
+        if (!cond)
+            throw new AssertionError();
+    }
+
+    public static void main(String[] args) {
+
+        A a = Fee<String>#new(); //constructor reference to Fee<T>()
+        a.m().make();
+
+        B b = Fee<String>#new(String); //constructor reference to Fee<T>(String)
+        b.m("hi").make();
+
+        C c = MethodRef4#new; //constructor reference to MethodRef4()
+        assertTrue( c.m() instanceof MethodRef4 );
+        c = MethodRef4#new(); //constructor reference to MethodRef4()
+        assertTrue( c.m() instanceof MethodRef4 );
+        c = Fee<String>#new(); //constructor reference to Fee<T>()
+        assertTrue( c.m() instanceof Fee );
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/methodReference/MethodRef5.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary  Test method reference with SAM interface Comparator<T>
+ * @compile MethodRef5.java
+ * @run main MethodRef5
+ */
+
+import java.util.Collections;
+import java.util.List;
+import java.util.ArrayList;
+
+public class MethodRef5 {
+
+    static class Person {
+
+        private String firstName;
+        private String lastName;
+        private int age;
+
+        public Person() { }
+
+        public Person(String fn, String ln, int a) {
+            firstName = fn;
+            lastName = ln;
+            age = a;
+        }
+
+        public String getLastName() {
+            return lastName;
+        }
+
+        public int getAge() {
+            return age;
+        }
+
+        //the following 2 methods are signature-compatible with Comparator<Person>.compare():
+        public static int compareByAge(Person a, Person b) {
+            return a.age - b.age;
+        }
+
+        public int compareByLastName(Person a, Person b) {
+            return a.lastName.compareToIgnoreCase(b.lastName);
+        }
+    }
+
+    private static void assertTrue(boolean cond) {
+        if (!cond)
+            throw new AssertionError();
+    }
+
+    public static void main(String[] args) {
+
+        List<Person> persons = new ArrayList<Person>();
+        persons.add(new Person("John", "Smith", 49));
+        persons.add(new Person("Abraham", "Lincoln", 30));
+        persons.add(new Person("George", "Washington", 29));
+        persons.add(new Person("Peter", "Derby", 50));
+        Collections.sort(persons, Person#compareByAge);//static method reference to compareByAge(Person, Person)
+        String age = "";
+        for (Person p : persons) {
+            age += p.getAge() + " ";
+        }
+        assertTrue( (age.equals("29 30 49 50 ")) );
+        Collections.sort(persons, new Person()#compareByLastName);//instance method reference to compareByLastName(Person, Person)
+        String lastName = "";
+        for (Person p : persons) {
+            lastName += p.getLastName() + " ";
+        }
+        assertTrue( lastName.equals("Derby Lincoln Smith Washington ") );
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/methodReference/MethodRef6.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary  Test that the most specific reference is selected when method parameters are elided
+ * @compile MethodRef6.java
+ * @run main MethodRef6
+ */
+
+public class MethodRef6 {
+
+    static interface A { String make(Integer i); }
+
+    static interface B { String make(Number i); }
+
+    private static void assertTrue(boolean cond) {
+        if (!cond)
+            throw new AssertionError();
+    }
+
+    static String m(Object o) {
+        return "Object " + o;
+    }
+
+    static String m(Number n) {
+        return "Number " + n;
+    }
+
+    static String m(Integer i) {
+        return "Integer " + i;
+    }
+
+    static String m(int i) {
+        return "int " + i;
+    }
+
+    public static void main(String[] args) {
+        A a = MethodRef6#m;
+        assertTrue(a.make(1).equals("Integer 1"));//method parameter type inferred from SAM descriptor, boxing applied
+        B b = MethodRef6#m;
+        assertTrue(b.make(1).equals("Number 1"));//method parameter type inferred from SAM descriptor, boxing and widen applied
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/methodReference/MethodRef7.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @summary  Test that parameter types are inferred from SAM descriptor when method parameters are elided,
+             with different types of method references
+ * @compile MethodRef7.java
+ * @run main MethodRef7
+ */
+
+public class MethodRef7 {
+
+    static interface A {void m();}
+
+    static interface A2 {void m(int n);}
+
+    static interface B {String m();}
+
+    static interface B2 {String m(int n);}
+
+    static interface C {String m(MethodRef7 mr);}
+
+    static interface C2 {String m(MethodRef7 mr, int n);}
+
+    static interface D {Fee<String> m();}
+
+    static interface D2 {Fee<String> m(String s);}
+
+    static class Fee<T> {
+
+        public Fee() {
+            System.out.println("Fee<T> instantiated");
+        }
+
+        public Fee(String s) {
+            System.out.println("Fee<T> instantiated: " + s);
+        }
+    }
+
+    private static void assertTrue(boolean cond) {
+        if (!cond)
+            throw new AssertionError();
+    }
+
+    static void bar() {
+        System.out.println("MethodRef_neg1.bar()");
+    }
+
+    static void bar(int x) {
+        System.out.println("MethodRef_neg1.bar(int) " + x);
+    }
+
+    String wahoo() {
+        return "wahoo";
+    }
+
+    String wahoo(int x) {
+        return "wahoo " + x;
+    }
+
+    public static void main(String[] args) {
+
+        A a = MethodRef7#bar; //static reference to bar()
+        a.m();
+        A2 a2 = MethodRef7#bar; //static reference to bar(int x)
+        a2.m(10);
+
+        MethodRef7 mr = new MethodRef7();
+        B b = mr#wahoo; //instance reference to wahoo()
+        assertTrue(b.m().equals("wahoo"));
+        B2 b2 = mr#wahoo; //instance reference to wahoo(int x)
+        assertTrue(b2.m(1).equals("wahoo 1"));
+
+        C c = MethodRef7#wahoo; //unbound reference to wahoo()
+        assertTrue(c.m(mr).equals("wahoo"));
+        C2 c2 = MethodRef7#wahoo; //unbound reference to wahoo(int x)
+        assertTrue(c2.m(mr, 2).equals("wahoo 2"));
+
+        D d = Fee<String>#new; //constructor reference to Fee()
+        D2 d2 = Fee<String>#new; //constructor reference to Fee(String s)
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/methodReference/MethodRef_neg.java	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,34 @@
+/**
+ * @test     /nodynamiccopyright/
+ * @summary  This is negative test for wrong parameter/return type in method references
+ * @compile/fail/ref=MethodRef_neg.out -XDrawDiagnostics MethodRef_neg.java
+ */
+
+public class MethodRef_neg {
+
+    static interface A {void m(Integer i);}
+
+    static interface B {void m(String s);}
+
+    static interface C {Integer m();}
+
+    static interface D {String m();}
+
+
+    static void bar(int x) { }
+
+    int foo() {
+        return 5;
+    }
+
+    static void make() { }
+
+    void method() {
+        A a = MethodRef_neg#bar; //boxing on parameter type is ok
+        B b = MethodRef_neg#bar; //wrong parameter type, required: String, actual: int
+        C c = this#foo; //boxing on return type is ok
+        D d = this#foo; //wrong return type, required: String, actual: int
+        a = MethodRef_neg#make; //missing parameter
+        c = MethodRef_neg#make; //missing return type
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/sqe/methodReference/MethodRef_neg.out	Mon Jul 11 13:39:22 2011 -0700
@@ -0,0 +1,5 @@
+MethodRef_neg.java:28:15: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.reference.not.found: kindname.method, bar, java.lang.String)), compiler.misc.type.mref, MethodRef_neg.B
+MethodRef_neg.java:30:15: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.infer.incompatible.ret.types.in.lambda: int)), compiler.misc.type.mref, MethodRef_neg.D
+MethodRef_neg.java:31:13: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.reference.not.found: kindname.method, make, java.lang.Integer)), compiler.misc.type.mref, MethodRef_neg.A
+MethodRef_neg.java:32:13: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.infer.incompatible.ret.types.in.lambda: void)), compiler.misc.type.mref, MethodRef_neg.C
+4 errors