summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/analysis/ClassInheritanceTreeNode.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/analysis/ClassInheritanceTreeNode.java')
-rw-r--r--src/main/java/cuchaz/enigma/analysis/ClassInheritanceTreeNode.java105
1 files changed, 52 insertions, 53 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/ClassInheritanceTreeNode.java b/src/main/java/cuchaz/enigma/analysis/ClassInheritanceTreeNode.java
index 8a60fc7..24e7cb0 100644
--- a/src/main/java/cuchaz/enigma/analysis/ClassInheritanceTreeNode.java
+++ b/src/main/java/cuchaz/enigma/analysis/ClassInheritanceTreeNode.java
@@ -8,74 +8,73 @@
8 * Contributors: 8 * Contributors:
9 * Jeff Martin - initial API and implementation 9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/ 10 ******************************************************************************/
11
11package cuchaz.enigma.analysis; 12package cuchaz.enigma.analysis;
12 13
13import com.google.common.collect.Lists; 14import com.google.common.collect.Lists;
14
15import java.util.List;
16
17import javax.swing.tree.DefaultMutableTreeNode;
18
19import cuchaz.enigma.mapping.ClassEntry; 15import cuchaz.enigma.mapping.ClassEntry;
20import cuchaz.enigma.mapping.Translator; 16import cuchaz.enigma.mapping.Translator;
21 17
18import javax.swing.tree.DefaultMutableTreeNode;
19import java.util.List;
20
22public class ClassInheritanceTreeNode extends DefaultMutableTreeNode { 21public class ClassInheritanceTreeNode extends DefaultMutableTreeNode {
23 22
24 private Translator deobfuscatingTranslator; 23 private Translator deobfuscatingTranslator;
25 private String obfClassName; 24 private String obfClassName;
26 25
27 public ClassInheritanceTreeNode(Translator deobfuscatingTranslator, String obfClassName) { 26 public ClassInheritanceTreeNode(Translator deobfuscatingTranslator, String obfClassName) {
28 this.deobfuscatingTranslator = deobfuscatingTranslator; 27 this.deobfuscatingTranslator = deobfuscatingTranslator;
29 this.obfClassName = obfClassName; 28 this.obfClassName = obfClassName;
30 } 29 }
31 30
32 public String getObfClassName() { 31 public static ClassInheritanceTreeNode findNode(ClassInheritanceTreeNode node, ClassEntry entry) {
33 return this.obfClassName; 32 // is this the node?
34 } 33 if (node.getObfClassName().equals(entry.getName())) {
34 return node;
35 }
35 36
36 public String getDeobfClassName() { 37 // recurse
37 return this.deobfuscatingTranslator.translateClass(this.obfClassName); 38 for (int i = 0; i < node.getChildCount(); i++) {
38 } 39 ClassInheritanceTreeNode foundNode = findNode((ClassInheritanceTreeNode) node.getChildAt(i), entry);
40 if (foundNode != null) {
41 return foundNode;
42 }
43 }
44 return null;
45 }
39 46
40 @Override 47 public String getObfClassName() {
41 public String toString() { 48 return this.obfClassName;
42 String deobfClassName = getDeobfClassName(); 49 }
43 if (deobfClassName != null) {
44 return deobfClassName;
45 }
46 return this.obfClassName;
47 }
48 50
49 public void load(TranslationIndex ancestries, boolean recurse) { 51 public String getDeobfClassName() {
50 // get all the child nodes 52 return this.deobfuscatingTranslator.translateClass(this.obfClassName);
51 List<ClassInheritanceTreeNode> nodes = Lists.newArrayList(); 53 }
52 for (ClassEntry subclassEntry : ancestries.getSubclass(new ClassEntry(this.obfClassName))) {
53 nodes.add(new ClassInheritanceTreeNode(this.deobfuscatingTranslator, subclassEntry.getName()));
54 }
55 54
56 // add them to this node 55 @Override
57 nodes.forEach(this::add); 56 public String toString() {
57 String deobfClassName = getDeobfClassName();
58 if (deobfClassName != null) {
59 return deobfClassName;
60 }
61 return this.obfClassName;
62 }
58 63
59 if (recurse) { 64 public void load(TranslationIndex ancestries, boolean recurse) {
60 for (ClassInheritanceTreeNode node : nodes) { 65 // get all the child nodes
61 node.load(ancestries, true); 66 List<ClassInheritanceTreeNode> nodes = Lists.newArrayList();
62 } 67 for (ClassEntry subclassEntry : ancestries.getSubclass(new ClassEntry(this.obfClassName))) {
63 } 68 nodes.add(new ClassInheritanceTreeNode(this.deobfuscatingTranslator, subclassEntry.getName()));
64 } 69 }
65 70
66 public static ClassInheritanceTreeNode findNode(ClassInheritanceTreeNode node, ClassEntry entry) { 71 // add them to this node
67 // is this the node? 72 nodes.forEach(this::add);
68 if (node.getObfClassName().equals(entry.getName())) {
69 return node;
70 }
71 73
72 // recurse 74 if (recurse) {
73 for (int i = 0; i < node.getChildCount(); i++) { 75 for (ClassInheritanceTreeNode node : nodes) {
74 ClassInheritanceTreeNode foundNode = findNode((ClassInheritanceTreeNode) node.getChildAt(i), entry); 76 node.load(ancestries, true);
75 if (foundNode != null) { 77 }
76 return foundNode; 78 }
77 } 79 }
78 }
79 return null;
80 }
81} 80}