diff options
author | Sasikanth Bharadwaj | 2014-11-13 06:53:21 +0000 |
---|---|---|
committer | Sasikanth Bharadwaj | 2014-11-13 06:53:21 +0000 |
commit | 35ce3cd769971f5dca3aae3c48f3088e32084ea9 (patch) | |
tree | 0c126e21574e2ae683e360e7742bf80e377dea90 | |
parent | 4ce91958103bed0391aa763e032ff18d6e80eeff (diff) | |
download | eclipse.jdt.core-35ce3cd769971f5dca3aae3c48f3088e32084ea9.tar.gz eclipse.jdt.core-35ce3cd769971f5dca3aae3c48f3088e32084ea9.tar.xz eclipse.jdt.core-35ce3cd769971f5dca3aae3c48f3088e32084ea9.zip |
Fixed bug 449063: [1.8][compiler] Bring back generic signatures for
Lambda Expressions
8 files changed, 383 insertions, 6 deletions
diff --git a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java index 7cef2f0729..67e7d8b083 100644 --- a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java +++ b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java @@ -141,6 +141,7 @@ public class CompilerToolTests extends TestCase { "-proc:none", "-proc:only", "-parameters", + "-genericsignature" }; static final String[] FAKE_ZERO_ARG_OPTIONS = new String[] { // a series of fake options to test the behavior upon ignored and diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java index a581509f65..4b2f1fffee 100644 --- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java +++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2013 IBM Corporation and others. + * Copyright (c) 2006, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -65,6 +65,7 @@ public final class Options { Options.ZERO_ARGUMENT_OPTIONS.add("-XprintProcessorInfo");//$NON-NLS-1$ Options.ZERO_ARGUMENT_OPTIONS.add("-XprintRounds");//$NON-NLS-1$ Options.ZERO_ARGUMENT_OPTIONS.add("-parameters");//$NON-NLS-1$ + Options.ZERO_ARGUMENT_OPTIONS.add("-genericsignature");//$NON-NLS-1$ FILE_MANAGER_OPTIONS = new HashSet<String>(); Options.FILE_MANAGER_OPTIONS.add("-bootclasspath");//$NON-NLS-1$ diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java index 0593e57dbc..1f4894bb8a 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java @@ -1653,6 +1653,7 @@ public void test012(){ " -inlineJSR inline JSR bytecode (implicit if target >= 1.5)\n" + " -enableJavadoc consider references in javadoc\n" + " -parameters generate method parameters attribute (for target >= 1.8)\n" + + " -genericsignature generate generic signature for lambda expressions\n" + " -Xemacs used to enable emacs-style output in the console.\n" + " It does not affect the xml log output\n" + " -missingNullDefault report missing default nullness annotation\n" + @@ -1897,6 +1898,7 @@ public void test012b(){ " <option key=\"org.eclipse.jdt.core.compiler.annotation.nullable\" value=\"org.eclipse.jdt.annotation.Nullable\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.annotation.nullanalysis\" value=\"disabled\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode\" value=\"disabled\"/>\n" + + " <option key=\"org.eclipse.jdt.core.compiler.codegen.lambda.genericSignature\" value=\"do not generate\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.codegen.methodParameters\" value=\"do not generate\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.codegen.shareCommonFinallyBlocks\" value=\"disabled\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.codegen.targetPlatform\" value=\"1.5\"/>\n" + diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java index fbe0f029cd..d7346a7966 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java @@ -5144,6 +5144,358 @@ public void test448802() throws Exception { }, "true"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449063, [1.8][compiler] Bring back generic signatures for Lambda Expressions +public void test449063() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_LambdaGenericSignature, CompilerOptions.GENERATE); + this.runConformTest( + new String[] { + "Test.java", + "import java.io.Serializable;\n" + + "import java.lang.invoke.SerializedLambda;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Type;\n" + + "public class Test {\n" + + " public static interface Map<IN, OUT> {\n" + + " public OUT map(IN in);\n" + + " }\n" + + " public static class Tuple<T1, T2> {\n" + + " private T1 field1;\n" + + " private T2 field2;\n" + + " }\n" + + " public static void main(String[] strings) throws Exception {\n" + + " Map<Tuple<String, Double>, Tuple<Integer, String>> map = (in) -> new Tuple<>();\n" + + " for(Method m : Test.class.getDeclaredMethods()) {\n" + + " // Use the type information stored in signature\n" + + " if (m.getName().contains(\"lambda\")) {\n" + + " System.out.println(m.getGenericReturnType());\n" + + " for (Type t : m.getGenericParameterTypes()) {\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "Test.Test$Tuple<java.lang.Integer, java.lang.String>\n" + + "Test.Test$Tuple<java.lang.String, java.lang.Double>", + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449063, [1.8][compiler] Bring back generic signatures for Lambda Expressions +public void test449063a() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_LambdaGenericSignature, CompilerOptions.GENERATE); + this.runConformTest( + new String[] { + "Test.java", + "import java.io.Serializable;\n" + + "import java.lang.invoke.SerializedLambda;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Type;\n" + + "public class Test {\n" + + " public static interface Map<IN, OUT> extends Serializable {\n" + + " public OUT map(IN in);\n" + + " }\n" + + " public static class Tuple<T1, T2> {\n" + + " private T1 field1;\n" + + " private T2 field2;\n" + + " }\n" + + " public static void main(String[] strings) throws Exception {\n" + + " Map<Tuple<String, Double>, Tuple<Integer, String>> map = (in) -> new Tuple<>();\n" + + " SerializedLambda sl = getSerializedLambda(map); \n" + + " Method m = getLambdaMethod(sl);\n" + + " // Use the type information stored in signature\n" + + " System.out.println(m.getGenericReturnType());\n" + + " for (Type t : m.getGenericParameterTypes()) {\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static Method getLambdaMethod(SerializedLambda lambda) throws Exception {\n" + + " String implClassName = lambda.getImplClass().replace(\'/\', \'.\');\n" + + " Class<?> implClass = Class.forName(implClassName);\n" + + " String lambdaName = lambda.getImplMethodName();\n" + + " for (Method m : implClass.getDeclaredMethods()) {\n" + + " if (m.getName().equals(lambdaName)) {\n" + + " return m;\n" + + " }\n" + + " }\n" + + " throw new Exception(\"Lambda Method not found\");\n" + + " }\n" + + " public static SerializedLambda getSerializedLambda(Object function) throws Exception {\n" + + " if (function == null || !(function instanceof java.io.Serializable)) {\n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " for (Class<?> clazz = function.getClass(); clazz != null; clazz = clazz.getSuperclass()) {\n" + + " try {\n" + + " Method replaceMethod = clazz.getDeclaredMethod(\"writeReplace\");\n" + + " replaceMethod.setAccessible(true);\n" + + " Object serializedForm = replaceMethod.invoke(function);\n" + + " if (serializedForm instanceof SerializedLambda) {\n" + + " return (SerializedLambda) serializedForm;\n" + + " }\n" + + " }\n" + + " catch (NoSuchMethodError e) {\n" + + " // fall through the loop and try the next class\n" + + " }\n" + + " catch (Throwable t) {\n" + + " throw new RuntimeException(\"Error while extracting serialized lambda\", t);\n" + + " }\n" + + " }\n" + + " throw new Exception(\"writeReplace method not found\");\n" + + " }\n" + + "}" + }, + "Test.Test$Tuple<java.lang.Integer, java.lang.String>\n" + + "Test.Test$Tuple<java.lang.String, java.lang.Double>", + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449063, [1.8][compiler] Bring back generic signatures for Lambda Expressions +public void test449063b() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_LambdaGenericSignature, CompilerOptions.DO_NOT_GENERATE); + this.runConformTest( + new String[] { + "Test.java", + "import java.io.Serializable;\n" + + "import java.lang.invoke.SerializedLambda;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Type;\n" + + "public class Test {\n" + + " public static interface Map<IN, OUT> {\n" + + " public OUT map(IN in);\n" + + " }\n" + + " public static class Tuple<T1, T2> {\n" + + " private T1 field1;\n" + + " private T2 field2;\n" + + " }\n" + + " public static void main(String[] strings) throws Exception {\n" + + " Map<Tuple<String, Double>, Tuple<Integer, String>> map = (in) -> new Tuple<>();\n" + + " for(Method m : Test.class.getDeclaredMethods()) {\n" + + " // Use the type information stored in signature\n" + + " if (m.getName().contains(\"lambda\")) {\n" + + " System.out.println(m.getGenericReturnType());\n" + + " for (Type t : m.getGenericParameterTypes()) {\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "class Test$Tuple\n" + + "class Test$Tuple", + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449063, [1.8][compiler] Bring back generic signatures for Lambda Expressions +public void test449063c() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_LambdaGenericSignature, CompilerOptions.DO_NOT_GENERATE); + this.runConformTest( + new String[] { + "Test.java", + "import java.io.Serializable;\n" + + "import java.lang.invoke.SerializedLambda;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Type;\n" + + "public class Test {\n" + + " public static interface Map<IN, OUT> extends Serializable {\n" + + " public OUT map(IN in);\n" + + " }\n" + + " public static class Tuple<T1, T2> {\n" + + " private T1 field1;\n" + + " private T2 field2;\n" + + " }\n" + + " public static void main(String[] strings) throws Exception {\n" + + " Map<Tuple<String, Double>, Tuple<Integer, String>> map = (in) -> new Tuple<>();\n" + + " SerializedLambda sl = getSerializedLambda(map); \n" + + " Method m = getLambdaMethod(sl);\n" + + " // Use the type information stored in signature\n" + + " System.out.println(m.getGenericReturnType());\n" + + " for (Type t : m.getGenericParameterTypes()) {\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static Method getLambdaMethod(SerializedLambda lambda) throws Exception {\n" + + " String implClassName = lambda.getImplClass().replace(\'/\', \'.\');\n" + + " Class<?> implClass = Class.forName(implClassName);\n" + + " String lambdaName = lambda.getImplMethodName();\n" + + " for (Method m : implClass.getDeclaredMethods()) {\n" + + " if (m.getName().equals(lambdaName)) {\n" + + " return m;\n" + + " }\n" + + " }\n" + + " throw new Exception(\"Lambda Method not found\");\n" + + " }\n" + + " public static SerializedLambda getSerializedLambda(Object function) throws Exception {\n" + + " if (function == null || !(function instanceof java.io.Serializable)) {\n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " for (Class<?> clazz = function.getClass(); clazz != null; clazz = clazz.getSuperclass()) {\n" + + " try {\n" + + " Method replaceMethod = clazz.getDeclaredMethod(\"writeReplace\");\n" + + " replaceMethod.setAccessible(true);\n" + + " Object serializedForm = replaceMethod.invoke(function);\n" + + " if (serializedForm instanceof SerializedLambda) {\n" + + " return (SerializedLambda) serializedForm;\n" + + " }\n" + + " }\n" + + " catch (NoSuchMethodError e) {\n" + + " // fall through the loop and try the next class\n" + + " }\n" + + " catch (Throwable t) {\n" + + " throw new RuntimeException(\"Error while extracting serialized lambda\", t);\n" + + " }\n" + + " }\n" + + " throw new Exception(\"writeReplace method not found\");\n" + + " }\n" + + "}" + }, + "class Test$Tuple\n" + + "class Test$Tuple", + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449063, [1.8][compiler] Bring back generic signatures for Lambda Expressions +public void test449063d() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_LambdaGenericSignature, CompilerOptions.GENERATE); + this.runConformTest( + new String[] { + "Test.java", + "import java.io.Serializable;\n" + + "import java.lang.invoke.SerializedLambda;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Type;\n" + + "public class Test {\n" + + " public static interface Map<IN, OUT> {\n" + + " public OUT map(IN in);\n" + + " }\n" + + " public static Tuple<Integer, String> noop(Tuple<String, Double> t){return null;}\n" + + " public static class Tuple<T1, T2> {\n" + + " private T1 field1;\n" + + " private T2 field2;\n" + + " }\n" + + " public static void main(String[] strings) throws Exception {\n" + + " Map<Tuple<String, Double>, Tuple<Integer, String>> map = Test::noop;\n" + + " for(Method m : Test.class.getDeclaredMethods()) {\n" + + " // Use the type information stored in signature\n" + + " if (m.getName().contains(\"lambda\")) {\n" + + " System.out.println(m.getGenericReturnType());\n" + + " for (Type t : m.getGenericParameterTypes()) {\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449063, [1.8][compiler] Bring back generic signatures for Lambda Expressions +public void test449063e() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_LambdaGenericSignature, CompilerOptions.DO_NOT_GENERATE); + this.runConformTest( + new String[] { + "Test.java", + "import java.io.Serializable;\n" + + "import java.lang.invoke.SerializedLambda;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Type;\n" + + "public class Test {\n" + + " public static interface Map<IN, OUT> extends Serializable {\n" + + " public OUT map(IN in);\n" + + " }\n" + + " public static Tuple<Integer, String> noop(Tuple<String, Double> t){return null;}\n" + + " public static class Tuple<T1, T2> {\n" + + " private T1 field1;\n" + + " private T2 field2;\n" + + " }\n" + + " public static void main(String[] strings) throws Exception {\n" + + " Map<Tuple<String, Double>, Tuple<Integer, String>> map = Test::noop;\n" + + " SerializedLambda sl = getSerializedLambda(map); \n" + + " Method m = getLambdaMethod(sl);\n" + + " // Use the type information stored in signature\n" + + " System.out.println(m.getGenericReturnType());\n" + + " for (Type t : m.getGenericParameterTypes()) {\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static Method getLambdaMethod(SerializedLambda lambda) throws Exception {\n" + + " String implClassName = lambda.getImplClass().replace(\'/\', \'.\');\n" + + " Class<?> implClass = Class.forName(implClassName);\n" + + " String lambdaName = lambda.getImplMethodName();\n" + + " for (Method m : implClass.getDeclaredMethods()) {\n" + + " if (m.getName().equals(lambdaName)) {\n" + + " return m;\n" + + " }\n" + + " }\n" + + " throw new Exception(\"Lambda Method not found\");\n" + + " }\n" + + " public static SerializedLambda getSerializedLambda(Object function) throws Exception {\n" + + " if (function == null || !(function instanceof java.io.Serializable)) {\n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " for (Class<?> clazz = function.getClass(); clazz != null; clazz = clazz.getSuperclass()) {\n" + + " try {\n" + + " Method replaceMethod = clazz.getDeclaredMethod(\"writeReplace\");\n" + + " replaceMethod.setAccessible(true);\n" + + " Object serializedForm = replaceMethod.invoke(function);\n" + + " if (serializedForm instanceof SerializedLambda) {\n" + + " return (SerializedLambda) serializedForm;\n" + + " }\n" + + " }\n" + + " catch (NoSuchMethodError e) {\n" + + " // fall through the loop and try the next class\n" + + " }\n" + + " catch (Throwable t) {\n" + + " throw new RuntimeException(\"Error while extracting serialized lambda\", t);\n" + + " }\n" + + " }\n" + + " throw new Exception(\"writeReplace method not found\");\n" + + " }\n" + + "}" + }, + "Test.Test$Tuple<java.lang.Integer, java.lang.String>\n" + + "Test.Test$Tuple<java.lang.String, java.lang.Double>", + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449063, [1.8][compiler] Bring back generic signatures for Lambda Expressions +public void test449063f() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_LambdaGenericSignature, CompilerOptions.GENERATE); + this.runConformTest( + new String[] { + "Test.java", + "import java.io.Serializable;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Type;\n" + + "public class Test implements Serializable{\n" + + " public static interface Map<IN, OUT> {\n" + + " public OUT map(IN in);\n" + + " }\n" + + " public static Tuple<Integer, String> noop(Tuple<String, Double> t){return null;}\n" + + " public static class Tuple<T1, T2> {\n" + + " private T1 field1;\n" + + " private T2 field2;\n" + + " }\n" + + " public static void main(String[] strings) throws Exception {\n" + + " Map<Tuple<String, Double>, Tuple<Integer, String>> map = Test::noop;\n" + + " for(Method m : Test.class.getDeclaredMethods()) {\n" + + " // Use the type information stored in signature\n" + + " if (m.getName().contains(\"lambda\")) {\n" + + " System.out.println(m.getGenericReturnType());\n" + + " for (Type t : m.getGenericParameterTypes()) {\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + customOptions); +} public static Class testClass() { return LambdaExpressionsTest.class; } diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java index 3e4c44e603..d6f919529d 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java @@ -2199,6 +2199,13 @@ public void configure(String[] argv) { CompilerOptions.GENERATE); continue; } + if (currentArg.equals("-genericsignature")) { //$NON-NLS-1$ + mode = DEFAULT; + this.options.put( + CompilerOptions.OPTION_LambdaGenericSignature, + CompilerOptions.GENERATE); + continue; + } if (currentArg.startsWith("-g")) { //$NON-NLS-1$ mode = DEFAULT; String debugOption = currentArg; diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties index 72975fd1ee..d43f4714d3 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2013 IBM Corporation and others. +# Copyright (c) 2000, 2014 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -259,6 +259,7 @@ misc.usage = {1} {2}\n\ \ -inlineJSR inline JSR bytecode (implicit if target >= 1.5)\n\ \ -enableJavadoc consider references in javadoc\n\ \ -parameters generate method parameters attribute (for target >= 1.8)\n\ +\ -genericsignature generate generic signature for lambda expressions\n\ \ -Xemacs used to enable emacs-style output in the console.\n\ \ It does not affect the xml log output\n\ \ -missingNullDefault report missing default nullness annotation\n\ diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java index 6e3e113bdc..47b1f7ce35 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java @@ -337,6 +337,7 @@ public class LambdaExpression extends FunctionalExpression implements IPolyExpre } } } + boolean genericSignatureNeeded = this.requiresGenericSignature || blockScope.compilerOptions().generateGenericSignatureForLambdaExpressions; for (int i = 0; i < argumentsLength; i++) { Argument argument = this.arguments[i]; TypeBinding argumentType; @@ -349,7 +350,7 @@ public class LambdaExpression extends FunctionalExpression implements IPolyExpre this.resolvedType = null; // continue to type check. } } - if (this.requiresGenericSignature) { + if (genericSignatureNeeded) { TypeBinding leafType = argumentType.leafComponentType(); if (leafType instanceof ReferenceBinding && (((ReferenceBinding) leafType).modifiers & ExtraCompilerModifiers.AccGenericSignature) != 0) this.binding.modifiers |= ExtraCompilerModifiers.AccGenericSignature; @@ -389,7 +390,7 @@ public class LambdaExpression extends FunctionalExpression implements IPolyExpre if ((exception.tagBits & TagBits.HasMissingType) != 0) { this.binding.tagBits |= TagBits.HasMissingType; } - if (this.requiresGenericSignature) + if (genericSignatureNeeded) this.binding.modifiers |= (exception.modifiers & ExtraCompilerModifiers.AccGenericSignature); } @@ -398,7 +399,7 @@ public class LambdaExpression extends FunctionalExpression implements IPolyExpre if ((returnType.tagBits & TagBits.HasMissingType) != 0) { this.binding.tagBits |= TagBits.HasMissingType; } - if (this.requiresGenericSignature) { + if (genericSignatureNeeded) { TypeBinding leafType = returnType.leafComponentType(); if (leafType instanceof ReferenceBinding && (((ReferenceBinding) leafType).modifiers & ExtraCompilerModifiers.AccGenericSignature) != 0) this.binding.modifiers |= ExtraCompilerModifiers.AccGenericSignature; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java index 7c5f157ba6..776739776b 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java @@ -51,6 +51,7 @@ public class CompilerOptions { public static final String OPTION_SourceFileAttribute = "org.eclipse.jdt.core.compiler.debug.sourceFile"; //$NON-NLS-1$ public static final String OPTION_PreserveUnusedLocal = "org.eclipse.jdt.core.compiler.codegen.unusedLocal"; //$NON-NLS-1$ public static final String OPTION_MethodParametersAttribute = "org.eclipse.jdt.core.compiler.codegen.methodParameters"; //$NON-NLS-1$ + public static final String OPTION_LambdaGenericSignature = "org.eclipse.jdt.core.compiler.codegen.lambda.genericSignature"; //$NON-NLS-1$ public static final String OPTION_DocCommentSupport= "org.eclipse.jdt.core.compiler.doc.comment.support"; //$NON-NLS-1$ public static final String OPTION_ReportMethodWithConstructorName = "org.eclipse.jdt.core.compiler.problem.methodWithConstructorName"; //$NON-NLS-1$ public static final String OPTION_ReportOverridingPackageDefaultMethod = "org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod"; //$NON-NLS-1$ @@ -314,7 +315,9 @@ public class CompilerOptions { /** Classfile debug information, may contain source file name, line numbers, local variable tables, etc... */ public int produceDebugAttributes; /** Classfile method patameters information as per JEP 118... */ - public boolean produceMethodParameters; + public boolean produceMethodParameters; + /** Indicates whether generic signature should be generated for lambda expressions */ + public boolean generateGenericSignatureForLambdaExpressions; /** Compliance level for the compiler, refers to a JDK version, e.g. {@link ClassFileConstants#JDK1_4} */ public long complianceLevel; /** Original compliance level for the compiler, refers to a JDK version, e.g. {@link ClassFileConstants#JDK1_4}, @@ -1040,6 +1043,7 @@ public class CompilerOptions { optionsMap.put(OPTION_LineNumberAttribute, (this.produceDebugAttributes & ClassFileConstants.ATTR_LINES) != 0 ? GENERATE : DO_NOT_GENERATE); optionsMap.put(OPTION_SourceFileAttribute, (this.produceDebugAttributes & ClassFileConstants.ATTR_SOURCE) != 0 ? GENERATE : DO_NOT_GENERATE); optionsMap.put(OPTION_MethodParametersAttribute, this.produceMethodParameters ? GENERATE : DO_NOT_GENERATE); + optionsMap.put(OPTION_LambdaGenericSignature, this.generateGenericSignatureForLambdaExpressions ? GENERATE : DO_NOT_GENERATE); optionsMap.put(OPTION_PreserveUnusedLocal, this.preserveAllLocalVariables ? PRESERVE : OPTIMIZE_OUT); optionsMap.put(OPTION_DocCommentSupport, this.docCommentSupport ? ENABLED : DISABLED); optionsMap.put(OPTION_ReportMethodWithConstructorName, getSeverityString(MethodWithConstructorName)); @@ -1534,6 +1538,13 @@ public class CompilerOptions { this.produceMethodParameters = false; } } + if ((optionValue = optionsMap.get(OPTION_LambdaGenericSignature)) != null) { + if (GENERATE.equals(optionValue)) { + this.generateGenericSignatureForLambdaExpressions = true; + } else if (DO_NOT_GENERATE.equals(optionValue)) { + this.generateGenericSignatureForLambdaExpressions = false; + } + } if ((optionValue = optionsMap.get(OPTION_SuppressWarnings)) != null) { if (ENABLED.equals(optionValue)) { this.suppressWarnings = true; @@ -1826,6 +1837,7 @@ public class CompilerOptions { buf.append("\n\t- line number debug attributes: ").append((this.produceDebugAttributes & ClassFileConstants.ATTR_LINES) != 0 ? "ON" : " OFF"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ buf.append("\n\t- source debug attributes: ").append((this.produceDebugAttributes & ClassFileConstants.ATTR_SOURCE) != 0 ? "ON" : " OFF"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ buf.append("\n\t- MethodParameters attributes: ").append(this.produceMethodParameters ? GENERATE : DO_NOT_GENERATE); //$NON-NLS-1$ + buf.append("\n\t- Generic signature for lambda expressions: ").append(this.generateGenericSignatureForLambdaExpressions ? GENERATE : DO_NOT_GENERATE); //$NON-NLS-1$ buf.append("\n\t- preserve all local variables: ").append(this.preserveAllLocalVariables ? "ON" : " OFF"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ buf.append("\n\t- method with constructor name: ").append(getSeverityString(MethodWithConstructorName)); //$NON-NLS-1$ buf.append("\n\t- overridden package default method: ").append(getSeverityString(OverriddenPackageDefaultMethod)); //$NON-NLS-1$ |