diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java b/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java deleted file mode 100644 index b09f7ac..0000000 --- a/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java +++ /dev/null | |||
| @@ -1,85 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.analysis; | ||
| 13 | |||
| 14 | import com.google.common.collect.Lists; | ||
| 15 | import cuchaz.enigma.analysis.index.EntryIndex; | ||
| 16 | import cuchaz.enigma.analysis.index.InheritanceIndex; | ||
| 17 | import cuchaz.enigma.analysis.index.JarIndex; | ||
| 18 | import cuchaz.enigma.translation.Translator; | ||
| 19 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
| 20 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | ||
| 21 | |||
| 22 | import javax.swing.tree.DefaultMutableTreeNode; | ||
| 23 | import java.util.Collection; | ||
| 24 | import java.util.List; | ||
| 25 | |||
| 26 | public class MethodImplementationsTreeNode extends DefaultMutableTreeNode { | ||
| 27 | |||
| 28 | private final Translator translator; | ||
| 29 | private MethodEntry entry; | ||
| 30 | |||
| 31 | public MethodImplementationsTreeNode(Translator translator, MethodEntry entry) { | ||
| 32 | this.translator = translator; | ||
| 33 | if (entry == null) { | ||
| 34 | throw new IllegalArgumentException("Entry cannot be null!"); | ||
| 35 | } | ||
| 36 | |||
| 37 | this.entry = entry; | ||
| 38 | } | ||
| 39 | |||
| 40 | public static MethodImplementationsTreeNode findNode(MethodImplementationsTreeNode node, MethodEntry entry) { | ||
| 41 | // is this the node? | ||
| 42 | if (node.getMethodEntry().equals(entry)) { | ||
| 43 | return node; | ||
| 44 | } | ||
| 45 | |||
| 46 | // recurse | ||
| 47 | for (int i = 0; i < node.getChildCount(); i++) { | ||
| 48 | MethodImplementationsTreeNode foundNode = findNode((MethodImplementationsTreeNode) node.getChildAt(i), entry); | ||
| 49 | if (foundNode != null) { | ||
| 50 | return foundNode; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | return null; | ||
| 54 | } | ||
| 55 | |||
| 56 | public MethodEntry getMethodEntry() { | ||
| 57 | return this.entry; | ||
| 58 | } | ||
| 59 | |||
| 60 | @Override | ||
| 61 | public String toString() { | ||
| 62 | MethodEntry translatedEntry = translator.translate(entry); | ||
| 63 | String className = translatedEntry.getParent().getFullName(); | ||
| 64 | String methodName = translatedEntry.getName(); | ||
| 65 | return className + "." + methodName + "()"; | ||
| 66 | } | ||
| 67 | |||
| 68 | public void load(JarIndex index) { | ||
| 69 | // get all method implementations | ||
| 70 | List<MethodImplementationsTreeNode> nodes = Lists.newArrayList(); | ||
| 71 | EntryIndex entryIndex = index.getEntryIndex(); | ||
| 72 | InheritanceIndex inheritanceIndex = index.getInheritanceIndex(); | ||
| 73 | |||
| 74 | Collection<ClassEntry> descendants = inheritanceIndex.getDescendants(entry.getParent()); | ||
| 75 | for (ClassEntry inheritor : descendants) { | ||
| 76 | MethodEntry methodEntry = entry.withParent(inheritor); | ||
| 77 | if (entryIndex.hasMethod(methodEntry)) { | ||
| 78 | nodes.add(new MethodImplementationsTreeNode(translator, methodEntry)); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | // add them to this node | ||
| 83 | nodes.forEach(this::add); | ||
| 84 | } | ||
| 85 | } | ||