Fix uninitalized debugger in JavaEditor.

Looks like constructor in Editor called from from JavaEditor is calling an overloaded method back in JavaEditor that expects debugger to have been initialized which is not possible since the parent constructor has not returned. This switches to loading debugger on demand (upon calling getDebugger) which allows for the Editor to use overloaded methods that expect debugger to be initialized.
This commit is contained in:
A Pottinger
2020-03-07 17:28:00 -08:00
parent 3d56960fff
commit 507e7fae54

View File

@@ -1,3 +1,4 @@
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
@@ -84,7 +85,7 @@ public class JavaEditor extends Editor {
protected PreprocService preprocService;
protected Debugger debugger;
protected Debugger debugger = null;
private InspectMode inspect;
private ShowUsage usage;
@@ -104,12 +105,11 @@ public class JavaEditor extends Editor {
super(base, path, state, mode);
jmode = (JavaMode) mode;
debugger = new Debugger(this);
// set breakpoints from marker comments
for (LineID lineID : stripBreakpointComments()) {
//System.out.println("setting: " + lineID);
debugger.setBreakpoint(lineID);
getDebugger().setBreakpoint(lineID);
}
// setting breakpoints will flag sketch as modified, so override this here
getSketch().setModified(false);
@@ -268,7 +268,7 @@ public class JavaEditor extends Editor {
public void actionPerformed(ActionEvent e) {
if (isDebuggerEnabled()) {
Messages.log("Invoked 'Stop' menu item");
debugger.stopDebug();
getDebugger().stopDebug();
} else {
handleStop();
}
@@ -1098,12 +1098,12 @@ public class JavaEditor extends Editor {
if (isDebuggerEnabled()) {
// Hitting Run while a sketch is running should restart the sketch
// https://github.com/processing/processing/issues/3623
if (debugger.isStarted()) {
debugger.stopDebug();
if (getDebugger().isStarted()) {
getDebugger().stopDebug();
}
// Don't start the sketch paused, continue until a breakpoint or error
// https://github.com/processing/processing/issues/3096
debugger.continueDebug();
getDebugger().continueDebug();
} else {
handleLaunch(false, false);
@@ -1159,9 +1159,8 @@ public class JavaEditor extends Editor {
* session or performs standard stop action if not currently debugging.
*/
public void handleStop() {
if (debugger.isStarted()) {
debugger.stopDebug();
if (getDebugger().isStarted()) {
getDebugger().stopDebug();
} else {
toolbar.activateStop();
@@ -1207,7 +1206,7 @@ public class JavaEditor extends Editor {
@Override
public void toggleBreakpoint(int lineIndex) {
debugger.toggleBreakpoint(lineIndex);
getDebugger().toggleBreakpoint(lineIndex);
}
@@ -1219,14 +1218,14 @@ public class JavaEditor extends Editor {
boolean saved = super.handleSaveAs();
if (saved) {
// re-set breakpoints in first tab (name has changed)
List<LineBreakpoint> bps = debugger.getBreakpoints(oldName);
debugger.clearBreakpoints(oldName);
List<LineBreakpoint> bps = getDebugger().getBreakpoints(oldName);
getDebugger().clearBreakpoints(oldName);
String newName = getSketch().getCode(0).getFileName();
//System.out.println("new name: " + newName);
for (LineBreakpoint bp : bps) {
LineID line = new LineID(newName, bp.lineID().lineIdx());
//System.out.println("setting: " + line);
debugger.setBreakpoint(line);
getDebugger().setBreakpoint(line);
}
// add breakpoint marker comments to source file
for (SketchCode code : getSketch().getCode()) {
@@ -1359,10 +1358,10 @@ public class JavaEditor extends Editor {
public void dispose() {
//System.out.println("window dispose");
// quit running debug session
if (debugger.isEnabled()) {
debugger.stopDebug();
if (getDebugger().isEnabled()) {
getDebugger().stopDebug();
}
debugger.dispose();
getDebugger().dispose();
preprocService.dispose();
inspect.dispose();
@@ -1379,14 +1378,14 @@ public class JavaEditor extends Editor {
@Override
public boolean isDebuggerEnabled() {
return debugger.isEnabled();
return getDebugger().isEnabled();
}
@Override
public JMenu buildModeMenu() {
//return buildDebugMenu();
return debugger.buildMenu();
return getDebugger().buildMenu();
}
@@ -1468,7 +1467,7 @@ public class JavaEditor extends Editor {
Messages.loge("Illegal tab name to addBreakpointComments() " + tabFilename);
return;
}
List<LineBreakpoint> bps = debugger.getBreakpoints(tab.getFileName());
List<LineBreakpoint> bps = getDebugger().getBreakpoints(tab.getFileName());
// load the source file
////switched to using methods provided by the SketchCode class
@@ -1536,7 +1535,7 @@ public class JavaEditor extends Editor {
*/
protected void setTabContents(String tabFilename, String code) {
// remove all breakpoints of this tab
debugger.clearBreakpoints(tabFilename);
getDebugger().clearBreakpoints(tabFilename);
SketchCode currentTab = getCurrentTab();
@@ -1609,6 +1608,9 @@ public class JavaEditor extends Editor {
public Debugger getDebugger() {
if (debugger == null) {
debugger = new Debugger(this);
}
return debugger;
}
@@ -1808,7 +1810,7 @@ public class JavaEditor extends Editor {
public void activateRun() {
debugger.enableMenuItem(false);
getDebugger().enableMenuItem(false);
toolbar.activateRun();
}
@@ -1821,7 +1823,7 @@ public class JavaEditor extends Editor {
*/
public void deactivateRun() {
toolbar.deactivateRun();
debugger.enableMenuItem(true);
getDebugger().enableMenuItem(true);
}