summaryrefslogtreecommitdiff
path: root/src/test/java/cuchaz/enigma/TokenChecker.java
diff options
context:
space:
mode:
authorGravatar Runemoro2020-03-09 06:04:08 -0400
committerGravatar GitHub2020-03-09 10:04:08 +0000
commit58c0aeb15a65324de08a914dfa62cc68a516a4e3 (patch)
treef45e8141c0864692051149a478c5a0a6bbe68686 /src/test/java/cuchaz/enigma/TokenChecker.java
parentMade Enigma gui translatable (#193) (diff)
downloadenigma-fork-58c0aeb15a65324de08a914dfa62cc68a516a4e3.tar.gz
enigma-fork-58c0aeb15a65324de08a914dfa62cc68a516a4e3.tar.xz
enigma-fork-58c0aeb15a65324de08a914dfa62cc68a516a4e3.zip
CFR support (#192)
* Add decompiler API * Add CFR support
Diffstat (limited to 'src/test/java/cuchaz/enigma/TokenChecker.java')
-rw-r--r--src/test/java/cuchaz/enigma/TokenChecker.java27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/test/java/cuchaz/enigma/TokenChecker.java b/src/test/java/cuchaz/enigma/TokenChecker.java
index 1dde034..48d0c83 100644
--- a/src/test/java/cuchaz/enigma/TokenChecker.java
+++ b/src/test/java/cuchaz/enigma/TokenChecker.java
@@ -12,10 +12,10 @@
12package cuchaz.enigma; 12package cuchaz.enigma;
13 13
14import com.google.common.collect.Lists; 14import com.google.common.collect.Lists;
15import com.strobel.decompiler.languages.java.ast.CompilationUnit;
16import cuchaz.enigma.analysis.ClassCache; 15import cuchaz.enigma.analysis.ClassCache;
17import cuchaz.enigma.analysis.EntryReference; 16import cuchaz.enigma.analysis.EntryReference;
18import cuchaz.enigma.analysis.SourceIndex; 17import cuchaz.enigma.source.SourceIndex;
18import cuchaz.enigma.source.*;
19import cuchaz.enigma.analysis.Token; 19import cuchaz.enigma.analysis.Token;
20import cuchaz.enigma.translation.representation.entry.Entry; 20import cuchaz.enigma.translation.representation.entry.Entry;
21 21
@@ -25,43 +25,40 @@ import java.util.Collection;
25import java.util.List; 25import java.util.List;
26 26
27public class TokenChecker { 27public class TokenChecker {
28 28 private final Decompiler decompiler;
29 private SourceProvider sourceProvider;
30 29
31 protected TokenChecker(Path path) throws IOException { 30 protected TokenChecker(Path path) throws IOException {
32 ClassCache classCache = ClassCache.of(path); 31 ClassCache classCache = ClassCache.of(path);
33 32 decompiler = Decompilers.PROCYON.create(classCache, new SourceSettings(false, false));
34 CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(classCache);
35 sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader);
36 } 33 }
37 34
38 protected String getDeclarationToken(Entry<?> entry) { 35 protected String getDeclarationToken(Entry<?> entry) {
39 // decompile the class 36 // decompile the class
40 CompilationUnit tree = sourceProvider.getSources(entry.getContainingClass().getFullName()); 37 Source source = decompiler.getSource(entry.getContainingClass().getFullName());
41 // DEBUG 38 // DEBUG
42 // 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 );
43 String source = sourceProvider.writeSourceToString(tree); 40 String string = source.asString();
44 SourceIndex index = SourceIndex.buildIndex(source, tree, true); 41 SourceIndex index = source.index();
45 42
46 // get the token value 43 // get the token value
47 Token token = index.getDeclarationToken(entry); 44 Token token = index.getDeclarationToken(entry);
48 if (token == null) { 45 if (token == null) {
49 return null; 46 return null;
50 } 47 }
51 return source.substring(token.start, token.end); 48 return string.substring(token.start, token.end);
52 } 49 }
53 50
54 @SuppressWarnings("unchecked") 51 @SuppressWarnings("unchecked")
55 protected Collection<String> getReferenceTokens(EntryReference<? extends Entry<?>, ? extends Entry<?>> reference) { 52 protected Collection<String> getReferenceTokens(EntryReference<? extends Entry<?>, ? extends Entry<?>> reference) {
56 // decompile the class 53 // decompile the class
57 CompilationUnit tree = sourceProvider.getSources(reference.context.getContainingClass().getFullName()); 54 Source source = decompiler.getSource(reference.context.getContainingClass().getFullName());
58 String source = sourceProvider.writeSourceToString(tree); 55 String string = source.asString();
59 SourceIndex index = SourceIndex.buildIndex(source, tree, true); 56 SourceIndex index = source.index();
60 57
61 // get the token values 58 // get the token values
62 List<String> values = Lists.newArrayList(); 59 List<String> values = Lists.newArrayList();
63 for (Token token : index.getReferenceTokens((EntryReference<Entry<?>, Entry<?>>) reference)) { 60 for (Token token : index.getReferenceTokens((EntryReference<Entry<?>, Entry<?>>) reference)) {
64 values.add(source.substring(token.start, token.end)); 61 values.add(string.substring(token.start, token.end));
65 } 62 }
66 return values; 63 return values;
67 } 64 }