diff --git a/app/.gitignore b/app/.gitignore index 81e75864d6..3ddbdcaa12 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1,2 +1,3 @@ bin pde.jar +/utils/build/ diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c40365758d..f8df30c9cb 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -98,6 +98,7 @@ compose.desktop { dependencies { implementation(project(":core")) runtimeOnly(project(":java")) + implementation(project(":app:utils")) implementation(libs.flatlaf) diff --git a/app/src/processing/app/Mode.java b/app/src/processing/app/Mode.java index 29e9ad6d3a..28e5267e82 100644 --- a/app/src/processing/app/Mode.java +++ b/app/src/processing/app/Mode.java @@ -40,6 +40,7 @@ import processing.app.ui.Recent; import processing.app.ui.Toolkit; import processing.core.PApplet; +import processing.utils.SketchException; public abstract class Mode { diff --git a/app/src/processing/app/SketchException.java b/app/src/processing/app/SketchException.java deleted file mode 100644 index 4a32d2e79d..0000000000 --- a/app/src/processing/app/SketchException.java +++ /dev/null @@ -1,162 +0,0 @@ -/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - -/* - Part of the Processing project - http://processing.org - - Copyright (c) 2004-08 Ben Fry and Casey Reas - Copyright (c) 2001-04 Massachusetts Institute of Technology - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -package processing.app; - - -/** - * An exception with a line number attached that occurs - * during either pre-processing, compile, or run time. - */ -public class SketchException extends Exception { - protected String message; - protected int codeIndex; - protected int codeLine; - protected int codeColumn; - protected boolean showStackTrace; - - - public SketchException(String message) { - this(message, true); - } - - - public SketchException(String message, boolean showStackTrace) { - this(message, -1, -1, -1, showStackTrace); - } - - - public SketchException(String message, int file, int line) { - this(message, file, line, -1, true); - } - - - public SketchException(String message, int file, int line, int column) { - this(message, file, line, column, true); - } - - - public SketchException(String message, int file, int line, int column, - boolean showStackTrace) { - this.message = message; - this.codeIndex = file; - this.codeLine = line; - this.codeColumn = column; - this.showStackTrace = showStackTrace; - } - - - /** - * Override getMessage() in Throwable, so that I can set - * the message text outside the constructor. - */ - public String getMessage() { - return message; - } - - - public void setMessage(String message) { - this.message = message; - } - - - public int getCodeIndex() { - return codeIndex; - } - - - public void setCodeIndex(int index) { - codeIndex = index; - } - - - public boolean hasCodeIndex() { - return codeIndex != -1; - } - - - public int getCodeLine() { - return codeLine; - } - - - public void setCodeLine(int line) { - this.codeLine = line; - } - - - public boolean hasCodeLine() { - return codeLine != -1; - } - - - public void setCodeColumn(int column) { - this.codeColumn = column; - } - - - public int getCodeColumn() { - return codeColumn; - } - - - public void showStackTrace() { - showStackTrace = true; - } - - - public void hideStackTrace() { - showStackTrace = false; - } - - - public boolean isStackTraceEnabled() { - return showStackTrace; - } - - - /** - * Nix the java.lang crap out of an exception message - * because it scares the children. - *

- * This function must be static to be used with super() - * in each of the constructors above. - */ - /* - static public final String massage(String msg) { - if (msg.indexOf("java.lang.") == 0) { - //int dot = msg.lastIndexOf('.'); - msg = msg.substring("java.lang.".length()); - } - return msg; - //return (dot == -1) ? msg : msg.substring(dot+1); - } - */ - - - public void printStackTrace() { - if (showStackTrace) { - super.printStackTrace(); - } - } -} diff --git a/app/src/processing/app/ui/Editor.java b/app/src/processing/app/ui/Editor.java index a06cbe2383..7764a00e26 100644 --- a/app/src/processing/app/ui/Editor.java +++ b/app/src/processing/app/ui/Editor.java @@ -61,7 +61,7 @@ import processing.app.RunnerListener; import processing.app.Sketch; import processing.app.SketchCode; -import processing.app.SketchException; +import processing.utils.SketchException; import processing.app.contrib.ContributionManager; import processing.app.laf.PdeMenuItemUI; import processing.app.syntax.*; @@ -2736,6 +2736,7 @@ public void highlight(Problem p) { } int tabIndex = p.getTabIndex(); + sketch.setCurrentCode(tabIndex); // so we are looking at the right offsets below int lineNumber = p.getLineNumber(); int lineStart = textarea.getLineStartOffset(lineNumber); int lineEnd = textarea.getLineStopOffset(lineNumber); diff --git a/app/utils/build.gradle.kts b/app/utils/build.gradle.kts new file mode 100644 index 0000000000..2e73f72dad --- /dev/null +++ b/app/utils/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("java") +} + +group = "org.example" +version = "unspecified" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(platform("org.junit:junit-bom:5.10.0")) + testImplementation("org.junit.jupiter:junit-jupiter") +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/app/utils/src/main/java/processing/utils/SketchException.java b/app/utils/src/main/java/processing/utils/SketchException.java new file mode 100644 index 0000000000..a7f0e7511c --- /dev/null +++ b/app/utils/src/main/java/processing/utils/SketchException.java @@ -0,0 +1,162 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2004-08 Ben Fry and Casey Reas + Copyright (c) 2001-04 Massachusetts Institute of Technology + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package processing.utils; + + +/** + * An exception with a line number attached that occurs + * during either pre-processing, compile, or run time. + */ +public class SketchException extends Exception { + protected String message; + protected int codeIndex; + protected int codeLine; + protected int codeColumn; + protected boolean showStackTrace; + + + public SketchException(String message) { + this(message, true); + } + + + public SketchException(String message, boolean showStackTrace) { + this(message, -1, -1, -1, showStackTrace); + } + + + public SketchException(String message, int file, int line) { + this(message, file, line, -1, true); + } + + + public SketchException(String message, int file, int line, int column) { + this(message, file, line, column, true); + } + + + public SketchException(String message, int file, int line, int column, + boolean showStackTrace) { + this.message = message; + this.codeIndex = file; + this.codeLine = line; + this.codeColumn = column; + this.showStackTrace = showStackTrace; + } + + + /** + * Override getMessage() in Throwable, so that I can set + * the message text outside the constructor. + */ + public String getMessage() { + return message; + } + + + public void setMessage(String message) { + this.message = message; + } + + + public int getCodeIndex() { + return codeIndex; + } + + + public void setCodeIndex(int index) { + codeIndex = index; + } + + + public boolean hasCodeIndex() { + return codeIndex != -1; + } + + + public int getCodeLine() { + return codeLine; + } + + + public void setCodeLine(int line) { + this.codeLine = line; + } + + + public boolean hasCodeLine() { + return codeLine != -1; + } + + + public void setCodeColumn(int column) { + this.codeColumn = column; + } + + + public int getCodeColumn() { + return codeColumn; + } + + + public void showStackTrace() { + showStackTrace = true; + } + + + public void hideStackTrace() { + showStackTrace = false; + } + + + public boolean isStackTraceEnabled() { + return showStackTrace; + } + + + /** + * Nix the java.lang crap out of an exception message + * because it scares the children. + *

+ * This function must be static to be used with super() + * in each of the constructors above. + */ + /* + static public final String massage(String msg) { + if (msg.indexOf("java.lang.") == 0) { + //int dot = msg.lastIndexOf('.'); + msg = msg.substring("java.lang.".length()); + } + return msg; + //return (dot == -1) ? msg : msg.substring(dot+1); + } + */ + + + public void printStackTrace() { + if (showStackTrace) { + super.printStackTrace(); + } + } +} diff --git a/java/build.gradle.kts b/java/build.gradle.kts index 0f8e052780..2f87d39bdd 100644 --- a/java/build.gradle.kts +++ b/java/build.gradle.kts @@ -26,6 +26,7 @@ dependencies{ implementation(project(":app")) implementation(project(":core")) implementation(project(":java:preprocessor")) + implementation(project(":app:utils")) implementation(libs.eclipseJDT) implementation(libs.eclipseJDTCompiler) diff --git a/java/preprocessor/build.gradle.kts b/java/preprocessor/build.gradle.kts index c6855df06d..f2bc2a2d9f 100644 --- a/java/preprocessor/build.gradle.kts +++ b/java/preprocessor/build.gradle.kts @@ -26,6 +26,7 @@ dependencies{ implementation(libs.eclipseJDT) implementation(project(":core")) + implementation(project(":app:utils")) } mavenPublishing{ diff --git a/java/src/processing/mode/java/Commander.java b/java/src/processing/mode/java/Commander.java index 2a2ee9bc0c..b13c1a5f11 100644 --- a/java/src/processing/mode/java/Commander.java +++ b/java/src/processing/mode/java/Commander.java @@ -33,7 +33,7 @@ import processing.app.Preferences; import processing.app.RunnerListener; import processing.app.Sketch; -import processing.mode.java.preproc.SketchException; +import processing.utils.SketchException; import processing.app.Util; import processing.app.contrib.ModeContribution; import processing.core.PApplet; diff --git a/java/src/processing/mode/java/Compiler.java b/java/src/processing/mode/java/Compiler.java index 3e97931699..c7ec613b45 100644 --- a/java/src/processing/mode/java/Compiler.java +++ b/java/src/processing/mode/java/Compiler.java @@ -26,7 +26,7 @@ import processing.app.*; import processing.app.ui.Editor; import processing.core.*; -import processing.mode.java.preproc.SketchException; +import processing.utils.SketchException; import java.io.*; import java.lang.reflect.Method; diff --git a/java/src/processing/mode/java/JavaBuild.java b/java/src/processing/mode/java/JavaBuild.java index aed0bc1327..b09f7d8dc0 100644 --- a/java/src/processing/mode/java/JavaBuild.java +++ b/java/src/processing/mode/java/JavaBuild.java @@ -46,7 +46,7 @@ import processing.mode.java.preproc.ImportStatement; import processing.mode.java.preproc.PdePreprocessor; import processing.mode.java.preproc.PreprocessorResult; -import processing.mode.java.preproc.SketchException; +import processing.utils.SketchException; public class JavaBuild { @@ -281,8 +281,8 @@ public PreprocessorResult preprocess(File srcFolder, Library library = null; try{ library = mode.getLibrary(entry); - }catch (processing.app.SketchException e){ - throw new SketchException(e.getMessage(), e.getCodeIndex(), e.getCodeLine(), e.getCodeColumn(), e.isStackTraceEnabled()); + }catch (processing.utils.SketchException e){ + throw e; } if (library != null) { @@ -345,7 +345,7 @@ public PreprocessorResult preprocess(File srcFolder, for (SketchCode sc : sketch.getCode()) { if (sc.isExtension("java")) { // In most cases, no pre-processing services necessary for Java files. - // Just write the the contents of 'program' to a .java file + // Just write the contents of 'program' to a .java file // into the build directory. However, if a default package is being // used (as in Android), and no package is specified in the source, // then we need to move this code to the same package as the sketch. diff --git a/java/src/processing/mode/java/JavaMode.java b/java/src/processing/mode/java/JavaMode.java index ca448368eb..31d189ff52 100644 --- a/java/src/processing/mode/java/JavaMode.java +++ b/java/src/processing/mode/java/JavaMode.java @@ -33,7 +33,7 @@ import processing.app.ui.EditorException; import processing.app.ui.EditorState; -import processing.mode.java.preproc.SketchException; +import processing.utils.SketchException; import processing.mode.java.runner.Runner; import processing.mode.java.tweak.SketchParser; diff --git a/java/src/processing/mode/java/PreprocService.java b/java/src/processing/mode/java/PreprocService.java index 4f91505613..410cff02f6 100644 --- a/java/src/processing/mode/java/PreprocService.java +++ b/java/src/processing/mode/java/PreprocService.java @@ -62,6 +62,8 @@ import processing.data.IntList; import processing.data.StringList; +import processing.utils.SketchException; + /** * Service which preprocesses code to check for and report on issues. diff --git a/java/src/processing/mode/java/RuntimePathBuilder.java b/java/src/processing/mode/java/RuntimePathBuilder.java index f60471e0af..ad3ec0e010 100644 --- a/java/src/processing/mode/java/RuntimePathBuilder.java +++ b/java/src/processing/mode/java/RuntimePathBuilder.java @@ -38,7 +38,7 @@ import processing.app.*; import processing.mode.java.preproc.ImportStatement; - +import processing.utils.SketchException; /** * Builder which generates runtime paths using a series of caches. diff --git a/java/src/processing/mode/java/preproc/PdePreprocessor.java b/java/src/processing/mode/java/preproc/PdePreprocessor.java index 8217268162..91c74565c9 100644 --- a/java/src/processing/mode/java/preproc/PdePreprocessor.java +++ b/java/src/processing/mode/java/preproc/PdePreprocessor.java @@ -32,6 +32,7 @@ import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.ParseTreeWalker; import processing.app.Preferences; +import processing.utils.SketchException; /** diff --git a/java/src/processing/mode/java/preproc/SketchException.java b/java/src/processing/mode/java/preproc/SketchException.java deleted file mode 100644 index 47a0bba533..0000000000 --- a/java/src/processing/mode/java/preproc/SketchException.java +++ /dev/null @@ -1,162 +0,0 @@ -/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - -/* - Part of the Processing project - http://processing.org - - Copyright (c) 2004-08 Ben Fry and Casey Reas - Copyright (c) 2001-04 Massachusetts Institute of Technology - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -package processing.mode.java.preproc; - - -/** - * An exception with a line number attached that occurs - * during either pre-processing, compile, or run time. - */ -public class SketchException extends Exception { - protected String message; - protected int codeIndex; - protected int codeLine; - protected int codeColumn; - protected boolean showStackTrace; - - - public SketchException(String message) { - this(message, true); - } - - - public SketchException(String message, boolean showStackTrace) { - this(message, -1, -1, -1, showStackTrace); - } - - - public SketchException(String message, int file, int line) { - this(message, file, line, -1, true); - } - - - public SketchException(String message, int file, int line, int column) { - this(message, file, line, column, true); - } - - - public SketchException(String message, int file, int line, int column, - boolean showStackTrace) { - this.message = message; - this.codeIndex = file; - this.codeLine = line; - this.codeColumn = column; - this.showStackTrace = showStackTrace; - } - - - /** - * Override getMessage() in Throwable, so that I can set - * the message text outside the constructor. - */ - public String getMessage() { - return message; - } - - - public void setMessage(String message) { - this.message = message; - } - - - public int getCodeIndex() { - return codeIndex; - } - - - public void setCodeIndex(int index) { - codeIndex = index; - } - - - public boolean hasCodeIndex() { - return codeIndex != -1; - } - - - public int getCodeLine() { - return codeLine; - } - - - public void setCodeLine(int line) { - this.codeLine = line; - } - - - public boolean hasCodeLine() { - return codeLine != -1; - } - - - public void setCodeColumn(int column) { - this.codeColumn = column; - } - - - public int getCodeColumn() { - return codeColumn; - } - - - public void showStackTrace() { - showStackTrace = true; - } - - - public void hideStackTrace() { - showStackTrace = false; - } - - - public boolean isStackTraceEnabled() { - return showStackTrace; - } - - - /** - * Nix the java.lang crap out of an exception message - * because it scares the children. - *

- * This function must be static to be used with super() - * in each of the constructors above. - */ - /* - static public final String massage(String msg) { - if (msg.indexOf("java.lang.") == 0) { - //int dot = msg.lastIndexOf('.'); - msg = msg.substring("java.lang.".length()); - } - return msg; - //return (dot == -1) ? msg : msg.substring(dot+1); - } - */ - - - public void printStackTrace() { - if (showStackTrace) { - super.printStackTrace(); - } - } -} diff --git a/java/src/processing/mode/java/runner/Runner.java b/java/src/processing/mode/java/runner/Runner.java index b4dc517707..c6f6b217f7 100644 --- a/java/src/processing/mode/java/runner/Runner.java +++ b/java/src/processing/mode/java/runner/Runner.java @@ -43,7 +43,7 @@ import com.sun.jdi.connect.Connector.Argument; import com.sun.jdi.event.*; import com.sun.jdi.request.*; -import processing.mode.java.preproc.SketchException; +import processing.utils.SketchException; /** diff --git a/java/test/processing/mode/java/ParserTests.java b/java/test/processing/mode/java/ParserTests.java index c4717a7959..df34795f06 100644 --- a/java/test/processing/mode/java/ParserTests.java +++ b/java/test/processing/mode/java/ParserTests.java @@ -17,7 +17,7 @@ import processing.app.Preferences; import processing.mode.java.preproc.PreprocessorResult; import processing.mode.java.preproc.PdePreprocessIssueException; -import processing.mode.java.preproc.SketchException; +import processing.utils.SketchException; public class ParserTests { diff --git a/java/test/processing/mode/java/ProcessingTestUtil.java b/java/test/processing/mode/java/ProcessingTestUtil.java index 40f42d5575..37cf5ca0be 100644 --- a/java/test/processing/mode/java/ProcessingTestUtil.java +++ b/java/test/processing/mode/java/ProcessingTestUtil.java @@ -10,7 +10,7 @@ import processing.mode.java.preproc.PdePreprocessor; import processing.mode.java.preproc.PreprocessorResult; import processing.mode.java.preproc.PdePreprocessIssueException; -import processing.mode.java.preproc.SketchException; +import processing.utils.SketchException; public class ProcessingTestUtil { diff --git a/java/test/processing/mode/java/RuntimePathFactoryTestUtil.java b/java/test/processing/mode/java/RuntimePathFactoryTestUtil.java index 665f9761d5..ef37322456 100644 --- a/java/test/processing/mode/java/RuntimePathFactoryTestUtil.java +++ b/java/test/processing/mode/java/RuntimePathFactoryTestUtil.java @@ -23,7 +23,7 @@ import org.mockito.Mockito; import processing.app.Library; import processing.app.Sketch; -import processing.app.SketchException; +import processing.utils.SketchException; import processing.mode.java.preproc.ImportStatement; import java.io.File; diff --git a/settings.gradle.kts b/settings.gradle.kts index 4bdcd880e8..8f8cb74c7f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -11,4 +11,5 @@ include( "java:libraries:pdf", "java:libraries:serial", "java:libraries:svg", -) \ No newline at end of file +) +include("app:utils") \ No newline at end of file