Add inheritance map file reading

This commit is contained in:
Agaricus 2013-01-29 20:31:47 -08:00
parent 29900947d1
commit 4725e6d913
2 changed files with 46 additions and 2 deletions

View File

@ -30,13 +30,23 @@ package net.md_5.specialsource;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.*; import java.util.*;
public class InheritanceMap { public class InheritanceMap implements IInheritanceProvider {
private final Map<String, ArrayList<String>> inheritanceMap = new HashMap<String, ArrayList<String>>(); public final Map<String, ArrayList<String>> inheritanceMap = new HashMap<String, ArrayList<String>>();
public InheritanceMap() {
}
public InheritanceMap(BufferedReader bufferedReader) throws IOException {
load(bufferedReader);
}
/** /**
* Generate an inheritance map for the given classes * Generate an inheritance map for the given classes
@ -91,4 +101,25 @@ public class InheritanceMap {
writer.println(Joiner.on(' ').join(parents)); writer.println(Joiner.on(' ').join(parents));
} }
} }
public void load(BufferedReader reader) throws IOException {
String line;
while ((line = reader.readLine()) != null) {
String[] tokens = line.split(" ");
if (tokens.length < 2) {
continue;
}
String className = tokens[0];
List<String> parents = Arrays.asList(tokens).subList(1, tokens.length - 1);
inheritanceMap.put(className, new ArrayList<String>(parents));
}
}
public List<String> getParents(String className) {
return inheritanceMap.get(className);
}
} }

View File

@ -86,6 +86,9 @@ public class SpecialSource {
acceptsAll(asList("H", "write-inheritance"), "Write inheritance map to file") acceptsAll(asList("H", "write-inheritance"), "Write inheritance map to file")
.withRequiredArg() .withRequiredArg()
.ofType(File.class); .ofType(File.class);
acceptsAll(asList("h", "read-inheritance"), "Read inheritance map from file")
.withRequiredArg()
.ofType(File.class);
acceptsAll(asList("q", "quiet"), "Quiet mode"); acceptsAll(asList("q", "quiet"), "Quiet mode");
} }
@ -155,6 +158,16 @@ public class SpecialSource {
inheritanceProviders.add(new RuntimeInheritanceProvider(ClassLoader.getSystemClassLoader(), !options.has("quiet"))); inheritanceProviders.add(new RuntimeInheritanceProvider(ClassLoader.getSystemClassLoader(), !options.has("quiet")));
} }
if (options.has("read-inheritance")) {
InheritanceMap inheritanceMap = new InheritanceMap();
BufferedReader reader = new BufferedReader(new FileReader((File) options.valueOf("read-inheritance")));
inheritanceMap.load(reader);
log("Loaded inheritance map for "+inheritanceMap.inheritanceMap.size()+" classes");
inheritanceProviders.add(inheritanceMap);
}
if (options.has("in-jar")) { if (options.has("in-jar")) {
if (!options.has("out-jar")) { if (!options.has("out-jar")) {