mirror of
https://github.com/processing/processing4.git
synced 2026-05-09 12:22:43 +02:00
Merge pull request #1196 from joshgiesbrecht/SketchException-refactor-redo
Refactoring `SketchException` to be available outside of `app`
This commit is contained in:
@@ -98,6 +98,7 @@ compose.desktop {
|
||||
dependencies {
|
||||
implementation(project(":core"))
|
||||
runtimeOnly(project(":java"))
|
||||
implementation(project(":app:utils"))
|
||||
|
||||
implementation(libs.flatlaf)
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ import processing.app.ui.ExamplesFrame;
|
||||
import processing.app.ui.Recent;
|
||||
import processing.app.ui.Toolkit;
|
||||
import processing.core.PApplet;
|
||||
import processing.utils.SketchException;
|
||||
|
||||
|
||||
public abstract class Mode {
|
||||
|
||||
@@ -1,162 +1,30 @@
|
||||
/* -*- 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
|
||||
*/
|
||||
// temporary band-aid class to support modes which are still looking here for the now-refactored class.
|
||||
// - josh giesbrecht
|
||||
|
||||
package processing.app;
|
||||
|
||||
@Deprecated
|
||||
// please migrate to using processing.utils.SketchException instead! all class functionality is the same as before.
|
||||
public class SketchException extends processing.utils.SketchException {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* <P>
|
||||
* 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());
|
||||
// Idea complained without all these super wrappers for constructors. ¯\_(ツ)_/¯ sure, why not?
|
||||
public SketchException(String message) {
|
||||
super(message);
|
||||
}
|
||||
return msg;
|
||||
//return (dot == -1) ? msg : msg.substring(dot+1);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public void printStackTrace() {
|
||||
if (showStackTrace) {
|
||||
super.printStackTrace();
|
||||
public SketchException(String message, boolean showStackTrace) {
|
||||
super(message, showStackTrace);
|
||||
}
|
||||
|
||||
public SketchException(String message, int file, int line) {
|
||||
super(message, file, line);
|
||||
}
|
||||
|
||||
public SketchException(String message, int file, int line, int column) {
|
||||
super(message, file, line, column);
|
||||
}
|
||||
|
||||
public SketchException(String message, int file, int line, int column, boolean showStackTrace) {
|
||||
super(message, file, line, column, showStackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ import processing.app.Problem;
|
||||
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.*;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
plugins {
|
||||
id("java")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation(platform("org.junit:junit-bom:5.10.0"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
@@ -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.
|
||||
* <P>
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -26,6 +26,7 @@ dependencies{
|
||||
implementation(libs.eclipseJDT)
|
||||
|
||||
implementation(project(":core"))
|
||||
implementation(project(":app:utils"))
|
||||
}
|
||||
|
||||
mavenPublishing{
|
||||
|
||||
@@ -33,7 +33,7 @@ import processing.app.Platform;
|
||||
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;
|
||||
|
||||
@@ -26,7 +26,7 @@ package processing.mode.java;
|
||||
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;
|
||||
|
||||
@@ -46,7 +46,7 @@ import processing.data.XML;
|
||||
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 class JavaBuild {
|
||||
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 class JavaBuild {
|
||||
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.
|
||||
|
||||
@@ -33,7 +33,7 @@ import processing.app.ui.Editor;
|
||||
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;
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ import processing.mode.java.preproc.TextTransform.OffsetMapper;
|
||||
import processing.data.IntList;
|
||||
import processing.data.StringList;
|
||||
|
||||
import processing.utils.SketchException;
|
||||
|
||||
|
||||
/**
|
||||
* Service which preprocesses code to check for and report on issues.
|
||||
|
||||
@@ -38,7 +38,7 @@ import com.google.classpath.ClassPathFactory;
|
||||
|
||||
import processing.app.*;
|
||||
import processing.mode.java.preproc.ImportStatement;
|
||||
|
||||
import processing.utils.SketchException;
|
||||
|
||||
/**
|
||||
* Builder which generates runtime paths using a series of caches.
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
import processing.app.Preferences;
|
||||
import processing.utils.SketchException;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
* <P>
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ import com.sun.jdi.connect.*;
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.junit.Test;
|
||||
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 {
|
||||
|
||||
@@ -10,7 +10,7 @@ import processing.app.Preferences;
|
||||
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 {
|
||||
|
||||
@@ -23,7 +23,7 @@ package processing.mode.java;
|
||||
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;
|
||||
|
||||
+2
-1
@@ -11,4 +11,5 @@ include(
|
||||
"java:libraries:pdf",
|
||||
"java:libraries:serial",
|
||||
"java:libraries:svg",
|
||||
)
|
||||
)
|
||||
include("app:utils")
|
||||
Reference in New Issue
Block a user