mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
Allow anonymous classes in static mode
catch: if they have a method in their body named setup or draw, mode is always (sometimes incorrectly) detected as Active Fixes #533
This commit is contained in:
@@ -212,13 +212,24 @@ public class ErrorCheckerService implements Runnable {
|
||||
*/
|
||||
final public String importRegexp = "(?:^|;)\\s*(import\\s+)((?:static\\s+)?\\S+)(\\s*;)";
|
||||
|
||||
// /**
|
||||
// * Regexp for function declarations. (Used from Processing source)
|
||||
// */
|
||||
// final Pattern FUNCTION_DECL = Pattern
|
||||
// .compile("(^|;)\\s*((public|private|protected|final|static)\\s+)*"
|
||||
// + "(void|int|float|double|String|char|byte|boolean)"
|
||||
// + "(\\s*\\[\\s*\\])?\\s+[a-zA-Z0-9]+\\s*\\(", Pattern.MULTILINE);
|
||||
|
||||
/**
|
||||
* Regexp for function declarations. (Used from Processing source)
|
||||
* Matches setup or draw function declaration. We search for all those
|
||||
* modifiers and return types in order to have proper error message
|
||||
* when people use incompatible modifiers or non-void return type
|
||||
*/
|
||||
final Pattern FUNCTION_DECL = Pattern
|
||||
.compile("(^|;)\\s*((public|private|protected|final|static)\\s+)*"
|
||||
+ "(void|int|float|double|String|char|byte|boolean)"
|
||||
+ "(\\s*\\[\\s*\\])?\\s+[a-zA-Z0-9]+\\s*\\(", Pattern.MULTILINE);
|
||||
private static final Pattern SETUP_OR_DRAW_FUNCTION_DECL =
|
||||
Pattern.compile("(^|;)\\s*((public|private|protected|final|static)\\s+)*" +
|
||||
"(void|int|float|double|String|char|byte)" +
|
||||
"(\\s*\\[\\s*\\])?\\s+(setup|draw)\\s*\\(",
|
||||
Pattern.MULTILINE);
|
||||
|
||||
protected ErrorMessageSimplifier errorMsgSimplifier;
|
||||
|
||||
@@ -1302,9 +1313,10 @@ public class ErrorCheckerService implements Runnable {
|
||||
className = (editor == null) ?
|
||||
"DefaultClass" : editor.getSketch().getName();
|
||||
|
||||
// Check whether the code is being written in STATIC mode(no function
|
||||
// declarations) - append class declaration and void setup() declaration
|
||||
Matcher matcher = FUNCTION_DECL.matcher(sourceAlt);
|
||||
// Check whether the code is being written in STATIC mode
|
||||
// (no setup or draw function declarations) - append class
|
||||
// declaration and void setup() declaration
|
||||
Matcher matcher = SETUP_OR_DRAW_FUNCTION_DECL.matcher(sourceAlt);
|
||||
staticMode = !matcher.find();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(xqpreproc.prepareImports(programImports));
|
||||
|
||||
@@ -37,9 +37,6 @@ import processing.app.Preferences;
|
||||
import processing.app.SketchException;
|
||||
import processing.core.PApplet;
|
||||
import processing.data.StringList;
|
||||
import processing.mode.java.preproc.PdeLexer;
|
||||
import processing.mode.java.preproc.PdeRecognizer;
|
||||
import processing.mode.java.preproc.PdeTokenTypes;
|
||||
|
||||
import antlr.*;
|
||||
import antlr.collections.AST;
|
||||
@@ -183,11 +180,22 @@ public class PdePreprocessor {
|
||||
Pattern.compile("(^|;)\\s*public\\s+class\\s+\\S+\\s+extends\\s+PApplet", Pattern.MULTILINE);
|
||||
|
||||
|
||||
private static final Pattern FUNCTION_DECL =
|
||||
Pattern.compile("(^|;)\\s*((public|private|protected|final|static)\\s+)*" +
|
||||
"(void|int|float|double|String|char|byte)" +
|
||||
"(\\s*\\[\\s*\\])?\\s+[a-zA-Z0-9]+\\s*\\(",
|
||||
Pattern.MULTILINE);
|
||||
// private static final Pattern FUNCTION_DECL =
|
||||
// Pattern.compile("(^|;)\\s*((public|private|protected|final|static)\\s+)*" +
|
||||
// "(void|int|float|double|String|char|byte)" +
|
||||
// "(\\s*\\[\\s*\\])?\\s+[a-zA-Z0-9]+\\s*\\(",
|
||||
// Pattern.MULTILINE);
|
||||
|
||||
/**
|
||||
* Matches setup or draw function declaration. We search for all those
|
||||
* modifiers and return types in order to have proper error message
|
||||
* when people use incompatible modifiers or non-void return type
|
||||
*/
|
||||
private static final Pattern SETUP_OR_DRAW_FUNCTION_DECL =
|
||||
Pattern.compile("(^|;)\\s*((public|private|protected|final|static)\\s+)*" +
|
||||
"(void|int|float|double|String|char|byte)" +
|
||||
"(\\s*\\[\\s*\\])?\\s+(setup|draw)\\s*\\(",
|
||||
Pattern.MULTILINE);
|
||||
|
||||
|
||||
public PdePreprocessor(final String sketchName) {
|
||||
@@ -863,7 +871,7 @@ public class PdePreprocessor {
|
||||
parser = createParser(program);
|
||||
parser.pdeProgram();
|
||||
}
|
||||
} else if (FUNCTION_DECL.matcher(uncomment).find()) {
|
||||
} else if (SETUP_OR_DRAW_FUNCTION_DECL.matcher(uncomment).find()) {
|
||||
setMode(Mode.ACTIVE);
|
||||
parser.activeProgram();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user