Skip to content

Commit 198f593

Browse files
authored
Merge pull request #1196 from joshgiesbrecht/SketchException-refactor-redo
Refactoring `SketchException` to be available outside of `app`
2 parents 9805bba + 627eafb commit 198f593

21 files changed

+219
-327
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ compose.desktop {
9898
dependencies {
9999
implementation(project(":core"))
100100
runtimeOnly(project(":java"))
101+
implementation(project(":app:utils"))
101102

102103
implementation(libs.flatlaf)
103104

app/src/processing/app/Mode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import processing.app.ui.Recent;
4141
import processing.app.ui.Toolkit;
4242
import processing.core.PApplet;
43+
import processing.utils.SketchException;
4344

4445

4546
public abstract class Mode {
Lines changed: 19 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,162 +1,30 @@
1-
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2-
3-
/*
4-
Part of the Processing project - http://processing.org
5-
6-
Copyright (c) 2004-08 Ben Fry and Casey Reas
7-
Copyright (c) 2001-04 Massachusetts Institute of Technology
8-
9-
This program is free software; you can redistribute it and/or modify
10-
it under the terms of the GNU General Public License as published by
11-
the Free Software Foundation; either version 2 of the License, or
12-
(at your option) any later version.
13-
14-
This program is distributed in the hope that it will be useful,
15-
but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17-
GNU General Public License for more details.
18-
19-
You should have received a copy of the GNU General Public License
20-
along with this program; if not, write to the Free Software Foundation,
21-
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22-
*/
1+
// temporary band-aid class to support modes which are still looking here for the now-refactored class.
2+
// - josh giesbrecht
233

244
package processing.app;
255

6+
@Deprecated
7+
// please migrate to using processing.utils.SketchException instead! all class functionality is the same as before.
8+
public class SketchException extends processing.utils.SketchException {
269

27-
/**
28-
* An exception with a line number attached that occurs
29-
* during either pre-processing, compile, or run time.
30-
*/
31-
public class SketchException extends Exception {
32-
protected String message;
33-
protected int codeIndex;
34-
protected int codeLine;
35-
protected int codeColumn;
36-
protected boolean showStackTrace;
37-
38-
39-
public SketchException(String message) {
40-
this(message, true);
41-
}
42-
43-
44-
public SketchException(String message, boolean showStackTrace) {
45-
this(message, -1, -1, -1, showStackTrace);
46-
}
47-
48-
49-
public SketchException(String message, int file, int line) {
50-
this(message, file, line, -1, true);
51-
}
52-
53-
54-
public SketchException(String message, int file, int line, int column) {
55-
this(message, file, line, column, true);
56-
}
57-
58-
59-
public SketchException(String message, int file, int line, int column,
60-
boolean showStackTrace) {
61-
this.message = message;
62-
this.codeIndex = file;
63-
this.codeLine = line;
64-
this.codeColumn = column;
65-
this.showStackTrace = showStackTrace;
66-
}
67-
68-
69-
/**
70-
* Override getMessage() in Throwable, so that I can set
71-
* the message text outside the constructor.
72-
*/
73-
public String getMessage() {
74-
return message;
75-
}
76-
77-
78-
public void setMessage(String message) {
79-
this.message = message;
80-
}
81-
82-
83-
public int getCodeIndex() {
84-
return codeIndex;
85-
}
86-
87-
88-
public void setCodeIndex(int index) {
89-
codeIndex = index;
90-
}
91-
92-
93-
public boolean hasCodeIndex() {
94-
return codeIndex != -1;
95-
}
96-
97-
98-
public int getCodeLine() {
99-
return codeLine;
100-
}
101-
102-
103-
public void setCodeLine(int line) {
104-
this.codeLine = line;
105-
}
106-
107-
108-
public boolean hasCodeLine() {
109-
return codeLine != -1;
110-
}
111-
112-
113-
public void setCodeColumn(int column) {
114-
this.codeColumn = column;
115-
}
116-
117-
118-
public int getCodeColumn() {
119-
return codeColumn;
120-
}
121-
122-
123-
public void showStackTrace() {
124-
showStackTrace = true;
125-
}
126-
127-
128-
public void hideStackTrace() {
129-
showStackTrace = false;
130-
}
131-
132-
133-
public boolean isStackTraceEnabled() {
134-
return showStackTrace;
135-
}
10+
// Idea complained without all these super wrappers for constructors. ¯\_(ツ)_/¯ sure, why not?
11+
public SketchException(String message) {
12+
super(message);
13+
}
13614

15+
public SketchException(String message, boolean showStackTrace) {
16+
super(message, showStackTrace);
17+
}
13718

138-
/**
139-
* Nix the java.lang crap out of an exception message
140-
* because it scares the children.
141-
* <P>
142-
* This function must be static to be used with super()
143-
* in each of the constructors above.
144-
*/
145-
/*
146-
static public final String massage(String msg) {
147-
if (msg.indexOf("java.lang.") == 0) {
148-
//int dot = msg.lastIndexOf('.');
149-
msg = msg.substring("java.lang.".length());
19+
public SketchException(String message, int file, int line) {
20+
super(message, file, line);
15021
}
151-
return msg;
152-
//return (dot == -1) ? msg : msg.substring(dot+1);
153-
}
154-
*/
15522

23+
public SketchException(String message, int file, int line, int column) {
24+
super(message, file, line, column);
25+
}
15626

157-
public void printStackTrace() {
158-
if (showStackTrace) {
159-
super.printStackTrace();
27+
public SketchException(String message, int file, int line, int column, boolean showStackTrace) {
28+
super(message, file, line, column, showStackTrace);
16029
}
161-
}
16230
}

app/src/processing/app/ui/Editor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
import processing.app.RunnerListener;
6262
import processing.app.Sketch;
6363
import processing.app.SketchCode;
64-
import processing.app.SketchException;
64+
import processing.utils.SketchException;
6565
import processing.app.contrib.ContributionManager;
6666
import processing.app.laf.PdeMenuItemUI;
6767
import processing.app.syntax.*;

app/utils/build.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
plugins {
2+
id("java")
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
testImplementation(platform("org.junit:junit-bom:5.10.0"))
11+
testImplementation("org.junit.jupiter:junit-jupiter")
12+
}
13+
14+
tasks.test {
15+
useJUnitPlatform()
16+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
3+
/*
4+
Part of the Processing project - http://processing.org
5+
6+
Copyright (c) 2004-08 Ben Fry and Casey Reas
7+
Copyright (c) 2001-04 Massachusetts Institute of Technology
8+
9+
This program is free software; you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation; either version 2 of the License, or
12+
(at your option) any later version.
13+
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with this program; if not, write to the Free Software Foundation,
21+
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22+
*/
23+
24+
package processing.utils;
25+
26+
27+
/**
28+
* An exception with a line number attached that occurs
29+
* during either pre-processing, compile, or run time.
30+
*/
31+
public class SketchException extends Exception {
32+
protected String message;
33+
protected int codeIndex;
34+
protected int codeLine;
35+
protected int codeColumn;
36+
protected boolean showStackTrace;
37+
38+
39+
public SketchException(String message) {
40+
this(message, true);
41+
}
42+
43+
44+
public SketchException(String message, boolean showStackTrace) {
45+
this(message, -1, -1, -1, showStackTrace);
46+
}
47+
48+
49+
public SketchException(String message, int file, int line) {
50+
this(message, file, line, -1, true);
51+
}
52+
53+
54+
public SketchException(String message, int file, int line, int column) {
55+
this(message, file, line, column, true);
56+
}
57+
58+
59+
public SketchException(String message, int file, int line, int column,
60+
boolean showStackTrace) {
61+
this.message = message;
62+
this.codeIndex = file;
63+
this.codeLine = line;
64+
this.codeColumn = column;
65+
this.showStackTrace = showStackTrace;
66+
}
67+
68+
69+
/**
70+
* Override getMessage() in Throwable, so that I can set
71+
* the message text outside the constructor.
72+
*/
73+
public String getMessage() {
74+
return message;
75+
}
76+
77+
78+
public void setMessage(String message) {
79+
this.message = message;
80+
}
81+
82+
83+
public int getCodeIndex() {
84+
return codeIndex;
85+
}
86+
87+
88+
public void setCodeIndex(int index) {
89+
codeIndex = index;
90+
}
91+
92+
93+
public boolean hasCodeIndex() {
94+
return codeIndex != -1;
95+
}
96+
97+
98+
public int getCodeLine() {
99+
return codeLine;
100+
}
101+
102+
103+
public void setCodeLine(int line) {
104+
this.codeLine = line;
105+
}
106+
107+
108+
public boolean hasCodeLine() {
109+
return codeLine != -1;
110+
}
111+
112+
113+
public void setCodeColumn(int column) {
114+
this.codeColumn = column;
115+
}
116+
117+
118+
public int getCodeColumn() {
119+
return codeColumn;
120+
}
121+
122+
123+
public void showStackTrace() {
124+
showStackTrace = true;
125+
}
126+
127+
128+
public void hideStackTrace() {
129+
showStackTrace = false;
130+
}
131+
132+
133+
public boolean isStackTraceEnabled() {
134+
return showStackTrace;
135+
}
136+
137+
138+
/**
139+
* Nix the java.lang crap out of an exception message
140+
* because it scares the children.
141+
* <P>
142+
* This function must be static to be used with super()
143+
* in each of the constructors above.
144+
*/
145+
/*
146+
static public final String massage(String msg) {
147+
if (msg.indexOf("java.lang.") == 0) {
148+
//int dot = msg.lastIndexOf('.');
149+
msg = msg.substring("java.lang.".length());
150+
}
151+
return msg;
152+
//return (dot == -1) ? msg : msg.substring(dot+1);
153+
}
154+
*/
155+
156+
157+
public void printStackTrace() {
158+
if (showStackTrace) {
159+
super.printStackTrace();
160+
}
161+
}
162+
}

java/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies{
2626
implementation(project(":app"))
2727
implementation(project(":core"))
2828
implementation(project(":java:preprocessor"))
29+
implementation(project(":app:utils"))
2930

3031
implementation(libs.eclipseJDT)
3132
implementation(libs.eclipseJDTCompiler)

0 commit comments

Comments
 (0)