Merge
authorjjg
Wed, 27 Jan 2016 20:49:44 -0800
changeset 35421 145c5b260ea1
parent 35420 9303ae941f69 (current diff)
parent 35418 8681d57fc3f8 (diff)
child 35422 1f1990a69517
Merge
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Wed Jan 27 20:47:21 2016 -0800
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Wed Jan 27 20:49:44 2016 -0800
@@ -1812,7 +1812,7 @@
 
             TranslationContext(T tree) {
                 this.tree = tree;
-                this.owner = owner();
+                this.owner = owner(true);
                 this.depth = frameStack.size() - 1;
                 this.prev = context();
                 ClassSymbol csym =
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java	Wed Jan 27 20:47:21 2016 -0800
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java	Wed Jan 27 20:49:44 2016 -0800
@@ -2173,8 +2173,8 @@
         }
 
     public void visitTypeCast(JCTypeCast tree) {
+        result = genExpr(tree.expr, tree.clazz.type).load();
         setTypeAnnotationPositions(tree.pos);
-        result = genExpr(tree.expr, tree.clazz.type).load();
         // Additional code is only needed if we cast to a reference type
         // which is not statically a supertype of the expression's type.
         // For basic types, the coerce(...) in genExpr(...) will do
@@ -2191,8 +2191,8 @@
     }
 
     public void visitTypeTest(JCInstanceOf tree) {
+        genExpr(tree.expr, tree.expr.type).load();
         setTypeAnnotationPositions(tree.pos);
-        genExpr(tree.expr, tree.expr.type).load();
         code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type));
         result = items.makeStackItem(syms.booleanType);
     }
--- a/langtools/test/tools/javac/MethodParameters/LambdaTest.out	Wed Jan 27 20:47:21 2016 -0800
+++ b/langtools/test/tools/javac/MethodParameters/LambdaTest.out	Wed Jan 27 20:49:44 2016 -0800
@@ -2,6 +2,6 @@
 LambdaTest.<init>()
 LambdaTest.foo(i)
 LambdaTest.lambda$static$1(arg0)/*synthetic*/
-LambdaTest.lambda$null$0(arg0, arg1)/*synthetic*/
+LambdaTest.lambda$static$0(arg0, arg1)/*synthetic*/
 static interface LambdaTest$I -- inner
 LambdaTest$I.m(x)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/typeAnnotations/classfile/NestedLambdasCastedTest.java	Wed Jan 27 20:49:44 2016 -0800
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2016, 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
+ * @bug 8144168
+ * @summary No type annotations generated for nested lambdas
+ * @library /tools/lib
+ * @modules jdk.compiler/com.sun.tools.javac.api
+ *          jdk.compiler/com.sun.tools.javac.file
+ *          jdk.compiler/com.sun.tools.javac.main
+ * @build ToolBox
+ * @run compile NestedLambdasCastedTest.java
+ * @run main NestedLambdasCastedTest
+ */
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+public class NestedLambdasCastedTest {
+
+    // Expected output can't be directly encoded into NestedLambdasCastedTest !!!
+    static class ExpectedOutputHolder {
+        public String [] outputs = {
+                      "public static strictfp void main(java.lang.String[])",
+                      "private static strictfp void lambda$main$3();",
+                      "private static strictfp void lambda$main$2();",
+                      "private static strictfp void lambda$main$1();",
+                      "private static strictfp void lambda$main$0();",
+                      "0: #63(#64=s#65): CAST, offset=5, type_index=0",
+                      "0: #63(#64=s#70): CAST, offset=5, type_index=0",
+                      "0: #63(#64=s#73): CAST, offset=5, type_index=0",
+                      "0: #63(#64=s#76): CAST, offset=5, type_index=0"
+        };
+    }
+
+    @Target(ElementType.TYPE_USE)
+    public @interface TA {
+        String value() default "";
+    };
+
+    public static strictfp void main(String args[]) throws Exception {
+        Runnable one = (@TA("1") Runnable) () -> {
+            Runnable two = (@TA("2") Runnable) () -> {
+                Runnable three = (@TA("3") Runnable) () -> {
+                    Runnable four = (@TA("4") Runnable) () -> {
+                    };
+                };
+            };
+        };
+        ToolBox tb = new ToolBox();
+        Path classPath = Paths.get(ToolBox.testClasses, "NestedLambdasCastedTest.class");
+        String javapOut = tb.new JavapTask()
+                .options("-v", "-p")
+                .classes(classPath.toString())
+                .run()
+                .getOutput(ToolBox.OutputKind.DIRECT);
+        ExpectedOutputHolder holder = new ExpectedOutputHolder();
+        for (String s : holder.outputs)
+        if (!javapOut.contains(s))
+            throw new AssertionError("Expected type annotation on LOCAL_VARIABLE missing");
+    }
+}