diff options
Diffstat (limited to 'src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java')
| -rw-r--r-- | src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java b/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java new file mode 100644 index 0000000..d3386c5 --- /dev/null +++ b/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java | |||
| @@ -0,0 +1,142 @@ | |||
| 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 com.google.common.collect.HashMultiset; | ||
| 14 | import com.google.common.collect.Multiset; | ||
| 15 | import com.strobel.assembler.metadata.MemberReference; | ||
| 16 | import com.strobel.assembler.metadata.MethodDefinition; | ||
| 17 | import com.strobel.assembler.metadata.ParameterDefinition; | ||
| 18 | import com.strobel.assembler.metadata.TypeReference; | ||
| 19 | import com.strobel.decompiler.languages.TextLocation; | ||
| 20 | import com.strobel.decompiler.languages.java.ast.ConstructorDeclaration; | ||
| 21 | import com.strobel.decompiler.languages.java.ast.IdentifierExpression; | ||
| 22 | import com.strobel.decompiler.languages.java.ast.InvocationExpression; | ||
| 23 | import com.strobel.decompiler.languages.java.ast.Keys; | ||
| 24 | import com.strobel.decompiler.languages.java.ast.MemberReferenceExpression; | ||
| 25 | import com.strobel.decompiler.languages.java.ast.MethodDeclaration; | ||
| 26 | import com.strobel.decompiler.languages.java.ast.ParameterDeclaration; | ||
| 27 | import com.strobel.decompiler.languages.java.ast.SimpleType; | ||
| 28 | |||
| 29 | import cuchaz.enigma.mapping.ArgumentEntry; | ||
| 30 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 31 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 32 | import cuchaz.enigma.mapping.Entry; | ||
| 33 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 34 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 35 | |||
| 36 | public class SourceIndexBehaviorVisitor extends SourceIndexVisitor | ||
| 37 | { | ||
| 38 | private BehaviorEntry m_behaviorEntry; | ||
| 39 | private Multiset<Entry> m_indices; | ||
| 40 | |||
| 41 | public SourceIndexBehaviorVisitor( BehaviorEntry behaviorEntry ) | ||
| 42 | { | ||
| 43 | m_behaviorEntry = behaviorEntry; | ||
| 44 | m_indices = HashMultiset.create(); | ||
| 45 | } | ||
| 46 | |||
| 47 | @Override | ||
| 48 | public Void visitMethodDeclaration( MethodDeclaration node, SourceIndex index ) | ||
| 49 | { | ||
| 50 | return recurse( node, index ); | ||
| 51 | } | ||
| 52 | |||
| 53 | @Override | ||
| 54 | public Void visitConstructorDeclaration( ConstructorDeclaration node, SourceIndex index ) | ||
| 55 | { | ||
| 56 | return recurse( node, index ); | ||
| 57 | } | ||
| 58 | |||
| 59 | @Override | ||
| 60 | public Void visitInvocationExpression( InvocationExpression node, SourceIndex index ) | ||
| 61 | { | ||
| 62 | MemberReference ref = node.getUserData( Keys.MEMBER_REFERENCE ); | ||
| 63 | ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); | ||
| 64 | MethodEntry methodEntry = new MethodEntry( classEntry, ref.getName(), ref.getSignature() ); | ||
| 65 | if( node.getTarget() instanceof MemberReferenceExpression ) | ||
| 66 | { | ||
| 67 | m_indices.add( methodEntry ); | ||
| 68 | index.addReference( | ||
| 69 | ((MemberReferenceExpression)node.getTarget()).getMemberNameToken(), | ||
| 70 | new EntryReference<Entry,Entry>( methodEntry, m_behaviorEntry, m_indices.count( methodEntry ) ) | ||
| 71 | ); | ||
| 72 | } | ||
| 73 | |||
| 74 | return recurse( node, index ); | ||
| 75 | } | ||
| 76 | |||
| 77 | @Override | ||
| 78 | public Void visitMemberReferenceExpression( MemberReferenceExpression node, SourceIndex index ) | ||
| 79 | { | ||
| 80 | MemberReference ref = node.getUserData( Keys.MEMBER_REFERENCE ); | ||
| 81 | if( ref != null ) | ||
| 82 | { | ||
| 83 | ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); | ||
| 84 | FieldEntry fieldEntry = new FieldEntry( classEntry, ref.getName() ); | ||
| 85 | m_indices.add( fieldEntry ); | ||
| 86 | index.addReference( | ||
| 87 | node.getMemberNameToken(), | ||
| 88 | new EntryReference<Entry,Entry>( fieldEntry, m_behaviorEntry, m_indices.count( fieldEntry ) ) | ||
| 89 | ); | ||
| 90 | } | ||
| 91 | |||
| 92 | return recurse( node, index ); | ||
| 93 | } | ||
| 94 | |||
| 95 | @Override | ||
| 96 | public Void visitSimpleType( SimpleType node, SourceIndex index ) | ||
| 97 | { | ||
| 98 | TypeReference ref = node.getUserData( Keys.TYPE_REFERENCE ); | ||
| 99 | if( node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY ) | ||
| 100 | { | ||
| 101 | ClassEntry classEntry = new ClassEntry( ref.getInternalName() ); | ||
| 102 | m_indices.add( classEntry ); | ||
| 103 | index.addReference( | ||
| 104 | node.getIdentifierToken(), | ||
| 105 | new EntryReference<Entry,Entry>( classEntry, m_behaviorEntry, m_indices.count( classEntry ) ) | ||
| 106 | ); | ||
| 107 | } | ||
| 108 | |||
| 109 | return recurse( node, index ); | ||
| 110 | } | ||
| 111 | |||
| 112 | @Override | ||
| 113 | public Void visitParameterDeclaration( ParameterDeclaration node, SourceIndex index ) | ||
| 114 | { | ||
| 115 | ParameterDefinition def = node.getUserData( Keys.PARAMETER_DEFINITION ); | ||
| 116 | ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() ); | ||
| 117 | MethodDefinition methodDef = (MethodDefinition)def.getMethod(); | ||
| 118 | MethodEntry methodEntry = new MethodEntry( classEntry, methodDef.getName(), methodDef.getSignature() ); | ||
| 119 | ArgumentEntry argumentEntry = new ArgumentEntry( methodEntry, def.getPosition(), def.getName() ); | ||
| 120 | index.addDeclaration( node.getNameToken(), argumentEntry ); | ||
| 121 | |||
| 122 | return recurse( node, index ); | ||
| 123 | } | ||
| 124 | |||
| 125 | @Override | ||
| 126 | public Void visitIdentifierExpression( IdentifierExpression node, SourceIndex index ) | ||
| 127 | { | ||
| 128 | MemberReference ref = node.getUserData( Keys.MEMBER_REFERENCE ); | ||
| 129 | if( ref != null ) | ||
| 130 | { | ||
| 131 | ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); | ||
| 132 | FieldEntry fieldEntry = new FieldEntry( classEntry, ref.getName() ); | ||
| 133 | m_indices.add( fieldEntry ); | ||
| 134 | index.addReference( | ||
| 135 | node.getIdentifierToken(), | ||
| 136 | new EntryReference<Entry,Entry>( fieldEntry, m_behaviorEntry, m_indices.count( fieldEntry ) ) | ||
| 137 | ); | ||
| 138 | } | ||
| 139 | |||
| 140 | return recurse( node, index ); | ||
| 141 | } | ||
| 142 | } | ||