summaryrefslogtreecommitdiff
path: root/src/test/java/cuchaz/enigma/TokenChecker.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/cuchaz/enigma/TokenChecker.java')
-rw-r--r--src/test/java/cuchaz/enigma/TokenChecker.java32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/test/java/cuchaz/enigma/TokenChecker.java b/src/test/java/cuchaz/enigma/TokenChecker.java
index 0746320..c6ced48 100644
--- a/src/test/java/cuchaz/enigma/TokenChecker.java
+++ b/src/test/java/cuchaz/enigma/TokenChecker.java
@@ -4,34 +4,34 @@
4 * are made available under the terms of the GNU Lesser General Public 4 * are made available under the terms of the GNU Lesser General Public
5 * License v3.0 which accompanies this distribution, and is available at 5 * License v3.0 which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html 6 * http://www.gnu.org/licenses/lgpl.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * Jeff Martin - initial API and implementation 9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/ 10 ******************************************************************************/
11package cuchaz.enigma;
12 11
13import java.io.IOException; 12package cuchaz.enigma;
14import java.util.Collection;
15import java.util.List;
16import java.util.jar.JarFile;
17 13
18import com.google.common.collect.Lists; 14import com.google.common.collect.Lists;
19import com.strobel.decompiler.languages.java.ast.CompilationUnit; 15import com.strobel.decompiler.languages.java.ast.CompilationUnit;
20
21import cuchaz.enigma.analysis.EntryReference; 16import cuchaz.enigma.analysis.EntryReference;
22import cuchaz.enigma.analysis.SourceIndex; 17import cuchaz.enigma.analysis.SourceIndex;
23import cuchaz.enigma.analysis.Token; 18import cuchaz.enigma.analysis.Token;
24import cuchaz.enigma.mapping.Entry; 19import cuchaz.enigma.mapping.Entry;
25 20
21import java.io.IOException;
22import java.util.Collection;
23import java.util.List;
24import java.util.jar.JarFile;
25
26public class TokenChecker { 26public class TokenChecker {
27 27
28 private Deobfuscator deobfuscator; 28 private Deobfuscator deobfuscator;
29 29
30 protected TokenChecker(JarFile jarFile) 30 protected TokenChecker(JarFile jarFile)
31 throws IOException { 31 throws IOException {
32 deobfuscator = new Deobfuscator(jarFile); 32 deobfuscator = new Deobfuscator(jarFile);
33 } 33 }
34 34
35 protected String getDeclarationToken(Entry entry) { 35 protected String getDeclarationToken(Entry entry) {
36 // decompile the class 36 // decompile the class
37 CompilationUnit tree = deobfuscator.getSourceTree(entry.getClassName()); 37 CompilationUnit tree = deobfuscator.getSourceTree(entry.getClassName());
@@ -39,7 +39,7 @@ public class TokenChecker {
39 // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null ); 39 // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null );
40 String source = deobfuscator.getSource(tree); 40 String source = deobfuscator.getSource(tree);
41 SourceIndex index = deobfuscator.getSourceIndex(tree, source); 41 SourceIndex index = deobfuscator.getSourceIndex(tree, source);
42 42
43 // get the token value 43 // get the token value
44 Token token = index.getDeclarationToken(entry); 44 Token token = index.getDeclarationToken(entry);
45 if (token == null) { 45 if (token == null) {
@@ -47,17 +47,17 @@ public class TokenChecker {
47 } 47 }
48 return source.substring(token.start, token.end); 48 return source.substring(token.start, token.end);
49 } 49 }
50 50
51 @SuppressWarnings("unchecked") 51 @SuppressWarnings("unchecked")
52 protected Collection<String> getReferenceTokens(EntryReference<? extends Entry,? extends Entry> reference) { 52 protected Collection<String> getReferenceTokens(EntryReference<? extends Entry, ? extends Entry> reference) {
53 // decompile the class 53 // decompile the class
54 CompilationUnit tree = deobfuscator.getSourceTree(reference.context.getClassName()); 54 CompilationUnit tree = deobfuscator.getSourceTree(reference.context.getClassName());
55 String source = deobfuscator.getSource(tree); 55 String source = deobfuscator.getSource(tree);
56 SourceIndex index = deobfuscator.getSourceIndex(tree, source); 56 SourceIndex index = deobfuscator.getSourceIndex(tree, source);
57 57
58 // get the token values 58 // get the token values
59 List<String> values = Lists.newArrayList(); 59 List<String> values = Lists.newArrayList();
60 for (Token token : index.getReferenceTokens((EntryReference<Entry,Entry>)reference)) { 60 for (Token token : index.getReferenceTokens((EntryReference<Entry, Entry>) reference)) {
61 values.add(source.substring(token.start, token.end)); 61 values.add(source.substring(token.start, token.end));
62 } 62 }
63 return values; 63 return values;