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
commit 63177f98ddf6c736e4f3ac00a37368153aa75122 Author: Josh Tynjala <[email protected]> AuthorDate: Wed Jan 8 09:04:29 2025 -0800 formatter: insert space after multi-line comment in some cases --- .../apache/royale/formatter/ASTokenFormatter.java | 2 +- .../royale/formatter/TestMultiLineComment.java | 62 +++++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java b/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java index 2768c802f..360622daa 100644 --- a/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java +++ b/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java @@ -1071,8 +1071,8 @@ public class ASTokenFormatter extends BaseTokenFormatter { if (!skipWhitespaceBeforeSemicolon) { if (nextTokenOrExtra != null && nextTokenOrExtra.getType() == TOKEN_TYPE_EXTRA) { numRequiredNewLines = Math.max(0, countNewLinesInExtra(nextTokenOrExtra)); - requiredSpace = true; } + requiredSpace = true; } break; } diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestMultiLineComment.java b/formatter/src/test/java/org/apache/royale/formatter/TestMultiLineComment.java index 99dd26ce1..d9a621349 100644 --- a/formatter/src/test/java/org/apache/royale/formatter/TestMultiLineComment.java +++ b/formatter/src/test/java/org/apache/royale/formatter/TestMultiLineComment.java @@ -25,7 +25,47 @@ import org.junit.Test; public class TestMultiLineComment extends BaseFormatterTests { @Test - public void testAtEndOfStatement() { + public void testAtStartOfStatement() { + FormatterSettings settings = new FormatterSettings(); + settings.insertSpaceAfterKeywordsInControlFlowStatements = true; + settings.placeOpenBraceOnNewLine = true; + settings.insertSpaces = false; + ASTokenFormatter formatter = new ASTokenFormatter(settings); + String result = formatter.format("file.as", + // @formatter:off + "/* this is a comment */statement;", + // @formatter:on + problems + ); + assertEquals( + // @formatter:off + "/* this is a comment */ statement;", + // @formatter:on + result); + } + + @Test + public void testAtEndOfStatementBeforeSemicolon() { + FormatterSettings settings = new FormatterSettings(); + settings.insertSpaceAfterKeywordsInControlFlowStatements = true; + settings.placeOpenBraceOnNewLine = true; + settings.insertSpaces = false; + ASTokenFormatter formatter = new ASTokenFormatter(settings); + String result = formatter.format("file.as", + // @formatter:off + "statement/* this is a comment */;", + // @formatter:on + problems + ); + assertEquals( + // @formatter:off + "statement /* this is a comment */;", + // @formatter:on + result); + } + + @Test + public void testAfterStatementAndSemicolon() { FormatterSettings settings = new FormatterSettings(); settings.insertSpaceAfterKeywordsInControlFlowStatements = true; settings.placeOpenBraceOnNewLine = true; @@ -44,6 +84,26 @@ public class TestMultiLineComment extends BaseFormatterTests { result); } + @Test + public void testBeforeVariableInitializer() { + FormatterSettings settings = new FormatterSettings(); + settings.insertSpaceAfterKeywordsInControlFlowStatements = true; + settings.placeOpenBraceOnNewLine = true; + settings.insertSpaces = false; + ASTokenFormatter formatter = new ASTokenFormatter(settings); + String result = formatter.format("file.as", + // @formatter:off + "var myVar:Number=/* this is a comment */123.4;", + // @formatter:on + problems + ); + assertEquals( + // @formatter:off + "var myVar:Number = /* this is a comment */ 123.4;", + // @formatter:on + result); + } + @Test public void testOnLineBeforeStatement() { FormatterSettings settings = new FormatterSettings();
