Store a SketchCode instance in RunnerException

Previously, the index of the SketchCode instance in the list kept by
Sketch was kept, which isn't really robust.

With this change, Sketch.indexOfCode is no longer needed and is removed.
This commit is contained in:
Matthijs Kooijman 2015-12-17 15:25:00 +01:00 committed by Martino Facchin
parent a07a9ff895
commit dfa60dacc1
4 changed files with 20 additions and 27 deletions

View File

@ -2679,8 +2679,8 @@ public class Editor extends JFrame implements RunnerListener {
if (e instanceof RunnerException) {
RunnerException re = (RunnerException) e;
if (re.hasCodeIndex()) {
selectTab(re.getCodeIndex());
if (re.hasCodeFile()) {
selectTab(findTabIndex(re.getCodeFile()));
}
if (re.hasCodeLine()) {
int line = re.getCodeLine();

View File

@ -584,8 +584,7 @@ public class Compiler implements MessageConsumer {
RunnerException exception = placeException(error, pieces[1], PApplet.parseInt(pieces[2]) - 1);
if (exception != null) {
SketchCode code = sketch.getCode(exception.getCodeIndex());
String fileName = code.getPrettyName();
String fileName = exception.getCodeFile().getPrettyName();
int lineNum = exception.getCodeLine() + 1;
s = fileName + ":" + lineNum + ": error: " + error + msg;
}
@ -616,7 +615,7 @@ public class Compiler implements MessageConsumer {
private RunnerException placeException(String message, String fileName, int line) {
for (SketchCode code : sketch.getCodes()) {
if (new File(fileName).getName().equals(code.getFileName())) {
return new RunnerException(message, sketch.indexOfCode(code), line);
return new RunnerException(message, code, line);
}
}
return null;

View File

@ -205,10 +205,6 @@ public class Sketch {
System.err.println("removeCode: internal error.. could not find code");
}
public int indexOfCode(SketchCode who) {
return codes.indexOf(who);
}
public String getName() {
return name;
}

View File

@ -23,6 +23,7 @@
package processing.app.debug;
import processing.app.SketchCode;
/**
* An exception with a line number attached that occurs
@ -31,7 +32,7 @@ package processing.app.debug;
@SuppressWarnings("serial")
public class RunnerException extends Exception {
protected String message;
protected int codeIndex;
protected SketchCode codeFile;
protected int codeLine;
protected int codeColumn;
protected boolean showStackTrace;
@ -42,23 +43,23 @@ public class RunnerException extends Exception {
}
public RunnerException(String message, boolean showStackTrace) {
this(message, -1, -1, -1, showStackTrace);
this(message, null, -1, -1, showStackTrace);
}
public RunnerException(String message, int file, int line) {
public RunnerException(String message, SketchCode file, int line) {
this(message, file, line, -1, true);
}
public RunnerException(String message, int file, int line, int column) {
public RunnerException(String message, SketchCode file, int line, int column) {
this(message, file, line, column, true);
}
public RunnerException(String message, int file, int line, int column,
public RunnerException(String message, SketchCode file, int line, int column,
boolean showStackTrace) {
this.message = message;
this.codeIndex = file;
this.codeFile = file;
this.codeLine = line;
this.codeColumn = column;
this.showStackTrace = showStackTrace;
@ -84,18 +85,17 @@ public class RunnerException extends Exception {
}
public int getCodeIndex() {
return codeIndex;
public SketchCode getCodeFile() {
return codeFile;
}
public void setCodeIndex(int index) {
codeIndex = index;
public void setCodeFile(SketchCode file) {
codeFile = file;
}
public boolean hasCodeIndex() {
return codeIndex != -1;
public boolean hasCodeFile() {
return codeFile != null;
}
@ -108,7 +108,6 @@ public class RunnerException extends Exception {
this.codeLine = line;
}
public boolean hasCodeLine() {
return codeLine != -1;
}
@ -118,7 +117,6 @@ public class RunnerException extends Exception {
this.codeColumn = column;
}
public int getCodeColumn() {
return codeColumn;
}