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 22:31:37 UTC

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

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 b2a1d92  formatter: unary - after colon
     new 92c3eca  formatter: don't insert space before ... if it's the first parameter
     new 5b05a53  formatter: fix extra spaces before and after * type
     new bf83e8f  formatter: block close before paren close or comma does not require a new line
     new c2bee35  formatter: fix unnecessary escape of quote if wrapping quote is different

The 4 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     |  50 +++++++++--
 .../royale/formatter/TestFunctionDeclaration.java  | 100 +++++++++++++++++++++
 .../apache/royale/formatter/TestStringLiteral.java |  42 ++++++++-
 .../royale/formatter/TestVariableDeclaration.java  |  38 ++++++++
 4 files changed, 221 insertions(+), 9 deletions(-)

[royale-compiler] 01/04: formatter: don't insert space before ... if it's the first parameter

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 92c3ecaee893d9b3cce24ffaaad12f64f4c88a43
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 6 14:12:31 2021 -0700

    formatter: don't insert space before ... if it's the first parameter
---
 .../org/apache/royale/formatter/FORMATTER.java     |  5 ++-
 .../royale/formatter/TestFunctionDeclaration.java  | 50 ++++++++++++++++++++++
 2 files changed, 54 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 ab2983e..51cddb5 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -737,7 +737,10 @@ class FORMATTER {
 						break;
 					}
 					case ASTokenTypes.TOKEN_ELLIPSIS: {
-						requiredSpace = true;
+						boolean isFirstArg = prevToken == null || prevToken.getType() == ASTokenTypes.TOKEN_PAREN_OPEN;
+						if (!isFirstArg) {
+							requiredSpace = true;
+						}
 						break;
 					}
 					case ASTokenTypes.TOKEN_KEYWORD_DEFAULT:
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java b/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java
index af3eec3..50729e2 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java
@@ -220,4 +220,54 @@ public class TestFunctionDeclaration extends BaseFormatterTests {
 				// @formatter:on
 				result);
 	}
+
+	@Test
+	public void testParametersWithRest() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = true;
+		formatter.insertSpaces = false;
+		String result = formatter.formatText(
+		// @formatter:off
+			"function myFunction(p1:String, ...rest)\n" +
+			"{\n" +
+			"\tstatement;\n" +
+			"}",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"function myFunction(p1:String, ...rest)\n" +
+				"{\n" +
+				"\tstatement;\n" +
+				"}",
+				// @formatter:on
+				result);
+	}
+
+	@Test
+	public void testParametersRestOnly() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = true;
+		formatter.insertSpaces = false;
+		String result = formatter.formatText(
+		// @formatter:off
+			"function myFunction(...rest)\n" +
+			"{\n" +
+			"\tstatement;\n" +
+			"}",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"function myFunction(...rest)\n" +
+				"{\n" +
+				"\tstatement;\n" +
+				"}",
+				// @formatter:on
+				result);
+	}
 }

[royale-compiler] 03/04: formatter: block close before paren close or comma does not require a new line

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 bf83e8f06799519ccfaf316b657b409c236e0723
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 6 14:43:22 2021 -0700

    formatter: block close before paren close or comma does not require a new line
---
 .../org/apache/royale/formatter/FORMATTER.java     |  4 +-
 .../royale/formatter/TestFunctionDeclaration.java  | 50 ++++++++++++++++++++++
 2 files changed, 53 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 4b542eb..02dec76 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -899,7 +899,9 @@ class FORMATTER {
 								blockStack.remove(blockStack.size() - 1);
 							}
 							if (!(item instanceof ObjectLiteralBlockStackItem)
-									&& (nextToken == null || nextToken.getType() != ASTokenTypes.TOKEN_SEMICOLON)) {
+									&& (nextToken == null || (nextToken.getType() != ASTokenTypes.TOKEN_SEMICOLON
+											&& nextToken.getType() != ASTokenTypes.TOKEN_PAREN_CLOSE
+											&& nextToken.getType() != ASTokenTypes.TOKEN_COMMA))) {
 								numRequiredNewLines = Math.max(numRequiredNewLines, 1);
 							}
 						}
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java b/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java
index 50729e2..a15fa8d 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java
@@ -270,4 +270,54 @@ public class TestFunctionDeclaration extends BaseFormatterTests {
 				// @formatter:on
 				result);
 	}
