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.java65
1 files changed, 0 insertions, 65 deletions
diff --git a/src/test/java/cuchaz/enigma/TokenChecker.java b/src/test/java/cuchaz/enigma/TokenChecker.java
deleted file mode 100644
index 48d0c83..0000000
--- a/src/test/java/cuchaz/enigma/TokenChecker.java
+++ /dev/null
@@ -1,65 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2015 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
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
6 * http://www.gnu.org/licenses/lgpl.html
7 *
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11
12package cuchaz.enigma;
13
14import com.google.common.collect.Lists;
15import cuchaz.enigma.analysis.ClassCache;
16import cuchaz.enigma.analysis.EntryReference;
17import cuchaz.enigma.source.SourceIndex;
18import cuchaz.enigma.source.*;
19import cuchaz.enigma.analysis.Token;
20import cuchaz.enigma.translation.representation.entry.Entry;
21
22import java.io.IOException;
23import java.nio.file.Path;
24import java.util.Collection;
25import java.util.List;
26
27public class TokenChecker {
28 private final Decompiler decompiler;
29
30 protected TokenChecker(Path path) throws IOException {
31 ClassCache classCache = ClassCache.of(path);
32 decompiler = Decompilers.PROCYON.create(classCache, new SourceSettings(false, false));
33 }
34
35 protected String getDeclarationToken(Entry<?> entry) {
36 // decompile the class
37 Source source = decompiler.getSource(entry.getContainingClass().getFullName());
38 // DEBUG
39 // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null );
40 String string = source.asString();
41 SourceIndex index = source.index();
42
43 // get the token value
44 Token token = index.getDeclarationToken(entry);
45 if (token == null) {
46 return null;
47 }
48 return string.substring(token.start, token.end);
49 }
50
51 @SuppressWarnings("unchecked")
52 protected Collection<String> getReferenceTokens(EntryReference<? extends Entry<?>, ? extends Entry<?>> reference) {
53 // decompile the class
54 Source source = decompiler.getSource(reference.context.getContainingClass().getFullName());
55 String string = source.asString();
56 SourceIndex index = source.index();
57
58 // get the token values
59 List<String> values = Lists.newArrayList();
60 for (Token token : index.getReferenceTokens((EntryReference<Entry<?>, Entry<?>>) reference)) {
61 values.add(string.substring(token.start, token.end));
62 }
63 return values;
64 }
65}