From dfa60dacc15dce00f174fb0e0315d33a3438cc06 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Thu, 17 Dec 2015 15:25:00 +0100 Subject: [PATCH] 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. --- app/src/processing/app/Editor.java | 4 +-- arduino-core/src/cc/arduino/Compiler.java | 5 ++- arduino-core/src/processing/app/Sketch.java | 4 --- .../processing/app/debug/RunnerException.java | 34 +++++++++---------- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index d4093a82f..cf2153e94 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -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(); diff --git a/arduino-core/src/cc/arduino/Compiler.java b/arduino-core/src/cc/arduino/Compiler.java index f800f32c8..4c7632eec 100644 --- a/arduino-core/src/cc/arduino/Compiler.java +++ b/arduino-core/src/cc/arduino/Compiler.java @@ -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; diff --git a/arduino-core/src/processing/app/Sketch.java b/arduino-core/src/processing/app/Sketch.java index a7e2850af..e0d9429f4 100644 --- a/arduino-core/src/processing/app/Sketch.java +++ b/arduino-core/src/processing/app/Sketch.java @@ -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; } diff --git a/arduino-core/src/processing/app/debug/RunnerException.java b/arduino-core/src/processing/app/debug/RunnerException.java index 0a67d1e80..c5aa79520 100644 --- a/arduino-core/src/processing/app/debug/RunnerException.java +++ b/arduino-core/src/processing/app/debug/RunnerException.java @@ -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; } @@ -107,8 +107,7 @@ public class RunnerException extends Exception { public void setCodeLine(int line) { this.codeLine = line; } - - + public boolean hasCodeLine() { return codeLine != -1; } @@ -117,8 +116,7 @@ public class RunnerException extends Exception { public void setCodeColumn(int column) { this.codeColumn = column; } - - + public int getCodeColumn() { return codeColumn; }