+
+	@Test
+	public void testWrappedInParentheses() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = true;
+		formatter.insertSpaces = false;
+		String result = formatter.formatText(
+		// @formatter:off
+			"(function myFunction(...rest)\n" +
+			"{\n" +
+			"\tstatement;\n" +
+			"});",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"(function myFunction(...rest)\n" +
+				"{\n" +
+				"\tstatement;\n" +
+				"});",
+				// @formatter:on
+				result);
+	}
+
+	@Test
+	public void testAsArgument() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = true;
+		formatter.insertSpaces = false;
+		String result = formatter.formatText(
+		// @formatter:off
+			"identifier(function myFunction(...rest)\n" +
+			"{\n" +
+			"\tstatement;\n" +
+			"}, 123.4);",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"identifier(function myFunction(...rest)\n" +
+				"{\n" +
+				"\tstatement;\n" +
+				"}, 123.4);",
+				// @formatter:on
+				result);
+	}
 }

[royale-compiler] 04/04: formatter: fix unnecessary escape of quote if wrapping quote is different

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 c2bee35552de82f6d3cafebe6b316c48c9abfb04
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 6 14:58:51 2021 -0700

    formatter: fix unnecessary escape of quote if wrapping quote is different
---
 .../org/apache/royale/formatter/FORMATTER.java     | 12 +++++--
 .../apache/royale/formatter/TestStringLiteral.java | 42 ++++++++++++++++++++--
 2 files changed, 49 insertions(+), 5 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 02dec76..7608a45 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -1241,14 +1241,20 @@ class FORMATTER {
 	}
 
 	private String formatLiteralString(String string) {
-		String charsToEscape = "\b\t\n\f\r\"\'\\";
-		String escapeChars = "btnfr\"\'\\";
+		String charsToEscape = "\b\t\n\f\r\\";
+		String escapeChars = "btnfr\\";
 		int escapeIndex = -1;
 		char currChar;
 		StringBuilder builder = new StringBuilder();
 		for (int i = 0; i < string.length(); ++i) {
 			currChar = string.charAt(i);
-			if (i == 0 || i == string.length() - 1) {
+			if (i == 0) {
+				charsToEscape += currChar;
+				escapeChars += currChar;
+				builder.append(currChar);
+				continue;
+			}
+			if (i == string.length() - 1) {
 				builder.append(currChar);
 				continue;
 			}
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestStringLiteral.java b/formatter/src/test/java/org/apache/royale/formatter/TestStringLiteral.java
index f32e5b9..437338f 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestStringLiteral.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestStringLiteral.java
@@ -63,7 +63,7 @@ public class TestStringLiteral extends BaseFormatterTests {
 	}
 
 	@Test
-	public void testWithEscapedDoubleQuote() {
+	public void testDoubleQuoteWithEscapedDoubleQuote() {
 		FORMATTER formatter = new FORMATTER();
 		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
 		formatter.placeOpenBraceOnNewLine = true;
@@ -82,7 +82,26 @@ public class TestStringLiteral extends BaseFormatterTests {
 	}
 
 	@Test
-	public void testWithEscapedSingleQuote() {
+	public void testDoubleQuoteWithUnescapedSingleQuote() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = true;
+		formatter.insertSpaces = false;
+		String result = formatter.formatText(
+		// @formatter:off
+			"\"'\";",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"\"'\";",
+				// @formatter:on
+				result);
+	}
+
+	@Test
+	public void testSingleQuoteWithEscapedSingleQuote() {
 		FORMATTER formatter = new FORMATTER();
 		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
 		formatter.placeOpenBraceOnNewLine = true;
@@ -99,4 +118,23 @@ public class TestStringLiteral extends BaseFormatterTests {
 				// @formatter:on
 				result);
 	}
+
+	@Test
+	public void testSingleQuoteWithUnescapedDoubleQuote() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = true;
+		formatter.insertSpaces = false;
+		String result = formatter.formatText(
+		// @formatter:off
+			"'\"';",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"'\"';",
+				// @formatter:on
+				result);
+	}
 }

[royale-compiler] 02/04: formatter: fix extra spaces before and after * type

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 5b05a53b65a90e2f1ef3846b216e3a4118fa0a76
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 6 14:24:47 2021 -0700

    formatter: fix extra spaces before and after * type
---
 .../org/apache/royale/formatter/FORMATTER.java     | 29 +++++++++++++++--
 .../royale/formatter/TestVariableDeclaration.java  | 38 ++++++++++++++++++++++
 2 files changed, 65 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 51cddb5..4b542eb 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -685,7 +685,6 @@ class FORMATTER {
 					case ASTokenTypes.TOKEN_OPERATOR_GREATER_THAN:
 					case ASTokenTypes.TOKEN_OPERATOR_LESS_THAN_EQUALS:
 					case ASTokenTypes.TOKEN_OPERATOR_GREATER_THAN_EQUALS:
-					case ASTokenTypes.TOKEN_OPERATOR_STAR:
 					case ASTokenTypes.TOKEN_OPERATOR_DIVISION:
 					case ASTokenTypes.TOKEN_OPERATOR_MODULO:
 					case ASTokenTypes.TOKEN_OPERATOR_BITWISE_AND:
@@ -714,6 +713,15 @@ class FORMATTER {
 						}
 						break;
 					}
+					case ASTokenTypes.TOKEN_OPERATOR_STAR: {
+						boolean isAnyType = checkTokenBeforeAnyType(prevTokenNotComment);
+						boolean isAnyVectorType = checkTokensForAnyVectorType(prevTokenNotComment, nextTokenNotComment);
+						if (!isAnyType && !isAnyVectorType && insertSpaceBeforeAndAfterBinaryOperators
+								&& !skipWhitespaceBeforeSemicolon) {
+							requiredSpace = true;
+						}
+						break;
+					}
 					case ASTokenTypes.TOKEN_OPERATOR_PLUS:
 					case ASTokenTypes.TOKEN_OPERATOR_MINUS: {
 						boolean isUnary = checkTokenBeforeUnaryOperator(prevTokenNotComment);
@@ -1113,7 +1121,6 @@ class FORMATTER {
 					case ASTokenTypes.TOKEN_OPERATOR_GREATER_THAN:
 					case ASTokenTypes.TOKEN_OPERATOR_LESS_THAN_EQUALS:
 					case ASTokenTypes.TOKEN_OPERATOR_GREATER_THAN_EQUALS:
-					case ASTokenTypes.TOKEN_OPERATOR_STAR:
 					case ASTokenTypes.TOKEN_OPERATOR_DIVISION:
 					case ASTokenTypes.TOKEN_OPERATOR_MODULO:
 					case ASTokenTypes.TOKEN_OPERATOR_TERNARY:
@@ -1143,6 +1150,15 @@ class FORMATTER {
 						}
 						break;
 					}
+					case ASTokenTypes.TOKEN_OPERATOR_STAR: {
+						boolean isAnyType = checkTokenBeforeAnyType(prevTokenNotComment);
+						boolean isAnyVectorType = checkTokensForAnyVectorType(prevTokenNotComment, nextTokenNotComment);
+						if (!isAnyType && !isAnyVectorType && insertSpaceBeforeAndAfterBinaryOperators
+								&& !skipWhitespaceBeforeSemicolon) {
+							requiredSpace = true;
+						}
+						break;
+					}
 					case ASTokenTypes.TOKEN_OPERATOR_PLUS:
 					case ASTokenTypes.TOKEN_OPERATOR_MINUS: {
 						boolean isUnary = checkTokenBeforeUnaryOperator(prevTokenNotComment);
@@ -1355,6 +1371,15 @@ class FORMATTER {
 		return builder.toString();
 	}
 
+	private boolean checkTokenBeforeAnyType(IASToken token) {
+		return token.getType() == ASTokenTypes.TOKEN_COLON;
+	}
+
+	private boolean checkTokensForAnyVectorType(IASToken prevToken, IASToken nextToken) {
+		return prevToken != null && nextToken != null && prevToken.getType() == ASTokenTypes.TOKEN_TYPED_COLLECTION_OPEN
+				&& nextToken.getType() == ASTokenTypes.TOKEN_TYPED_COLLECTION_CLOSE;
+	}
+
 	private boolean checkTokenBeforeUnaryOperator(IASToken token) {
 		return (token instanceof ASToken) ? ((ASToken) token).isOperator()
 				|| token.getType() == ASTokenTypes.TOKEN_SQUARE_OPEN || token.getType() == ASTokenTypes.TOKEN_PAREN_OPEN
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestVariableDeclaration.java b/formatter/src/test/java/org/apache/royale/formatter/TestVariableDeclaration.java
index 51cb0a5..c769066 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestVariableDeclaration.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestVariableDeclaration.java
@@ -81,4 +81,42 @@ public class TestVariableDeclaration extends BaseFormatterTests {
 				// @formatter:on
 				result);
 	}
+
+	@Test
+	public void testWithAnyType() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = true;
+		formatter.insertSpaces = false;
+		String result = formatter.formatText(
+		// @formatter:off
+			"var myVar:*;",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"var myVar:*;",
+				// @formatter:on
+				result);
+	}
+
+	@Test
+	public void testWithVectorAnyType() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = true;
+		formatter.insertSpaces = false;
+		String result = formatter.formatText(
+		// @formatter:off
+			"var myVar:Vector.<*>;",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"var myVar:Vector.<*>;",
+				// @formatter:on
+				result);
+	}
 }