diff test/tools/javac/lambda/LambdaExpr02.java @ 553:7704dcd17e0b

initial lambda push; the current prototype suuports the following features: *) function types syntax (optionally enabled with -XDallowFunctionTypes) *) function types subtyping *) full support for lambda expression of type 1 and 2 *) inference of thrown types/return type in a lambda *) lambda conversion using rules specified in v0.1.5 draft *) support references to 'this' (both explicit and implicit) *) translation using method handles The modified script build of the langtools repository now generates an additional jarfile called javacrt.jar which contains an helper class to be used during SAM conversion; after the build, the generated scripts javac/java will take care of automatically setting up the required dependencies so that code containing lambda expressions can be compiled and executed.
author mcimadamore
date Thu, 27 May 2010 18:11:12 +0100
parents
children 1f2a6005435d
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/LambdaExpr02.java	Thu May 27 18:11:12 2010 +0100
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2010 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary basic test for simple lambda expressions in multiple scopes
+ * @author  Brian Goetz
+ * @author  Maurizio Cimadamore
+ * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles LambdaExpr02
+ */
+
+public class LambdaExpr02 {
+
+    static int assertionCount = 0;
+
+    static void assertTrue(boolean cond) {
+        assertionCount++;
+        if (!cond)
+            throw new AssertionError();
+    }
+
+    static {
+        int i1 = #(){ return 3; }.();
+        assertTrue(3 == i1);
+        Integer i2 = #(){ return 3; }.();
+        assertTrue(3 == i2);
+        int i3 = #(int x){ return x + 1; }.(3);
+        assertTrue(4 == i3);
+        int i4 = #(Number x){ return x.intValue(); }.(new Float(3.0f));
+        assertTrue(3 == i4);
+        Object o = #(){ return 3; };
+        assertTrue(o != null);
+    }
+
+    {
+        int i1 = #(){ return 3; }.();
+        assertTrue(3 == i1);
+        Integer i2 = #(){ return 3; }.();
+        assertTrue(3 == i2);
+        int i3 = #(int x){ return x + 1; }.(3);
+        assertTrue(4 == i3);
+        int i4 = #(Number x){ return x.intValue(); }.(new Float(3.0f));
+        assertTrue(3 == i4);
+        Object o = #(){ return 3; };
+        assertTrue(o != null);
+    }
+
+    static void test1() {
+        int i1 = #(){ return 3; }.();
+        assertTrue(3 == i1);
+        Integer i2 = #(){ return 3; }.();
+        assertTrue(3 == i2);
+        int i3 = #(int x){ return x + 1; }.(3);
+        assertTrue(4 == i3);
+        int i4 = #(Number x){ return x.intValue(); }.(new Float(3.0f));
+        assertTrue(3 == i4);
+        Object o = #(){ return 3; };
+        assertTrue(o != null);
+    }
+
+    void test2() {
+        int i1 = #(){ return 3; }.();
+        assertTrue(3 == i1);
+        Integer i2 = #(){ return 3; }.();
+        assertTrue(3 == i2);
+        int i3 = #(int x){ return x + 1; }.(3);
+        assertTrue(4 == i3);
+        int i4 = #(Number x){ return x.intValue(); }.(new Float(3.0f));
+        assertTrue(3 == i4);
+        Object o = #(){ return 3; };
+        assertTrue(o != null);
+    }
+
+    public static void main(String[] args) {
+        test1();
+        new LambdaExpr02().test2();
+        assertTrue(assertionCount == 20);
+    }
+}