diff options
| author | 2014-09-14 23:56:43 -0400 | |
|---|---|---|
| committer | 2014-09-14 23:56:43 -0400 | |
| commit | 72e918a5134c2bf747a476284bcfa1bd2ef2fa21 (patch) | |
| tree | 2fd256d6a8bbe38b7b9fe1892f444a8c29de08ef /src | |
| parent | added test to check constructor references (diff) | |
| download | enigma-72e918a5134c2bf747a476284bcfa1bd2ef2fa21.tar.gz enigma-72e918a5134c2bf747a476284bcfa1bd2ef2fa21.tar.xz enigma-72e918a5134c2bf747a476284bcfa1bd2ef2fa21.zip | |
added tests to check constructor tokens
fixed a bug with constructor tokens too
Diffstat (limited to 'src')
| -rw-r--r-- | src/cuchaz/enigma/analysis/SourceIndex.java | 10 | ||||
| -rw-r--r-- | src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java | 51 | ||||
| -rw-r--r-- | src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java | 1 |
3 files changed, 50 insertions, 12 deletions
diff --git a/src/cuchaz/enigma/analysis/SourceIndex.java b/src/cuchaz/enigma/analysis/SourceIndex.java index 1a5a80d6..b777f9fd 100644 --- a/src/cuchaz/enigma/analysis/SourceIndex.java +++ b/src/cuchaz/enigma/analysis/SourceIndex.java | |||
| @@ -20,7 +20,7 @@ import com.google.common.collect.Lists; | |||
| 20 | import com.google.common.collect.Maps; | 20 | import com.google.common.collect.Maps; |
| 21 | import com.google.common.collect.Multimap; | 21 | import com.google.common.collect.Multimap; |
| 22 | import com.strobel.decompiler.languages.Region; | 22 | import com.strobel.decompiler.languages.Region; |
| 23 | import com.strobel.decompiler.languages.java.ast.Identifier; | 23 | import com.strobel.decompiler.languages.java.ast.AstNode; |
| 24 | 24 | ||
| 25 | import cuchaz.enigma.mapping.Entry; | 25 | import cuchaz.enigma.mapping.Entry; |
| 26 | 26 | ||
| @@ -56,7 +56,7 @@ public class SourceIndex | |||
| 56 | return m_source; | 56 | return m_source; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | public Token getToken( Identifier node ) | 59 | public Token getToken( AstNode node ) |
| 60 | { | 60 | { |
| 61 | // get a token for this node's region | 61 | // get a token for this node's region |
| 62 | Region region = node.getRegion(); | 62 | Region region = node.getRegion(); |
| @@ -71,7 +71,7 @@ public class SourceIndex | |||
| 71 | ); | 71 | ); |
| 72 | 72 | ||
| 73 | // for tokens representing inner classes, make sure we only get the simple name | 73 | // for tokens representing inner classes, make sure we only get the simple name |
| 74 | int pos = node.getName().lastIndexOf( '$' ); | 74 | int pos = node.toString().lastIndexOf( '$' ); |
| 75 | if( pos >= 0 ) | 75 | if( pos >= 0 ) |
| 76 | { | 76 | { |
| 77 | token.end -= pos + 1; | 77 | token.end -= pos + 1; |
| @@ -92,7 +92,7 @@ public class SourceIndex | |||
| 92 | return token; | 92 | return token; |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | public void addReference( Identifier node, EntryReference<Entry,Entry> deobfReference ) | 95 | public void addReference( AstNode node, EntryReference<Entry,Entry> deobfReference ) |
| 96 | { | 96 | { |
| 97 | Token token = getToken( node ); | 97 | Token token = getToken( node ); |
| 98 | if( token != null ) | 98 | if( token != null ) |
| @@ -102,7 +102,7 @@ public class SourceIndex | |||
| 102 | } | 102 | } |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | public void addDeclaration( Identifier node, Entry deobfEntry ) | 105 | public void addDeclaration( AstNode node, Entry deobfEntry ) |
| 106 | { | 106 | { |
| 107 | Token token = getToken( node ); | 107 | Token token = getToken( node ); |
| 108 | if( token != null ) | 108 | if( token != null ) |
diff --git a/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java b/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java index ab505528..a1dac4b5 100644 --- a/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java +++ b/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java | |||
| @@ -12,9 +12,11 @@ package cuchaz.enigma.analysis; | |||
| 12 | 12 | ||
| 13 | import com.strobel.assembler.metadata.MemberReference; | 13 | import com.strobel.assembler.metadata.MemberReference; |
| 14 | import com.strobel.assembler.metadata.MethodDefinition; | 14 | import com.strobel.assembler.metadata.MethodDefinition; |
| 15 | import com.strobel.assembler.metadata.MethodReference; | ||
| 15 | import com.strobel.assembler.metadata.ParameterDefinition; | 16 | import com.strobel.assembler.metadata.ParameterDefinition; |
| 16 | import com.strobel.assembler.metadata.TypeReference; | 17 | import com.strobel.assembler.metadata.TypeReference; |
| 17 | import com.strobel.decompiler.languages.TextLocation; | 18 | import com.strobel.decompiler.languages.TextLocation; |
| 19 | import com.strobel.decompiler.languages.java.ast.AstNode; | ||
| 18 | import com.strobel.decompiler.languages.java.ast.ConstructorDeclaration; | 20 | import com.strobel.decompiler.languages.java.ast.ConstructorDeclaration; |
| 19 | import com.strobel.decompiler.languages.java.ast.IdentifierExpression; | 21 | import com.strobel.decompiler.languages.java.ast.IdentifierExpression; |
| 20 | import com.strobel.decompiler.languages.java.ast.InvocationExpression; | 22 | import com.strobel.decompiler.languages.java.ast.InvocationExpression; |
| @@ -24,6 +26,8 @@ import com.strobel.decompiler.languages.java.ast.MethodDeclaration; | |||
| 24 | import com.strobel.decompiler.languages.java.ast.ObjectCreationExpression; | 26 | import com.strobel.decompiler.languages.java.ast.ObjectCreationExpression; |
| 25 | import com.strobel.decompiler.languages.java.ast.ParameterDeclaration; | 27 | import com.strobel.decompiler.languages.java.ast.ParameterDeclaration; |
| 26 | import com.strobel.decompiler.languages.java.ast.SimpleType; | 28 | import com.strobel.decompiler.languages.java.ast.SimpleType; |
| 29 | import com.strobel.decompiler.languages.java.ast.SuperReferenceExpression; | ||
| 30 | import com.strobel.decompiler.languages.java.ast.ThisReferenceExpression; | ||
| 27 | 31 | ||
| 28 | import cuchaz.enigma.mapping.ArgumentEntry; | 32 | import cuchaz.enigma.mapping.ArgumentEntry; |
| 29 | import cuchaz.enigma.mapping.BehaviorEntry; | 33 | import cuchaz.enigma.mapping.BehaviorEntry; |
| @@ -58,14 +62,49 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor | |||
| 58 | public Void visitInvocationExpression( InvocationExpression node, SourceIndex index ) | 62 | public Void visitInvocationExpression( InvocationExpression node, SourceIndex index ) |
| 59 | { | 63 | { |
| 60 | MemberReference ref = node.getUserData( Keys.MEMBER_REFERENCE ); | 64 | MemberReference ref = node.getUserData( Keys.MEMBER_REFERENCE ); |
| 65 | |||
| 66 | // get the behavior entry | ||
| 61 | ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); | 67 | ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); |
| 62 | if( node.getTarget() instanceof MemberReferenceExpression ) | 68 | BehaviorEntry behaviorEntry = null; |
| 69 | if( ref instanceof MethodReference ) | ||
| 63 | { | 70 | { |
| 64 | MethodEntry methodEntry = new MethodEntry( classEntry, ref.getName(), ref.getSignature() ); | 71 | MethodReference methodRef = (MethodReference)ref; |
| 65 | index.addReference( | 72 | if( methodRef.isConstructor() ) |
| 66 | ((MemberReferenceExpression)node.getTarget()).getMemberNameToken(), | 73 | { |
| 67 | new EntryReference<Entry,Entry>( methodEntry, m_behaviorEntry ) | 74 | behaviorEntry = new ConstructorEntry( classEntry, ref.getSignature() ); |
| 68 | ); | 75 | } |
| 76 | else if( methodRef.isTypeInitializer() ) | ||
| 77 | { | ||
| 78 | behaviorEntry = new ConstructorEntry( classEntry ); | ||
| 79 | } | ||
| 80 | else | ||
| 81 | { | ||
| 82 | behaviorEntry = new MethodEntry( classEntry, ref.getName(), ref.getSignature() ); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | if( behaviorEntry != null ) | ||
| 86 | { | ||
| 87 | // get the node for the token | ||
| 88 | AstNode tokenNode = null; | ||
| 89 | if( node.getTarget() instanceof MemberReferenceExpression ) | ||
| 90 | { | ||
| 91 | tokenNode = ((MemberReferenceExpression)node.getTarget()).getMemberNameToken(); | ||
| 92 | } | ||
| 93 | else if( node.getTarget() instanceof SuperReferenceExpression ) | ||
| 94 | { | ||
| 95 | tokenNode = node.getTarget(); | ||
| 96 | } | ||
| 97 | else if( node.getTarget() instanceof ThisReferenceExpression ) | ||
| 98 | { | ||
| 99 | tokenNode = node.getTarget(); | ||
| 100 | } | ||
| 101 | if( tokenNode != null ) | ||
| 102 | { | ||
| 103 | index.addReference( | ||
| 104 | tokenNode, | ||
| 105 | new EntryReference<Entry,Entry>( behaviorEntry, m_behaviorEntry ) | ||
| 106 | ); | ||
| 107 | } | ||
| 69 | } | 108 | } |
| 70 | 109 | ||
| 71 | return recurse( node, index ); | 110 | return recurse( node, index ); |
diff --git a/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java b/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java index a1c82711..b7897268 100644 --- a/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java +++ b/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java | |||
| @@ -97,7 +97,6 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor | |||
| 97 | ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() ); | 97 | ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() ); |
| 98 | ConstructorEntry constructorEntry = new ConstructorEntry( classEntry, def.getSignature() ); | 98 | ConstructorEntry constructorEntry = new ConstructorEntry( classEntry, def.getSignature() ); |
| 99 | index.addDeclaration( node.getNameToken(), constructorEntry ); | 99 | index.addDeclaration( node.getNameToken(), constructorEntry ); |
| 100 | |||
| 101 | return node.acceptVisitor( new SourceIndexBehaviorVisitor( constructorEntry ), index ); | 100 | return node.acceptVisitor( new SourceIndexBehaviorVisitor( constructorEntry ), index ); |
| 102 | } | 101 | } |
| 103 | 102 | ||