summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/analysis
diff options
context:
space:
mode:
Diffstat (limited to 'src/cuchaz/enigma/analysis')
-rw-r--r--src/cuchaz/enigma/analysis/EntryReference.java43
-rw-r--r--src/cuchaz/enigma/analysis/JarIndex.java7
-rw-r--r--src/cuchaz/enigma/analysis/SourceIndex.java29
-rw-r--r--src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java27
-rw-r--r--src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java6
-rw-r--r--src/cuchaz/enigma/analysis/Token.java10
-rw-r--r--src/cuchaz/enigma/analysis/TreeDumpVisitor.java2
7 files changed, 83 insertions, 41 deletions
diff --git a/src/cuchaz/enigma/analysis/EntryReference.java b/src/cuchaz/enigma/analysis/EntryReference.java
index 768c113..df977fb 100644
--- a/src/cuchaz/enigma/analysis/EntryReference.java
+++ b/src/cuchaz/enigma/analysis/EntryReference.java
@@ -10,21 +10,28 @@
10 ******************************************************************************/ 10 ******************************************************************************/
11package cuchaz.enigma.analysis; 11package cuchaz.enigma.analysis;
12 12
13import java.util.Arrays;
14import java.util.List;
15
13import cuchaz.enigma.Util; 16import cuchaz.enigma.Util;
14import cuchaz.enigma.mapping.ClassEntry; 17import cuchaz.enigma.mapping.ClassEntry;
18import cuchaz.enigma.mapping.ConstructorEntry;
15import cuchaz.enigma.mapping.Entry; 19import cuchaz.enigma.mapping.Entry;
16 20
17public class EntryReference<E extends Entry, C extends Entry> 21public class EntryReference<E extends Entry, C extends Entry>
18{ 22{
23 private static final List<String> ConstructorNonNames = Arrays.asList( "this", "super" );
19 public E entry; 24 public E entry;
20 public C context; 25 public C context;
21 26
22 public EntryReference( E entry ) 27 private boolean m_isNamed;
28
29 public EntryReference( E entry, String sourceName )
23 { 30 {
24 this( entry, null ); 31 this( entry, sourceName, null );
25 } 32 }
26 33
27 public EntryReference( E entry, C context ) 34 public EntryReference( E entry, String sourceName, C context )
28 { 35 {
29 if( entry == null ) 36 if( entry == null )
30 { 37 {
@@ -33,9 +40,22 @@ public class EntryReference<E extends Entry, C extends Entry>
33 40
34 this.entry = entry; 41 this.entry = entry;
35 this.context = context; 42 this.context = context;
43
44 m_isNamed = sourceName != null && sourceName.length() > 0;
45 if( entry instanceof ConstructorEntry && ConstructorNonNames.contains( sourceName ) )
46 {
47 m_isNamed = false;
48 }
49 }
50
51 public EntryReference( E entry, C context, EntryReference<E,C> other )
52 {
53 this.entry = entry;
54 this.context = context;
55 m_isNamed = other.m_isNamed;
36 } 56 }
37 57
38 public ClassEntry getClassEntry( ) 58 public ClassEntry getLocationClassEntry( )
39 { 59 {
40 if( context != null ) 60 if( context != null )
41 { 61 {
@@ -44,6 +64,21 @@ public class EntryReference<E extends Entry, C extends Entry>
44 return entry.getClassEntry(); 64 return entry.getClassEntry();
45 } 65 }
46 66
67 public boolean isNamed( )
68 {
69 return m_isNamed;
70 }
71
72 public Entry getNameableEntry( )
73 {
74 if( entry instanceof ConstructorEntry )
75 {
76 // renaming a constructor really means renaming the class
77 return entry.getClassEntry();
78 }
79 return entry;
80 }
81
47 @Override 82 @Override
48 public int hashCode( ) 83 public int hashCode( )
49 { 84 {
diff --git a/src/cuchaz/enigma/analysis/JarIndex.java b/src/cuchaz/enigma/analysis/JarIndex.java
index a2f6bf3..604e485 100644
--- a/src/cuchaz/enigma/analysis/JarIndex.java
+++ b/src/cuchaz/enigma/analysis/JarIndex.java
@@ -277,6 +277,7 @@ public class JarIndex
277 } 277 }
278 EntryReference<BehaviorEntry,BehaviorEntry> reference = new EntryReference<BehaviorEntry,BehaviorEntry>( 278 EntryReference<BehaviorEntry,BehaviorEntry> reference = new EntryReference<BehaviorEntry,BehaviorEntry>(
279 calledMethodEntry, 279 calledMethodEntry,
280 call.getMethodName(),
280 behaviorEntry 281 behaviorEntry
281 ); 282 );
282 m_behaviorReferences.put( calledMethodEntry, reference ); 283 m_behaviorReferences.put( calledMethodEntry, reference );
@@ -300,6 +301,7 @@ public class JarIndex
300 } 301 }
301 EntryReference<FieldEntry,BehaviorEntry> reference = new EntryReference<FieldEntry,BehaviorEntry>( 302 EntryReference<FieldEntry,BehaviorEntry> reference = new EntryReference<FieldEntry,BehaviorEntry>(
302 calledFieldEntry, 303 calledFieldEntry,
304 call.getFieldName(),
303 behaviorEntry 305 behaviorEntry
304 ); 306 );
305 m_fieldReferences.put( calledFieldEntry, reference ); 307 m_fieldReferences.put( calledFieldEntry, reference );
@@ -308,9 +310,6 @@ public class JarIndex
308 @Override 310 @Override
309 public void edit( ConstructorCall call ) 311 public void edit( ConstructorCall call )
310 { 312 {
311 // TODO: save isSuper in the reference somehow
312 boolean isSuper = call.getMethodName().equals( "super" );
313
314 String className = Descriptor.toJvmName( call.getClassName() ); 313 String className = Descriptor.toJvmName( call.getClassName() );
315 ConstructorEntry calledConstructorEntry = new ConstructorEntry( 314 ConstructorEntry calledConstructorEntry = new ConstructorEntry(
316 new ClassEntry( className ), 315 new ClassEntry( className ),
@@ -318,6 +317,7 @@ public class JarIndex
318 ); 317 );
319 EntryReference<BehaviorEntry,BehaviorEntry> reference = new EntryReference<BehaviorEntry,BehaviorEntry>( 318 EntryReference<BehaviorEntry,BehaviorEntry> reference = new EntryReference<BehaviorEntry,BehaviorEntry>(
320 calledConstructorEntry, 319 calledConstructorEntry,
320 call.getMethodName(),
321 behaviorEntry 321 behaviorEntry
322 ); 322 );
323 m_behaviorReferences.put( calledConstructorEntry, reference ); 323 m_behaviorReferences.put( calledConstructorEntry, reference );
@@ -333,6 +333,7 @@ public class JarIndex
333 ); 333 );
334 EntryReference<BehaviorEntry,BehaviorEntry> reference = new EntryReference<BehaviorEntry,BehaviorEntry>( 334 EntryReference<BehaviorEntry,BehaviorEntry> reference = new EntryReference<BehaviorEntry,BehaviorEntry>(
335 calledConstructorEntry, 335 calledConstructorEntry,
336 call.getClassName(),
336 behaviorEntry 337 behaviorEntry
337 ); 338 );
338 m_behaviorReferences.put( calledConstructorEntry, reference ); 339 m_behaviorReferences.put( calledConstructorEntry, reference );
diff --git a/src/cuchaz/enigma/analysis/SourceIndex.java b/src/cuchaz/enigma/analysis/SourceIndex.java
index 38d10da..faae1a1 100644
--- a/src/cuchaz/enigma/analysis/SourceIndex.java
+++ b/src/cuchaz/enigma/analysis/SourceIndex.java
@@ -21,6 +21,7 @@ import com.google.common.collect.Maps;
21import com.google.common.collect.Multimap; 21import com.google.common.collect.Multimap;
22import com.strobel.decompiler.languages.Region; 22import com.strobel.decompiler.languages.Region;
23import com.strobel.decompiler.languages.java.ast.AstNode; 23import com.strobel.decompiler.languages.java.ast.AstNode;
24import com.strobel.decompiler.languages.java.ast.Identifier;
24 25
25import cuchaz.enigma.mapping.Entry; 26import cuchaz.enigma.mapping.Entry;
26 27
@@ -58,40 +59,54 @@ public class SourceIndex
58 59
59 public Token getToken( AstNode node ) 60 public Token getToken( AstNode node )
60 { 61 {
62 // get the text of the node
63 String name = "";
64 if( node instanceof Identifier )
65 {
66 name = ((Identifier)node).getName();
67 }
68
61 // get a token for this node's region 69 // get a token for this node's region
62 Region region = node.getRegion(); 70 Region region = node.getRegion();
63 if( region.getBeginLine() == 0 || region.getEndLine() == 0 ) 71 if( region.getBeginLine() == 0 || region.getEndLine() == 0 )
64 { 72 {
65 // DEBUG 73 // DEBUG
66 //System.err.println( "WARNING: " + node.getNodeType() + " node has invalid region: " + region ); 74 System.err.println( String.format( "WARNING: %s \"%s\" has invalid region: %s", node.getNodeType(), name, region ) );
67 return null; 75 return null;
68 } 76 }
69 Token token = new Token( 77 Token token = new Token(
70 toPos( region.getBeginLine(), region.getBeginColumn() ), 78 toPos( region.getBeginLine(), region.getBeginColumn() ),
71 toPos( region.getEndLine(), region.getEndColumn() ) 79 toPos( region.getEndLine(), region.getEndColumn() ),
80 m_source
72 ); 81 );
73 if( token.start == 0 ) 82 if( token.start == 0 )
74 { 83 {
75 // DEBUG 84 // DEBUG
76 //System.err.println( "WARNING: " + node.getNodeType() + " node has invalid start: " + region ); 85 System.err.println( String.format( "WARNING: %s \"%s\" has invalid start: %s", node.getNodeType(), name, region ) );
77 return null; 86 return null;
78 } 87 }
79 88
89 // DEBUG
90 //System.out.println( String.format( "%s \"%s\" region: %s", node.getNodeType(), name, region ) );
91
92 /* TODO: double check that we still need this
80 // for tokens representing inner classes, make sure we only get the simple name 93 // for tokens representing inner classes, make sure we only get the simple name
81 int pos = node.toString().lastIndexOf( '$' ); 94 int pos = node.getText().lastIndexOf( '$' );
82 if( pos >= 0 ) 95 if( pos >= 0 )
83 { 96 {
84 token.end -= pos + 1; 97 token.end -= pos + 1;
85 } 98 }
99 */
86 100
87 return token; 101 return token;
88 } 102 }
89 103
90 public void addReference( AstNode node, EntryReference<Entry,Entry> deobfReference ) 104 public void addReference( AstNode node, Entry deobfEntry, Entry deobfContext )
91 { 105 {
92 Token token = getToken( node ); 106 Token token = getToken( node );
93 if( token != null ) 107 if( token != null )
94 { 108 {
109 EntryReference<Entry,Entry> deobfReference = new EntryReference<Entry,Entry>( deobfEntry, token.text, deobfContext );
95 m_tokenToReference.put( token, deobfReference ); 110 m_tokenToReference.put( token, deobfReference );
96 m_referenceToTokens.put( deobfReference, token ); 111 m_referenceToTokens.put( deobfReference, token );
97 } 112 }
@@ -102,7 +117,7 @@ public class SourceIndex
102 Token token = getToken( node ); 117 Token token = getToken( node );
103 if( token != null ) 118 if( token != null )
104 { 119 {
105 EntryReference<Entry,Entry> reference = new EntryReference<Entry,Entry>( deobfEntry ); 120 EntryReference<Entry,Entry> reference = new EntryReference<Entry,Entry>( deobfEntry, token.text );
106 m_tokenToReference.put( token, reference ); 121 m_tokenToReference.put( token, reference );
107 m_referenceToTokens.put( reference, token ); 122 m_referenceToTokens.put( reference, token );
108 m_declarationToToken.put( deobfEntry, token ); 123 m_declarationToToken.put( deobfEntry, token );
@@ -111,7 +126,7 @@ public class SourceIndex
111 126
112 public Token getReferenceToken( int pos ) 127 public Token getReferenceToken( int pos )
113 { 128 {
114 Token token = m_tokenToReference.floorKey( new Token( pos, pos ) ); 129 Token token = m_tokenToReference.floorKey( new Token( pos, pos, null ) );
115 if( token != null && token.contains( pos ) ) 130 if( token != null && token.contains( pos ) )
116 { 131 {
117 return token; 132 return token;
diff --git a/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java b/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java
index f307c11..b883087 100644
--- a/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java
+++ b/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java
@@ -33,7 +33,6 @@ import cuchaz.enigma.mapping.ArgumentEntry;
33import cuchaz.enigma.mapping.BehaviorEntry; 33import cuchaz.enigma.mapping.BehaviorEntry;
34import cuchaz.enigma.mapping.ClassEntry; 34import cuchaz.enigma.mapping.ClassEntry;
35import cuchaz.enigma.mapping.ConstructorEntry; 35import cuchaz.enigma.mapping.ConstructorEntry;
36import cuchaz.enigma.mapping.Entry;
37import cuchaz.enigma.mapping.FieldEntry; 36import cuchaz.enigma.mapping.FieldEntry;
38import cuchaz.enigma.mapping.MethodEntry; 37import cuchaz.enigma.mapping.MethodEntry;
39 38
@@ -100,10 +99,7 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor
100 } 99 }
101 if( tokenNode != null ) 100 if( tokenNode != null )
102 { 101 {
103 index.addReference( 102 index.addReference( tokenNode, behaviorEntry, m_behaviorEntry );
104 tokenNode,
105 new EntryReference<Entry,Entry>( behaviorEntry, m_behaviorEntry )
106 );
107 } 103 }
108 } 104 }
109 105
@@ -124,10 +120,7 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor
124 120
125 ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); 121 ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() );
126 FieldEntry fieldEntry = new FieldEntry( classEntry, ref.getName() ); 122 FieldEntry fieldEntry = new FieldEntry( classEntry, ref.getName() );
127 index.addReference( 123 index.addReference( node.getMemberNameToken(), fieldEntry, m_behaviorEntry );
128 node.getMemberNameToken(),
129 new EntryReference<Entry,Entry>( fieldEntry, m_behaviorEntry )
130 );
131 } 124 }
132 125
133 return recurse( node, index ); 126 return recurse( node, index );
@@ -140,10 +133,7 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor
140 if( node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY ) 133 if( node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY )
141 { 134 {
142 ClassEntry classEntry = new ClassEntry( ref.getInternalName() ); 135 ClassEntry classEntry = new ClassEntry( ref.getInternalName() );
143 index.addReference( 136 index.addReference( node.getIdentifierToken(), classEntry, m_behaviorEntry );
144 node.getIdentifierToken(),
145 new EntryReference<Entry,Entry>( classEntry, m_behaviorEntry )
146 );
147 } 137 }
148 138
149 return recurse( node, index ); 139 return recurse( node, index );
@@ -178,10 +168,7 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor
178 { 168 {
179 ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); 169 ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() );
180 FieldEntry fieldEntry = new FieldEntry( classEntry, ref.getName() ); 170 FieldEntry fieldEntry = new FieldEntry( classEntry, ref.getName() );
181 index.addReference( 171 index.addReference( node.getIdentifierToken(), fieldEntry, m_behaviorEntry );
182 node.getIdentifierToken(),
183 new EntryReference<Entry,Entry>( fieldEntry, m_behaviorEntry )
184 );
185 } 172 }
186 173
187 return recurse( node, index ); 174 return recurse( node, index );
@@ -197,10 +184,8 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor
197 ConstructorEntry constructorEntry = new ConstructorEntry( classEntry, ref.getSignature() ); 184 ConstructorEntry constructorEntry = new ConstructorEntry( classEntry, ref.getSignature() );
198 if( node.getType() instanceof SimpleType ) 185 if( node.getType() instanceof SimpleType )
199 { 186 {
200 index.addReference( 187 SimpleType simpleTypeNode = (SimpleType)node.getType();
201 ((SimpleType)node.getType()).getIdentifierToken(), 188 index.addReference( simpleTypeNode.getIdentifierToken(), constructorEntry, m_behaviorEntry );
202 new EntryReference<Entry,Entry>( constructorEntry, m_behaviorEntry )
203 );
204 } 189 }
205 } 190 }
206 191
diff --git a/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java b/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java
index 5d8a383..fc8cd66 100644
--- a/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java
+++ b/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java
@@ -28,7 +28,6 @@ import cuchaz.enigma.mapping.BehaviorEntry;
28import cuchaz.enigma.mapping.BehaviorEntryFactory; 28import cuchaz.enigma.mapping.BehaviorEntryFactory;
29import cuchaz.enigma.mapping.ClassEntry; 29import cuchaz.enigma.mapping.ClassEntry;
30import cuchaz.enigma.mapping.ConstructorEntry; 30import cuchaz.enigma.mapping.ConstructorEntry;
31import cuchaz.enigma.mapping.Entry;
32import cuchaz.enigma.mapping.FieldEntry; 31import cuchaz.enigma.mapping.FieldEntry;
33 32
34public class SourceIndexClassVisitor extends SourceIndexVisitor 33public class SourceIndexClassVisitor extends SourceIndexVisitor
@@ -63,10 +62,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor
63 if( node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY ) 62 if( node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY )
64 { 63 {
65 ClassEntry classEntry = new ClassEntry( ref.getInternalName() ); 64 ClassEntry classEntry = new ClassEntry( ref.getInternalName() );
66 index.addReference( 65 index.addReference( node.getIdentifierToken(), classEntry, m_classEntry );
67 node.getIdentifierToken(),
68 new EntryReference<Entry,Entry>( classEntry, m_classEntry )
69 );
70 } 66 }
71 67
72 return recurse( node, index ); 68 return recurse( node, index );
diff --git a/src/cuchaz/enigma/analysis/Token.java b/src/cuchaz/enigma/analysis/Token.java
index d0f2b70..5e70db7 100644
--- a/src/cuchaz/enigma/analysis/Token.java
+++ b/src/cuchaz/enigma/analysis/Token.java
@@ -14,11 +14,21 @@ public class Token implements Comparable<Token>
14{ 14{
15 public int start; 15 public int start;
16 public int end; 16 public int end;
17 public String text;
17 18
18 public Token( int start, int end ) 19 public Token( int start, int end )
19 { 20 {
21 this( start, end, null );
22 }
23
24 public Token( int start, int end, String source )
25 {
20 this.start = start; 26 this.start = start;
21 this.end = end; 27 this.end = end;
28 if( source != null )
29 {
30 this.text = source.substring( start, end );
31 }
22 } 32 }
23 33
24 public boolean contains( int pos ) 34 public boolean contains( int pos )
diff --git a/src/cuchaz/enigma/analysis/TreeDumpVisitor.java b/src/cuchaz/enigma/analysis/TreeDumpVisitor.java
index 12febef..e6ecb10 100644
--- a/src/cuchaz/enigma/analysis/TreeDumpVisitor.java
+++ b/src/cuchaz/enigma/analysis/TreeDumpVisitor.java
@@ -141,7 +141,7 @@ public class TreeDumpVisitor implements IAstVisitor<Void, Void>
141 { 141 {
142 if( node instanceof Identifier ) 142 if( node instanceof Identifier )
143 { 143 {
144 return "\"" + node.getText() + "\""; 144 return "\"" + ((Identifier)node).getName() + "\"";
145 } 145 }
146 return ""; 146 return "";
147 } 147 }