diff options
| author | 2018-12-08 11:21:18 +0100 | |
|---|---|---|
| committer | 2018-12-08 11:21:18 +0100 | |
| commit | 4bc3afe4ff08b9f0c08952ec7f6e0ac930280cc5 (patch) | |
| tree | 99e43aa385d7fa1248c7fe474c022db55c364592 /src/main/java/cuchaz/enigma/analysis/SourceIndex.java | |
| parent | work around Procyon weirdness (diff) | |
| download | enigma-fork-4bc3afe4ff08b9f0c08952ec7f6e0ac930280cc5.tar.gz enigma-fork-4bc3afe4ff08b9f0c08952ec7f6e0ac930280cc5.tar.xz enigma-fork-4bc3afe4ff08b9f0c08952ec7f6e0ac930280cc5.zip | |
add barebones plugin framework, cleanup
Diffstat (limited to 'src/main/java/cuchaz/enigma/analysis/SourceIndex.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/analysis/SourceIndex.java | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/SourceIndex.java b/src/main/java/cuchaz/enigma/analysis/SourceIndex.java index 78195cb..4c84e69 100644 --- a/src/main/java/cuchaz/enigma/analysis/SourceIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/SourceIndex.java | |||
| @@ -22,10 +22,7 @@ import com.strobel.decompiler.languages.java.ast.Identifier; | |||
| 22 | import com.strobel.decompiler.languages.java.ast.TypeDeclaration; | 22 | import com.strobel.decompiler.languages.java.ast.TypeDeclaration; |
| 23 | import cuchaz.enigma.mapping.entry.Entry; | 23 | import cuchaz.enigma.mapping.entry.Entry; |
| 24 | 24 | ||
| 25 | import java.util.Collection; | 25 | import java.util.*; |
| 26 | import java.util.List; | ||
| 27 | import java.util.Map; | ||
| 28 | import java.util.TreeMap; | ||
| 29 | import java.util.regex.Pattern; | 26 | import java.util.regex.Pattern; |
| 30 | 27 | ||
| 31 | public class SourceIndex { | 28 | public class SourceIndex { |
| @@ -48,9 +45,12 @@ public class SourceIndex { | |||
| 48 | this.tokenToReference = Maps.newTreeMap(); | 45 | this.tokenToReference = Maps.newTreeMap(); |
| 49 | this.referenceToTokens = HashMultimap.create(); | 46 | this.referenceToTokens = HashMultimap.create(); |
| 50 | this.declarationToToken = Maps.newHashMap(); | 47 | this.declarationToToken = Maps.newHashMap(); |
| 51 | this.lineOffsets = Lists.newArrayList(); | 48 | calculateLineOffsets(); |
| 49 | } | ||
| 52 | 50 | ||
| 51 | private void calculateLineOffsets() { | ||
| 53 | // count the lines | 52 | // count the lines |
| 53 | this.lineOffsets = Lists.newArrayList(); | ||
| 54 | this.lineOffsets.add(0); | 54 | this.lineOffsets.add(0); |
| 55 | for (int i = 0; i < source.length(); i++) { | 55 | for (int i = 0; i < source.length(); i++) { |
| 56 | if (source.charAt(i) == '\n') { | 56 | if (source.charAt(i) == '\n') { |
| @@ -59,6 +59,32 @@ public class SourceIndex { | |||
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | public void remap(String source, Map<Token, Token> tokenMap) { | ||
| 63 | this.source = source; | ||
| 64 | calculateLineOffsets(); | ||
| 65 | |||
| 66 | for (Entry entry : Lists.newArrayList(declarationToToken.keySet())) { | ||
| 67 | Token token = declarationToToken.get(entry); | ||
| 68 | declarationToToken.put(entry, tokenMap.getOrDefault(token, token)); | ||
| 69 | } | ||
| 70 | |||
| 71 | for (Token token : Lists.newArrayList(tokenToReference.keySet())) { | ||
| 72 | EntryReference<Entry, Entry> e = tokenToReference.remove(token); | ||
| 73 | tokenToReference.put(tokenMap.getOrDefault(token, token), e); | ||
| 74 | } | ||
| 75 | |||
| 76 | for (EntryReference<Entry, Entry> ref : Lists.newArrayList(referenceToTokens.keySet())) { | ||
| 77 | List<Token> newTokens = new ArrayList<>(); | ||
| 78 | |||
| 79 | for (Token token : referenceToTokens.get(ref)) { | ||
| 80 | newTokens.add(tokenMap.getOrDefault(token, token)); | ||
| 81 | } | ||
| 82 | |||
| 83 | referenceToTokens.removeAll(ref); | ||
| 84 | referenceToTokens.putAll(ref, newTokens); | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 62 | public String getSource() { | 88 | public String getSource() { |
| 63 | return this.source; | 89 | return this.source; |
| 64 | } | 90 | } |