From 3e7aab9556d0b46b1defe4890f17851421877bf5 Mon Sep 17 00:00:00 2001 From: A Pottinger Date: Sat, 21 Nov 2020 10:14:54 -0800 Subject: [PATCH 1/5] Added tests for smooth and noSmooth for preproc. In response to https://github.com/processing/processing4/issues/149, adding tests to catch issues with smooth and noSmooth in the preprocessor. Issue found by @benfry. --- .../processing/mode/java/ParserTests.java | 15 ++++++ java/test/resources/nosmooth.expected | 48 +++++++++++++++++++ java/test/resources/nosmooth.pde | 12 +++++ java/test/resources/smoothnoparam.expected | 48 +++++++++++++++++++ java/test/resources/smoothnoparam.pde | 12 +++++ java/test/resources/smoothparam.expected | 48 +++++++++++++++++++ java/test/resources/smoothparam.pde | 12 +++++ 7 files changed, 195 insertions(+) create mode 100644 java/test/resources/nosmooth.expected create mode 100644 java/test/resources/nosmooth.pde create mode 100644 java/test/resources/smoothnoparam.expected create mode 100644 java/test/resources/smoothnoparam.pde create mode 100644 java/test/resources/smoothparam.expected create mode 100644 java/test/resources/smoothparam.pde diff --git a/java/test/processing/mode/java/ParserTests.java b/java/test/processing/mode/java/ParserTests.java index cb94cfcd1..6fd29e368 100644 --- a/java/test/processing/mode/java/ParserTests.java +++ b/java/test/processing/mode/java/ParserTests.java @@ -365,4 +365,19 @@ public class ParserTests { expectGood("colorreturn"); } + @Test + public void testNoSmooth() { + expectGood("nosmooth"); + } + + @Test + public void testSmooth() { + expectGood("smoothnoparam"); + } + + @Test + public void testSmoothWithParam() { + expectGood("smoothparam"); + } + } diff --git a/java/test/resources/nosmooth.expected b/java/test/resources/nosmooth.expected new file mode 100644 index 000000000..8983c1099 --- /dev/null +++ b/java/test/resources/nosmooth.expected @@ -0,0 +1,48 @@ +import processing.core.*; +import processing.data.*; +import processing.event.*; +import processing.opengl.*; + +import java.util.HashMap; +import java.util.ArrayList; +import java.io.File; +import java.io.BufferedReader; +import java.io.PrintWriter; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; + +public class nosmooth extends PApplet { + +public void setup() { + /* size commented out by preprocessor */; + /* noSmooth commented out by preprocessor */; +} + +@Override public void draw() { + background(0); + fill(255,0,0); + ellipse(100,100,100,100); + fill(0,255,0); + ellipse(150,150,100,100); +} + +class Test { + private void draw() {} +} + + + public void settings() { + size(300,300, P2D); + noSmooth(); + } + + static public void main(String[] passedArgs) { + String[] appletArgs = new String[] { "nosmooth" }; + if (passedArgs != null) { + PApplet.main(concat(appletArgs, passedArgs)); + } else { + PApplet.main(appletArgs); + } + } +} diff --git a/java/test/resources/nosmooth.pde b/java/test/resources/nosmooth.pde new file mode 100644 index 000000000..02f069f69 --- /dev/null +++ b/java/test/resources/nosmooth.pde @@ -0,0 +1,12 @@ +void setup(){ + size(300,300, P2D); + noSmooth(); +} + +void draw(){ + background(0); + fill(255,0,0); + ellipse(100,100,100,100); + fill(0,255,0); + ellipse(150,150,100,100); +} diff --git a/java/test/resources/smoothnoparam.expected b/java/test/resources/smoothnoparam.expected new file mode 100644 index 000000000..a5c2f7d39 --- /dev/null +++ b/java/test/resources/smoothnoparam.expected @@ -0,0 +1,48 @@ +import processing.core.*; +import processing.data.*; +import processing.event.*; +import processing.opengl.*; + +import java.util.HashMap; +import java.util.ArrayList; +import java.io.File; +import java.io.BufferedReader; +import java.io.PrintWriter; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; + +public class smoothnoparam extends PApplet { + +public void setup() { + /* size commented out by preprocessor */; + /* smooth commented out by preprocessor */; +} + +@Override public void draw() { + background(0); + fill(255,0,0); + ellipse(100,100,100,100); + fill(0,255,0); + ellipse(150,150,100,100); +} + +class Test { + private void draw() {} +} + + + public void settings() { + size(300,300, P2D); + smooth(); + } + + static public void main(String[] passedArgs) { + String[] appletArgs = new String[] { "smoothnoparam" }; + if (passedArgs != null) { + PApplet.main(concat(appletArgs, passedArgs)); + } else { + PApplet.main(appletArgs); + } + } +} diff --git a/java/test/resources/smoothnoparam.pde b/java/test/resources/smoothnoparam.pde new file mode 100644 index 000000000..0873171ae --- /dev/null +++ b/java/test/resources/smoothnoparam.pde @@ -0,0 +1,12 @@ +void setup(){ + size(300,300, P2D); + smooth(); +} + +void draw(){ + background(0); + fill(255,0,0); + ellipse(100,100,100,100); + fill(0,255,0); + ellipse(150,150,100,100); +} diff --git a/java/test/resources/smoothparam.expected b/java/test/resources/smoothparam.expected new file mode 100644 index 000000000..f7efe8ec0 --- /dev/null +++ b/java/test/resources/smoothparam.expected @@ -0,0 +1,48 @@ +import processing.core.*; +import processing.data.*; +import processing.event.*; +import processing.opengl.*; + +import java.util.HashMap; +import java.util.ArrayList; +import java.io.File; +import java.io.BufferedReader; +import java.io.PrintWriter; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; + +public class smoothparam extends PApplet { + +public void setup() { + /* size commented out by preprocessor */; + /* smooth commented out by preprocessor */; +} + +@Override public void draw() { + background(0); + fill(255,0,0); + ellipse(100,100,100,100); + fill(0,255,0); + ellipse(150,150,100,100); +} + +class Test { + private void draw() {} +} + + + public void settings() { + size(300,300, P2D); + smooth(4); + } + + static public void main(String[] passedArgs) { + String[] appletArgs = new String[] { "smoothparam" }; + if (passedArgs != null) { + PApplet.main(concat(appletArgs, passedArgs)); + } else { + PApplet.main(appletArgs); + } + } +} diff --git a/java/test/resources/smoothparam.pde b/java/test/resources/smoothparam.pde new file mode 100644 index 000000000..8e0851e4a --- /dev/null +++ b/java/test/resources/smoothparam.pde @@ -0,0 +1,12 @@ +void setup(){ + size(300,300, P2D); + smooth(4); +} + +void draw(){ + background(0); + fill(255,0,0); + ellipse(100,100,100,100); + fill(0,255,0); + ellipse(150,150,100,100); +} From c41e4d24add90f6cfbcb91f8601fb674865babd9 Mon Sep 17 00:00:00 2001 From: A Pottinger Date: Sat, 21 Nov 2020 10:41:14 -0800 Subject: [PATCH 2/5] Fixed preproc of noSmooth as part of #149. --- .../java/preproc/PdeParseTreeListener.java | 147 ++++++++++-------- .../processing/mode/java/ParserTests.java | 4 +- java/test/resources/nosmooth.expected | 28 ++-- 3 files changed, 92 insertions(+), 87 deletions(-) diff --git a/java/src/processing/mode/java/preproc/PdeParseTreeListener.java b/java/src/processing/mode/java/preproc/PdeParseTreeListener.java index ff6410f5a..50a11a3cf 100644 --- a/java/src/processing/mode/java/preproc/PdeParseTreeListener.java +++ b/java/src/processing/mode/java/preproc/PdeParseTreeListener.java @@ -51,6 +51,8 @@ import processing.mode.java.preproc.PdePreprocessor.Mode; public class PdeParseTreeListener extends ProcessingBaseListener { private static final String SIZE_METHOD_NAME = "size"; + private static final String SMOOTH_METHOD_NAME = "smooth"; + private static final String NO_SMOOTH_METHOD_NAME = "noSmooth"; private static final String PIXEL_DENSITY_METHOD_NAME = "pixelDensity"; private static final String FULLSCREEN_METHOD_NAME = "fullScreen"; @@ -79,6 +81,7 @@ public class PdeParseTreeListener extends ProcessingBaseListener { private boolean sizeRequiresRewrite = false; private boolean pixelDensityRequiresRewrite = false; private boolean sizeIsFullscreen = false; + private boolean noSmoothRequiresRewrite = false; private RewriteResult headerResult; private RewriteResult footerResult; @@ -310,10 +313,10 @@ public class PdeParseTreeListener extends ProcessingBaseListener { if (SIZE_METHOD_NAME.equals(methodName) || FULLSCREEN_METHOD_NAME.equals(methodName)) { handleSizeCall(ctx); - } - - if (PIXEL_DENSITY_METHOD_NAME.equals(methodName)) { + } else if (PIXEL_DENSITY_METHOD_NAME.equals(methodName)) { handlePixelDensityCall(ctx); + } else if (NO_SMOOTH_METHOD_NAME.equals(methodName)) { + handleNoSmoothCall(ctx); } } @@ -585,22 +588,9 @@ public class PdeParseTreeListener extends ProcessingBaseListener { * @param ctx The context of the call. */ protected void handleSizeCall(ParserRuleContext ctx) { - ParserRuleContext testCtx = ctx.getParent() - .getParent() - .getParent() - .getParent(); - - boolean isInGlobal = - testCtx instanceof ProcessingParser.StaticProcessingSketchContext; - - boolean isInSetup; - if (!isInGlobal) { - ParserRuleContext methodDeclaration = testCtx.getParent() - .getParent(); - - isInSetup = isMethodSetup(methodDeclaration); - } else { - isInSetup = false; + // Check that this is the size call for processing and not a user defined size method. + if (!calledFromGlobalOrSetup(ctx)) { + return; } ParseTree argsContext = ctx.getChild(2); @@ -610,41 +600,41 @@ public class PdeParseTreeListener extends ProcessingBaseListener { boolean isSize = ctx.getChild(0).getText().equals(SIZE_METHOD_NAME); boolean isFullscreen = ctx.getChild(0).getText().equals(FULLSCREEN_METHOD_NAME); - if (isInGlobal || isInSetup) { + if (isSize && argsContext.getChildCount() > 2) { thisRequiresRewrite = true; - if (isSize && argsContext.getChildCount() > 2) { - sketchWidth = argsContext.getChild(0).getText(); - if (PApplet.parseInt(sketchWidth, -1) == -1 && - !sketchWidth.equals("displayWidth")) { - thisRequiresRewrite = false; - } - - sketchHeight = argsContext.getChild(2).getText(); - if (PApplet.parseInt(sketchHeight, -1) == -1 && - !sketchHeight.equals("displayHeight")) { - thisRequiresRewrite = false; - } - - if (argsContext.getChildCount() > 3) { - sketchRenderer = argsContext.getChild(4).getText(); - } - - if (argsContext.getChildCount() > 5) { - sketchOutputFilename = argsContext.getChild(6).getText(); - } + sketchWidth = argsContext.getChild(0).getText(); + boolean invalidWidth = PApplet.parseInt(sketchWidth, -1) == -1; + invalidWidth = invalidWidth && !sketchWidth.equals("displayWidth"); + if (invalidWidth) { + thisRequiresRewrite = false; } - if (isFullscreen) { - sketchWidth = "displayWidth"; - sketchWidth = "displayHeight"; + sketchHeight = argsContext.getChild(2).getText(); + boolean invalidHeight = PApplet.parseInt(sketchHeight, -1) == -1; + invalidHeight = invalidHeight && !sketchHeight.equals("displayHeight"); + if (invalidHeight) { + thisRequiresRewrite = false; + } - thisRequiresRewrite = true; - sizeIsFullscreen = true; + if (argsContext.getChildCount() > 3) { + sketchRenderer = argsContext.getChild(4).getText(); + } - if (argsContext.getChildCount() > 0) { - sketchRenderer = argsContext.getChild(0).getText(); - } + if (argsContext.getChildCount() > 5) { + sketchOutputFilename = argsContext.getChild(6).getText(); + } + } + + if (isFullscreen) { + sketchWidth = "displayWidth"; + sketchWidth = "displayHeight"; + + thisRequiresRewrite = true; + sizeIsFullscreen = true; + + if (argsContext.getChildCount() > 0) { + sketchRenderer = argsContext.getChild(0).getText(); } } @@ -656,32 +646,45 @@ public class PdeParseTreeListener extends ProcessingBaseListener { } protected void handlePixelDensityCall(ParserRuleContext ctx) { - ParserRuleContext testCtx = ctx.getParent() + // Check that this is a call for processing and not a user defined method. + if (!calledFromGlobalOrSetup(ctx)) { + return; + } + + ParseTree argsContext = ctx.getChild(2); + pixelDensity = argsContext.getChild(0).getText(); + delete(ctx.start, ctx.stop); + insertAfter(ctx.stop, "/* pixelDensity commented out by preprocessor */"); + pixelDensityRequiresRewrite = true; + } + + protected void handleNoSmoothCall(ParserRuleContext ctx) { + // Check that this is a call for processing and not a user defined method. + if (!calledFromGlobalOrSetup(ctx)) { + return; + } + + delete(ctx.start, ctx.stop); + insertAfter(ctx.stop, "/* noSmooth commented out by preprocessor */"); + noSmoothRequiresRewrite = true; + } + + protected boolean calledFromGlobalOrSetup(ParserRuleContext callContext) { + ParserRuleContext outerContext = callContext.getParent() .getParent() .getParent() .getParent(); - boolean isInGlobal = - testCtx instanceof ProcessingParser.StaticProcessingSketchContext; - - boolean isInSetup; - if (!isInGlobal) { - ParserRuleContext methodDeclaration = testCtx.getParent() - .getParent(); - - isInSetup = isMethodSetup(methodDeclaration); - } else { - isInSetup = false; + // Check static context first (global) + if (outerContext instanceof ProcessingParser.StaticProcessingSketchContext) { + return true; } - ParseTree argsContext = ctx.getChild(2); + // Otherwise check if method called form setup + ParserRuleContext methodDeclaration = outerContext.getParent() + .getParent(); - if (isInGlobal || isInSetup) { - pixelDensity = argsContext.getChild(0).getText(); - delete(ctx.start, ctx.stop); - insertAfter(ctx.stop, "/* pixelDensity commented out by preprocessor */"); - pixelDensityRequiresRewrite = true; - } + return isMethodSetup(methodDeclaration); } /** @@ -1010,10 +1013,15 @@ public class PdeParseTreeListener extends ProcessingBaseListener { protected void writeExtraFieldsAndMethods(PrintWriterWithEditGen classBodyWriter, RewriteResultBuilder resultBuilder) { - if (!sizeRequiresRewrite && !pixelDensityRequiresRewrite) { + // First check that a settings method is required at all + boolean noRewriteRequired = !sizeRequiresRewrite; + noRewriteRequired = noRewriteRequired && !pixelDensityRequiresRewrite; + noRewriteRequired = noRewriteRequired && !noSmoothRequiresRewrite; + if (noRewriteRequired) { return; } + // If needed, add the components via a string joiner. String settingsOuterTemplate = indent1 + "public void settings() { %s }"; StringJoiner settingsInner = new StringJoiner("\n"); @@ -1048,6 +1056,9 @@ public class PdeParseTreeListener extends ProcessingBaseListener { settingsInner.add(String.format("pixelDensity(%s);", pixelDensity)); } + if (noSmoothRequiresRewrite) { + settingsInner.add("noSmooth();"); + } String newCode = String.format(settingsOuterTemplate, settingsInner.toString()); diff --git a/java/test/processing/mode/java/ParserTests.java b/java/test/processing/mode/java/ParserTests.java index 6fd29e368..6c2a5c1f5 100644 --- a/java/test/processing/mode/java/ParserTests.java +++ b/java/test/processing/mode/java/ParserTests.java @@ -370,7 +370,7 @@ public class ParserTests { expectGood("nosmooth"); } - @Test + /*@Test public void testSmooth() { expectGood("smoothnoparam"); } @@ -378,6 +378,6 @@ public class ParserTests { @Test public void testSmoothWithParam() { expectGood("smoothparam"); - } + }*/ } diff --git a/java/test/resources/nosmooth.expected b/java/test/resources/nosmooth.expected index 8983c1099..6770b50fd 100644 --- a/java/test/resources/nosmooth.expected +++ b/java/test/resources/nosmooth.expected @@ -14,28 +14,22 @@ import java.io.IOException; public class nosmooth extends PApplet { -public void setup() { - /* size commented out by preprocessor */; - /* noSmooth commented out by preprocessor */; + public void setup(){ + /* size commented out by preprocessor */; + /* noSmooth commented out by preprocessor */; } -@Override public void draw() { - background(0); - fill(255,0,0); - ellipse(100,100,100,100); - fill(0,255,0); - ellipse(150,150,100,100); -} - -class Test { - private void draw() {} + public void draw(){ + background(0); + fill(255,0,0); + ellipse(100,100,100,100); + fill(0,255,0); + ellipse(150,150,100,100); } - public void settings() { - size(300,300, P2D); - noSmooth(); - } + public void settings() { size(300, 300, P2D); +noSmooth(); } static public void main(String[] passedArgs) { String[] appletArgs = new String[] { "nosmooth" }; From 721046b5934719b6068ba75182a5d2c92d7f6bfe Mon Sep 17 00:00:00 2001 From: A Pottinger Date: Sat, 21 Nov 2020 11:59:25 -0800 Subject: [PATCH 3/5] Finish fix of preproc handeling of smooth. Fixes #149 as reported by @benfry. --- build/shared/lib/languages/PDE.properties | 2 + .../java/preproc/PdeParseTreeListener.java | 55 +++++++++++++++++++ .../processing/mode/java/ParserTests.java | 4 +- java/test/resources/bug315g.expected | 5 +- java/test/resources/smoothnoparam.expected | 28 ++++------ java/test/resources/smoothparam.expected | 28 ++++------ 6 files changed, 84 insertions(+), 38 deletions(-) diff --git a/build/shared/lib/languages/PDE.properties b/build/shared/lib/languages/PDE.properties index b81fcd11e..a4dc37d2b 100644 --- a/build/shared/lib/languages/PDE.properties +++ b/build/shared/lib/languages/PDE.properties @@ -410,6 +410,8 @@ editor.status.bad.generic = Possibly missing type in generic near '%s'? editor.status.bad.identifier = Bad identifier? Did you forget a variable or start an identifier with digits near '%s'? editor.status.bad.parameter = Error on parameter or method declaration near '%s'? editor.status.bad.import = Import not allowed here. +editor.status.bad.size = Too many arguments to size. +editor.status.bad.smooth = Too many arguments to smooth. editor.status.extraneous = Incomplete statement or extra code near '%s'? editor.status.mismatched = Missing operator, semicolon, or '}' near '%s'? editor.status.missing.name = Missing name or ; near '%s'? diff --git a/java/src/processing/mode/java/preproc/PdeParseTreeListener.java b/java/src/processing/mode/java/preproc/PdeParseTreeListener.java index 50a11a3cf..314d7b0c2 100644 --- a/java/src/processing/mode/java/preproc/PdeParseTreeListener.java +++ b/java/src/processing/mode/java/preproc/PdeParseTreeListener.java @@ -75,6 +75,7 @@ public class PdeParseTreeListener extends ProcessingBaseListener { private String sketchWidth; private String sketchHeight; private String pixelDensity; + private String smoothParam; private String sketchRenderer = null; private String sketchOutputFilename = null; @@ -82,6 +83,7 @@ public class PdeParseTreeListener extends ProcessingBaseListener { private boolean pixelDensityRequiresRewrite = false; private boolean sizeIsFullscreen = false; private boolean noSmoothRequiresRewrite = false; + private boolean smoothRequiresRewrite = false; private RewriteResult headerResult; private RewriteResult footerResult; @@ -317,6 +319,8 @@ public class PdeParseTreeListener extends ProcessingBaseListener { handlePixelDensityCall(ctx); } else if (NO_SMOOTH_METHOD_NAME.equals(methodName)) { handleNoSmoothCall(ctx); + } else if (SMOOTH_METHOD_NAME.equals(methodName)) { + handleSmoothCall(ctx); } } @@ -624,6 +628,20 @@ public class PdeParseTreeListener extends ProcessingBaseListener { if (argsContext.getChildCount() > 5) { sketchOutputFilename = argsContext.getChild(6).getText(); } + + if (argsContext.getChildCount() > 7) { + pdeParseTreeErrorListenerMaybe.ifPresent((listener) -> { + Token token = ctx.getStart(); + int line = token.getLine(); + int charOffset = token.getCharPositionInLine(); + + listener.onError(new PdePreprocessIssue( + line, + charOffset, + PreprocessIssueMessageSimplifier.getLocalStr("editor.status.bad.size") + )); + }); + } } if (isFullscreen) { @@ -669,6 +687,38 @@ public class PdeParseTreeListener extends ProcessingBaseListener { noSmoothRequiresRewrite = true; } + protected void handleSmoothCall(ParserRuleContext ctx) { + // Check that this is a call for processing and not a user defined size method. + if (!calledFromGlobalOrSetup(ctx)) { + return; + } + + ParseTree argsContext = ctx.getChild(2); + if (argsContext.getChildCount() > 0) { + smoothParam = argsContext.getChild(0).getText(); + } else { + smoothParam = ""; + } + + if (argsContext.getChildCount() > 2) { + pdeParseTreeErrorListenerMaybe.ifPresent((listener) -> { + Token token = ctx.getStart(); + int line = token.getLine(); + int charOffset = token.getCharPositionInLine(); + + listener.onError(new PdePreprocessIssue( + line, + charOffset, + PreprocessIssueMessageSimplifier.getLocalStr("editor.status.bad.smooth") + )); + }); + } + + delete(ctx.start, ctx.stop); + insertAfter(ctx.stop, "/* smooth commented out by preprocessor */"); + smoothRequiresRewrite = true; + } + protected boolean calledFromGlobalOrSetup(ParserRuleContext callContext) { ParserRuleContext outerContext = callContext.getParent() .getParent() @@ -1017,6 +1067,7 @@ public class PdeParseTreeListener extends ProcessingBaseListener { boolean noRewriteRequired = !sizeRequiresRewrite; noRewriteRequired = noRewriteRequired && !pixelDensityRequiresRewrite; noRewriteRequired = noRewriteRequired && !noSmoothRequiresRewrite; + noRewriteRequired = noRewriteRequired && !smoothRequiresRewrite; if (noRewriteRequired) { return; } @@ -1060,6 +1111,10 @@ public class PdeParseTreeListener extends ProcessingBaseListener { settingsInner.add("noSmooth();"); } + if (smoothRequiresRewrite) { + settingsInner.add(String.format("smooth(%s);", smoothParam)); + } + String newCode = String.format(settingsOuterTemplate, settingsInner.toString()); classBodyWriter.addEmptyLine(); diff --git a/java/test/processing/mode/java/ParserTests.java b/java/test/processing/mode/java/ParserTests.java index 6c2a5c1f5..6fd29e368 100644 --- a/java/test/processing/mode/java/ParserTests.java +++ b/java/test/processing/mode/java/ParserTests.java @@ -370,7 +370,7 @@ public class ParserTests { expectGood("nosmooth"); } - /*@Test + @Test public void testSmooth() { expectGood("smoothnoparam"); } @@ -378,6 +378,6 @@ public class ParserTests { @Test public void testSmoothWithParam() { expectGood("smoothparam"); - }*/ + } } diff --git a/java/test/resources/bug315g.expected b/java/test/resources/bug315g.expected index 54de9127e..e771f41b6 100644 --- a/java/test/resources/bug315g.expected +++ b/java/test/resources/bug315g.expected @@ -16,7 +16,7 @@ public class bug315g extends PApplet { public void setup() { /* size commented out by preprocessor */; -smooth(); +/* smooth commented out by preprocessor */; int y; y = 60; int d; @@ -25,7 +25,8 @@ ellipse(75, y, d, d); noLoop(); } - public void settings() { size(480,120); } + public void settings() { size(480,120); +smooth();} static public void main(String[] passedArgs) { String[] appletArgs = new String[] { "bug315g" }; diff --git a/java/test/resources/smoothnoparam.expected b/java/test/resources/smoothnoparam.expected index a5c2f7d39..2d87ddbea 100644 --- a/java/test/resources/smoothnoparam.expected +++ b/java/test/resources/smoothnoparam.expected @@ -14,28 +14,22 @@ import java.io.IOException; public class smoothnoparam extends PApplet { -public void setup() { - /* size commented out by preprocessor */; - /* smooth commented out by preprocessor */; + public void setup(){ + /* size commented out by preprocessor */; + /* smooth commented out by preprocessor */; } -@Override public void draw() { - background(0); - fill(255,0,0); - ellipse(100,100,100,100); - fill(0,255,0); - ellipse(150,150,100,100); -} - -class Test { - private void draw() {} + public void draw(){ + background(0); + fill(255,0,0); + ellipse(100,100,100,100); + fill(0,255,0); + ellipse(150,150,100,100); } - public void settings() { - size(300,300, P2D); - smooth(); - } + public void settings() { size(300, 300, P2D); +smooth(); } static public void main(String[] passedArgs) { String[] appletArgs = new String[] { "smoothnoparam" }; diff --git a/java/test/resources/smoothparam.expected b/java/test/resources/smoothparam.expected index f7efe8ec0..99543096a 100644 --- a/java/test/resources/smoothparam.expected +++ b/java/test/resources/smoothparam.expected @@ -14,28 +14,22 @@ import java.io.IOException; public class smoothparam extends PApplet { -public void setup() { - /* size commented out by preprocessor */; - /* smooth commented out by preprocessor */; + public void setup(){ + /* size commented out by preprocessor */; + /* smooth commented out by preprocessor */; } -@Override public void draw() { - background(0); - fill(255,0,0); - ellipse(100,100,100,100); - fill(0,255,0); - ellipse(150,150,100,100); -} - -class Test { - private void draw() {} + public void draw(){ + background(0); + fill(255,0,0); + ellipse(100,100,100,100); + fill(0,255,0); + ellipse(150,150,100,100); } - public void settings() { - size(300,300, P2D); - smooth(4); - } + public void settings() { size(300, 300, P2D); +smooth(4); } static public void main(String[] passedArgs) { String[] appletArgs = new String[] { "smoothparam" }; From d30d34c00b0c0cbf9cd913dbf6b1fe2330f5a89d Mon Sep 17 00:00:00 2001 From: A Pottinger Date: Sat, 21 Nov 2020 12:08:10 -0800 Subject: [PATCH 4/5] Added test for smooth on static for good measure. --- .../processing/mode/java/ParserTests.java | 5 +++ .../test/resources/smoothparamstatic.expected | 40 +++++++++++++++++++ java/test/resources/smoothparamstatic.pde | 7 ++++ 3 files changed, 52 insertions(+) create mode 100644 java/test/resources/smoothparamstatic.expected create mode 100644 java/test/resources/smoothparamstatic.pde diff --git a/java/test/processing/mode/java/ParserTests.java b/java/test/processing/mode/java/ParserTests.java index 6fd29e368..34e8add92 100644 --- a/java/test/processing/mode/java/ParserTests.java +++ b/java/test/processing/mode/java/ParserTests.java @@ -380,4 +380,9 @@ public class ParserTests { expectGood("smoothparam"); } + @Test + public void testSmoothWithParamStatic() { + expectGood("smoothparamstatic"); + } + } diff --git a/java/test/resources/smoothparamstatic.expected b/java/test/resources/smoothparamstatic.expected new file mode 100644 index 000000000..4a8cb13b1 --- /dev/null +++ b/java/test/resources/smoothparamstatic.expected @@ -0,0 +1,40 @@ +import processing.core.*; +import processing.data.*; +import processing.event.*; +import processing.opengl.*; + +import java.util.HashMap; +import java.util.ArrayList; +import java.io.File; +import java.io.BufferedReader; +import java.io.PrintWriter; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; + +public class smoothparamstatic extends PApplet { + + public void setup() { +/* size commented out by preprocessor */; +/* smooth commented out by preprocessor */; +background(0); +fill(255,0,0); +ellipse(100,100,100,100); +fill(0,255,0); +ellipse(150,150,100,100); + + noLoop(); + } + + public void settings() { size(300, 300, P2D); +smooth(4); } + + static public void main(String[] passedArgs) { + String[] appletArgs = new String[] { "smoothparamstatic" }; + if (passedArgs != null) { + PApplet.main(concat(appletArgs, passedArgs)); + } else { + PApplet.main(appletArgs); + } + } +} diff --git a/java/test/resources/smoothparamstatic.pde b/java/test/resources/smoothparamstatic.pde new file mode 100644 index 000000000..1de819f5b --- /dev/null +++ b/java/test/resources/smoothparamstatic.pde @@ -0,0 +1,7 @@ +size(300,300, P2D); +smooth(4); +background(0); +fill(255,0,0); +ellipse(100,100,100,100); +fill(0,255,0); +ellipse(150,150,100,100); From 17aa235c6bb8ac989ea0cd7483fe28dfa1efdd3f Mon Sep 17 00:00:00 2001 From: A Pottinger Date: Sat, 21 Nov 2020 12:34:07 -0800 Subject: [PATCH 5/5] Allow ill advised but legal overridding of size, smooth, etc. --- build/shared/lib/languages/PDE.properties | 2 - .../java/preproc/PdeParseTreeListener.java | 40 +++++++------------ 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/build/shared/lib/languages/PDE.properties b/build/shared/lib/languages/PDE.properties index a4dc37d2b..b81fcd11e 100644 --- a/build/shared/lib/languages/PDE.properties +++ b/build/shared/lib/languages/PDE.properties @@ -410,8 +410,6 @@ editor.status.bad.generic = Possibly missing type in generic near '%s'? editor.status.bad.identifier = Bad identifier? Did you forget a variable or start an identifier with digits near '%s'? editor.status.bad.parameter = Error on parameter or method declaration near '%s'? editor.status.bad.import = Import not allowed here. -editor.status.bad.size = Too many arguments to size. -editor.status.bad.smooth = Too many arguments to smooth. editor.status.extraneous = Incomplete statement or extra code near '%s'? editor.status.mismatched = Missing operator, semicolon, or '}' near '%s'? editor.status.missing.name = Missing name or ; near '%s'? diff --git a/java/src/processing/mode/java/preproc/PdeParseTreeListener.java b/java/src/processing/mode/java/preproc/PdeParseTreeListener.java index 314d7b0c2..f1520c43e 100644 --- a/java/src/processing/mode/java/preproc/PdeParseTreeListener.java +++ b/java/src/processing/mode/java/preproc/PdeParseTreeListener.java @@ -630,17 +630,7 @@ public class PdeParseTreeListener extends ProcessingBaseListener { } if (argsContext.getChildCount() > 7) { - pdeParseTreeErrorListenerMaybe.ifPresent((listener) -> { - Token token = ctx.getStart(); - int line = token.getLine(); - int charOffset = token.getCharPositionInLine(); - - listener.onError(new PdePreprocessIssue( - line, - charOffset, - PreprocessIssueMessageSimplifier.getLocalStr("editor.status.bad.size") - )); - }); + thisRequiresRewrite = false; // Uesr may have overloaded size. } } @@ -670,7 +660,12 @@ public class PdeParseTreeListener extends ProcessingBaseListener { } ParseTree argsContext = ctx.getChild(2); + if (argsContext.getChildCount() == 0 || argsContext.getChildCount() > 3) { + return; // User override of pixel density. + } + pixelDensity = argsContext.getChild(0).getText(); + delete(ctx.start, ctx.stop); insertAfter(ctx.stop, "/* pixelDensity commented out by preprocessor */"); pixelDensityRequiresRewrite = true; @@ -682,6 +677,11 @@ public class PdeParseTreeListener extends ProcessingBaseListener { return; } + ParseTree argsContext = ctx.getChild(2); + if (argsContext.getChildCount() > 0) { + return; // User override of noSmooth. + } + delete(ctx.start, ctx.stop); insertAfter(ctx.stop, "/* noSmooth commented out by preprocessor */"); noSmoothRequiresRewrite = true; @@ -694,26 +694,16 @@ public class PdeParseTreeListener extends ProcessingBaseListener { } ParseTree argsContext = ctx.getChild(2); + if (argsContext.getChildCount() > 2) { + return; // User may have overloaded smooth; + } + if (argsContext.getChildCount() > 0) { smoothParam = argsContext.getChild(0).getText(); } else { smoothParam = ""; } - if (argsContext.getChildCount() > 2) { - pdeParseTreeErrorListenerMaybe.ifPresent((listener) -> { - Token token = ctx.getStart(); - int line = token.getLine(); - int charOffset = token.getCharPositionInLine(); - - listener.onError(new PdePreprocessIssue( - line, - charOffset, - PreprocessIssueMessageSimplifier.getLocalStr("editor.status.bad.smooth") - )); - }); - } - delete(ctx.start, ctx.stop); insertAfter(ctx.stop, "/* smooth commented out by preprocessor */"); smoothRequiresRewrite = true;