From 33d798867ff6c4c9bade3cf8140195779a0ed02d Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Sun, 8 Nov 2015 18:46:38 +0100 Subject: [PATCH 1/5] Threading: touch UI only on AWT --- java/src/processing/mode/java/Debugger.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/java/src/processing/mode/java/Debugger.java b/java/src/processing/mode/java/Debugger.java index db972c680..dc69dc8e3 100644 --- a/java/src/processing/mode/java/Debugger.java +++ b/java/src/processing/mode/java/Debugger.java @@ -22,6 +22,7 @@ package processing.mode.java; import com.sun.jdi.*; import com.sun.jdi.event.*; +import com.sun.jdi.event.Event; import com.sun.jdi.request.*; import java.io.*; @@ -661,7 +662,12 @@ public class Debugger implements VMEventListener { // disallow stepping into invisible lines if (!locationIsVisible(se.location())) { // TODO: this leads to stepping, should it run on the EDT? - stepOutIntoViewOrContinue(); + javax.swing.SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + stepOutIntoViewOrContinue(); + } + }); } } From bbbfea9129b8e3471f50de3cea21e1ce9c2b5151 Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Sun, 8 Nov 2015 19:25:57 +0100 Subject: [PATCH 2/5] Fix modifiers on step button Fixes #4116 --- java/src/processing/mode/java/JavaEditor.java | 8 ++++---- java/src/processing/mode/java/JavaToolbar.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/java/src/processing/mode/java/JavaEditor.java b/java/src/processing/mode/java/JavaEditor.java index 4314d2c68..0fa66b537 100644 --- a/java/src/processing/mode/java/JavaEditor.java +++ b/java/src/processing/mode/java/JavaEditor.java @@ -1178,11 +1178,11 @@ public class JavaEditor extends Editor { Logger.getLogger(getClass().getName()).log(Level.INFO, "Invoked 'Step Over' menu item"); debugger.stepOver(); - } else if ((modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0) { + } else if ((modifiers & ActionEvent.SHIFT_MASK) != 0) { Logger.getLogger(getClass().getName()).log(Level.INFO, "Invoked 'Step Into' menu item"); debugger.stepInto(); - } else if ((modifiers & KeyEvent.ALT_DOWN_MASK) != 0) { + } else if ((modifiers & ActionEvent.ALT_MASK) != 0) { Logger.getLogger(getClass().getName()).log(Level.INFO, "Invoked 'Step Out' menu item"); debugger.stepOut(); } @@ -1494,7 +1494,7 @@ public class JavaEditor extends Editor { item = Toolkit.newJMenuItemShift(Language.text("menu.debug.step_into"), KeyEvent.VK_J); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - handleStep(KeyEvent.SHIFT_DOWN_MASK); + handleStep(ActionEvent.SHIFT_MASK); } }); debugMenu.add(item); @@ -1503,7 +1503,7 @@ public class JavaEditor extends Editor { item = Toolkit.newJMenuItemAlt(Language.text("menu.debug.step_out"), KeyEvent.VK_J); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - handleStep(KeyEvent.ALT_DOWN_MASK); + handleStep(ActionEvent.ALT_MASK); } }); debugMenu.add(item); diff --git a/java/src/processing/mode/java/JavaToolbar.java b/java/src/processing/mode/java/JavaToolbar.java index 6ac83ca88..105b3596d 100644 --- a/java/src/processing/mode/java/JavaToolbar.java +++ b/java/src/processing/mode/java/JavaToolbar.java @@ -79,7 +79,7 @@ public class JavaToolbar extends EditorToolbar { Language.text("menu.debug.step_out")) { @Override public void actionPerformed(ActionEvent e) { - final int mask = KeyEvent.SHIFT_DOWN_MASK | KeyEvent.ALT_DOWN_MASK; + final int mask = ActionEvent.SHIFT_MASK | ActionEvent.ALT_MASK; jeditor.handleStep(e.getModifiers() & mask); } }; From 15b3a4718d85961d54ffabbce55d1b1aea1177b5 Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Sun, 8 Nov 2015 19:27:41 +0100 Subject: [PATCH 3/5] Fix crash when entering static methods Fixes #3590 --- java/src/processing/mode/java/Debugger.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java/src/processing/mode/java/Debugger.java b/java/src/processing/mode/java/Debugger.java index dc69dc8e3..8f1ccd72f 100644 --- a/java/src/processing/mode/java/Debugger.java +++ b/java/src/processing/mode/java/Debugger.java @@ -920,7 +920,8 @@ public class Debugger implements VMEventListener { if (!t.isSuspended() || t.frameCount() == 0) { return ""; } - return t.frame(0).thisObject().referenceType().name(); + ObjectReference ref = t.frame(0).thisObject(); + return ref == null ? "" : ref.referenceType().name(); } catch (IncompatibleThreadStateException ex) { log(Level.SEVERE, null, ex); From 97ad08c2da1ed5e89e4e654d853088f9abcbf5e4 Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Sun, 8 Nov 2015 19:37:03 +0100 Subject: [PATCH 4/5] Fix typo in debugger --- java/src/processing/mode/java/Debugger.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/src/processing/mode/java/Debugger.java b/java/src/processing/mode/java/Debugger.java index 8f1ccd72f..45d6ffc7a 100644 --- a/java/src/processing/mode/java/Debugger.java +++ b/java/src/processing/mode/java/Debugger.java @@ -1124,13 +1124,13 @@ public class Debugger implements VMEventListener { } else { StackFrame sf = t.frame(0); ObjectReference thisObject = sf.thisObject(); - if (this != null) { + if (thisObject != null) { ReferenceType type = thisObject.referenceType(); System.out.println("fields in this (" + type.name() + "):"); for (Field f : type.visibleFields()) { System.out.println(f.typeName() + " " + f.name() + " = " + thisObject.getValue(f)); } - } else { // TODO [this is not reachable - fry] + } else { System.out.println("can't get this (in native or static method)"); } } From 05b66536a2029e0c6a6aa11ffdf7ea5a58d0b243 Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Sun, 8 Nov 2015 19:38:33 +0100 Subject: [PATCH 5/5] Code styling --- java/src/processing/mode/java/Debugger.java | 26 +++++++++------------ 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/java/src/processing/mode/java/Debugger.java b/java/src/processing/mode/java/Debugger.java index 45d6ffc7a..ae146f20c 100644 --- a/java/src/processing/mode/java/Debugger.java +++ b/java/src/processing/mode/java/Debugger.java @@ -22,7 +22,6 @@ package processing.mode.java; import com.sun.jdi.*; import com.sun.jdi.event.*; -import com.sun.jdi.event.Event; import com.sun.jdi.request.*; import java.io.*; @@ -72,28 +71,25 @@ public class Debugger implements VMEventListener { protected ReferenceType mainClass; /// holds all loaded classes in the debuggee VM - protected Set classes = new HashSet(); + protected Set classes = new HashSet<>(); /// listeners for class load events - protected List classLoadListeners = - new ArrayList(); + protected List classLoadListeners = new ArrayList<>(); /// path to the src folder of the current build protected String srcPath; /// list of current breakpoints - protected List breakpoints = - new ArrayList(); + protected List breakpoints = new ArrayList<>(); /// the step request we are currently in, or null if not in a step protected StepRequest requestedStep; /// maps line number changes at runtime (orig -> changed) - protected Map runtimeLineChanges = - new HashMap(); + protected Map runtimeLineChanges = new HashMap<>(); /// tab filenames which already have been tracked for runtime changes - protected Set runtimeTabsTracked = new HashSet(); + protected Set runtimeTabsTracked = new HashSet<>(); public Debugger(JavaEditor editor) { @@ -521,7 +517,7 @@ public class Debugger implements VMEventListener { * @return the list of breakpoints in the given tab */ synchronized List getBreakpoints(String tabFilename) { - List list = new ArrayList(); + List list = new ArrayList<>(); for (LineBreakpoint bp : breakpoints) { if (bp.lineID().fileName().equals(tabFilename)) { list.add(bp); @@ -973,7 +969,7 @@ public class Debugger implements VMEventListener { */ protected List getLocals(ThreadReference t, int depth) { //System.out.println("getting locals"); - List vars = new ArrayList(); + List vars = new ArrayList<>(); try { if (t.frameCount() > 0) { StackFrame sf = t.frame(0); @@ -1015,7 +1011,7 @@ public class Debugger implements VMEventListener { } catch (IncompatibleThreadStateException ex) { log(Level.SEVERE, null, ex); } - return new ArrayList(); + return new ArrayList<>(); } @@ -1030,7 +1026,7 @@ public class Debugger implements VMEventListener { protected List getFields(Value value, int depth, int maxDepth, boolean includeInherited) { // remember: Value <- ObjectReference, ArrayReference - List vars = new ArrayList(); + List vars = new ArrayList<>(); if (depth <= maxDepth) { if (value instanceof ArrayReference) { return getArrayFields((ArrayReference) value); @@ -1072,7 +1068,7 @@ public class Debugger implements VMEventListener { * @return list of array fields */ protected List getArrayFields(ArrayReference array) { - List fields = new ArrayList(); + List fields = new ArrayList<>(); if (array != null) { String arrayType = array.type().name(); if (arrayType.endsWith("[]")) { @@ -1096,7 +1092,7 @@ public class Debugger implements VMEventListener { * @return call stack as list of {@link DefaultMutableTreeNode}s */ protected List getStackTrace(ThreadReference t) { - List stack = new ArrayList(); + List stack = new ArrayList<>(); try { for (StackFrame f : t.frames()) { stack.add(new DefaultMutableTreeNode(locationToString(f.location())));