Bug 533619 - [11][batch][compiler] support command line --enable-preview
minor version set to 0xffff
Change-Id: I56dc4ccacffde5e1166e76efb184e2d7a4520f41
Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest2.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest2.java
index ff8095f..e437a96 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest2.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest2.java
@@ -1,3 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2018 IBM Corporation.
+ * 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
+ *******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
import java.io.File;
@@ -52,35 +66,35 @@
"Preview of features is supported only at the latest source level\n",
true);
}
- public void test002() {
- this.runNegativeTest(
- new String[] {
+public void test002() throws Exception {
+ this.runNegativeTest(
+ new String[] {
"X.java",
"import java.util.List;\n" +
- "\n" +
- "@SuppressWarnings(\"all\"//$NON-NLS-1$\n" +
- ")\n" +
- "public class X {\n" +
- " public static void main(String[] args) {\n" +
- " if (false) {\n" +
- " ;\n" +
- " } else {\n" +
- " }\n" +
- " Zork z;\n" +
- " }\n" +
- "}"
- },
- "\"" + OUTPUT_DIR + File.separator + "X.java\""
- + " -11 --enable-preview",
- "",
- "----------\n" +
- "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 11)\n" +
- " Zork z;\n" +
- " ^^^^\n" +
- "Zork cannot be resolved to a type\n" +
- "----------\n" +
- "1 problem (1 error)\n",
- true);
+ "\n" +
+ "@SuppressWarnings(\"all\"//$NON-NLS-1$\n" +
+ ")\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " if (false) {\n" +
+ " ;\n" +
+ " } else {\n" +
+ " }\n" +
+ " Zork z;\n" +
+ " }\n" +
+ "}"
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " -11 --enable-preview",
+ "",
+ "----------\n" +
+ "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 11)\n" +
+ " Zork z;\n" +
+ " ^^^^\n" +
+ "Zork cannot be resolved to a type\n" +
+ "----------\n" +
+ "1 problem (1 error)\n",
+ true);
}
public void test003() {
this.runNegativeTest(
@@ -108,4 +122,79 @@
"1 problem (1 error)\n",
true);
}
+public void test004() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "import java.util.List;\n" +
+ "\n" +
+ "@SuppressWarnings(\"all\"//$NON-NLS-1$\n" +
+ ")\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " if (false) {\n" +
+ " ;\n" +
+ " } else {\n" +
+ " }\n" +
+ " }\n" +
+ "}"
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " -11 --enable-preview",
+ "",
+ "",
+ true);
+ String expectedOutput = "// Compiled from X.java (version 11 : 55.65535, super bit)";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput);
+}
+public void test005() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "import java.util.List;\n" +
+ "\n" +
+ "@SuppressWarnings(\"all\"//$NON-NLS-1$\n" +
+ ")\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " if (false) {\n" +
+ " ;\n" +
+ " } else {\n" +
+ " }\n" +
+ " }\n" +
+ "}"
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " --enable-preview -11 ",
+ "",
+ "",
+ true);
+ String expectedOutput = "// Compiled from X.java (version 11 : 55.65535, super bit)";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput);
+}
+public void test006() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "import java.util.List;\n" +
+ "\n" +
+ "@SuppressWarnings(\"all\"//$NON-NLS-1$\n" +
+ ")\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " if (false) {\n" +
+ " ;\n" +
+ " } else {\n" +
+ " }\n" +
+ " }\n" +
+ "}"
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " -source 11",
+ "",
+ "",
+ true);
+ String expectedOutput = "// Compiled from X.java (version 11 : 55.0, super bit)";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput);
+}
}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.java
index 7644176..272de14 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.java
@@ -138,6 +138,7 @@
int MINOR_VERSION_2 = 2;
int MINOR_VERSION_3 = 3;
int MINOR_VERSION_4 = 4;
+ int MINOR_VERSION_PREVIEW = 0xffff;
// JDK 1.1 -> 9, comparable value allowing to check both major/minor version at once 1.4.1 > 1.4.0
// 16 unsigned bits for major, then 16 bits for minor
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 4c21bc5..ec38f6c 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
@@ -1623,6 +1623,9 @@
if ((optionValue = optionsMap.get(OPTION_TargetPlatform)) != null) {
long level = versionToJdkLevel(optionValue);
if (level != 0) {
+ if (this.enablePreviewFeatures) {
+ level |= ClassFileConstants.MINOR_VERSION_PREVIEW;
+ }
this.targetJDK = level;
}
if (this.targetJDK >= ClassFileConstants.JDK1_5) this.inlineJsrBytecode = true; // forced from 1.5 mode on
@@ -2056,6 +2059,8 @@
if ((optionValue = optionsMap.get(OPTION_EnablePreviews)) != null) {
if (ENABLED.equals(optionValue)) {
this.enablePreviewFeatures = true;
+ if (this.targetJDK != 0)
+ this.targetJDK |= ClassFileConstants.MINOR_VERSION_PREVIEW;
} else if (DISABLED.equals(optionValue)) {
this.enablePreviewFeatures = false;
}