diff options
| author | 2020-06-03 13:39:42 -0400 | |
|---|---|---|
| committer | 2020-06-03 18:39:42 +0100 | |
| commit | 0f47403d0220757fed189b76e2071e25b1025cb8 (patch) | |
| tree | 879bf72c4476f0a5e0d82da99d7ff2b2276bcaca /src/test/java/cuchaz/enigma/TokenChecker.java | |
| parent | Fix search dialog hanging for a short time sometimes (#250) (diff) | |
| download | enigma-fork-0f47403d0220757fed189b76e2071e25b1025cb8.tar.gz enigma-fork-0f47403d0220757fed189b76e2071e25b1025cb8.tar.xz enigma-fork-0f47403d0220757fed189b76e2071e25b1025cb8.zip | |
Split GUI code to separate module (#242)
* Split into modules
* Post merge compile fixes
Co-authored-by: modmuss50 <modmuss50@gmail.com>
Diffstat (limited to 'src/test/java/cuchaz/enigma/TokenChecker.java')
| -rw-r--r-- | src/test/java/cuchaz/enigma/TokenChecker.java | 65 |
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 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import com.google.common.collect.Lists; | ||
| 15 | import cuchaz.enigma.analysis.ClassCache; | ||
| 16 | import cuchaz.enigma.analysis.EntryReference; | ||
| 17 | import cuchaz.enigma.source.SourceIndex; | ||
| 18 | import cuchaz.enigma.source.*; | ||
| 19 | import cuchaz.enigma.analysis.Token; | ||
| 20 | import cuchaz.enigma.translation.representation.entry.Entry; | ||
| 21 | |||
| 22 | import java.io.IOException; | ||
| 23 | import java.nio.file.Path; | ||
| 24 | import java.util.Collection; | ||
| 25 | import java.util.List; | ||
| 26 | |||
| 27 | public 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 | } | ||