diff options
| author | 2014-08-26 00:27:44 -0400 | |
|---|---|---|
| committer | 2014-08-26 00:27:44 -0400 | |
| commit | 5f44aac70f59898197c2a7625b74f901c3b31106 (patch) | |
| tree | 7d2cc2e48201c92867786793966f356810b464fa /src/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java | |
| parent | wrote CheckCastIterator to try to do generic type inference. It's too hard to... (diff) | |
| download | enigma-fork-5f44aac70f59898197c2a7625b74f901c3b31106.tar.gz enigma-fork-5f44aac70f59898197c2a7625b74f901c3b31106.tar.xz enigma-fork-5f44aac70f59898197c2a7625b74f901c3b31106.zip | |
implemented proper support for interfaces
Diffstat (limited to '')
| -rw-r--r-- | src/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java b/src/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java new file mode 100644 index 0000000..b529f3f --- /dev/null +++ b/src/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java | |||
| @@ -0,0 +1,111 @@ | |||
| 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 MethodImplementationsTreeNode extends DefaultMutableTreeNode | ||
| 24 | { | ||
| 25 | private static final long serialVersionUID = 3781080657461899915L; | ||
| 26 | |||
| 27 | private Translator m_deobfuscatingTranslator; | ||
| 28 | private MethodEntry m_entry; | ||
| 29 | |||
| 30 | public MethodImplementationsTreeNode( Translator deobfuscatingTranslator, MethodEntry entry ) | ||
| 31 | { | ||
| 32 | m_deobfuscatingTranslator = deobfuscatingTranslator; | ||
| 33 | m_entry = entry; | ||
| 34 | } | ||
| 35 | |||
| 36 | public MethodEntry getMethodEntry( ) | ||
| 37 | { | ||
| 38 | return m_entry; | ||
| 39 | } | ||
| 40 | |||
| 41 | public String getDeobfClassName( ) | ||
| 42 | { | ||
| 43 | return m_deobfuscatingTranslator.translateClass( m_entry.getClassName() ); | ||
| 44 | } | ||
| 45 | |||
| 46 | public String getDeobfMethodName( ) | ||
| 47 | { | ||
| 48 | return m_deobfuscatingTranslator.translate( m_entry ); | ||
| 49 | } | ||
| 50 | |||
| 51 | @Override | ||
| 52 | public String toString( ) | ||
| 53 | { | ||
| 54 | String className = getDeobfClassName(); | ||
| 55 | if( className == null ) | ||
| 56 | { | ||
| 57 | className = m_entry.getClassName(); | ||
| 58 | } | ||
| 59 | |||
| 60 | String methodName = getDeobfMethodName(); | ||
| 61 | if( methodName == null ) | ||
| 62 | { | ||
| 63 | methodName = m_entry.getName(); | ||
| 64 | } | ||
| 65 | return className + "." + methodName + "()"; | ||
| 66 | } | ||
| 67 | |||
| 68 | public void load( JarIndex index ) | ||
| 69 | { | ||
| 70 | // get all method implementations | ||
| 71 | List<MethodImplementationsTreeNode> nodes = Lists.newArrayList(); | ||
| 72 | for( String implementingClassName : index.getAncestries().getImplementingClasses( m_entry.getClassName() ) ) | ||
| 73 | { | ||
| 74 | MethodEntry methodEntry = new MethodEntry( | ||
| 75 | new ClassEntry( implementingClassName ), | ||
| 76 | m_entry.getName(), | ||
| 77 | m_entry.getSignature() | ||
| 78 | ); | ||
| 79 | if( index.isMethodImplemented( methodEntry ) ) | ||
| 80 | { | ||
| 81 | nodes.add( new MethodImplementationsTreeNode( m_deobfuscatingTranslator, methodEntry ) ); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | // add them to this node | ||
| 86 | for( MethodImplementationsTreeNode node : nodes ) | ||
| 87 | { | ||
| 88 | this.add( node ); | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | public static MethodImplementationsTreeNode findNode( MethodImplementationsTreeNode node, MethodEntry entry ) | ||
| 93 | { | ||
| 94 | // is this the node? | ||
| 95 | if( node.getMethodEntry().equals( entry ) ) | ||
| 96 | { | ||
| 97 | return node; | ||
| 98 | } | ||
| 99 | |||
| 100 | // recurse | ||
| 101 | for( int i=0; i<node.getChildCount(); i++ ) | ||
| 102 | { | ||
| 103 | MethodImplementationsTreeNode foundNode = findNode( (MethodImplementationsTreeNode)node.getChildAt( i ), entry ); | ||
| 104 | if( foundNode != null ) | ||
| 105 | { | ||
| 106 | return foundNode; | ||
| 107 | } | ||
| 108 | } | ||
| 109 | return null; | ||
| 110 | } | ||
| 111 | } | ||