From 71c224f83f672272c9f6f30785340493f5a8ff97 Mon Sep 17 00:00:00 2001 From: SuspiciousActivity <38253929+SuspiciousActivity@users.noreply.github.com> Date: Fri, 12 Mar 2021 00:29:09 +0100 Subject: [PATCH] Indentation in decompilers to 4 spaces, fixed some threading issues --- src/me/ByteEdit/boxes/TypeOpenBox.java | 3 +- .../decompiler/FernflowerDecompiler.java | 1 + src/me/ByteEdit/decompiler/JDDecompiler.java | 2 +- src/me/ByteEdit/edit/TypeOpenBox.java | 3 +- src/me/ByteEdit/main/Main.java | 53 +++++++++++-------- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/me/ByteEdit/boxes/TypeOpenBox.java b/src/me/ByteEdit/boxes/TypeOpenBox.java index 26e9b73..85e6858 100644 --- a/src/me/ByteEdit/boxes/TypeOpenBox.java +++ b/src/me/ByteEdit/boxes/TypeOpenBox.java @@ -40,11 +40,10 @@ public TypeOpenBox() { DefaultListModel model = new DefaultListModel<>(); JList list = new JList(model); list.addListSelectionListener(new ListSelectionListener() { - + @Override public void valueChanged(ListSelectionEvent e) { String val = list.getSelectedValue(); if (val != null && !val.equals(Main.currentNodeName)) { - SingleThreadedExecutor.execute(() -> Main.selectFile(val)); } } diff --git a/src/me/ByteEdit/decompiler/FernflowerDecompiler.java b/src/me/ByteEdit/decompiler/FernflowerDecompiler.java index 1649784..02fef9e 100644 --- a/src/me/ByteEdit/decompiler/FernflowerDecompiler.java +++ b/src/me/ByteEdit/decompiler/FernflowerDecompiler.java @@ -63,6 +63,7 @@ public String doDecompilation(ClassNode cn, byte[] b) { for (Entry entry : options.entrySet()) { map.put(entry.getKey(), entry.getValue() ? "1" : "0"); } + map.put("ind", " "); Fernflower f = new Fernflower(this, this, map, new IFernflowerLogger() { @Override public void writeMessage(String message, Throwable t) { diff --git a/src/me/ByteEdit/decompiler/JDDecompiler.java b/src/me/ByteEdit/decompiler/JDDecompiler.java index cee2e60..5721a47 100644 --- a/src/me/ByteEdit/decompiler/JDDecompiler.java +++ b/src/me/ByteEdit/decompiler/JDDecompiler.java @@ -43,7 +43,7 @@ public byte[] load(String internalName) throws LoaderException { return cw.toByteArray(); } - protected static final String TAB = " "; + protected static final String TAB = " "; protected static final String NEWLINE = "\n"; protected int indentationCount = 0; diff --git a/src/me/ByteEdit/edit/TypeOpenBox.java b/src/me/ByteEdit/edit/TypeOpenBox.java index 5690785..470df0d 100644 --- a/src/me/ByteEdit/edit/TypeOpenBox.java +++ b/src/me/ByteEdit/edit/TypeOpenBox.java @@ -48,11 +48,10 @@ public TypeOpenBox() { DefaultListModel model = new DefaultListModel<>(); JList list = new JList(model); list.addListSelectionListener(new ListSelectionListener() { - + @Override public void valueChanged(ListSelectionEvent e) { String val = list.getSelectedValue(); if (val != null && !val.equals(Main.currentNodeName)) { - SingleThreadedExecutor.execute(() -> Main.selectFile(val)); } } diff --git a/src/me/ByteEdit/main/Main.java b/src/me/ByteEdit/main/Main.java index 0df2b92..d0c025d 100644 --- a/src/me/ByteEdit/main/Main.java +++ b/src/me/ByteEdit/main/Main.java @@ -303,7 +303,7 @@ public void run() { try { ArchiveTreeModel model = new ArchiveTreeModel(new ZipFile(jarFile), classNodes, otherFiles); - EventQueue.invokeLater(new Runnable() { + EventQueue.invokeAndWait(new Runnable() { public void run() { synchronized (treeLock) { tree.setModel(model); @@ -320,7 +320,7 @@ public void run() { } } }); - } catch (IOException e) { + } catch (Exception e) { e.printStackTrace(); } } @@ -458,7 +458,7 @@ public void run() { try { ArchiveTreeModel model = new ArchiveTreeModel(new ZipFile(jarFile), classNodes, otherFiles); - EventQueue.invokeLater(new Runnable() { + EventQueue.invokeAndWait(new Runnable() { public void run() { synchronized (treeLock) { tree.setModel(model); @@ -467,7 +467,7 @@ public void run() { } } }); - } catch (IOException e) { + } catch (Exception e) { e.printStackTrace(); } } @@ -545,7 +545,7 @@ public void run() { try { ArchiveTreeModel model = new ArchiveTreeModel(new ZipFile(jarFile), classNodes, otherFiles); - EventQueue.invokeLater(new Runnable() { + EventQueue.invokeAndWait(new Runnable() { public void run() { synchronized (treeLock) { tree.setModel(model); @@ -562,7 +562,7 @@ public void run() { } } }); - } catch (IOException e) { + } catch (Exception e) { e.printStackTrace(); } } @@ -667,12 +667,14 @@ public void itemStateChanged(ItemEvent e) { decompileCurrentNode(); try { EventQueue.invokeAndWait(() -> { - txtByteEditView.setCaretPosition(0); - try { - txtByteEditView.setSyntaxEditingStyle(decompiler.getSyntaxStyle()); - } catch (Throwable t) { + synchronized (treeLock) { + txtByteEditView.setCaretPosition(0); + try { + txtByteEditView.setSyntaxEditingStyle(decompiler.getSyntaxStyle()); + } catch (Throwable t) { + } + txtByteEditView.setEditable(decompiler.isEditable()); } - txtByteEditView.setEditable(decompiler.isEditable()); }); } catch (Exception e1) { e1.printStackTrace(); @@ -796,9 +798,14 @@ public static void decompileCurrentNode() { } } } - txtByteEditView.setText(dis); - if (dis.length() > prev) - txtByteEditView.setCaretPosition(prev); + String fdis = dis; + EventQueue.invokeAndWait(() -> { + synchronized (treeLock) { + txtByteEditView.setText(fdis); + if (fdis.length() > prev) + txtByteEditView.setCaretPosition(prev); + } + }); } catch (Exception e2) { e2.printStackTrace(); } @@ -857,14 +864,18 @@ protected JDialog createDialog(final Component parent) throws HeadlessException public void run() { synchronized (treeLock) { save(file, classNodes.values()); - EventQueue.invokeLater(new Runnable() { - public void run() { - synchronized (treeLock) { - isChangingFile = false; - Main.this.setTitle("ByteEdit"); + try { + EventQueue.invokeAndWait(new Runnable() { + public void run() { + synchronized (treeLock) { + isChangingFile = false; + Main.this.setTitle("ByteEdit"); + } } - } - }); + }); + } catch (Exception e) { + e.printStackTrace(); + } } } }).start();