From b59ad6718106d8f5b6309d43db9a1606c7119981 Mon Sep 17 00:00:00 2001 From: A Samuel Pottinger Date: Sat, 10 Dec 2022 17:21:03 +0000 Subject: [PATCH 1/3] Add failing test to address #619 --- .../processing/mode/java/ParserTests.java | 5 ++ .../test/resources/staticannotations.expected | 65 +++++++++++++++++++ java/test/resources/staticannotations.pde | 34 ++++++++++ 3 files changed, 104 insertions(+) create mode 100644 java/test/resources/staticannotations.expected create mode 100644 java/test/resources/staticannotations.pde diff --git a/java/test/processing/mode/java/ParserTests.java b/java/test/processing/mode/java/ParserTests.java index 9a1a2c753..040600228 100644 --- a/java/test/processing/mode/java/ParserTests.java +++ b/java/test/processing/mode/java/ParserTests.java @@ -318,6 +318,11 @@ public void annotations() { expectGood("annotations", true); } + @Test + public void staticannotations() { + expectGood("staticannotations", true); + } + @Test public void generics() { expectGood("generics", true); diff --git a/java/test/resources/staticannotations.expected b/java/test/resources/staticannotations.expected new file mode 100644 index 000000000..b56a8584b --- /dev/null +++ b/java/test/resources/staticannotations.expected @@ -0,0 +1,65 @@ +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 staticannotations extends PApplet { + + public void setup() { + +class Button { + + int x, y, radius; + + public Button (int x, int y, int radius) { + this.x = x; + this.y = y; + this.radius = radius; + } + + boolean over() { + return dist(mouseX, mouseY, this.x, this.y) < this.radius; + } + + void draw() { + ellipse(this.x, this.y, this.radius * 2, this.radius * 2); + } + + @Deprecated + void old() { + ellipse(this.x, this.y, this.radius, this.radius); + } + +} + + +class ButtonOther extends Button { + + @Override + boolean over() { + return dist(mouseX, mouseY, this.x, this.y) < this.radius / 2; + } + +} + + noLoop(); + } + + static public void main(String[] passedArgs) { + String[] appletArgs = new String[] { "staticannotations" }; + if (passedArgs != null) { + PApplet.main(concat(appletArgs, passedArgs)); + } else { + PApplet.main(appletArgs); + } + } +} \ No newline at end of file diff --git a/java/test/resources/staticannotations.pde b/java/test/resources/staticannotations.pde new file mode 100644 index 000000000..db5089042 --- /dev/null +++ b/java/test/resources/staticannotations.pde @@ -0,0 +1,34 @@ +class Button { + + int x, y, radius; + + public Button (int x, int y, int radius) { + this.x = x; + this.y = y; + this.radius = radius; + } + + boolean over() { + return dist(mouseX, mouseY, this.x, this.y) < this.radius; + } + + void draw() { + ellipse(this.x, this.y, this.radius * 2, this.radius * 2); + } + + @Deprecated + void old() { + ellipse(this.x, this.y, this.radius, this.radius); + } + +} + + +class ButtonOther extends Button { + + @Override + boolean over() { + return dist(mouseX, mouseY, this.x, this.y) < this.radius / 2; + } + +} From c211eb133e1ff30ac71fd82332400b8dd26be20b Mon Sep 17 00:00:00 2001 From: A Samuel Pottinger Date: Sat, 10 Dec 2022 17:31:38 +0000 Subject: [PATCH 2/3] Fix #619 --- .../mode/java/preproc/PdeParseTreeListener.java | 2 +- java/test/resources/staticannotations.expected | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/java/src/processing/mode/java/preproc/PdeParseTreeListener.java b/java/src/processing/mode/java/preproc/PdeParseTreeListener.java index d774b6e92..8e10e1c33 100644 --- a/java/src/processing/mode/java/preproc/PdeParseTreeListener.java +++ b/java/src/processing/mode/java/preproc/PdeParseTreeListener.java @@ -591,7 +591,7 @@ public void exitMethodDeclaration(ProcessingParser.MethodDeclarationContext ctx) if (annoationPoint == null) { insertBefore(possibleModifiers.getStart(), "public "); } else { - insertAfter(annoationPoint.getStop(), "public "); + insertAfter(annoationPoint.getStop(), " public "); } } diff --git a/java/test/resources/staticannotations.expected b/java/test/resources/staticannotations.expected index b56a8584b..2b651f2b4 100644 --- a/java/test/resources/staticannotations.expected +++ b/java/test/resources/staticannotations.expected @@ -26,16 +26,16 @@ class Button { this.radius = radius; } - boolean over() { + public boolean over() { return dist(mouseX, mouseY, this.x, this.y) < this.radius; } - void draw() { + public void draw() { ellipse(this.x, this.y, this.radius * 2, this.radius * 2); } @Deprecated - void old() { + public void old() { ellipse(this.x, this.y, this.radius, this.radius); } @@ -45,7 +45,7 @@ class Button { class ButtonOther extends Button { @Override - boolean over() { + public boolean over() { return dist(mouseX, mouseY, this.x, this.y) < this.radius / 2; } From e5f58a16023db0e36e32a021dd16722b38e18f4b Mon Sep 17 00:00:00 2001 From: A Samuel Pottinger Date: Sat, 10 Dec 2022 17:45:19 +0000 Subject: [PATCH 3/3] Fix typo on annotationPoint. --- .../mode/java/preproc/PdeParseTreeListener.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/java/src/processing/mode/java/preproc/PdeParseTreeListener.java b/java/src/processing/mode/java/preproc/PdeParseTreeListener.java index 8e10e1c33..f2953b284 100644 --- a/java/src/processing/mode/java/preproc/PdeParseTreeListener.java +++ b/java/src/processing/mode/java/preproc/PdeParseTreeListener.java @@ -566,7 +566,7 @@ public void exitMethodDeclaration(ProcessingParser.MethodDeclarationContext ctx) int numChildren = possibleModifiers.getChildCount(); - ParserRuleContext annoationPoint = null; + ParserRuleContext annotationPoint = null; for (int i = 0; i < numChildren; i++) { boolean childIsVisibility; @@ -582,16 +582,16 @@ public void exitMethodDeclaration(ProcessingParser.MethodDeclarationContext ctx) boolean isModifier = child instanceof ProcessingParser.ModifierContext; if (isModifier && isAnnotation((ProcessingParser.ModifierContext) child)) { - annoationPoint = (ParserRuleContext) child; + annotationPoint = (ParserRuleContext) child; } } // Insert at start of method or after annoation if (!hasVisibilityModifier) { - if (annoationPoint == null) { + if (annotationPoint == null) { insertBefore(possibleModifiers.getStart(), "public "); } else { - insertAfter(annoationPoint.getStop(), " public "); + insertAfter(annotationPoint.getStop(), " public "); } }