diff options
| author | 2015-02-03 22:00:53 -0500 | |
|---|---|---|
| committer | 2015-02-03 22:00:53 -0500 | |
| commit | 52ab426d8fad3dbee7e728f523a35af94facebda (patch) | |
| tree | 146fadfd8e639a909d6c1d6a193e7eddeab0be4a /src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java | |
| download | enigma-fork-52ab426d8fad3dbee7e728f523a35af94facebda.tar.gz enigma-fork-52ab426d8fad3dbee7e728f523a35af94facebda.tar.xz enigma-fork-52ab426d8fad3dbee7e728f523a35af94facebda.zip | |
oops, don't depend on local procyon project
Diffstat (limited to 'src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java')
| -rw-r--r-- | src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java b/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java new file mode 100644 index 0000000..7b902a9 --- /dev/null +++ b/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java | |||
| @@ -0,0 +1,114 @@ | |||
| 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.strobel.assembler.metadata.FieldDefinition; | ||
| 14 | import com.strobel.assembler.metadata.MethodDefinition; | ||
| 15 | import com.strobel.assembler.metadata.TypeDefinition; | ||
| 16 | import com.strobel.assembler.metadata.TypeReference; | ||
| 17 | import com.strobel.decompiler.languages.TextLocation; | ||
| 18 | import com.strobel.decompiler.languages.java.ast.AstNode; | ||
| 19 | import com.strobel.decompiler.languages.java.ast.ConstructorDeclaration; | ||
| 20 | import com.strobel.decompiler.languages.java.ast.EnumValueDeclaration; | ||
| 21 | import com.strobel.decompiler.languages.java.ast.FieldDeclaration; | ||
| 22 | import com.strobel.decompiler.languages.java.ast.Keys; | ||
| 23 | import com.strobel.decompiler.languages.java.ast.MethodDeclaration; | ||
| 24 | import com.strobel.decompiler.languages.java.ast.SimpleType; | ||
| 25 | import com.strobel.decompiler.languages.java.ast.TypeDeclaration; | ||
| 26 | import com.strobel.decompiler.languages.java.ast.VariableInitializer; | ||
| 27 | |||
| 28 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 29 | import cuchaz.enigma.mapping.BehaviorEntryFactory; | ||
| 30 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 31 | import cuchaz.enigma.mapping.ConstructorEntry; | ||
| 32 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 33 | |||
| 34 | public class SourceIndexClassVisitor extends SourceIndexVisitor { | ||
| 35 | |||
| 36 | private ClassEntry m_classEntry; | ||
| 37 | |||
| 38 | public SourceIndexClassVisitor(ClassEntry classEntry) { | ||
| 39 | m_classEntry = classEntry; | ||
| 40 | } | ||
| 41 | |||
| 42 | @Override | ||
| 43 | public Void visitTypeDeclaration(TypeDeclaration node, SourceIndex index) { | ||
| 44 | // is this this class, or a subtype? | ||
| 45 | TypeDefinition def = node.getUserData(Keys.TYPE_DEFINITION); | ||
| 46 | ClassEntry classEntry = new ClassEntry(def.getInternalName()); | ||
| 47 | if (!classEntry.equals(m_classEntry)) { | ||
| 48 | // it's a sub-type, recurse | ||
| 49 | index.addDeclaration(node.getNameToken(), classEntry); | ||
| 50 | return node.acceptVisitor(new SourceIndexClassVisitor(classEntry), index); | ||
| 51 | } | ||
| 52 | |||
| 53 | return recurse(node, index); | ||
| 54 | } | ||
| 55 | |||
| 56 | @Override | ||
| 57 | public Void visitSimpleType(SimpleType node, SourceIndex index) { | ||
| 58 | TypeReference ref = node.getUserData(Keys.TYPE_REFERENCE); | ||
| 59 | if (node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY) { | ||
| 60 | ClassEntry classEntry = new ClassEntry(ref.getInternalName()); | ||
| 61 | index.addReference(node.getIdentifierToken(), classEntry, m_classEntry); | ||
| 62 | } | ||
| 63 | |||
| 64 | return recurse(node, index); | ||
| 65 | } | ||
| 66 | |||
| 67 | @Override | ||
| 68 | public Void visitMethodDeclaration(MethodDeclaration node, SourceIndex index) { | ||
| 69 | MethodDefinition def = node.getUserData(Keys.METHOD_DEFINITION); | ||
| 70 | ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); | ||
| 71 | BehaviorEntry behaviorEntry = BehaviorEntryFactory.create(classEntry, def.getName(), def.getSignature()); | ||
| 72 | AstNode tokenNode = node.getNameToken(); | ||
| 73 | if (behaviorEntry instanceof ConstructorEntry) { | ||
| 74 | ConstructorEntry constructorEntry = (ConstructorEntry)behaviorEntry; | ||
| 75 | if (constructorEntry.isStatic()) { | ||
| 76 | tokenNode = node.getModifiers().firstOrNullObject(); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | index.addDeclaration(tokenNode, behaviorEntry); | ||
| 80 | return node.acceptVisitor(new SourceIndexBehaviorVisitor(behaviorEntry), index); | ||
| 81 | } | ||
| 82 | |||
| 83 | @Override | ||
| 84 | public Void visitConstructorDeclaration(ConstructorDeclaration node, SourceIndex index) { | ||
| 85 | MethodDefinition def = node.getUserData(Keys.METHOD_DEFINITION); | ||
| 86 | ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); | ||
| 87 | ConstructorEntry constructorEntry = new ConstructorEntry(classEntry, def.getSignature()); | ||
| 88 | index.addDeclaration(node.getNameToken(), constructorEntry); | ||
| 89 | return node.acceptVisitor(new SourceIndexBehaviorVisitor(constructorEntry), index); | ||
| 90 | } | ||
| 91 | |||
| 92 | @Override | ||
| 93 | public Void visitFieldDeclaration(FieldDeclaration node, SourceIndex index) { | ||
| 94 | FieldDefinition def = node.getUserData(Keys.FIELD_DEFINITION); | ||
| 95 | ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); | ||
| 96 | FieldEntry fieldEntry = new FieldEntry(classEntry, def.getName()); | ||
| 97 | assert (node.getVariables().size() == 1); | ||
| 98 | VariableInitializer variable = node.getVariables().firstOrNullObject(); | ||
| 99 | index.addDeclaration(variable.getNameToken(), fieldEntry); | ||
| 100 | |||
| 101 | return recurse(node, index); | ||
| 102 | } | ||
| 103 | |||
| 104 | @Override | ||
| 105 | public Void visitEnumValueDeclaration(EnumValueDeclaration node, SourceIndex index) { | ||
| 106 | // treat enum declarations as field declarations | ||
| 107 | FieldDefinition def = node.getUserData(Keys.FIELD_DEFINITION); | ||
| 108 | ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); | ||
| 109 | FieldEntry fieldEntry = new FieldEntry(classEntry, def.getName()); | ||
| 110 | index.addDeclaration(node.getNameToken(), fieldEntry); | ||
| 111 | |||
| 112 | return recurse(node, index); | ||
| 113 | } | ||
| 114 | } | ||