diff options
| author | 2019-01-24 14:48:32 +0200 | |
|---|---|---|
| committer | 2019-01-24 13:48:32 +0100 | |
| commit | 00fcd0550fcdda621c2e4662f6ddd55ce673b931 (patch) | |
| tree | 6f9e4c24dbcc6d118fceec56adf7bf9d747a485c /src/main/java/cuchaz/enigma/gui/CodeReader.java | |
| parent | mark as 0.13.0-SNAPSHOT for preliminary development (diff) | |
| download | enigma-fork-00fcd0550fcdda621c2e4662f6ddd55ce673b931.tar.gz enigma-fork-00fcd0550fcdda621c2e4662f6ddd55ce673b931.tar.xz enigma-fork-00fcd0550fcdda621c2e4662f6ddd55ce673b931.zip | |
[WIP] Mapping rework (#91)
* Move packages
* Mapping & entry refactor: first pass
* Fix deobf -> obf tree remapping
* Resolve various issues
* Give all entries the potential for parents and treat inner classes as children
* Deobf UI tree elements
* Tests pass
* Sort mapping output
* Fix delta tracking
* Index separation and first pass for #97
* Keep track of remapped jar index
* Fix child entries not being remapped
* Drop non-root entries
* Track dropped mappings
* Fix enigma mapping ordering
* EntryTreeNode interface
* Small tweaks
* Naive full index remap on rename
* Entries can resolve to more than one root entry
* Support alternative resolution strategies
* Bridge method resolution
* Tests pass
* Fix mappings being used where there are none
* Fix methods with different descriptors being considered unique. closes #89
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/CodeReader.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/CodeReader.java | 57 |
1 files changed, 4 insertions, 53 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/CodeReader.java b/src/main/java/cuchaz/enigma/gui/CodeReader.java index 137c730..0810043 100644 --- a/src/main/java/cuchaz/enigma/gui/CodeReader.java +++ b/src/main/java/cuchaz/enigma/gui/CodeReader.java | |||
| @@ -16,9 +16,8 @@ import cuchaz.enigma.Deobfuscator; | |||
| 16 | import cuchaz.enigma.analysis.EntryReference; | 16 | import cuchaz.enigma.analysis.EntryReference; |
| 17 | import cuchaz.enigma.analysis.SourceIndex; | 17 | import cuchaz.enigma.analysis.SourceIndex; |
| 18 | import cuchaz.enigma.analysis.Token; | 18 | import cuchaz.enigma.analysis.Token; |
| 19 | import cuchaz.enigma.gui.highlight.SelectionHighlightPainter; | 19 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 20 | import cuchaz.enigma.mapping.entry.ClassEntry; | 20 | import cuchaz.enigma.translation.representation.entry.Entry; |
| 21 | import cuchaz.enigma.mapping.entry.Entry; | ||
| 22 | import de.sciss.syntaxpane.DefaultSyntaxKit; | 21 | import de.sciss.syntaxpane.DefaultSyntaxKit; |
| 23 | 22 | ||
| 24 | import javax.swing.*; | 23 | import javax.swing.*; |
| @@ -33,7 +32,6 @@ public class CodeReader extends JEditorPane { | |||
| 33 | private static final long serialVersionUID = 3673180950485748810L; | 32 | private static final long serialVersionUID = 3673180950485748810L; |
| 34 | 33 | ||
| 35 | private static final Object lock = new Object(); | 34 | private static final Object lock = new Object(); |
| 36 | private SelectionHighlightPainter selectionHighlightPainter; | ||
| 37 | private SourceIndex sourceIndex; | 35 | private SourceIndex sourceIndex; |
| 38 | private SelectionListener selectionListener; | 36 | private SelectionListener selectionListener; |
| 39 | 37 | ||
| @@ -58,8 +56,6 @@ public class CodeReader extends JEditorPane { | |||
| 58 | } | 56 | } |
| 59 | } | 57 | } |
| 60 | }); | 58 | }); |
| 61 | |||
| 62 | selectionHighlightPainter = new SelectionHighlightPainter(); | ||
| 63 | } | 59 | } |
| 64 | 60 | ||
| 65 | // HACKHACK: someday we can update the main GUI to use this code reader | 61 | // HACKHACK: someday we can update the main GUI to use this code reader |
| @@ -144,7 +140,7 @@ public class CodeReader extends JEditorPane { | |||
| 144 | 140 | ||
| 145 | // decompile it | 141 | // decompile it |
| 146 | 142 | ||
| 147 | CompilationUnit sourceTree = deobfuscator.getSourceTree(classEntry.getOutermostClassName()); | 143 | CompilationUnit sourceTree = deobfuscator.getSourceTree(classEntry.getName()); |
| 148 | String source = deobfuscator.getSource(sourceTree); | 144 | String source = deobfuscator.getSource(sourceTree); |
| 149 | setCode(source); | 145 | setCode(source); |
| 150 | sourceIndex = deobfuscator.getSourceIndex(sourceTree, source, ignoreBadTokens); | 146 | sourceIndex = deobfuscator.getSourceIndex(sourceTree, source, ignoreBadTokens); |
| @@ -155,52 +151,7 @@ public class CodeReader extends JEditorPane { | |||
| 155 | }).start(); | 151 | }).start(); |
| 156 | } | 152 | } |
| 157 | 153 | ||
| 158 | public void navigateToClassDeclaration(ClassEntry classEntry) { | ||
| 159 | |||
| 160 | // navigate to the class declaration | ||
| 161 | Token token = sourceIndex.getDeclarationToken(classEntry); | ||
| 162 | if (token == null) { | ||
| 163 | // couldn't find the class declaration token, might be an anonymous class | ||
| 164 | // look for any declaration in that class instead | ||
| 165 | for (Entry entry : sourceIndex.declarations()) { | ||
| 166 | if (entry.getOwnerClassEntry().equals(classEntry)) { | ||
| 167 | token = sourceIndex.getDeclarationToken(entry); | ||
| 168 | break; | ||
| 169 | } | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | if (token != null) { | ||
| 174 | navigateToToken(token); | ||
| 175 | } else { | ||
| 176 | // couldn't find anything =( | ||
| 177 | System.out.println("Unable to find declaration in source for " + classEntry); | ||
| 178 | } | ||
| 179 | } | ||
| 180 | |||
| 181 | public void navigateToToken(final Token token) { | ||
| 182 | navigateToToken(this, token, selectionHighlightPainter); | ||
| 183 | } | ||
| 184 | |||
| 185 | public void setHighlightedTokens(Iterable<Token> tokens, HighlightPainter painter) { | ||
| 186 | for (Token token : tokens) { | ||
| 187 | setHighlightedToken(token, painter); | ||
| 188 | } | ||
| 189 | } | ||
| 190 | |||
| 191 | public void setHighlightedToken(Token token, HighlightPainter painter) { | ||
| 192 | try { | ||
| 193 | getHighlighter().addHighlight(token.start, token.end, painter); | ||
| 194 | } catch (BadLocationException ex) { | ||
| 195 | throw new IllegalArgumentException(ex); | ||
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | public void clearHighlights() { | ||
| 200 | getHighlighter().removeAllHighlights(); | ||
| 201 | } | ||
| 202 | |||
| 203 | public interface SelectionListener { | 154 | public interface SelectionListener { |
| 204 | void onSelect(EntryReference<Entry, Entry> reference); | 155 | void onSelect(EntryReference<Entry<?>, Entry<?>> reference); |
| 205 | } | 156 | } |
| 206 | } | 157 | } |