Skip to content

Commit 850f8f8

Browse files
committed
remove sketchXxxx() overrides, move size() statement to settings, cleanup AST code
1 parent 2f74bc5 commit 850f8f8

File tree

3 files changed

+45
-29
lines changed

3 files changed

+45
-29
lines changed

core/todo.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ _ args[] should be null if none passed (otherwise args == null checks are weird)
129129

130130

131131
full screen
132-
_ Fullscreen window on second monitor without using present mode
132+
_ Full screen window on second monitor without using present mode
133133
_ https://github.com/processing/processing/issues/3271
134134
_ "run sketches on display" not working in 3.0a7
135135
_ https://github.com/processing/processing/issues/3264

java/src/processing/mode/java/JavaBuild.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -245,25 +245,21 @@ public String preprocess(File srcFolder,
245245
}
246246
}
247247

248-
// // initSketchSize() sets the internal sketchWidth/Height/Renderer vars
249-
// // in the preprocessor. Those are used in preproc.write() so that they
250-
// // can be turned into sketchXxxx() methods.
251-
// // This also returns the size info as an array so that we can figure out
252-
// // if this fella is OpenGL, and if so, to add the import. It's messy and
253-
// // gross and someday we'll just always include OpenGL.
254-
// String[] sizeInfo =
248+
// initSketchSize() sets the internal sketchWidth/Height/Renderer vars
249+
// in the preprocessor. Those are used in preproc.write() so that they
250+
// can be used to add methods (settings() or sketchXxxx())
251+
String[] sizeParts =
255252
preprocessor.initSketchSize(sketch.getMainProgram(), sizeWarning);
256-
// //PdePreprocessor.parseSketchSize(sketch.getMainProgram(), false);
257-
// if (sizeInfo != null) {
258-
// String sketchRenderer = sizeInfo[3];
259-
// if (sketchRenderer != null) {
260-
// if (sketchRenderer.equals("P2D") ||
261-
// sketchRenderer.equals("P3D") ||
262-
// sketchRenderer.equals("OPENGL")) {
263-
// bigCode.insert(0, "import processing.opengl.*; ");
264-
// }
265-
// }
266-
// }
253+
//System.out.format("size() is '%s'%n", info[0]);
254+
255+
// Remove the size() statement (will be added back by writeFooter())
256+
if (sizeParts != null) {
257+
String sizeStatement = sizeParts[0];
258+
if (sizeStatement != null) {
259+
int index = bigCode.indexOf(sizeStatement);
260+
bigCode.delete(index, index + sizeStatement.length());
261+
}
262+
}
267263

268264
PreprocessorResult result;
269265
try {
@@ -1833,7 +1829,7 @@ protected void packClassPathIntoZipFile(String path,
18331829
}
18341830
}
18351831
file.close();
1836-
1832+
18371833
} catch (IOException e) {
18381834
System.err.println("Error in file " + pieces[i]);
18391835
e.printStackTrace();

java/src/processing/mode/java/preproc/PdePreprocessor.java

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,15 @@ protected void writeFooter(PrintWriter out, String className) {
939939
}
940940

941941
if ((mode == Mode.STATIC) || (mode == Mode.ACTIVE)) {
942+
// doesn't remove the oriiginal size() method, but calling size()
943+
// again in setup() is harmless.
944+
if (!hasMethod("settings") && sizeStatement != null) {
945+
out.println(indent + "public void settings() { " + sizeStatement + " }");
946+
// out.println(indent + "public void settings() {");
947+
// out.println(indent + indent + sizeStatement);
948+
// out.println(indent + "}");
949+
}
950+
/*
942951
if (sketchWidth != null && !hasMethod("sketchWidth")) {
943952
// Only include if it's a number (a variable will be a problem)
944953
if (PApplet.parseInt(sketchWidth, -1) != -1 || sketchWidth.equals("displayWidth")) {
@@ -960,6 +969,7 @@ protected void writeFooter(PrintWriter out, String className) {
960969
if (sketchOutputPath != null && !hasMethod("sketchOutputPath")) {
961970
out.println(indent + "public String sketchOutputPath() { return " + sketchOutputPath + "; }");
962971
}
972+
*/
963973

964974
if (!hasMethod("main")) {
965975
out.println(indent + "static public void main(String[] passedArgs) {");
@@ -1036,6 +1046,10 @@ public boolean ignoreImport(String pkg) {
10361046
// return pkg.startsWith("processing.xml.");
10371047
}
10381048

1049+
1050+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1051+
1052+
10391053
/**
10401054
* Find the first CLASS_DEF node in the tree, and return the name of the
10411055
* class in question.
@@ -1049,11 +1063,13 @@ String getFirstClassName(AST ast) {
10491063
return t;
10501064
}
10511065

1066+
10521067
public void debugAST(final AST ast, final boolean includeHidden) {
10531068
System.err.println("------------------");
10541069
debugAST(ast, includeHidden, 0);
10551070
}
10561071

1072+
10571073
private void debugAST(final AST ast, final boolean includeHidden,
10581074
final int indent) {
10591075
for (int i = 0; i < indent; i++)
@@ -1073,23 +1089,24 @@ private void debugAST(final AST ast, final boolean includeHidden,
10731089
debugAST(kid, includeHidden, indent + 1);
10741090
}
10751091

1092+
10761093
private String debugHiddenAfter(AST ast) {
1077-
if (!(ast instanceof antlr.CommonASTWithHiddenTokens))
1078-
return "";
1079-
return debugHiddenTokens(((antlr.CommonASTWithHiddenTokens) ast)
1080-
.getHiddenAfter());
1094+
return (ast instanceof antlr.CommonASTWithHiddenTokens) ?
1095+
debugHiddenTokens(((antlr.CommonASTWithHiddenTokens) ast).getHiddenAfter()) : "";
10811096
}
10821097

10831098
private String debugHiddenBefore(AST ast) {
1084-
if (!(ast instanceof antlr.CommonASTWithHiddenTokens))
1099+
if (!(ast instanceof antlr.CommonASTWithHiddenTokens)) {
10851100
return "";
1086-
antlr.CommonHiddenStreamToken child = null, parent = ((antlr.CommonASTWithHiddenTokens) ast)
1087-
.getHiddenBefore();
1101+
}
1102+
antlr.CommonHiddenStreamToken parent =
1103+
((antlr.CommonASTWithHiddenTokens) ast).getHiddenBefore();
10881104

10891105
if (parent == null) {
10901106
return "";
10911107
}
10921108

1109+
antlr.CommonHiddenStreamToken child = null;
10931110
do {
10941111
child = parent;
10951112
parent = child.getHiddenBefore();
@@ -1098,15 +1115,18 @@ private String debugHiddenBefore(AST ast) {
10981115
return debugHiddenTokens(child);
10991116
}
11001117

1118+
11011119
private String debugHiddenTokens(antlr.CommonHiddenStreamToken t) {
11021120
final StringBuilder sb = new StringBuilder();
11031121
for (; t != null; t = filter.getHiddenAfter(t)) {
1104-
if (sb.length() == 0)
1122+
if (sb.length() == 0) {
11051123
sb.append("[");
1124+
}
11061125
sb.append(t.getText().replace("\n", "\\n"));
11071126
}
1108-
if (sb.length() > 0)
1127+
if (sb.length() > 0) {
11091128
sb.append("]");
1129+
}
11101130
return sb.toString();
11111131
}
11121132
}

0 commit comments

Comments
 (0)