Skip to content

Commit

Permalink
Refactored: renamed classes
Browse files Browse the repository at this point in the history
  • Loading branch information
luontola committed Jul 8, 2015
1 parent 46b0d84 commit 0971556
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
Expand Up @@ -39,9 +39,9 @@ public static void run(Config config) throws Throwable {
Thread.currentThread().setContextClassLoader(new NonDelegatingClassLoader(asUrls(classpath)));

ClassHierarchyAnalyzer analyzer = new ClassHierarchyAnalyzer();
ClassSaver saver = new ClassSaver(outputDir);
OutputDirectory outputDirectory = new OutputDirectory(outputDir);
Transformers transformers = new Transformers(bytecodeVersion, defaultMethodsEnabled, analyzer);
LambdaClassSaver lambdaClassSaver = new LambdaClassSaver(saver, transformers);
LambdaClassSaver lambdaClassSaver = new LambdaClassSaver(outputDirectory, transformers);

try (LambdaClassDumper dumper = new LambdaClassDumper(lambdaClassSaver)) {
if (PreMain.isAgentLoaded()) {
Expand All @@ -50,15 +50,15 @@ public static void run(Config config) throws Throwable {
dumper.install();
}

visitFiles(inputDir, includedFiles, new BytecodeFileVisitor() {
visitFiles(inputDir, includedFiles, new ClasspathVisitor() {
@Override
protected void visitClass(byte[] bytecode) {
analyzer.analyze(bytecode);
}

@Override
protected void visitResource(Path relativePath, byte[] content) throws IOException {
saver.saveResource(relativePath, content);
outputDirectory.writeFile(relativePath, content);
}
});

Expand All @@ -80,7 +80,7 @@ protected void visitResource(Path relativePath, byte[] content) throws IOExcepti
// We need to load some of the classes (for calling the lambda metafactory)
// so we need to take care not to modify any bytecode before loading them.
for (byte[] bytecode : transformed) {
saver.saveClass(bytecode);
outputDirectory.writeClass(bytecode);
}
}
}
Expand Down
Expand Up @@ -8,7 +8,7 @@
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;

public abstract class BytecodeFileVisitor extends SimpleFileVisitor<Path> {
public abstract class ClasspathVisitor extends SimpleFileVisitor<Path> {

private Path baseDir;

Expand Down
Expand Up @@ -9,24 +9,24 @@
import java.io.IOException;
import java.nio.file.*;

public class ClassSaver {
public class OutputDirectory {

private final Path outputDir;

public ClassSaver(Path outputDir) {
public OutputDirectory(Path outputDir) {
this.outputDir = outputDir;
}

public void saveClass(byte[] bytecode) throws IOException {
public void writeClass(byte[] bytecode) throws IOException {
if (bytecode == null) {
return;
}
ClassReader cr = new ClassReader(bytecode);
Path relativePath = Paths.get(cr.getClassName() + ".class");
saveResource(relativePath, bytecode);
writeFile(relativePath, bytecode);
}

public void saveResource(Path relativePath, byte[] content) throws IOException {
public void writeFile(Path relativePath, byte[] content) throws IOException {
Path outputFile = outputDir.resolve(relativePath);
Files.createDirectories(outputFile.getParent());
Files.write(outputFile, content);
Expand Down
Expand Up @@ -5,15 +5,15 @@
package net.orfjackal.retrolambda.lambdas;

import net.orfjackal.retrolambda.Transformers;
import net.orfjackal.retrolambda.files.ClassSaver;
import net.orfjackal.retrolambda.files.OutputDirectory;
import org.objectweb.asm.ClassReader;

public class LambdaClassSaver {

private final ClassSaver saver;
private final OutputDirectory saver;
private final Transformers transformers;

public LambdaClassSaver(ClassSaver saver, Transformers transformers) {
public LambdaClassSaver(OutputDirectory saver, Transformers transformers) {
this.saver = saver;
this.transformers = transformers;
}
Expand All @@ -27,7 +27,7 @@ public void saveIfLambda(String className, byte[] bytecode) {
private void reifyLambdaClass(String className, byte[] bytecode) {
try {
System.out.println("Saving lambda class: " + className);
saver.saveClass(transformers.backportLambdaClass(new ClassReader(bytecode)));
saver.writeClass(transformers.backportLambdaClass(new ClassReader(bytecode)));

} catch (Throwable t) {
// print to stdout to keep in sync with other log output
Expand Down

0 comments on commit 0971556

Please sign in to comment.