Skip to content

Commit c13537a

Browse files
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.
1 parent a767e17 commit c13537a

File tree

4 files changed

+20
-27
lines changed

4 files changed

+20
-27
lines changed

app/src/processing/app/Editor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,8 +2614,8 @@ public void statusError(Exception e) {
26142614

26152615
if (e instanceof RunnerException) {
26162616
RunnerException re = (RunnerException) e;
2617-
if (re.hasCodeIndex()) {
2618-
selectTab(re.getCodeIndex());
2617+
if (re.hasCodeFile()) {
2618+
selectTab(findTabIndex(re.getCodeFile()));
26192619
}
26202620
if (re.hasCodeLine()) {
26212621
int line = re.getCodeLine();

arduino-core/src/cc/arduino/Compiler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,7 @@ public void message(String s) {
565565
RunnerException exception = placeException(error, pieces[1], PApplet.parseInt(pieces[2]) - 1);
566566

567567
if (exception != null) {
568-
SketchCode code = sketch.getCode(exception.getCodeIndex());
569-
String fileName = code.getPrettyName();
568+
String fileName = exception.getCodeFile().getPrettyName();
570569
int lineNum = exception.getCodeLine() + 1;
571570
s = fileName + ":" + lineNum + ": error: " + error + msg;
572571
}
@@ -597,7 +596,7 @@ public void message(String s) {
597596
private RunnerException placeException(String message, String fileName, int line) {
598597
for (SketchCode code : sketch.getCodes()) {
599598
if (new File(fileName).getName().equals(code.getFileName())) {
600-
return new RunnerException(message, sketch.indexOfCode(code), line);
599+
return new RunnerException(message, code, line);
601600
}
602601
}
603602
return null;

arduino-core/src/processing/app/Sketch.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,6 @@ protected void removeCode(SketchCode which) {
205205
System.err.println("removeCode: internal error.. could not find code");
206206
}
207207

208-
public int indexOfCode(SketchCode who) {
209-
return codes.indexOf(who);
210-
}
211-
212208
public String getName() {
213209
return name;
214210
}

arduino-core/src/processing/app/debug/RunnerException.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
package processing.app.debug;
2525

26+
import processing.app.SketchCode;
2627

2728
/**
2829
* An exception with a line number attached that occurs
@@ -31,7 +32,7 @@
3132
@SuppressWarnings("serial")
3233
public class RunnerException extends Exception {
3334
protected String message;
34-
protected int codeIndex;
35+
protected SketchCode codeFile;
3536
protected int codeLine;
3637
protected int codeColumn;
3738
protected boolean showStackTrace;
@@ -42,23 +43,23 @@ public RunnerException(String message) {
4243
}
4344

4445
public RunnerException(String message, boolean showStackTrace) {
45-
this(message, -1, -1, -1, showStackTrace);
46+
this(message, null, -1, -1, showStackTrace);
4647
}
4748

48-
public RunnerException(String message, int file, int line) {
49+
public RunnerException(String message, SketchCode file, int line) {
4950
this(message, file, line, -1, true);
5051
}
5152

5253

53-
public RunnerException(String message, int file, int line, int column) {
54+
public RunnerException(String message, SketchCode file, int line, int column) {
5455
this(message, file, line, column, true);
5556
}
5657

5758

58-
public RunnerException(String message, int file, int line, int column,
59+
public RunnerException(String message, SketchCode file, int line, int column,
5960
boolean showStackTrace) {
6061
this.message = message;
61-
this.codeIndex = file;
62+
this.codeFile = file;
6263
this.codeLine = line;
6364
this.codeColumn = column;
6465
this.showStackTrace = showStackTrace;
@@ -84,18 +85,17 @@ public void setMessage(String message) {
8485
}
8586

8687

87-
public int getCodeIndex() {
88-
return codeIndex;
88+
public SketchCode getCodeFile() {
89+
return codeFile;
8990
}
9091

9192

92-
public void setCodeIndex(int index) {
93-
codeIndex = index;
93+
public void setCodeFile(SketchCode file) {
94+
codeFile = file;
9495
}
95-
96-
97-
public boolean hasCodeIndex() {
98-
return codeIndex != -1;
96+
97+
public boolean hasCodeFile() {
98+
return codeFile != null;
9999
}
100100

101101

@@ -107,8 +107,7 @@ public int getCodeLine() {
107107
public void setCodeLine(int line) {
108108
this.codeLine = line;
109109
}
110-
111-
110+
112111
public boolean hasCodeLine() {
113112
return codeLine != -1;
114113
}
@@ -117,8 +116,7 @@ public boolean hasCodeLine() {
117116
public void setCodeColumn(int column) {
118117
this.codeColumn = column;
119118
}
120-
121-
119+
122120
public int getCodeColumn() {
123121
return codeColumn;
124122
}

0 commit comments

Comments
 (0)