summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java134
1 files changed, 134 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java b/src/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java
new file mode 100644
index 0000000..1fecf48
--- /dev/null
+++ b/src/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java
@@ -0,0 +1,134 @@
1/*******************************************************************************
2 * Copyright (c) 2014 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Public License v3.0
5 * which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/gpl.html
7 *
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11package cuchaz.enigma.analysis;
12
13import java.util.List;
14
15import javax.swing.tree.DefaultMutableTreeNode;
16
17import com.google.common.collect.Lists;
18
19import cuchaz.enigma.mapping.ClassEntry;
20import cuchaz.enigma.mapping.MethodEntry;
21import cuchaz.enigma.mapping.Translator;
22
23public class MethodInheritanceTreeNode extends DefaultMutableTreeNode
24{
25 private static final long serialVersionUID = 1096677030991810007L;
26
27 private Translator m_deobfuscatingTranslator;
28 private MethodEntry m_entry;
29 private boolean m_isImplemented;
30
31 public MethodInheritanceTreeNode( Translator deobfuscatingTranslator, MethodEntry entry, boolean isImplemented )
32 {
33 m_deobfuscatingTranslator = deobfuscatingTranslator;
34 m_entry = entry;
35 m_isImplemented = isImplemented;
36 }
37
38 public MethodEntry getMethodEntry( )
39 {
40 return m_entry;
41 }
42
43 public String getDeobfClassName( )
44 {
45 return m_deobfuscatingTranslator.translateClass( m_entry.getClassName() );
46 }
47
48 public String getDeobfMethodName( )
49 {
50 return m_deobfuscatingTranslator.translate( m_entry );
51 }
52
53 public boolean isImplemented( )
54 {
55 return m_isImplemented;
56 }
57
58 @Override
59 public String toString( )
60 {
61 String className = getDeobfClassName();
62 if( className == null )
63 {
64 className = m_entry.getClassName();
65 }
66
67 if( !m_isImplemented )
68 {
69 return className;
70 }
71 else
72 {
73 String methodName = getDeobfMethodName();
74 if( methodName == null )
75 {
76 methodName = m_entry.getName();
77 }
78 return className + "." + methodName + "()";
79 }
80 }
81
82 public void load( Ancestries ancestries, boolean recurse )
83 {
84 // get all the child nodes
85 List<MethodInheritanceTreeNode> nodes = Lists.newArrayList();
86 for( String subclassName : ancestries.getSubclasses( m_entry.getClassName() ) )
87 {
88 MethodEntry methodEntry = new MethodEntry(
89 new ClassEntry( subclassName ),
90 m_entry.getName(),
91 m_entry.getSignature()
92 );
93 nodes.add( new MethodInheritanceTreeNode(
94 m_deobfuscatingTranslator,
95 methodEntry,
96 ancestries.isMethodImplemented( subclassName, m_entry.getName(), m_entry.getSignature() )
97 ) );
98 }
99
100 // add them to this node
101 for( MethodInheritanceTreeNode node : nodes )
102 {
103 this.add( node );
104 }
105
106 if( recurse )
107 {
108 for( MethodInheritanceTreeNode node : nodes )
109 {
110 node.load( ancestries, true );
111 }
112 }
113 }
114
115 public static MethodInheritanceTreeNode findNode( MethodInheritanceTreeNode node, MethodEntry entry )
116 {
117 // is this the node?
118 if( node.getMethodEntry().equals( entry ) )
119 {
120 return node;
121 }
122
123 // recurse
124 for( int i=0; i<node.getChildCount(); i++ )
125 {
126 MethodInheritanceTreeNode foundNode = findNode( (MethodInheritanceTreeNode)node.getChildAt( i ), entry );
127 if( foundNode != null )
128 {
129 return foundNode;
130 }
131 }
132 return null;
133 }
134}