Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 9c915da60 -> b9f85fd32


Support Java 9, 10, and 11 bytecode


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/b9f85fd3
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/b9f85fd3
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/b9f85fd3

Branch: refs/heads/GROOVY_2_5_X
Commit: b9f85fd32da7b06c1b8a35d176911da40c762e33
Parents: 9c915da
Author: Keegan Witt <[email protected]>
Authored: Sun Sep 2 12:32:26 2018 -0400
Committer: Keegan Witt <[email protected]>
Committed: Sun Sep 9 17:18:59 2018 -0400

----------------------------------------------------------------------
 .../groovy/classgen/asm/WriterController.java   | 24 +++++---------------
 .../groovy/control/CompilerConfiguration.java   | 23 ++++++++++++++-----
 2 files changed, 23 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/b9f85fd3/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java 
b/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
index 820aba7..b22c580 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
@@ -144,28 +144,16 @@ public class WriterController {
         return new LoggableClassVisitor(cv);
     }
     private static int chooseBytecodeVersion(final boolean invokedynamic, 
final String targetBytecode) {
-        if (invokedynamic) {
-            if (CompilerConfiguration.JDK8.equals(targetBytecode)) {
-                return Opcodes.V1_8;
-            }
+        Integer bytecodeVersion = 
CompilerConfiguration.JDK_TO_BYTECODE_VERSION_MAP.get(targetBytecode);
+
+        if (invokedynamic && bytecodeVersion < Opcodes.V1_7) {
             return Opcodes.V1_7;
         } else {
-            if (CompilerConfiguration.JDK4.equals(targetBytecode)) {
-                return Opcodes.V1_4;
-            }
-            if (CompilerConfiguration.JDK5.equals(targetBytecode)) {
-                return Opcodes.V1_5;
-            }
-            if (CompilerConfiguration.JDK6.equals(targetBytecode)) {
-                return Opcodes.V1_6;
-            }
-            if (CompilerConfiguration.JDK7.equals(targetBytecode)) {
-                return Opcodes.V1_7;
-            }
-            if (CompilerConfiguration.JDK8.equals(targetBytecode)) {
-                return Opcodes.V1_8;
+            if (null != bytecodeVersion) {
+                return bytecodeVersion;
             }
         }
+
         throw new GroovyBugError("Bytecode version ["+targetBytecode+"] is not 
supported by the compiler");
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/b9f85fd3/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java 
b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
index ed5ae18..c25a229 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -18,6 +18,7 @@
  */
 package org.codehaus.groovy.control;
 
+import org.apache.groovy.util.Maps;
 import org.codehaus.groovy.control.customizers.CompilationCustomizer;
 import org.codehaus.groovy.control.io.NullWriter;
 import org.codehaus.groovy.control.messages.WarningMessage;
@@ -50,7 +51,7 @@ import static 
org.apache.groovy.util.SystemUtil.getSystemPropertySafe;
  */
 public class CompilerConfiguration {
 
-    /** This (<code>"indy"</code>) is the Optimization Option value for 
enabling <code>invokedynamic</code> complilation. */
+    /** This (<code>"indy"</code>) is the Optimization Option value for 
enabling <code>invokedynamic</code> compilation. */
     public static final String INVOKEDYNAMIC = "indy";
 
     /** This (<code>"1.4"</code>) is the value for targetBytecode to compile 
for a JDK 1.4. **/
@@ -76,8 +77,20 @@ public class CompilerConfiguration {
     /** This (<code>"1.4"</code>) is the value for targetBytecode to compile 
for a JDK 1.4 JVM. **/
     public static final String PRE_JDK5 = JDK4;
 
+    /** JDK version to bytecode version mapping */
+    public static final Map<String, Integer> JDK_TO_BYTECODE_VERSION_MAP = 
Maps.of(
+            JDK4, Opcodes.V1_4,
+            JDK5, Opcodes.V1_5,
+            JDK6, Opcodes.V1_6,
+            JDK7, Opcodes.V1_7,
+            JDK8, Opcodes.V1_8,
+            JDK9, Opcodes.V9,
+            JDK10, Opcodes.V10,
+            JDK11, Opcodes.V11
+    );
+
     /** An array of the valid targetBytecode values **/
-    public static final String[] ALLOWED_JDKS = { JDK4, JDK5, JDK6, JDK7, 
JDK8, JDK9, JDK10, JDK11 };
+    public static final String[] ALLOWED_JDKS = 
JDK_TO_BYTECODE_VERSION_MAP.keySet().toArray(new String[0]);
 
     @Deprecated
     public static final String CURRENT_JVM_VERSION = getMinBytecodeVersion();
@@ -755,10 +768,8 @@ public class CompilerConfiguration {
      * @param version the bytecode compatibility level
      */
     public void setTargetBytecode(String version) {
-        for (String allowedJdk : ALLOWED_JDKS) {
-            if (allowedJdk.equals(version)) {
-                this.targetBytecode = version;
-            }
+        if (JDK_TO_BYTECODE_VERSION_MAP.keySet().contains(version)) {
+            this.targetBytecode = version;
         }
     }
 

Reply via email to