You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2021/10/14 22:24:45 UTC
[royale-compiler] branch develop updated: formatter: preserve
minimum whitespace at end of blank lines inside asdoc tags
This is an automated email from the ASF dual-hosted git repository.
joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
The following commit(s) were added to refs/heads/develop by this push:
new 1f6fc36 formatter: preserve minimum whitespace at end of blank lines inside asdoc <listing> tags
1f6fc36 is described below
commit 1f6fc36be468db2e6ccf66e70b114b2c29c1132c
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Oct 14 15:24:26 2021 -0700
formatter: preserve minimum whitespace at end of blank lines inside asdoc <listing> tags
---
.../org/apache/royale/formatter/FORMATTER.java | 46 +++++++++++++++++++++-
.../apache/royale/formatter/TestAsDocComment.java | 36 +++++++++++++++++
2 files changed, 80 insertions(+), 2 deletions(-)
diff --git a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
index 04cff34..9686eb0 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -71,6 +71,7 @@ public class FORMATTER {
private static final String NEWLINE = System.getProperty("line.separator");
private static final String DEFAULT_VAR = "files";
private static final String L10N_CONFIG_PREFIX = "org.apache.royale.compiler.internal.config.configuration";
+ private static final Pattern ASDOC_START_LINE_PATTERN = Pattern.compile("^\\*(\\s*)");
static enum ExitCode {
SUCCESS(0), PRINT_HELP(1), FAILED_WITH_PROBLEMS(2), FAILED_WITH_EXCEPTIONS(3), FAILED_WITH_CONFIG_PROBLEMS(4);
@@ -1346,18 +1347,59 @@ public class FORMATTER {
return builder.toString();
}
+ private boolean isInListing(String lineText, boolean alreadyInListing) {
+ int searchIndex = 0;
+ boolean inListing = alreadyInListing;
+ while (searchIndex < lineText.length()) {
+ System.err.println(searchIndex + " " + lineText.length() + " " + inListing);
+ if (!inListing) {
+ searchIndex = lineText.indexOf("<listing", searchIndex);
+ if (searchIndex == -1) {
+ return false;
+ }
+ searchIndex += 8;
+ inListing = true;
+ }
+ searchIndex = lineText.indexOf("</listing>", searchIndex);
+ if (searchIndex == -1) {
+ return true;
+ }
+ searchIndex += 10;
+ inListing = false;
+ }
+ return inListing;
+ }
+
private String formatASDocComment(String comment, int indent) {
String[] lines = comment.split("\n");
StringBuilder builder = new StringBuilder();
- builder.append(lines[0].trim());
+ String lineText = lines[0].trim();
+ builder.append(lineText);
+ boolean inListing = isInListing(lineText, false);
if (lines.length > 1) {
builder.append('\n');
}
+ String listingIndent = null;
for (int i = 1; i < lines.length - 1; i++) {
+ lineText = lines[i].trim();
+ if (inListing) {
+ Matcher startMatcher = ASDOC_START_LINE_PATTERN.matcher(lineText);
+ if (startMatcher.find()) {
+ if (listingIndent == null) {
+ listingIndent = startMatcher.group(1);
+ } else if (startMatcher.group().length() >= lineText.length()) {
+ lineText = "*" + listingIndent;
+ }
+ }
+ }
appendIndent(builder, indent);
builder.append(' ');
- builder.append(lines[i].trim());
+ builder.append(lineText);
builder.append('\n');
+ inListing = isInListing(lineText, inListing);
+ if (!inListing) {
+ listingIndent = null;
+ }
}
if (lines.length > 1) {
appendIndent(builder, indent);
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestAsDocComment.java b/formatter/src/test/java/org/apache/royale/formatter/TestAsDocComment.java
index cc905d4..4a6ec50 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestAsDocComment.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestAsDocComment.java
@@ -224,4 +224,40 @@ public class TestAsDocComment extends BaseFormatterTests {
// @formatter:on
result);
}
+ @Test
+ public void testListing() {
+ FORMATTER formatter = new FORMATTER();
+ formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+ formatter.placeOpenBraceOnNewLine = true;
+ formatter.insertSpaces = false;
+ String result = formatter.formatActionScriptText(
+ // @formatter:off
+ "/**\n" +
+ " * Description.\n" +
+ " * \n" +
+ " * <listing>\n" +
+ " * // before\n" +
+ " * \n" +
+ " * </listing>\n" +
+ " * \n" +
+ " * @see test\n" +
+ " */",
+ // @formatter:on
+ problems
+ );
+ assertEquals(
+ // @formatter:off
+ "/**\n" +
+ " * Description.\n" +
+ " *\n" +
+ " * <listing>\n" +
+ " * // before\n" +
+ " * \n" +
+ " * </listing>\n" +
+ " *\n" +
+ " * @see test\n" +
+ " */",
+ // @formatter:on
+ result);
+ }
}