diff options
Diffstat (limited to 'src/cuchaz/enigma/analysis/ClassImplementationsTreeNode.java')
| -rw-r--r-- | src/cuchaz/enigma/analysis/ClassImplementationsTreeNode.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/analysis/ClassImplementationsTreeNode.java b/src/cuchaz/enigma/analysis/ClassImplementationsTreeNode.java new file mode 100644 index 0000000..49aac5f --- /dev/null +++ b/src/cuchaz/enigma/analysis/ClassImplementationsTreeNode.java | |||
| @@ -0,0 +1,80 @@ | |||
| 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 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.analysis; | ||
| 12 | |||
| 13 | import java.util.List; | ||
| 14 | |||
| 15 | import javax.swing.tree.DefaultMutableTreeNode; | ||
| 16 | |||
| 17 | import com.google.common.collect.Lists; | ||
| 18 | |||
| 19 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 20 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 21 | import cuchaz.enigma.mapping.Translator; | ||
| 22 | |||
| 23 | public class ClassImplementationsTreeNode extends DefaultMutableTreeNode { | ||
| 24 | |||
| 25 | private static final long serialVersionUID = 3112703459157851912L; | ||
| 26 | |||
| 27 | private Translator m_deobfuscatingTranslator; | ||
| 28 | private ClassEntry m_entry; | ||
| 29 | |||
| 30 | public ClassImplementationsTreeNode(Translator deobfuscatingTranslator, ClassEntry entry) { | ||
| 31 | m_deobfuscatingTranslator = deobfuscatingTranslator; | ||
| 32 | m_entry = entry; | ||
| 33 | } | ||
| 34 | |||
| 35 | public ClassEntry getClassEntry() { | ||
| 36 | return m_entry; | ||
| 37 | } | ||
| 38 | |||
| 39 | public String getDeobfClassName() { | ||
| 40 | return m_deobfuscatingTranslator.translateClass(m_entry.getClassName()); | ||
| 41 | } | ||
| 42 | |||
| 43 | @Override | ||
| 44 | public String toString() { | ||
| 45 | String className = getDeobfClassName(); | ||
| 46 | if (className == null) { | ||
| 47 | className = m_entry.getClassName(); | ||
| 48 | } | ||
| 49 | return className; | ||
| 50 | } | ||
| 51 | |||
| 52 | public void load(JarIndex index) { | ||
| 53 | // get all method implementations | ||
| 54 | List<ClassImplementationsTreeNode> nodes = Lists.newArrayList(); | ||
| 55 | for (String implementingClassName : index.getImplementingClasses(m_entry.getClassName())) { | ||
| 56 | nodes.add(new ClassImplementationsTreeNode(m_deobfuscatingTranslator, new ClassEntry(implementingClassName))); | ||
| 57 | } | ||
| 58 | |||
| 59 | // add them to this node | ||
| 60 | for (ClassImplementationsTreeNode node : nodes) { | ||
| 61 | this.add(node); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | public static ClassImplementationsTreeNode findNode(ClassImplementationsTreeNode node, MethodEntry entry) { | ||
| 66 | // is this the node? | ||
| 67 | if (node.m_entry.equals(entry)) { | ||
| 68 | return node; | ||
| 69 | } | ||
| 70 | |||
| 71 | // recurse | ||
| 72 | for (int i = 0; i < node.getChildCount(); i++) { | ||
| 73 | ClassImplementationsTreeNode foundNode = findNode((ClassImplementationsTreeNode)node.getChildAt(i), entry); | ||
| 74 | if (foundNode != null) { | ||
| 75 | return foundNode; | ||
| 76 | } | ||
| 77 | } | ||
| 78 | return null; | ||
| 79 | } | ||
| 80 | } | ||