From 8ee119f15019e122e2df289df0fecab82570a1dd Mon Sep 17 00:00:00 2001 From: A Pottinger Date: Sat, 29 Jan 2022 20:05:34 -0800 Subject: [PATCH] As part of #371, finally disable SourceUtils transforms. SourceUtils has been doing unnecessary stuff but, until multiline strings, they weren't getting in the way so it stuck around. Adding flag to disable since the automaton inside SourceUtils is difficult to modify for the new language feature. --- java/src/processing/mode/java/PreprocService.java | 4 ++-- java/src/processing/mode/java/SourceUtil.java | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/java/src/processing/mode/java/PreprocService.java b/java/src/processing/mode/java/PreprocService.java index 1d325e30f..3029a6dfd 100644 --- a/java/src/processing/mode/java/PreprocService.java +++ b/java/src/processing/mode/java/PreprocService.java @@ -403,8 +403,8 @@ public class PreprocService { } // TODO: convert unicode escapes to chars - - SourceUtil.scrubCommentsAndStrings(workBuffer); + // TODO: This appears no longer to be needed. + // SourceUtil.scrubCommentsAndStrings(workBuffer); result.scrubbedPdeCode = workBuffer.toString(); diff --git a/java/src/processing/mode/java/SourceUtil.java b/java/src/processing/mode/java/SourceUtil.java index 3823bc907..d063bd338 100644 --- a/java/src/processing/mode/java/SourceUtil.java +++ b/java/src/processing/mode/java/SourceUtil.java @@ -17,6 +17,9 @@ import processing.mode.java.TextTransform.Edit; public class SourceUtil { + // No longer needed with use of ANTLR in the preprocessor service. + private static final boolean PERFORM_SOURCE_UTIL_TRANSFORMS = false; + public static final Pattern IMPORT_REGEX = Pattern.compile("(?:^|;)\\s*(import\\s+(?:(static)\\s+)?((?:\\w+\\s*\\.)*)\\s*(\\S+)\\s*;)", Pattern.MULTILINE | Pattern.DOTALL); @@ -162,6 +165,10 @@ public class SourceUtil { Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED; public static List preprocessAST(CompilationUnit cu) { + if (!PERFORM_SOURCE_UTIL_TRANSFORMS) { + return new ArrayList<>(); + } + final List edits = new ArrayList<>(); // Walk the tree @@ -251,6 +258,9 @@ public class SourceUtil { static public void scrubCommentsAndStrings(StringBuilder p) { + if (!PERFORM_SOURCE_UTIL_TRANSFORMS) { + return; + } final int length = p.length(); @@ -320,7 +330,7 @@ public class SourceUtil { } else { // Exiting block int blockEnd = i; - if (prevState == IN_BLOCK_COMMENT && i < length) blockEnd--; // preserve star in '*/' + if (prevState == IN_BLOCK_COMMENT && i < length) blockEnd--; for (int j = blockStart; j < blockEnd; j++) { char c = p.charAt(j); if (c != '\n' && c != '\r') p.setCharAt(j, ' '); @@ -330,7 +340,6 @@ public class SourceUtil { prevState = state; } - }