groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [17/50] [abbrv] groovy git commit: Minor refactoring
Date Wed, 10 May 2017 22:26:45 GMT
Minor refactoring


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

Branch: refs/heads/parrot
Commit: bd353a684a2c673779f79c7a18911970e24cff4d
Parents: b469cbb
Author: sunlan <sunlan@apache.org>
Authored: Sat May 6 01:44:14 2017 +0800
Committer: paulk <paulk@asert.com.au>
Committed: Thu May 11 08:09:11 2017 +1000

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


http://git-wip-us.apache.org/repos/asf/groovy/blob/bd353a68/src/main/org/codehaus/groovy/classgen/asm/WriterController.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/WriterController.java b/src/main/org/codehaus/groovy/classgen/asm/WriterController.java
index e4cfdbe..4eec57e 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/WriterController.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/WriterController.java
@@ -19,6 +19,8 @@
 package org.codehaus.groovy.classgen.asm;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import org.codehaus.groovy.GroovyBugError;
@@ -39,6 +41,8 @@ import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 
+import static org.codehaus.groovy.control.CompilerConfiguration.JDK_TO_BYTECODE_VERSION_MAP;
+
 public class WriterController {
 
     private AsmClassGenerator acg;
@@ -133,24 +137,16 @@ public class WriterController {
             if (CompilerConfiguration.JDK7.equals(targetBytecode)) {
                 return Opcodes.V1_7;
             }
+
             return Opcodes.V1_8;
         } 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;
+            Integer bytecodeVersion = JDK_TO_BYTECODE_VERSION_MAP.get(targetBytecode);
+
+            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/bd353a68/src/main/org/codehaus/groovy/control/CompilerConfiguration.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/control/CompilerConfiguration.java b/src/main/org/codehaus/groovy/control/CompilerConfiguration.java
index 1ee26d3..4278b55 100644
--- a/src/main/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -21,6 +21,7 @@ package org.codehaus.groovy.control;
 import org.codehaus.groovy.control.customizers.CompilationCustomizer;
 import org.codehaus.groovy.control.io.NullWriter;
 import org.codehaus.groovy.control.messages.WarningMessage;
+import org.objectweb.asm.Opcodes;
 
 import java.io.File;
 import java.io.PrintWriter;
@@ -60,6 +61,17 @@ public class CompilerConfiguration {
     /** An array of the valid targetBytecode values **/
     public static final String[] ALLOWED_JDKS = { JDK4, JDK5, JDK6, JDK7, JDK8 };
 
+    /**
+     * JDK version to bytecode version mapping
+     */
+    public static final Map<String, Integer> JDK_TO_BYTECODE_VERSION_MAP = Collections.unmodifiableMap(new
HashMap<String, Integer>() {{
+        put(JDK4, Opcodes.V1_4);
+        put(JDK5, Opcodes.V1_5);
+        put(JDK6, Opcodes.V1_6);
+        put(JDK7, Opcodes.V1_7);
+        put(JDK8, Opcodes.V1_8);
+    }});
+
     // Just call getVMVersion() once.
     public static final String currentJVMVersion = getVMVersion();
 


Mime
View raw message