diff options
| author | 2014-08-20 01:21:52 -0400 | |
|---|---|---|
| committer | 2014-08-20 01:21:52 -0400 | |
| commit | a85529d1ce6ec533809575ec84572de855464b36 (patch) | |
| tree | 8f1894c272edf0e7eb22aec2f3af41f6bd19c092 /src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java | |
| parent | started new reference navigation system (diff) | |
| download | enigma-fork-a85529d1ce6ec533809575ec84572de855464b36.tar.gz enigma-fork-a85529d1ce6ec533809575ec84572de855464b36.tar.xz enigma-fork-a85529d1ce6ec533809575ec84572de855464b36.zip | |
finished reference navigation system. Still need to debug and polish it, but the basic idea seems to work. =)
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..2d4c0f5 --- /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.google.common.collect.HashMultiset; | ||
| 14 | import com.google.common.collect.Multiset; | ||
| 15 | import com.strobel.assembler.metadata.FieldDefinition; | ||
| 16 | import com.strobel.assembler.metadata.MethodDefinition; | ||
| 17 | import com.strobel.assembler.metadata.TypeReference; | ||
| 18 | import com.strobel.decompiler.languages.TextLocation; | ||
| 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.ClassEntry; | ||
| 29 | import cuchaz.enigma.mapping.ConstructorEntry; | ||
| 30 | import cuchaz.enigma.mapping.Entry; | ||
| 31 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 32 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 33 | |||
| 34 | public class SourceIndexClassVisitor extends SourceIndexVisitor | ||
| 35 | { | ||
| 36 | private ClassEntry m_classEntry; | ||
| 37 | private Multiset<Entry> m_indices; | ||
| 38 | |||
| 39 | public SourceIndexClassVisitor( ClassEntry classEntry ) | ||
| 40 | { | ||
| 41 | m_classEntry = classEntry; | ||
| 42 | m_indices = HashMultiset.create(); | ||
| 43 | } | ||
| 44 | |||
| 45 | @Override | ||
| 46 | public Void visitTypeDeclaration( TypeDeclaration node, SourceIndex index ) | ||
| 47 | { | ||
| 48 | return recurse( node, index ); | ||
| 49 | } | ||
| 50 | |||
| 51 | @Override | ||
| 52 | public Void visitSimpleType( SimpleType node, SourceIndex index ) | ||
| 53 | { | ||
| 54 | TypeReference ref = node.getUserData( Keys.TYPE_REFERENCE ); | ||
| 55 | if( node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY ) | ||
| 56 | { | ||
| 57 | ClassEntry classEntry = new ClassEntry( ref.getInternalName() ); | ||
| 58 | index.addReference( | ||
| 59 | node.getIdentifierToken(), | ||
| 60 | new EntryReference<Entry,Entry>( classEntry, m_classEntry, m_indices.count( classEntry ) ) | ||
| 61 | ); | ||
| 62 | } | ||
| 63 | |||
| 64 | return recurse( node, index ); | ||
| 65 | } | ||
| 66 | |||
| 67 | @Override | ||
| 68 | public Void visitMethodDeclaration( MethodDeclaration node, SourceIndex index ) | ||
| 69 | { | ||
| 70 | MethodDefinition def = node.getUserData( Keys.METHOD_DEFINITION ); | ||
| 71 | ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() ); | ||
| 72 | MethodEntry methodEntry = new MethodEntry( classEntry, def.getName(), def.getSignature() ); | ||
| 73 | index.addDeclaration( node.getNameToken(), methodEntry ); | ||
| 74 | //if( !def.getName().equals( "<clinit>" ) ) | ||
| 75 | |||
| 76 | return node.acceptVisitor( new SourceIndexBehaviorVisitor( methodEntry ), index ); | ||
| 77 | } | ||
| 78 | |||
| 79 | @Override | ||
| 80 | public Void visitConstructorDeclaration( ConstructorDeclaration node, SourceIndex index ) | ||
| 81 | { | ||
| 82 | MethodDefinition def = node.getUserData( Keys.METHOD_DEFINITION ); | ||
| 83 | ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() ); | ||
| 84 | ConstructorEntry constructorEntry = new ConstructorEntry( classEntry, def.getSignature() ); | ||
| 85 | index.addDeclaration( node.getNameToken(), constructorEntry ); | ||
| 86 | |||
| 87 | return recurse( node, index ); | ||
| 88 | } | ||
| 89 | |||
| 90 | @Override | ||
| 91 | public Void visitFieldDeclaration( FieldDeclaration node, SourceIndex index ) | ||
| 92 | { | ||
| 93 | FieldDefinition def = node.getUserData( Keys.FIELD_DEFINITION ); | ||
| 94 | ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() ); | ||
| 95 | FieldEntry fieldEntry = new FieldEntry( classEntry, def.getName() ); | ||
| 96 | assert( node.getVariables().size() == 1 ); | ||
| 97 | VariableInitializer variable = node.getVariables().firstOrNullObject(); | ||
| 98 | index.addDeclaration( variable.getNameToken(), fieldEntry ); | ||
| 99 | |||
| 100 | return recurse( node, index ); | ||
| 101 | } | ||
| 102 | |||
| 103 | @Override | ||
| 104 | public Void visitEnumValueDeclaration( EnumValueDeclaration node, SourceIndex index ) | ||
| 105 | { | ||
| 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 | } | ||