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/06 18:00:23 UTC

[royale-compiler] branch develop updated (f0e2765 -> b2a1d92)

This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git.


    from f0e2765  playerglobalc: [Event] metadata
     new 64e040c  formatter: option to insert a space at the start of line comments
     new 92c76fe  formatter: extra test for block comments
     new 256a045  formatter: fix missing new line after single line comment
     new a963681  formatter: increase indent when opening square brackets
     new c816de4  formatter: unary - with return
     new c51f2fc  formatter: unary - after comma
     new b2a1d92  formatter: unary - after colon

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/royale/formatter/FORMATTER.java     | 32 ++++++++++++--
 .../royale/formatter/config/Configuration.java     | 18 ++++++++
 .../apache/royale/formatter/TestIdentifier.java    | 51 ++++++++++++++++++++++
 .../royale/formatter/TestMultiLineComment.java     | 23 ++++++++++
 .../royale/formatter/TestSingleLineComment.java    | 51 +++++++++++++++++++++-
 5 files changed, 171 insertions(+), 4 deletions(-)

[royale-compiler] 06/07: formatter: unary - after comma

Posted by jo...@apache.org.
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 c51f2fc5a1f27656341baa3b8904351da285a33d
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 6 10:57:52 2021 -0700

    formatter: unary - after comma
---
 .../java/org/apache/royale/formatter/FORMATTER.java     |  3 ++-
 .../org/apache/royale/formatter/TestIdentifier.java     | 17 +++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

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 e7dd6ea..6108806 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -1356,7 +1356,8 @@ class FORMATTER {
 		return (token instanceof ASToken) ? ((ASToken) token).isOperator()
 				|| token.getType() == ASTokenTypes.TOKEN_SQUARE_OPEN || token.getType() == ASTokenTypes.TOKEN_PAREN_OPEN
 				|| token.getType() == ASTokenTypes.TOKEN_BLOCK_OPEN || token.getType() == ASTokenTypes.TOKEN_SEMICOLON
-				|| token.getType() == ASTokenTypes.TOKEN_KEYWORD_RETURN : (token == null);
+				|| token.getType() == ASTokenTypes.TOKEN_KEYWORD_RETURN || token.getType() == ASTokenTypes.TOKEN_COMMA
+				: (token == null);
 	}
 
 	private int increaseIndent(int indent) {
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestIdentifier.java b/formatter/src/test/java/org/apache/royale/formatter/TestIdentifier.java
index 7dd43d9..94cc797 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestIdentifier.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestIdentifier.java
@@ -200,6 +200,23 @@ public class TestIdentifier extends BaseFormatterTests {
 	}
 
 	@Test
+	public void testUnaryMinusWithComma() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceBeforeAndAfterBinaryOperators = true;
+		String result = formatter.formatText(
+		// @formatter:off
+			"var array = [identifier, -identifier];",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"var array = [identifier, -identifier];",
+				// @formatter:on
+				result);
+	}
+
+	@Test
 	public void testNot() {
 		FORMATTER formatter = new FORMATTER();
 		formatter.insertSpaceBeforeAndAfterBinaryOperators = true;

[royale-compiler] 02/07: formatter: extra test for block comments

Posted by jo...@apache.org.
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 92c76fee90a3590f0edecd0e5716c3a83e7e974b
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 6 10:14:49 2021 -0700

    formatter: extra test for block comments
---
 .../royale/formatter/TestMultiLineComment.java     | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)

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 c2fa2c2..c3f8b24 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestMultiLineComment.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestMultiLineComment.java
@@ -85,4 +85,27 @@ public class TestMultiLineComment extends BaseFormatterTests {
 				result);
 	}
 
+	@Test
+	public void testPreserveMultilineFormatting() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = true;
+		formatter.insertSpaces = false;
+		String result = formatter.formatText(
+		// @formatter:off
+			"/*\n" +
+			"\tthis is a comment\n" +
+			"*/",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"/*\n" +
+				"\tthis is a comment\n" +
+				"*/",
+				// @formatter:on
+				result);
+	}
+
 }

[royale-compiler] 01/07: formatter: option to insert a space at the start of line comments

Posted by jo...@apache.org.
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 64e040c0ca0dfb0029098599de1ad895121550cf
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 6 10:04:40 2021 -0700

    formatter: option to insert a space at the start of line comments
