|
16 | 16 | import java.lang.reflect.InvocationTargetException; |
17 | 17 | import java.lang.reflect.Method; |
18 | 18 | import java.security.CodeSource; |
| 19 | +import java.util.Collections; |
19 | 20 | import java.util.HashMap; |
20 | 21 | import java.util.List; |
21 | 22 | import java.util.Map; |
@@ -250,6 +251,21 @@ public class GroovyCompiler { |
250 | 251 | */ |
251 | 252 | protected static final Version JAVA_12 = new Version(12); |
252 | 253 |
|
| 254 | + /** |
| 255 | + * The mapping of javac target to Groovy target bytecode. |
| 256 | + */ |
| 257 | + private static final Map<String, String> JAVAC_TARGET_TO_TARGET_BYTECODE; |
| 258 | + |
| 259 | + static { |
| 260 | + Map<String, String> javacTargetToTargetBytecode = new HashMap<>(); |
| 261 | + javacTargetToTargetBytecode.put("5", "1.5"); |
| 262 | + javacTargetToTargetBytecode.put("6", "1.6"); |
| 263 | + javacTargetToTargetBytecode.put("7", "1.7"); |
| 264 | + javacTargetToTargetBytecode.put("8", "1.8"); |
| 265 | + javacTargetToTargetBytecode.put("1.9", "9"); |
| 266 | + JAVAC_TARGET_TO_TARGET_BYTECODE = Collections.unmodifiableMap(javacTargetToTargetBytecode); |
| 267 | + } |
| 268 | + |
253 | 269 | private final ClassWrangler classWrangler; |
254 | 270 | private final Log log; |
255 | 271 |
|
@@ -758,13 +774,7 @@ protected void verifyGroovyVersionSupportsTargetBytecode(String targetBytecode) |
758 | 774 | } |
759 | 775 |
|
760 | 776 | public static String translateJavacTargetToTargetBytecode(String targetBytecode) { |
761 | | - Map<String, String> javacTargetToTargetBytecode = new HashMap<>(); |
762 | | - javacTargetToTargetBytecode.put("5", "1.5"); |
763 | | - javacTargetToTargetBytecode.put("6", "1.6"); |
764 | | - javacTargetToTargetBytecode.put("7", "1.7"); |
765 | | - javacTargetToTargetBytecode.put("8", "1.8"); |
766 | | - javacTargetToTargetBytecode.put("1.9", "9"); |
767 | | - return javacTargetToTargetBytecode.getOrDefault(targetBytecode, targetBytecode); |
| 777 | + return JAVAC_TARGET_TO_TARGET_BYTECODE.getOrDefault(targetBytecode, targetBytecode); |
768 | 778 | } |
769 | 779 |
|
770 | 780 | protected boolean isJavaSupportIndy() { |
|
0 commit comments