Skip to content

Commit

Permalink
Moved Java version description to a shared util
Browse files Browse the repository at this point in the history
  • Loading branch information
luontola committed Dec 15, 2015
1 parent dee2734 commit c8aee4d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
Expand Up @@ -11,8 +11,6 @@ public interface Config {

int getBytecodeVersion();

String getJavaVersion();

boolean isDefaultMethodsEnabled();

Path getInputDir();
Expand Down
Expand Up @@ -7,6 +7,7 @@
import net.orfjackal.retrolambda.files.*;
import net.orfjackal.retrolambda.interfaces.*;
import net.orfjackal.retrolambda.lambdas.*;
import net.orfjackal.retrolambda.util.Bytecode;

import java.io.IOException;
import java.net.*;
Expand All @@ -22,7 +23,7 @@ public static void run(Config config) throws Throwable {
Path outputDir = config.getOutputDir();
List<Path> classpath = config.getClasspath();
List<Path> includedFiles = config.getIncludedFiles();
System.out.println("Bytecode version: " + bytecodeVersion + " (" + config.getJavaVersion() + ")");
System.out.println("Bytecode version: " + bytecodeVersion + " (" + Bytecode.getJavaVersion(bytecodeVersion) + ")");
System.out.println("Default methods: " + defaultMethodsEnabled);
System.out.println("Input directory: " + inputDir);
System.out.println("Output directory: " + outputDir);
Expand Down
Expand Up @@ -26,18 +26,6 @@ public class SystemPropertiesConfig implements Config {
private static final List<String> requiredProperties = new ArrayList<>();
private static final Map<String, String> alternativeProperties = new HashMap<>();
private static final List<String> propertiesHelp = new ArrayList<>();
private static final Map<Integer, String> bytecodeVersionNames = new HashMap<>();

static {
bytecodeVersionNames.put(Opcodes.V1_1, "Java 1.1");
bytecodeVersionNames.put(Opcodes.V1_2, "Java 1.2");
bytecodeVersionNames.put(Opcodes.V1_3, "Java 1.3");
bytecodeVersionNames.put(Opcodes.V1_4, "Java 1.4");
bytecodeVersionNames.put(Opcodes.V1_5, "Java 5");
bytecodeVersionNames.put(Opcodes.V1_6, "Java 6");
bytecodeVersionNames.put(Opcodes.V1_7, "Java 7");
bytecodeVersionNames.put(Opcodes.V1_8, "Java 8");
}

private final Properties p;

Expand Down Expand Up @@ -86,11 +74,6 @@ public int getBytecodeVersion() {
return Integer.parseInt(p.getProperty(BYTECODE_VERSION, "" + Opcodes.V1_7));
}

@Override
public String getJavaVersion() {
return bytecodeVersionNames.getOrDefault(getBytecodeVersion(), "unknown version");
}


// default methods

Expand Down
Expand Up @@ -7,10 +7,29 @@
import net.orfjackal.retrolambda.lambdas.Handles;
import org.objectweb.asm.*;

import java.util.*;

import static org.objectweb.asm.Opcodes.*;

public class Bytecode {

private static final Map<Integer, String> bytecodeVersionNames = new HashMap<>();

static {
bytecodeVersionNames.put(Opcodes.V1_1, "Java 1.1");
bytecodeVersionNames.put(Opcodes.V1_2, "Java 1.2");
bytecodeVersionNames.put(Opcodes.V1_3, "Java 1.3");
bytecodeVersionNames.put(Opcodes.V1_4, "Java 1.4");
bytecodeVersionNames.put(Opcodes.V1_5, "Java 5");
bytecodeVersionNames.put(Opcodes.V1_6, "Java 6");
bytecodeVersionNames.put(Opcodes.V1_7, "Java 7");
bytecodeVersionNames.put(Opcodes.V1_8, "Java 8");
}

public static String getJavaVersion(int bytecodeVersion) {
return bytecodeVersionNames.getOrDefault(bytecodeVersion, "unknown version");
}

public static void generateDelegateMethod(ClassVisitor cv, int access, Handle method, Handle target) {
MethodVisitor mv = cv.visitMethod(access, method.getName(), method.getDesc(), null, null);
mv.visitCode();
Expand Down
Expand Up @@ -4,6 +4,7 @@

package net.orfjackal.retrolambda;

import net.orfjackal.retrolambda.util.Bytecode;
import org.junit.*;
import org.junit.rules.*;

Expand Down Expand Up @@ -49,11 +50,11 @@ public void can_use_alternative_parameter_instead_of_required_parameter() {
@Test
public void bytecode_version() {
assertThat("defaults to Java 7", config().getBytecodeVersion(), is(51));
assertThat("human printable format", config().getJavaVersion(), is("Java 7"));
assertThat("human printable format", Bytecode.getJavaVersion(config().getBytecodeVersion()), is("Java 7"));

systemProperties.setProperty(SystemPropertiesConfig.BYTECODE_VERSION, "50");
assertThat("can override the default", config().getBytecodeVersion(), is(50));
assertThat("human printable format", config().getJavaVersion(), is("Java 6"));
assertThat("human printable format", Bytecode.getJavaVersion(config().getBytecodeVersion()), is("Java 6"));
}

@Test
Expand Down

0 comments on commit c8aee4d

Please sign in to comment.