diff options
| author | 2016-06-30 00:49:21 +1000 | |
|---|---|---|
| committer | 2016-06-30 00:49:21 +1000 | |
| commit | 4be005617b3b8c3578cca07c5d085d12916f0d1d (patch) | |
| tree | db163431f38703e26da417ef05eaea2b27a498b9 /src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java | |
| parent | Some small changes to fix idea importing (diff) | |
| download | enigma-fork-4be005617b3b8c3578cca07c5d085d12916f0d1d.tar.gz enigma-fork-4be005617b3b8c3578cca07c5d085d12916f0d1d.tar.xz enigma-fork-4be005617b3b8c3578cca07c5d085d12916f0d1d.zip | |
Json format (#2)
* Added new format
* Fixed bug
* Updated Version
Diffstat (limited to 'src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java')
| -rw-r--r-- | src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java | 150 |
1 files changed, 0 insertions, 150 deletions
diff --git a/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java b/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java deleted file mode 100644 index a660a37..0000000 --- a/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java +++ /dev/null | |||
| @@ -1,150 +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 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.analysis; | ||
| 12 | |||
| 13 | import com.strobel.assembler.metadata.MemberReference; | ||
| 14 | import com.strobel.assembler.metadata.MethodDefinition; | ||
| 15 | import com.strobel.assembler.metadata.MethodReference; | ||
| 16 | import com.strobel.assembler.metadata.ParameterDefinition; | ||
| 17 | import com.strobel.assembler.metadata.TypeReference; | ||
| 18 | import com.strobel.decompiler.languages.TextLocation; | ||
| 19 | import com.strobel.decompiler.languages.java.ast.AstNode; | ||
| 20 | import com.strobel.decompiler.languages.java.ast.IdentifierExpression; | ||
| 21 | import com.strobel.decompiler.languages.java.ast.InvocationExpression; | ||
| 22 | import com.strobel.decompiler.languages.java.ast.Keys; | ||
| 23 | import com.strobel.decompiler.languages.java.ast.MemberReferenceExpression; | ||
| 24 | import com.strobel.decompiler.languages.java.ast.ObjectCreationExpression; | ||
| 25 | import com.strobel.decompiler.languages.java.ast.ParameterDeclaration; | ||
| 26 | import com.strobel.decompiler.languages.java.ast.SimpleType; | ||
| 27 | import com.strobel.decompiler.languages.java.ast.SuperReferenceExpression; | ||
| 28 | import com.strobel.decompiler.languages.java.ast.ThisReferenceExpression; | ||
| 29 | |||
| 30 | import cuchaz.enigma.mapping.ArgumentEntry; | ||
| 31 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 32 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 33 | import cuchaz.enigma.mapping.ConstructorEntry; | ||
| 34 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 35 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 36 | import cuchaz.enigma.mapping.ProcyonEntryFactory; | ||
| 37 | import cuchaz.enigma.mapping.Signature; | ||
| 38 | import cuchaz.enigma.mapping.Type; | ||
| 39 | |||
| 40 | public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { | ||
| 41 | |||
| 42 | private BehaviorEntry m_behaviorEntry; | ||
| 43 | |||
| 44 | public SourceIndexBehaviorVisitor(BehaviorEntry behaviorEntry) { | ||
| 45 | m_behaviorEntry = behaviorEntry; | ||
| 46 | } | ||
| 47 | |||
| 48 | @Override | ||
| 49 | public Void visitInvocationExpression(InvocationExpression node, SourceIndex index) { | ||
| 50 | MemberReference ref = node.getUserData(Keys.MEMBER_REFERENCE); | ||
| 51 | |||
| 52 | // get the behavior entry | ||
| 53 | ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName()); | ||
| 54 | BehaviorEntry behaviorEntry = null; | ||
| 55 | if (ref instanceof MethodReference) { | ||
| 56 | MethodReference methodRef = (MethodReference)ref; | ||
| 57 | if (methodRef.isConstructor()) { | ||
| 58 | behaviorEntry = new ConstructorEntry(classEntry, new Signature(ref.getErasedSignature())); | ||
| 59 | } else if (methodRef.isTypeInitializer()) { | ||
| 60 | behaviorEntry = new ConstructorEntry(classEntry); | ||
| 61 | } else { | ||
| 62 | behaviorEntry = new MethodEntry(classEntry, ref.getName(), new Signature(ref.getErasedSignature())); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | if (behaviorEntry != null) { | ||
| 66 | // get the node for the token | ||
| 67 | AstNode tokenNode = null; | ||
| 68 | if (node.getTarget() instanceof MemberReferenceExpression) { | ||
| 69 | tokenNode = ((MemberReferenceExpression)node.getTarget()).getMemberNameToken(); | ||
| 70 | } else if (node.getTarget() instanceof SuperReferenceExpression) { | ||
| 71 | tokenNode = node.getTarget(); | ||
| 72 | } else if (node.getTarget() instanceof ThisReferenceExpression) { | ||
| 73 | tokenNode = node.getTarget(); | ||
| 74 | } | ||
| 75 | if (tokenNode != null) { | ||
| 76 | index.addReference(tokenNode, behaviorEntry, m_behaviorEntry); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | return recurse(node, index); | ||
| 81 | } | ||
| 82 | |||
| 83 | @Override | ||
| 84 | public Void visitMemberReferenceExpression(MemberReferenceExpression node, SourceIndex index) { | ||
| 85 | MemberReference ref = node.getUserData(Keys.MEMBER_REFERENCE); | ||
| 86 | if (ref != null) { | ||
| 87 | // make sure this is actually a field | ||
| 88 | if (ref.getErasedSignature().indexOf('(') >= 0) { | ||
| 89 | throw new Error("Expected a field here! got " + ref); | ||
| 90 | } | ||
| 91 | |||
| 92 | ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName()); | ||
| 93 | FieldEntry fieldEntry = new FieldEntry(classEntry, ref.getName(), new Type(ref.getErasedSignature())); | ||
| 94 | index.addReference(node.getMemberNameToken(), fieldEntry, m_behaviorEntry); | ||
| 95 | } | ||
| 96 | |||
| 97 | return recurse(node, index); | ||
| 98 | } | ||
| 99 | |||
| 100 | @Override | ||
| 101 | public Void visitSimpleType(SimpleType node, SourceIndex index) { | ||
| 102 | TypeReference ref = node.getUserData(Keys.TYPE_REFERENCE); | ||
| 103 | if (node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY) { | ||
| 104 | ClassEntry classEntry = new ClassEntry(ref.getInternalName()); | ||
| 105 | index.addReference(node.getIdentifierToken(), classEntry, m_behaviorEntry); | ||
| 106 | } | ||
| 107 | |||
| 108 | return recurse(node, index); | ||
| 109 | } | ||
| 110 | |||
| 111 | @Override | ||
| 112 | public Void visitParameterDeclaration(ParameterDeclaration node, SourceIndex index) { | ||
| 113 | ParameterDefinition def = node.getUserData(Keys.PARAMETER_DEFINITION); | ||
| 114 | if (def.getMethod() instanceof MethodDefinition) { | ||
| 115 | MethodDefinition methodDef = (MethodDefinition)def.getMethod(); | ||
| 116 | BehaviorEntry behaviorEntry = ProcyonEntryFactory.getBehaviorEntry(methodDef); | ||
| 117 | ArgumentEntry argumentEntry = new ArgumentEntry(behaviorEntry, def.getPosition(), node.getName()); | ||
| 118 | index.addDeclaration(node.getNameToken(), argumentEntry); | ||
| 119 | } | ||
| 120 | |||
| 121 | return recurse(node, index); | ||
| 122 | } | ||
| 123 | |||
| 124 | @Override | ||
| 125 | public Void visitIdentifierExpression(IdentifierExpression node, SourceIndex index) { | ||
| 126 | MemberReference ref = node.getUserData(Keys.MEMBER_REFERENCE); | ||
| 127 | if (ref != null) { | ||
| 128 | ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName()); | ||
| 129 | FieldEntry fieldEntry = new FieldEntry(classEntry, ref.getName(), new Type(ref.getErasedSignature())); | ||
| 130 | index.addReference(node.getIdentifierToken(), fieldEntry, m_behaviorEntry); | ||
| 131 | } | ||
| 132 | |||
| 133 | return recurse(node, index); | ||
| 134 | } | ||
| 135 | |||
| 136 | @Override | ||
| 137 | public Void visitObjectCreationExpression(ObjectCreationExpression node, SourceIndex index) { | ||
| 138 | MemberReference ref = node.getUserData(Keys.MEMBER_REFERENCE); | ||
| 139 | if (ref != null) { | ||
| 140 | ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName()); | ||
| 141 | ConstructorEntry constructorEntry = new ConstructorEntry(classEntry, new Signature(ref.getErasedSignature())); | ||
| 142 | if (node.getType() instanceof SimpleType) { | ||
| 143 | SimpleType simpleTypeNode = (SimpleType)node.getType(); | ||
| 144 | index.addReference(simpleTypeNode.getIdentifierToken(), constructorEntry, m_behaviorEntry); | ||
| 145 | } | ||
| 146 | } | ||
| 147 | |||
| 148 | return recurse(node, index); | ||
| 149 | } | ||
| 150 | } | ||