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