|
3 | 3 | /* |
4 | 4 | Part of the Processing project - http://processing.org |
5 | 5 |
|
6 | | -Copyright (c) 2012-16 The Processing Foundation |
| 6 | +Copyright (c) 2012-19 The Processing Foundation |
7 | 7 | Copyright (c) 2004-12 Ben Fry and Casey Reas |
8 | 8 | Copyright (c) 2001-04 Massachusetts Institute of Technology |
9 | 9 |
|
|
58 | 58 | import processing.mode.java.preproc.PreprocessorResult; |
59 | 59 | import processing.mode.java.preproc.SurfaceInfo; |
60 | 60 |
|
61 | | -// Would you believe there's a java.lang.Compiler class? I wouldn't. |
62 | | - |
63 | 61 |
|
64 | 62 | public class JavaBuild { |
65 | 63 | public static final String PACKAGE_REGEX = |
@@ -224,10 +222,11 @@ public String preprocess(File srcFolder, |
224 | 222 |
|
225 | 223 | // Remove the entries being moved to settings(). They will be re-inserted |
226 | 224 | // by writeFooter() when it emits the settings() method. |
227 | | - if (sizeInfo != null && sizeInfo.hasSettings()) { |
228 | | -// String sizeStatement = sizeInfo.getStatement(); |
| 225 | + // If the user already has a settings() method, don't mess with anything. |
| 226 | + // https://github.com/processing/processing/issues/4703 |
| 227 | + if (!PdePreprocessor.hasSettingsMethod(bigCode.toString()) && |
| 228 | + sizeInfo != null && sizeInfo.hasSettings()) { |
229 | 229 | for (String stmt : sizeInfo.getStatements()) { |
230 | | - //System.out.format("size stmt is '%s'%n", sizeStatement); |
231 | 230 | // Don't remove newlines (and while you're at it, just keep spaces) |
232 | 231 | // https://github.com/processing/processing/issues/3654 |
233 | 232 | stmt = stmt.trim(); |
@@ -267,19 +266,10 @@ public String preprocess(File srcFolder, |
267 | 266 | // then search through for anyone else whose preprocName is null, |
268 | 267 | // since they've also been combined into the main pde. |
269 | 268 | int errorFile = findErrorFile(errorLine); |
270 | | -// System.out.println("error line is " + errorLine + ", file is " + errorFile); |
271 | 269 | errorLine -= sketch.getCode(errorFile).getPreprocOffset(); |
272 | | -// System.out.println(" preproc offset for that file: " + sketch.getCode(errorFile).getPreprocOffset()); |
273 | | - |
274 | | -// System.out.println("i found this guy snooping around.."); |
275 | | -// System.out.println("whatcha want me to do with 'im boss?"); |
276 | | -// System.out.println(errorLine + " " + errorFile + " " + code[errorFile].getPreprocOffset()); |
277 | 270 |
|
278 | 271 | String msg = re.getMessage(); |
279 | 272 |
|
280 | | - //System.out.println(java.getAbsolutePath()); |
281 | | -// System.out.println(bigCode); |
282 | | - |
283 | 273 | if (msg.contains("expecting RCURLY") || msg.contains("expecting LCURLY")) { |
284 | 274 | for (int i = 0; i < sketch.getCodeCount(); i++) { |
285 | 275 | SketchCode sc = sketch.getCode(i); |
@@ -294,8 +284,8 @@ public String preprocess(File srcFolder, |
294 | 284 | // the result of PApplet.match(msg, "found ('.*')") on missing |
295 | 285 | // LCURLY. |
296 | 286 | throw new SketchException(braceTest[0] > 0 |
297 | | - ? "Found one too many { characters without a } to match it." |
298 | | - : "Found one too many } characters without a { to match it.", |
| 287 | + ? "Found an extra { character without a } to match it." |
| 288 | + : "Found an extra } character without a { to match it.", |
299 | 289 | i, braceTest[1], braceTest[2], false); |
300 | 290 | } |
301 | 291 | } |
@@ -413,26 +403,19 @@ public String preprocess(File srcFolder, |
413 | 403 | javaLibraryPath += File.pathSeparator + core.getNativePath(); |
414 | 404 | } |
415 | 405 |
|
416 | | -// System.out.println("extra imports: " + result.extraImports); |
417 | 406 | for (String item : result.extraImports) { |
418 | | -// System.out.println("item = '" + item + "'"); |
419 | 407 | // remove things up to the last dot |
420 | 408 | int dot = item.lastIndexOf('.'); |
421 | 409 | // http://dev.processing.org/bugs/show_bug.cgi?id=1145 |
422 | 410 | String entry = (dot == -1) ? item : item.substring(0, dot); |
423 | | -// System.out.print(entry + " => "); |
424 | 411 |
|
425 | 412 | if (item.startsWith("static ")) { |
426 | 413 | // import static - https://github.com/processing/processing/issues/8 |
427 | | - // Remove more stuff. |
428 | 414 | int dot2 = item.lastIndexOf('.'); |
429 | 415 | entry = entry.substring(7, (dot2 == -1) ? entry.length() : dot2); |
430 | | -// System.out.println(entry); |
431 | 416 | } |
432 | 417 |
|
433 | | -// System.out.println("library searching for " + entry); |
434 | 418 | Library library = mode.getLibrary(entry); |
435 | | -// System.out.println(" found " + library); |
436 | 419 |
|
437 | 420 | if (library != null) { |
438 | 421 | if (!importedLibraries.contains(library)) { |
@@ -461,7 +444,6 @@ public String preprocess(File srcFolder, |
461 | 444 | } |
462 | 445 | } |
463 | 446 | } |
464 | | -// PApplet.println(PApplet.split(libraryPath, File.pathSeparatorChar)); |
465 | 447 |
|
466 | 448 | // Finally, add the regular Java CLASSPATH. This contains everything |
467 | 449 | // imported by the PDE itself (core.jar, pde.jar, quaqua.jar) which may |
@@ -533,6 +515,7 @@ public String preprocess(File srcFolder, |
533 | 515 | return result.className; |
534 | 516 | } |
535 | 517 |
|
| 518 | + |
536 | 519 | /** |
537 | 520 | * Returns true if this package isn't part of a library (it's a system import |
538 | 521 | * or something like that). Don't bother complaining about java.* or javax.* |
|