diff options
7 files changed, 64 insertions, 3 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 bf44e407ca..ff0640317f 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 @@ -1,12 +1,18 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 IBM Corporation and others. + * Copyright (c) 2006, 2013 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 * http://www.eclipse.org/legal/epl-v10.html * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation + * Jesper Steen Moeller - Contributions for: + * Bug 407297: [1.8][compiler] Control generation of parameter names by option *******************************************************************************/ package org.eclipse.jdt.compiler.tool.tests; @@ -137,6 +143,7 @@ public class CompilerToolTests extends TestCase { "-XprintProcessorInfo", "-proc:none", "-proc:only", + "-parameters", }; 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 2ba27f44f2..ac22b34668 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,12 +1,18 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 IBM Corporation and others. + * Copyright (c) 2006, 2013 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 * http://www.eclipse.org/legal/epl-v10.html * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation + * Jesper Steen Moeller - Contributions for: + * Bug 407297: [1.8][compiler] Control generation of parameter names by option *******************************************************************************/ package org.eclipse.jdt.internal.compiler.tool; @@ -62,6 +68,7 @@ public final class Options { Options.ZERO_ARGUMENT_OPTIONS.add("-proc:none");//$NON-NLS-1$ 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$ 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 b6128a7867..49295ecf20 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 @@ -29,6 +29,7 @@ * bug 383368 - [compiler][null] syntactic null analysis for field references * Jesper Steen Moller - Contributions for * bug 404146 - [1.7][compiler] nested try-catch-finally-blocks leads to unrunnable Java byte code + * bug 407297 - [1.8][compiler] Control generation of parameter names by option *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -1654,6 +1655,7 @@ public void test012(){ " -repeat <n> repeat compilation process <n> times for perf analysis\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" + " -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" + @@ -1898,6 +1900,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.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" + " <option key=\"org.eclipse.jdt.core.compiler.codegen.unusedLocal\" value=\"optimize out\"/>\n" + 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 35ae5b1059..66258bb693 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 @@ -23,6 +23,8 @@ * bug 375366 - ECJ ignores unusedParameterIncludeDocCommentReference unless enableJavadoc option is set * bug 388281 - [compiler][null] inheritance of null annotations as an option * bug 381443 - [compiler][null] Allow parameter widening from @NonNull to unannotated + * Jesper S Moller - Contributions for + * bug 407297 - [1.8][compiler] Control generation of parameter names by option *******************************************************************************/ package org.eclipse.jdt.internal.compiler.batch; @@ -2192,6 +2194,13 @@ public void configure(String[] argv) { CompilerOptions.ENABLED); continue; } + if (currentArg.equals("-parameters")) { //$NON-NLS-1$ + mode = DEFAULT; + this.options.put( + CompilerOptions.OPTION_MethodParametersAttribute, + 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 803f5e882c..3b7ebb94a0 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 @@ -5,6 +5,10 @@ # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html # +# This is an implementation of an early-draft specification developed under the Java +# Community Process (JCP) and is made available for testing and evaluation purposes +# only. The code is not compatible with any specification of the JCP. +# # Contributors: # IBM Corporation - initial API and implementation # Benjamin Muskalla - Contribution for bug 239066 @@ -16,6 +20,7 @@ # bug 374605 - Unreasonable warning for enum-based switch statements # bug 388281 - [compiler][null] inheritance of null annotations as an option # Alan Moraes <alan@kelon.org> - Contribution for bug 383644 +# Jesper S Moller - Contribution for bug 407297 - [1.8][compiler] Control generation of parameter names by option ############################################################################### ### JavaBatchCompiler messages. @@ -257,6 +262,7 @@ misc.usage = {1} {2}\n\ \ -repeat <n> repeat compilation process <n> times for perf analysis\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\ \ -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/impl/CompilerOptions.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java index c30f35dedc..5ad305b249 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 @@ -25,6 +25,7 @@ * bug 383368 - [compiler][null] syntactic null analysis for field references * Jesper Steen Moller - Contributions for * bug 404146 - [1.7][compiler] nested try-catch-finally-blocks leads to unrunnable Java byte code + * bug 407297 - [1.8][compiler] Control generation of parameter names by option *******************************************************************************/ package org.eclipse.jdt.internal.compiler.impl; @@ -51,6 +52,7 @@ public class CompilerOptions { public static final String OPTION_LineNumberAttribute = "org.eclipse.jdt.core.compiler.debug.lineNumber"; //$NON-NLS-1$ 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_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$ @@ -309,6 +311,8 @@ 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; /** 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}, @@ -1027,6 +1031,7 @@ public class CompilerOptions { optionsMap.put(OPTION_LocalVariableAttribute, (this.produceDebugAttributes & ClassFileConstants.ATTR_VARS) != 0 ? GENERATE : DO_NOT_GENERATE); 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_PreserveUnusedLocal, this.preserveAllLocalVariables ? PRESERVE : OPTIMIZE_OUT); optionsMap.put(OPTION_DocCommentSupport, this.docCommentSupport ? ENABLED : DISABLED); optionsMap.put(OPTION_ReportMethodWithConstructorName, getSeverityString(MethodWithConstructorName)); @@ -1507,6 +1512,13 @@ public class CompilerOptions { this.shareCommonFinallyBlocks = false; } } + if ((optionValue = optionsMap.get(OPTION_MethodParametersAttribute)) != null) { + if (GENERATE.equals(optionValue)) { + this.produceMethodParameters = true; + } else if (DO_NOT_GENERATE.equals(optionValue)) { + this.produceMethodParameters = false; + } + } if ((optionValue = optionsMap.get(OPTION_SuppressWarnings)) != null) { if (ENABLED.equals(optionValue)) { this.suppressWarnings = true; @@ -1774,6 +1786,7 @@ public class CompilerOptions { buf.append("\n\t- local variables debug attributes: ").append((this.produceDebugAttributes & ClassFileConstants.ATTR_VARS) != 0 ? "ON" : " OFF"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 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- 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$ diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java index ec6f02d6b6..58b7b55f06 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java @@ -102,7 +102,10 @@ * COMPILER_INHERIT_NULL_ANNOTATIONS * COMPILER_PB_NONNULL_PARAMETER_ANNOTATION_DROPPED * COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS - * Jesper S Moller - Contributions for bug 381345 : [1.8] Take care of the Java 8 major version + * Jesper S Moller - Contributions for bug 381345 : [1.8] Take care of the Java 8 major version + * - added the following constants: + * COMPILER_CODEGEN_METHOD_PARAMETERS_ATTR + * *******************************************************************************/ package org.eclipse.jdt.core; @@ -271,6 +274,19 @@ public final class JavaCore extends Plugin { */ public static final String COMPILER_CODEGEN_UNUSED_LOCAL = PLUGIN_ID + ".compiler.codegen.unusedLocal"; //$NON-NLS-1$ /** + * Compiler option ID: Generating Method Parameters Attribute. + * <p>When generated, this attribute will enable parameter names to be accessed from reflection libraries, annotation processing, + * code weaving, and in the debugger, from platform target level 1.8 and later.</p> + * <dl> + * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.codegen.methodParameters"</code></dd> + * <dt>Possible values:</dt><dd><code>{ "generate", "do not generate" }</code></dd> + * <dt>Default:</dt><dd><code>"do not generate"</code></dd> + * </dl> + * @since 3.9 BETA_JAVA8 + * @category CompilerOptionID + */ + public static final String COMPILER_CODEGEN_METHOD_PARAMETERS_ATTR = PLUGIN_ID + ".compiler.codegen.methodParameters"; //$NON-NLS-1$ + /** * Compiler option ID: Defining Target Java Platform. * <p>For binary compatibility reason, .class files can be tagged to with certain VM versions and later.</p> * <p>Note that <code>"1.4"</code> target requires to toggle compliance mode to <code>"1.4"</code>, <code>"1.5"</code> target requires |