Skip to content

Commit 794acbe

Browse files
committed
Customize syntax highlighting for bytecode
1 parent 506e012 commit 794acbe

File tree

7 files changed

+7521
-5
lines changed

7 files changed

+7521
-5
lines changed

src/main/java/the/bytecode/club/jda/JDA.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package the.bytecode.club.jda;
22

33
import org.apache.commons.io.FileUtils;
4+
import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory;
5+
import org.fife.ui.rsyntaxtextarea.TokenMakerFactory;
46
import org.objectweb.asm.ClassReader;
57
import org.objectweb.asm.ClassWriter;
68
import org.objectweb.asm.tree.ClassNode;
79
import the.bytecode.club.jda.api.ExceptionUI;
810
import the.bytecode.club.jda.api.Plugin;
911
import the.bytecode.club.jda.api.PluginLoader;
1012
import the.bytecode.club.jda.gui.MainViewerGUI;
13+
import the.bytecode.club.jda.gui.fileviewer.BytecodeTokenizer;
1114
import the.bytecode.club.jda.gui.navigation.FileNavigationPane;
1215
import the.bytecode.club.jda.settings.Settings;
1316

@@ -98,6 +101,9 @@ else if (!pluginsDir.isDirectory())
98101
}
99102

100103
public static void onGUILoad() {
104+
AbstractTokenMakerFactory atmf = (AbstractTokenMakerFactory)TokenMakerFactory.getDefaultInstance();
105+
atmf.putMapping(BytecodeTokenizer.SYNTAX_STYLE_BYTECODE, "the.bytecode.club.jda.gui.fileviewer.BytecodeTokenizer");
106+
101107
plugins.forEach(Plugin::onGUILoad);
102108
}
103109

src/main/java/the/bytecode/club/jda/api/ExceptionUI.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ private void setup(Throwable e, String author) {
6767
JDA.nl + JDA.nl + sw.toString());
6868
this.setLocationRelativeTo(null);
6969
this.setVisible(true);
70-
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
7170
}
7271

7372
private void setup(String e, String author) {
@@ -84,7 +83,6 @@ private void setup(String e, String author) {
8483
System.err.println(e);
8584
this.setLocationRelativeTo(null);
8685
this.setVisible(true);
87-
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
8886
}
8987

9088
}

src/main/java/the/bytecode/club/jda/decompilers/bytecode/InstructionPrinter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public ArrayList<String> createPrint() {
104104
if (firstLabel && parent.createLabelBrackets())
105105
info.add("}");
106106

107-
line = printLabelnode((LabelNode) ain);
107+
line = printLabelnode((LabelNode) ain) + ":";
108108

109109
if (parent.createLabelBrackets()) {
110110
if (!firstLabel)
@@ -156,6 +156,7 @@ public ArrayList<String> createPrint() {
156156
protected String printVarInsnNode(VarInsnNode vin, ListIterator<?> it) {
157157
StringBuilder sb = new StringBuilder();
158158
sb.append(nameOpcode(vin.opcode()));
159+
sb.append(" ");
159160
sb.append(vin.var);
160161
if (parent.createComments()) {
161162
if (vin.var == 0 && !Modifier.isStatic(mNode.access)) {

src/main/java/the/bytecode/club/jda/gui/PaneUpdaterThread.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import the.bytecode.club.jda.JDA;
77
import the.bytecode.club.jda.api.ExceptionUI;
88
import the.bytecode.club.jda.decompilers.JDADecompiler;
9+
import the.bytecode.club.jda.decompilers.bytecode.BytecodeDecompiler;
10+
import the.bytecode.club.jda.gui.fileviewer.BytecodeTokenizer;
911
import the.bytecode.club.jda.gui.fileviewer.ClassViewer;
1012
import the.bytecode.club.jda.settings.Settings;
1113

@@ -36,7 +38,7 @@ public PaneUpdaterThread(ClassViewer viewer, JDADecompiler decompiler, int paneI
3638
public void run() {
3739
try {
3840
RSyntaxTextArea panelArea = new RSyntaxTextArea();
39-
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
41+
panelArea.setSyntaxEditingStyle(decompiler instanceof BytecodeDecompiler ? BytecodeTokenizer.SYNTAX_STYLE_BYTECODE : SyntaxConstants.SYNTAX_STYLE_JAVA);
4042
panelArea.setCodeFoldingEnabled(true);
4143
panelArea.setAntiAliasingEnabled(true);
4244
final RTextScrollPane scrollPane = new RTextScrollPane(panelArea);

0 commit comments

Comments
 (0)