diff options
Diffstat (limited to 'src/main/java/cuchaz')
4 files changed, 38 insertions, 35 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/IndexTreeBuilder.java b/src/main/java/cuchaz/enigma/analysis/IndexTreeBuilder.java index 4ca7cd11..0c2dfd77 100644 --- a/src/main/java/cuchaz/enigma/analysis/IndexTreeBuilder.java +++ b/src/main/java/cuchaz/enigma/analysis/IndexTreeBuilder.java | |||
| @@ -1,13 +1,14 @@ | |||
| 1 | package cuchaz.enigma.analysis; | 1 | package cuchaz.enigma.analysis; |
| 2 | 2 | ||
| 3 | import com.google.common.collect.Lists; | 3 | import com.google.common.collect.Lists; |
| 4 | import cuchaz.enigma.analysis.index.EntryIndex; | ||
| 5 | import cuchaz.enigma.analysis.index.JarIndex; | 4 | import cuchaz.enigma.analysis.index.JarIndex; |
| 6 | import cuchaz.enigma.translation.Translator; | 5 | import cuchaz.enigma.translation.Translator; |
| 6 | import cuchaz.enigma.translation.mapping.EntryResolver; | ||
| 7 | import cuchaz.enigma.translation.mapping.ResolutionStrategy; | 7 | import cuchaz.enigma.translation.mapping.ResolutionStrategy; |
| 8 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 8 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 9 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | 9 | import cuchaz.enigma.translation.representation.entry.MethodEntry; |
| 10 | 10 | ||
| 11 | import java.util.Collection; | ||
| 11 | import java.util.List; | 12 | import java.util.List; |
| 12 | 13 | ||
| 13 | public class IndexTreeBuilder { | 14 | public class IndexTreeBuilder { |
| @@ -52,34 +53,20 @@ public class IndexTreeBuilder { | |||
| 52 | ); | 53 | ); |
| 53 | 54 | ||
| 54 | // expand the full tree | 55 | // expand the full tree |
| 55 | rootNode.load(index, true); | 56 | rootNode.load(index); |
| 56 | 57 | ||
| 57 | return rootNode; | 58 | return rootNode; |
| 58 | } | 59 | } |
| 59 | 60 | ||
| 60 | public List<MethodImplementationsTreeNode> buildMethodImplementations(Translator translator, MethodEntry obfMethodEntry) { | 61 | public List<MethodImplementationsTreeNode> buildMethodImplementations(Translator translator, MethodEntry obfMethodEntry) { |
| 61 | EntryIndex entryIndex = index.getEntryIndex(); | 62 | EntryResolver resolver = index.getEntryResolver(); |
| 62 | 63 | Collection<MethodEntry> resolvedEntries = resolver.resolveEntry(obfMethodEntry, ResolutionStrategy.RESOLVE_ROOT); | |
| 63 | List<MethodEntry> ancestorMethodEntries = Lists.newArrayList(); | ||
| 64 | |||
| 65 | if (entryIndex.hasMethod(obfMethodEntry)) { | ||
| 66 | ancestorMethodEntries.add(obfMethodEntry); | ||
| 67 | } | ||
| 68 | |||
| 69 | for (ClassEntry ancestorEntry : index.getInheritanceIndex().getAncestors(obfMethodEntry.getParent())) { | ||
| 70 | MethodEntry ancestorMethod = obfMethodEntry.withParent(ancestorEntry); | ||
| 71 | if (entryIndex.hasMethod(ancestorMethod)) { | ||
| 72 | ancestorMethodEntries.add(ancestorMethod); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | 64 | ||
| 76 | List<MethodImplementationsTreeNode> nodes = Lists.newArrayList(); | 65 | List<MethodImplementationsTreeNode> nodes = Lists.newArrayList(); |
| 77 | if (!ancestorMethodEntries.isEmpty()) { | 66 | for (MethodEntry resolvedEntry : resolvedEntries) { |
| 78 | for (MethodEntry interfaceMethodEntry : ancestorMethodEntries) { | 67 | MethodImplementationsTreeNode node = new MethodImplementationsTreeNode(translator, resolvedEntry); |
| 79 | MethodImplementationsTreeNode node = new MethodImplementationsTreeNode(translator, interfaceMethodEntry); | 68 | node.load(index); |
| 80 | node.load(index); | 69 | nodes.add(node); |
| 81 | nodes.add(node); | ||
| 82 | } | ||
| 83 | } | 70 | } |
| 84 | 71 | ||
| 85 | return nodes; | 72 | return nodes; |
diff --git a/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java b/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java index e4b03043..b09f7ac6 100644 --- a/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java +++ b/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java | |||
| @@ -71,8 +71,8 @@ public class MethodImplementationsTreeNode extends DefaultMutableTreeNode { | |||
| 71 | EntryIndex entryIndex = index.getEntryIndex(); | 71 | EntryIndex entryIndex = index.getEntryIndex(); |
| 72 | InheritanceIndex inheritanceIndex = index.getInheritanceIndex(); | 72 | InheritanceIndex inheritanceIndex = index.getInheritanceIndex(); |
| 73 | 73 | ||
| 74 | Collection<ClassEntry> inheritors = inheritanceIndex.getChildren(entry.getParent()); | 74 | Collection<ClassEntry> descendants = inheritanceIndex.getDescendants(entry.getParent()); |
| 75 | for (ClassEntry inheritor : inheritors) { | 75 | for (ClassEntry inheritor : descendants) { |
| 76 | MethodEntry methodEntry = entry.withParent(inheritor); | 76 | MethodEntry methodEntry = entry.withParent(inheritor); |
| 77 | if (entryIndex.hasMethod(methodEntry)) { | 77 | if (entryIndex.hasMethod(methodEntry)) { |
| 78 | nodes.add(new MethodImplementationsTreeNode(translator, methodEntry)); | 78 | nodes.add(new MethodImplementationsTreeNode(translator, methodEntry)); |
diff --git a/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java b/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java index f0fd1d28..862bb92a 100644 --- a/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java +++ b/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java | |||
| @@ -11,7 +11,6 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma.analysis; | 12 | package cuchaz.enigma.analysis; |
| 13 | 13 | ||
| 14 | import com.google.common.collect.Lists; | ||
| 15 | import cuchaz.enigma.analysis.index.EntryIndex; | 14 | import cuchaz.enigma.analysis.index.EntryIndex; |
| 16 | import cuchaz.enigma.analysis.index.InheritanceIndex; | 15 | import cuchaz.enigma.analysis.index.InheritanceIndex; |
| 17 | import cuchaz.enigma.analysis.index.JarIndex; | 16 | import cuchaz.enigma.analysis.index.JarIndex; |
| @@ -20,7 +19,6 @@ import cuchaz.enigma.translation.representation.entry.ClassEntry; | |||
| 20 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | 19 | import cuchaz.enigma.translation.representation.entry.MethodEntry; |
| 21 | 20 | ||
| 22 | import javax.swing.tree.DefaultMutableTreeNode; | 21 | import javax.swing.tree.DefaultMutableTreeNode; |
| 23 | import java.util.List; | ||
| 24 | 22 | ||
| 25 | public class MethodInheritanceTreeNode extends DefaultMutableTreeNode { | 23 | public class MethodInheritanceTreeNode extends DefaultMutableTreeNode { |
| 26 | 24 | ||
| @@ -58,6 +56,10 @@ public class MethodInheritanceTreeNode extends DefaultMutableTreeNode { | |||
| 58 | return this.isImplemented; | 56 | return this.isImplemented; |
| 59 | } | 57 | } |
| 60 | 58 | ||
| 59 | public boolean shouldExpand() { | ||
| 60 | return this.isImplemented || !this.isLeaf(); | ||
| 61 | } | ||
| 62 | |||
| 61 | @Override | 63 | @Override |
| 62 | public String toString() { | 64 | public String toString() { |
| 63 | MethodEntry translatedEntry = translator.translate(entry); | 65 | MethodEntry translatedEntry = translator.translate(entry); |
| @@ -71,23 +73,19 @@ public class MethodInheritanceTreeNode extends DefaultMutableTreeNode { | |||
| 71 | } | 73 | } |
| 72 | } | 74 | } |
| 73 | 75 | ||
| 74 | public void load(JarIndex index, boolean recurse) { | 76 | public void load(JarIndex index) { |
| 75 | // get all the child nodes | 77 | // get all the child nodes |
| 76 | List<MethodInheritanceTreeNode> nodes = Lists.newArrayList(); | ||
| 77 | EntryIndex entryIndex = index.getEntryIndex(); | 78 | EntryIndex entryIndex = index.getEntryIndex(); |
| 78 | InheritanceIndex inheritanceIndex = index.getInheritanceIndex(); | 79 | InheritanceIndex inheritanceIndex = index.getInheritanceIndex(); |
| 79 | 80 | ||
| 80 | for (ClassEntry inheritorEntry : inheritanceIndex.getChildren(this.entry.getParent())) { | 81 | for (ClassEntry inheritorEntry : inheritanceIndex.getChildren(this.entry.getParent())) { |
| 81 | MethodEntry methodEntry = new MethodEntry(inheritorEntry, this.entry.getName(), this.entry.getDesc()); | 82 | MethodEntry methodEntry = new MethodEntry(inheritorEntry, this.entry.getName(), this.entry.getDesc()); |
| 82 | nodes.add(new MethodInheritanceTreeNode(translator, methodEntry, entryIndex.hasMethod(methodEntry))); | ||
| 83 | } | ||
| 84 | 83 | ||
| 85 | // add them to this node | 84 | MethodInheritanceTreeNode node = new MethodInheritanceTreeNode(translator, methodEntry, entryIndex.hasMethod(methodEntry)); |
| 86 | nodes.forEach(this::add); | 85 | node.load(index); |
| 87 | 86 | ||
| 88 | if (recurse) { | 87 | if (node.shouldExpand()) { |
| 89 | for (MethodInheritanceTreeNode node : nodes) { | 88 | this.add(node); |
| 90 | node.load(index, true); | ||
| 91 | } | 89 | } |
| 92 | } | 90 | } |
| 93 | } | 91 | } |
diff --git a/src/main/java/cuchaz/enigma/analysis/index/InheritanceIndex.java b/src/main/java/cuchaz/enigma/analysis/index/InheritanceIndex.java index 1b8d9a8d..1ab2abdf 100644 --- a/src/main/java/cuchaz/enigma/analysis/index/InheritanceIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/index/InheritanceIndex.java | |||
| @@ -18,6 +18,7 @@ import cuchaz.enigma.translation.representation.entry.ClassDefEntry; | |||
| 18 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 18 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 19 | 19 | ||
| 20 | import java.util.Collection; | 20 | import java.util.Collection; |
| 21 | import java.util.HashSet; | ||
| 21 | import java.util.LinkedList; | 22 | import java.util.LinkedList; |
| 22 | import java.util.Set; | 23 | import java.util.Set; |
| 23 | 24 | ||
| @@ -60,6 +61,23 @@ public class InheritanceIndex implements JarIndexer { | |||
| 60 | return classChildren.get(classEntry); | 61 | return classChildren.get(classEntry); |
| 61 | } | 62 | } |
| 62 | 63 | ||
| 64 | public Collection<ClassEntry> getDescendants(ClassEntry classEntry) { | ||
| 65 | Collection<ClassEntry> descendants = new HashSet<>(); | ||
| 66 | |||
| 67 | LinkedList<ClassEntry> descendantQueue = new LinkedList<>(); | ||
| 68 | descendantQueue.push(classEntry); | ||
| 69 | |||
| 70 | while (!descendantQueue.isEmpty()) { | ||
| 71 | ClassEntry descendant = descendantQueue.pop(); | ||
| 72 | Collection<ClassEntry> children = getChildren(descendant); | ||
| 73 | |||
| 74 | children.forEach(descendantQueue::push); | ||
| 75 | descendants.addAll(children); | ||
| 76 | } | ||
| 77 | |||
| 78 | return descendants; | ||
| 79 | } | ||
| 80 | |||
| 63 | public Set<ClassEntry> getAncestors(ClassEntry classEntry) { | 81 | public Set<ClassEntry> getAncestors(ClassEntry classEntry) { |
| 64 | Set<ClassEntry> ancestors = Sets.newHashSet(); | 82 | Set<ClassEntry> ancestors = Sets.newHashSet(); |
| 65 | 83 | ||