diff --git a/src/main/java/net/md_5/specialsource/InheritanceMap.java b/src/main/java/net/md_5/specialsource/InheritanceMap.java index b345524..0ef1f22 100644 --- a/src/main/java/net/md_5/specialsource/InheritanceMap.java +++ b/src/main/java/net/md_5/specialsource/InheritanceMap.java @@ -30,13 +30,23 @@ package net.md_5.specialsource; import com.google.common.base.Joiner; +import java.io.BufferedReader; import java.io.File; +import java.io.IOException; import java.io.PrintWriter; import java.util.*; -public class InheritanceMap { +public class InheritanceMap implements IInheritanceProvider { - private final Map> inheritanceMap = new HashMap>(); + public final Map> inheritanceMap = new HashMap>(); + + public InheritanceMap() { + + } + + public InheritanceMap(BufferedReader bufferedReader) throws IOException { + load(bufferedReader); + } /** * Generate an inheritance map for the given classes @@ -91,4 +101,25 @@ public class InheritanceMap { 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 parents = Arrays.asList(tokens).subList(1, tokens.length - 1); + + inheritanceMap.put(className, new ArrayList(parents)); + } + } + + public List getParents(String className) { + return inheritanceMap.get(className); + } } diff --git a/src/main/java/net/md_5/specialsource/SpecialSource.java b/src/main/java/net/md_5/specialsource/SpecialSource.java index c45e54c..88cb6b4 100644 --- a/src/main/java/net/md_5/specialsource/SpecialSource.java +++ b/src/main/java/net/md_5/specialsource/SpecialSource.java @@ -86,6 +86,9 @@ public class SpecialSource { acceptsAll(asList("H", "write-inheritance"), "Write inheritance map to file") .withRequiredArg() .ofType(File.class); + acceptsAll(asList("h", "read-inheritance"), "Read inheritance map from file") + .withRequiredArg() + .ofType(File.class); acceptsAll(asList("q", "quiet"), "Quiet mode"); } @@ -155,6 +158,16 @@ public class SpecialSource { 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("out-jar")) {