Skip to content

Commit 74a0537

Browse files
committed
changes only when tab selected
1 parent 3194093 commit 74a0537

File tree

4 files changed

+54
-52
lines changed

4 files changed

+54
-52
lines changed

src/main/java/cn/enaium/joe/gui/panel/CodeAreaPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void actionPerformed(ActionEvent e) {
102102
// Create an object defining our search parameters.
103103
SearchContext context = new SearchContext();
104104
String text = searchField.getText();
105-
if (text.length() == 0) {
105+
if (text.isEmpty()) {
106106
return;
107107
}
108108
context.setSearchFor(text);

src/main/java/cn/enaium/joe/gui/panel/file/tabbed/tab/classes/ASMifierTablePanel.java

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
import cn.enaium.joe.gui.panel.CodeAreaPanel;
2525
import cn.enaium.joe.util.*;
2626
import cn.enaium.joe.util.classes.ASMClassLoader;
27-
import cn.enaium.joe.util.reflection.ReflectionHelper;
2827
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
29-
import org.objectweb.asm.ClassReader;
3028
import org.objectweb.asm.util.ASMifier;
3129
import org.objectweb.asm.util.TraceClassVisitor;
3230

@@ -44,42 +42,44 @@ public ASMifierTablePanel(ClassNode classNode) {
4442
setLayout(new BorderLayout());
4543
CodeAreaPanel codeAreaPanel = this.codeAreaPanel = new CodeAreaPanel() {{
4644
KeyStrokeUtil.register(getTextArea(), JavaOctetEditor.getInstance().config.getByClass(ApplicationConfig.class).keymap.getValue().save.getValue(), () -> {
47-
try {
48-
String className = "ASMifier" + Integer.toHexString(classNode.getInternalName().hashCode()) + Integer.toHexString(getTextArea().getText().hashCode());
49-
String stringBuilder =
50-
"import org.objectweb.asm.AnnotationVisitor;" +
51-
"import org.objectweb.asm.Attribute;" +
52-
"import org.objectweb.asm.ClassReader;" +
53-
"import org.objectweb.asm.ClassWriter;" +
54-
"import org.objectweb.asm.ConstantDynamic;" +
55-
"import org.objectweb.asm.FieldVisitor;" +
56-
"import org.objectweb.asm.Handle;" +
57-
"import org.objectweb.asm.Label;" +
58-
"import org.objectweb.asm.MethodVisitor;" +
59-
"import org.objectweb.asm.Opcodes;" +
60-
"import org.objectweb.asm.RecordComponentVisitor;" +
61-
"import org.objectweb.asm.ModuleVisitor;" +
62-
"import org.objectweb.asm.Type;" +
63-
"import org.objectweb.asm.TypePath;" +
64-
"public class " + className + " implements Opcodes" +
65-
"{" +
66-
"public static byte[] dump() throws Exception {" +
67-
getTextArea().getText() +
68-
"return classWriter.toByteArray();" +
69-
"}" +
70-
"}";
45+
if (ClassTabPanel.classTabIndex == 2) {
46+
try {
47+
String className = "ASMifier" + Integer.toHexString(classNode.getInternalName().hashCode()) + Integer.toHexString(getTextArea().getText().hashCode());
48+
String stringBuilder =
49+
"import org.objectweb.asm.AnnotationVisitor;" +
50+
"import org.objectweb.asm.Attribute;" +
51+
"import org.objectweb.asm.ClassReader;" +
52+
"import org.objectweb.asm.ClassWriter;" +
53+
"import org.objectweb.asm.ConstantDynamic;" +
54+
"import org.objectweb.asm.FieldVisitor;" +
55+
"import org.objectweb.asm.Handle;" +
56+
"import org.objectweb.asm.Label;" +
57+
"import org.objectweb.asm.MethodVisitor;" +
58+
"import org.objectweb.asm.Opcodes;" +
59+
"import org.objectweb.asm.RecordComponentVisitor;" +
60+
"import org.objectweb.asm.ModuleVisitor;" +
61+
"import org.objectweb.asm.Type;" +
62+
"import org.objectweb.asm.TypePath;" +
63+
"public class " + className + " implements Opcodes" +
64+
"{" +
65+
"public static byte[] dump() throws Exception {" +
66+
getTextArea().getText() +
67+
"return classWriter.toByteArray();" +
68+
"}" +
69+
"}";
7170

72-
StringWriter errorTracer = new StringWriter();
73-
byte[] dumpClazz = Compiler.compileSingle(className, stringBuilder, errorTracer);
74-
if (dumpClazz == null) {
75-
MessageUtil.error(errorTracer.toString());
71+
StringWriter errorTracer = new StringWriter();
72+
byte[] dumpClazz = Compiler.compileSingle(className, stringBuilder, errorTracer);
73+
if (dumpClazz == null) {
74+
MessageUtil.error(errorTracer.toString());
75+
}
76+
byte[] dumps = (byte[])new ASMClassLoader().defineClass(className, dumpClazz).getMethod("dump").invoke(null);
77+
classNode.accept(ClassNode.of(dumps));
78+
MessageUtil.info(LangUtil.i18n("success"));
79+
EditSaveSuccessEvent.trigger(classNode.getInternalName());
80+
} catch (Throwable e) {
81+
MessageUtil.error(e);
7682
}
77-
byte[] dumps = (byte[])new ASMClassLoader().defineClass(className, dumpClazz).getMethod("dump").invoke(null);
78-
classNode.accept(ClassNode.of(dumps));
79-
MessageUtil.info(LangUtil.i18n("success"));
80-
EditSaveSuccessEvent.trigger(classNode.getInternalName());
81-
} catch (Throwable e) {
82-
MessageUtil.error(e);
8383
}
8484
});
8585
}};

src/main/java/cn/enaium/joe/gui/panel/file/tabbed/tab/classes/DecompileTabPanel.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,19 @@ public DecompileTabPanel(ClassNode classNode) {
4040
setLayout(new BorderLayout());
4141
CodeAreaPanel codeAreaPanel = this.codeAreaPanel = new CodeAreaPanel() {{
4242
KeyStrokeUtil.register(getTextArea(), JavaOctetEditor.getInstance().config.getByClass(ApplicationConfig.class).keymap.getValue().save.getValue(), () -> {
43-
try {
44-
StringWriter tracer = new StringWriter();
45-
byte[] clazz = Compiler.compileSingle(classNode.getCanonicalName(), getTextArea().getText(), tracer);
46-
if (clazz == null) {
47-
MessageUtil.error("Compile failed \n" + tracer);
43+
if (ClassTabPanel.classTabIndex == 1) {
44+
try {
45+
StringWriter tracer = new StringWriter();
46+
byte[] clazz = Compiler.compileSingle(classNode.getCanonicalName(), getTextArea().getText(), tracer);
47+
if (clazz == null) {
48+
MessageUtil.error("Compile failed \n" + tracer);
49+
}
50+
classNode.accept(ClassNode.of(clazz));
51+
MessageUtil.info(LangUtil.i18n("success"));
52+
EditSaveSuccessEvent.trigger(classNode.getInternalName());
53+
} catch (Throwable e) {
54+
MessageUtil.error(e);
4855
}
49-
classNode.accept(ClassNode.of(clazz));
50-
MessageUtil.info(LangUtil.i18n("success"));
51-
EditSaveSuccessEvent.trigger(classNode.getInternalName());
52-
} catch (Throwable e) {
53-
MessageUtil.error(e);
5456
}
5557
});
5658
}};

src/main/java/cn/enaium/joe/gui/panel/file/tree/FileTreeCellRenderer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean
4646
setIcon(new FlatSVGIcon("icons/package.svg"));
4747
if (packageTreeNode instanceof ClassTreeNode) {
4848
ClassNode classNode = ((ClassTreeNode) packageTreeNode).classNode;
49-
if (classNode.getClassNode().access == (Opcodes.ACC_PUBLIC | Opcodes.ACC_ANNOTATION | Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE)) {
49+
if (classNode.getAccess() == (Opcodes.ACC_PUBLIC | Opcodes.ACC_ANNOTATION | Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE)) {
5050
setIcon(new FlatSVGIcon("icons/annotation.svg"));
51-
} else if (classNode.getClassNode().access == (Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE)) {
51+
} else if (classNode.getAccess() == (Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE)) {
5252
setIcon(new FlatSVGIcon("icons/interface.svg"));
53-
} else if (classNode.getClassNode().access == (Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_ABSTRACT)) {
53+
} else if (classNode.getAccess() == (Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_ABSTRACT)) {
5454
setIcon(new FlatSVGIcon("icons/abstractClass.svg"));
55-
} else if (classNode.getClassNode().access == (Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_SUPER | Opcodes.ACC_ENUM)) {
55+
} else if (classNode.getAccess() == (Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_SUPER | Opcodes.ACC_ENUM)) {
5656
setIcon(new FlatSVGIcon("icons/enum.svg"));
57-
} else if (classNode.getClassNode().access == (Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_SUPER)) {
57+
} else if (classNode.getAccess() == (Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_SUPER)) {
5858
setIcon(new FlatSVGIcon("icons/finalClass.svg"));
5959
} else {
6060
setIcon(new FlatSVGIcon("icons/class.svg"));

0 commit comments

Comments
 (0)