| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 863d60d commit 2827174
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -132,7 +132,7 @@ public class ErrorCheckerService implements Runnable { | |||
| 132 | 132 | /** | |
| 133 | 133 | * Is the sketch running in static mode or active mode? | |
| 134 | 134 | */ | |
| 135 | - public boolean staticMode = false; | ||
| 135 | + public PdePreprocessor.Mode mode = PdePreprocessor.Mode.ACTIVE; | ||
| 136 | 136 | ||
| 137 | 137 | /** | |
| 138 | 138 | * Compilation Unit for current sketch | |
@@ -1322,36 +1322,44 @@ protected String preprocessCode(String pdeCode) { | |||
| 1322 | 1322 | "DefaultClass" : editor.getSketch().getName(); | |
| 1323 | 1323 | ||
| 1324 | 1324 | // Check whether the code is being written in STATIC mode | |
| 1325 | - // (no setup or draw function declarations) - append class | ||
| 1326 | - // declaration and void setup() declaration | ||
| 1327 | - Matcher matcher = SETUP_OR_DRAW_FUNCTION_DECL.matcher(sourceAlt); | ||
| 1328 | - staticMode = !matcher.find(); | ||
| 1325 | + String uncommented = PdePreprocessor.scrubComments(sourceAlt); | ||
| 1326 | + | ||
| 1327 | + mode = PdePreprocessor.parseMode(uncommented); | ||
| 1328 | + | ||
| 1329 | 1329 | StringBuilder sb = new StringBuilder(); | |
| 1330 | + | ||
| 1331 | + // Imports | ||
| 1330 | 1332 | sb.append(xqpreproc.prepareImports(programImports)); | |
| 1331 | - sb.append("public class " + className + " extends PApplet {\n"); | ||
| 1332 | - if (staticMode) { | ||
| 1333 | - sb.append("public void setup() {\n"); | ||
| 1334 | - } | ||
| 1335 | - sb.append(sourceAlt); | ||
| 1336 | - if (staticMode) { | ||
| 1337 | - sb.append("\nnoLoop();\n}"); | ||
| 1333 | + | ||
| 1334 | + // Header | ||
| 1335 | + if (mode != PdePreprocessor.Mode.JAVA) { | ||
| 1336 | + sb.append("public class " + className + " extends PApplet {\n"); | ||
| 1337 | + if (mode == PdePreprocessor.Mode.STATIC) { | ||
| 1338 | + sb.append("public void setup() {\n"); | ||
| 1339 | + } | ||
| 1338 | 1340 | } | |
| 1339 | - sb.append("\n}"); | ||
| 1340 | - sourceAlt = sb.toString(); | ||
| 1341 | 1341 | ||
| 1342 | - int position = sourceAlt.indexOf("{") + 1; | ||
| 1342 | + // Grab the offset before adding contents of the editor | ||
| 1343 | 1343 | mainClassOffset = 1; | |
| 1344 | - for (int i = 0; i <= position; i++) { | ||
| 1345 | - if (sourceAlt.charAt(i) == '\n') { | ||
| 1344 | + for (int i = 0; i < sb.length(); i++) { | ||
| 1345 | + if (sb.charAt(i) == '\n') { | ||
| 1346 | 1346 | mainClassOffset++; | |
| 1347 | 1347 | } | |
| 1348 | 1348 | } | |
| 1349 | - if (staticMode) { | ||
| 1350 | - mainClassOffset++; | ||
| 1349 | + | ||
| 1350 | + // Editor content | ||
| 1351 | + sb.append(sourceAlt); | ||
| 1352 | + | ||
| 1353 | + // Footer | ||
| 1354 | + if (mode != PdePreprocessor.Mode.JAVA) { | ||
| 1355 | + if (mode == PdePreprocessor.Mode.STATIC) { | ||
| 1356 | + sb.append("\nnoLoop();\n}"); | ||
| 1357 | + } | ||
| 1358 | + sb.append("\n}"); | ||
| 1351 | 1359 | } | |
| 1352 | - sourceAlt = substituteUnicode(sourceAlt); | ||
| 1353 | - sourceCode = sourceAlt; | ||
| 1354 | - return sourceAlt; | ||
| 1360 | + | ||
| 1361 | + sourceCode = substituteUnicode(sb.toString()); | ||
| 1362 | + return sourceCode; | ||
| 1355 | 1363 | } | |
| 1356 | 1364 | ||
| 1357 | 1365 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments