summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/gui/CodeReader.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/CodeReader.java')
-rw-r--r--src/main/java/cuchaz/enigma/gui/CodeReader.java57
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;
16import cuchaz.enigma.analysis.EntryReference; 16import cuchaz.enigma.analysis.EntryReference;
17import cuchaz.enigma.analysis.SourceIndex; 17import cuchaz.enigma.analysis.SourceIndex;
18import cuchaz.enigma.analysis.Token; 18import cuchaz.enigma.analysis.Token;
19import cuchaz.enigma.gui.highlight.SelectionHighlightPainter; 19import cuchaz.enigma.translation.representation.entry.ClassEntry;
20import cuchaz.enigma.mapping.entry.ClassEntry; 20import cuchaz.enigma.translation.representation.entry.Entry;
21import cuchaz.enigma.mapping.entry.Entry;
22import de.sciss.syntaxpane.DefaultSyntaxKit; 21import de.sciss.syntaxpane.DefaultSyntaxKit;
23 22
24import javax.swing.*; 23import 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}