---
 .../org/apache/royale/formatter/FORMATTER.java     | 10 ++++++++-
 .../royale/formatter/config/Configuration.java     | 18 +++++++++++++++
 .../royale/formatter/TestSingleLineComment.java    | 26 +++++++++++++++++++++-
 3 files changed, 52 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 ee6ceb8..6eed027 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -104,6 +104,7 @@ class FORMATTER {
 	public boolean insertSpaceAfterFunctionKeywordForAnonymousFunctions = false;
 	public boolean insertSpaceBeforeAndAfterBinaryOperators = true;
 	public boolean insertSpaceAfterCommaDelimiter = true;
+	public boolean insertSpaceAtStartOfLineComment = true;
 	public int maxPreserveNewLines = 2;
 	public Semicolons semicolons = Semicolons.INSERT;
 	public boolean ignoreProblems = false;
@@ -293,6 +294,7 @@ class FORMATTER {
 					.getInsertSpaceAfterKeywordsInControlFlowStatements();
 			insertSpaceAfterSemicolonInForStatements = configuration.getInsertSpaceAfterSemicolonInForStatements();
 			insertSpaceBeforeAndAfterBinaryOperators = configuration.getInsertSpaceBeforeAndAfterBinaryOperators();
+			insertSpaceAtStartOfLineComment = configuration.getInsertSpaceAtStartOfLineComment();
 			insertSpaces = configuration.getInsertSpaces();
 			listChangedFiles = configuration.getListFiles();
 			maxPreserveNewLines = configuration.getMaxPreserveNewLines();
@@ -1187,7 +1189,13 @@ class FORMATTER {
 
 	private String formatSingleLineComment(String comment) {
 		comment = comment.substring(2).trim();
-		return "// " + comment;
+		StringBuilder builder = new StringBuilder();
+		builder.append("//");
+		if(insertSpaceAtStartOfLineComment) {
+			builder.append(" ");
+		}
+		builder.append(comment);
+		return builder.toString();
 	}
 
 	private String formatMultiLineComment(String comment) {
diff --git a/formatter/src/main/java/org/apache/royale/formatter/config/Configuration.java b/formatter/src/main/java/org/apache/royale/formatter/config/Configuration.java
index c66c8a9..1b6699f 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/config/Configuration.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/config/Configuration.java
@@ -347,6 +347,24 @@ public class Configuration {
     }
 
     //
+    // 'insert-space-line-comment' option
+    //
+
+    private boolean insertSpaceAtStartOfLineComment = true;
+
+    public boolean getInsertSpaceAtStartOfLineComment()
+    {
+        return insertSpaceAtStartOfLineComment;
+    }
+
+    @Config
+    @Mapping("insert-space-line-comment")
+    public void setInsertSpaceAtStartOfLineComment(ConfigurationValue cv, boolean b)
+    {
+        this.insertSpaceAtStartOfLineComment = b;
+    }
+
+    //
     // 'collapse-empty-blocks' option
     //
 
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestSingleLineComment.java b/formatter/src/test/java/org/apache/royale/formatter/TestSingleLineComment.java
index 1d96788..7d752be 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestSingleLineComment.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestSingleLineComment.java
@@ -25,11 +25,12 @@ import org.junit.Test;
 
 public class TestSingleLineComment extends BaseFormatterTests {
 	@Test
-	public void testWithoutSpace() {
+	public void testInsertSpaceAtStartOfLineComment() {
 		FORMATTER formatter = new FORMATTER();
 		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
 		formatter.placeOpenBraceOnNewLine = true;
 		formatter.insertSpaces = false;
+		formatter.insertSpaceAtStartOfLineComment = true;
 		String result = formatter.formatText(
 		// @formatter:off
 			"//this is a comment",
@@ -42,6 +43,25 @@ public class TestSingleLineComment extends BaseFormatterTests {
 				// @formatter:on
 				result);
 	}
+	@Test
+	public void testDisableInsertSpaceAtStartOfLineComment() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = true;
+		formatter.insertSpaces = false;
+		formatter.insertSpaceAtStartOfLineComment = false;
+		String result = formatter.formatText(
+		// @formatter:off
+			"// this is a comment",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"//this is a comment",
+				// @formatter:on
+				result);
+	}
 
 	@Test
 	public void testAtEndOfStatement() {
@@ -49,6 +69,7 @@ public class TestSingleLineComment extends BaseFormatterTests {
 		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
 		formatter.placeOpenBraceOnNewLine = true;
 		formatter.insertSpaces = false;
+		formatter.insertSpaceAtStartOfLineComment = true;
 		String result = formatter.formatText(
 		// @formatter:off
 			"statement; // this is a comment",
@@ -68,6 +89,7 @@ public class TestSingleLineComment extends BaseFormatterTests {
 		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
 		formatter.placeOpenBraceOnNewLine = true;
 		formatter.insertSpaces = false;
+		formatter.insertSpaceAtStartOfLineComment = true;
 		String result = formatter.formatText(
 		// @formatter:off
 			"// this is a comment\n" +
@@ -89,6 +111,7 @@ public class TestSingleLineComment extends BaseFormatterTests {
 		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
 		formatter.placeOpenBraceOnNewLine = true;
 		formatter.insertSpaces = false;
+		formatter.insertSpaceAtStartOfLineComment = true;
 		String result = formatter.formatText(
 		// @formatter:off
 			"statement;\n" +
@@ -110,6 +133,7 @@ public class TestSingleLineComment extends BaseFormatterTests {
 		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
 		formatter.placeOpenBraceOnNewLine = true;
 		formatter.insertSpaces = false;
+		formatter.insertSpaceAtStartOfLineComment = true;
 		String result = formatter.formatText(
 		// @formatter:off
 			"if (statement) // this is a comment\n" +

[royale-compiler] 05/07: formatter: unary - with return

Posted by jo...@apache.org.
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 c816de4693845cdd10d538931a97425c1d8d8738
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 6 10:55:48 2021 -0700

    formatter: unary - with return
---
 .../java/org/apache/royale/formatter/FORMATTER.java     |  2 +-
 .../org/apache/royale/formatter/TestIdentifier.java     | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

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 50a076d..e7dd6ea 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -1356,7 +1356,7 @@ class FORMATTER {
 		return (token instanceof ASToken) ? ((ASToken) token).isOperator()
 				|| token.getType() == ASTokenTypes.TOKEN_SQUARE_OPEN || token.getType() == ASTokenTypes.TOKEN_PAREN_OPEN
 				|| token.getType() == ASTokenTypes.TOKEN_BLOCK_OPEN || token.getType() == ASTokenTypes.TOKEN_SEMICOLON
-				: (token == null);
+				|| token.getType() == ASTokenTypes.TOKEN_KEYWORD_RETURN : (token == null);
 	}
 
 	private int increaseIndent(int indent) {
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestIdentifier.java b/formatter/src/test/java/org/apache/royale/formatter/TestIdentifier.java
index 2f00d8a..7dd43d9 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestIdentifier.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestIdentifier.java
@@ -183,6 +183,23 @@ public class TestIdentifier extends BaseFormatterTests {
 	}
 
 	@Test
+	public void testUnaryMinusWithReturn() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceBeforeAndAfterBinaryOperators = true;
+		String result = formatter.formatText(
+		// @formatter:off
+			"return -identifier;",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"return -identifier;",
+				// @formatter:on
+				result);
+	}
+
+	@Test
 	public void testNot() {
 		FORMATTER formatter = new FORMATTER();
 		formatter.insertSpaceBeforeAndAfterBinaryOperators = true;

[royale-compiler] 04/07: formatter: increase indent when opening square brackets

Posted by jo...@apache.org.
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 a9636818171e1c0e98287537fa7c67c15f9852ba
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 6 10:45:05 2021 -0700

    formatter: increase indent when opening square brackets
---
 .../java/org/apache/royale/formatter/FORMATTER.java     | 17 +++++++++++++++--
 1 file changed, 15 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 a93fc3f..50a076d 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -551,7 +551,7 @@ class FORMATTER {
 				}
 				if (!blockOpenPending) {
 					int newLinesInExtra = countNewLinesInExtra(token);
-					if(prevToken != null && prevToken.getType() == ASTokenTypes.HIDDEN_TOKEN_SINGLE_LINE_COMMENT) {
+					if (prevToken != null && prevToken.getType() == ASTokenTypes.HIDDEN_TOKEN_SINGLE_LINE_COMMENT) {
 						newLinesInExtra++;
 					}
 					numRequiredNewLines = Math.max(numRequiredNewLines, newLinesInExtra);
@@ -656,6 +656,15 @@ class FORMATTER {
 						}
 						break;
 					}
+					case ASTokenTypes.TOKEN_SQUARE_CLOSE:
+						if (!blockStack.isEmpty()) {
+							BlockStackItem item = blockStack.get(blockStack.size() - 1);
+							if (item.token.getType() == ASTokenTypes.TOKEN_SQUARE_OPEN) {
+								indent = decreaseIndent(indent);
+								blockStack.remove(item);
+							}
+						}
+						break;
 					case ASTokenTypes.TOKEN_KEYWORD_AS:
 					case ASTokenTypes.TOKEN_KEYWORD_IS:
 					case ASTokenTypes.TOKEN_KEYWORD_IN:
@@ -885,6 +894,10 @@ class FORMATTER {
 						}
 						break;
 					}
+					case ASTokenTypes.TOKEN_SQUARE_OPEN:
+						indent = increaseIndent(indent);
+						blockStack.add(new BlockStackItem(token));
+						break;
 					case ASTokenTypes.TOKEN_OPERATOR_INCREMENT:
 					case ASTokenTypes.TOKEN_OPERATOR_DECREMENT: {
 						if (!inControlFlowStatement && prevToken != null
@@ -1195,7 +1208,7 @@ class FORMATTER {
 		comment = comment.substring(2).trim();
 		StringBuilder builder = new StringBuilder();
 		builder.append("//");
-		if(insertSpaceAtStartOfLineComment) {
+		if (insertSpaceAtStartOfLineComment) {
 			builder.append(" ");
 		}
 		builder.append(comment);

[royale-compiler] 07/07: formatter: unary - after colon

Posted by jo...@apache.org.
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 b2a1d92738c136f036ba1ee037e0bf7dcf471abb
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 6 10:59:54 2021 -0700

    formatter: unary - after colon
---
 .../java/org/apache/royale/formatter/FORMATTER.java     |  2 +-
 .../org/apache/royale/formatter/TestIdentifier.java     | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

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 6108806..ab2983e 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -1357,7 +1357,7 @@ class FORMATTER {
 				|| token.getType() == ASTokenTypes.TOKEN_SQUARE_OPEN || token.getType() == ASTokenTypes.TOKEN_PAREN_OPEN
 				|| token.getType() == ASTokenTypes.TOKEN_BLOCK_OPEN || token.getType() == ASTokenTypes.TOKEN_SEMICOLON
 				|| token.getType() == ASTokenTypes.TOKEN_KEYWORD_RETURN || token.getType() == ASTokenTypes.TOKEN_COMMA
-				: (token == null);
+				|| token.getType() == ASTokenTypes.TOKEN_COLON : (token == null);
 	}
 
 	private int increaseIndent(int indent) {
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestIdentifier.java b/formatter/src/test/java/org/apache/royale/formatter/TestIdentifier.java
index 94cc797..af37e89 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestIdentifier.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestIdentifier.java
@@ -217,6 +217,23 @@ public class TestIdentifier extends BaseFormatterTests {
 	}
 
 	@Test
+	public void testUnaryMinusWithColon() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceBeforeAndAfterBinaryOperators = true;
+		String result = formatter.formatText(
+		// @formatter:off
+			"var obj = {field: -identifier};",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"var obj = {field: -identifier};",
+				// @formatter:on
+				result);
+	}
+
+	@Test
 	public void testNot() {
 		FORMATTER formatter = new FORMATTER();
 		formatter.insertSpaceBeforeAndAfterBinaryOperators = true;

[royale-compiler] 03/07: formatter: fix missing new line after single line comment

Posted by jo...@apache.org.
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 256a0456f8c95b2a039937c7913ecf8d85584b0b
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 6 10:25:50 2021 -0700

    formatter: fix missing new line after single line comment
---
 .../org/apache/royale/formatter/FORMATTER.java     |  6 +++++-
 .../royale/formatter/TestSingleLineComment.java    | 25 ++++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)

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 6eed027..a93fc3f 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -550,7 +550,11 @@ class FORMATTER {
 					break;
 				}
 				if (!blockOpenPending) {
-					numRequiredNewLines = Math.max(numRequiredNewLines, countNewLinesInExtra(token));
+					int newLinesInExtra = countNewLinesInExtra(token);
+					if(prevToken != null && prevToken.getType() == ASTokenTypes.HIDDEN_TOKEN_SINGLE_LINE_COMMENT) {
+						newLinesInExtra++;
+					}
+					numRequiredNewLines = Math.max(numRequiredNewLines, newLinesInExtra);
 					if (!indentedStatement && numRequiredNewLines > 0 && prevTokenNotComment != null
 							&& prevTokenNotComment.getType() != ASTokenTypes.TOKEN_SEMICOLON
 							&& prevTokenNotComment.getType() != ASTokenTypes.TOKEN_BLOCK_CLOSE
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestSingleLineComment.java b/formatter/src/test/java/org/apache/royale/formatter/TestSingleLineComment.java
index 7d752be..98f8202 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestSingleLineComment.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestSingleLineComment.java
@@ -106,6 +106,31 @@ public class TestSingleLineComment extends BaseFormatterTests {
 	}
 
 	@Test
+	public void testWithExtraLineBeforeStatement() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = true;
+		formatter.insertSpaces = false;
+		formatter.insertSpaceAtStartOfLineComment = true;
+		formatter.maxPreserveNewLines = 2;
+		String result = formatter.formatText(
+		// @formatter:off
+			"// this is a comment\n" +
+			"\n" +
+			"statement;",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"// this is a comment\n" +
+				"\n" +
+				"statement;",
+				// @formatter:on
+				result);
+	}
+
+	@Test
 	public void testOnLineAfterStatement() {
 		FORMATTER formatter = new FORMATTER();
 		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;