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/11/15 23:04:48 UTC

[royale-compiler] branch develop updated (16dcb98 -> 9fb3b29)

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 16dcb98  (minor) code tidy and update release notes.
     new 6e26571  formatter: disable and re-enable formatting with comments
     new 33e0b4a  formatter: some missing braces
     new 078dfca  formatter: MXML formatter off/on comments
     new 149dace  formatter: handle space before /> in MXML
     new 9fb3b29  formatter: minor cleanup of off/on tags for AS3

The 5 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     | 172 ++++++++++++++-------
 ...ncrementOperator.java => TestFormatterOff.java} |  71 +++++++--
 .../org/apache/royale/formatter/TestMXMLTag.java   |   2 +-
 3 files changed, 176 insertions(+), 69 deletions(-)
 copy formatter/src/test/java/org/apache/royale/formatter/{TestIncrementOperator.java => TestFormatterOff.java} (55%)

[royale-compiler] 03/05: formatter: MXML formatter off/on 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 078dfca354db96e8619074d7d95a27a7bdad965a
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Mon Nov 15 14:48:12 2021 -0800

    formatter: MXML formatter off/on comments
---
 .../org/apache/royale/formatter/FORMATTER.java     | 59 ++++++++++++++--------
 .../apache/royale/formatter/TestFormatterOff.java  | 43 +++++++++++++++-
 2 files changed, 81 insertions(+), 21 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 c379573..8fda9a1 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -1723,6 +1723,7 @@ public class FORMATTER {
 		boolean requiredSpace = false;
 		boolean inOpenTag = false;
 		boolean inCloseTag = false;
+		boolean skipFormatting = false;
 		String attributeIndent = "";
 		IMXMLToken prevToken = null;
 		IMXMLToken prevTokenOrExtra = null;
@@ -1737,30 +1738,38 @@ public class FORMATTER {
 				nextToken = tokens.get(i + 1);
 			}
 			if (token.getType() == TOKEN_TYPE_EXTRA) {
-				if (i == (tokens.size() - 1)) {
-					// if the last token is whitespace, include new lines
-					numRequiredNewLines = Math.max(0, countNewLinesInExtra(token));
-					appendNewLines(builder, numRequiredNewLines);
-					break;
+				if (skipFormatting) {
+					builder.append(token.getText());
+				} else {
+					if (i == (tokens.size() - 1)) {
+						// if the last token is whitespace, include new lines
+						numRequiredNewLines = Math.max(0, countNewLinesInExtra(token));
+						appendNewLines(builder, numRequiredNewLines);
+						break;
+					}
+					numRequiredNewLines = Math.max(numRequiredNewLines, countNewLinesInExtra(token));
 				}
-				numRequiredNewLines = Math.max(numRequiredNewLines, countNewLinesInExtra(token));
 				prevTokenOrExtra = token;
 				continue;
 			} else if (token.getType() == MXMLTokenTypes.TOKEN_WHITESPACE) {
-				if (elementStack.isEmpty() || !elementStack.get(elementStack.size() - 1).containsText) {
-					numRequiredNewLines = Math.max(numRequiredNewLines, countNewLinesInExtra(token));
-				} else {
-					// if the parent element contains text, treat whitespace
-					// the same as text, and don't reformat it
-					// text is never reformatted because some components use it
-					// without collapsing whitespace, and developers would be
-					// confused if whitespace that they deliberately added were
-					// to be removed
+				if (skipFormatting) {
 					builder.append(token.getText());
-				}
-				if (i == (tokens.size() - 1)) {
-					// if the last token is whitespace, append new lines
-					appendNewLines(builder, numRequiredNewLines);
+				} else {
+					if (elementStack.isEmpty() || !elementStack.get(elementStack.size() - 1).containsText) {
+						numRequiredNewLines = Math.max(numRequiredNewLines, countNewLinesInExtra(token));
+					} else {
+						// if the parent element contains text, treat whitespace
+						// the same as text, and don't reformat it
+						// text is never reformatted because some components use it
+						// without collapsing whitespace, and developers would be
+						// confused if whitespace that they deliberately added were
+						// to be removed
+						builder.append(token.getText());
+					}
+					if (i == (tokens.size() - 1)) {
+						// if the last token is whitespace, append new lines
+						appendNewLines(builder, numRequiredNewLines);
+					}
 				}
 				continue;
 			} else if (token.getType() == MXMLTokenTypes.TOKEN_OPEN_TAG_START
@@ -1821,7 +1830,7 @@ public class FORMATTER {
 				}
 			}
 
-			if (prevToken != null) {
+			if (!skipFormatting && prevToken != null) {
 				if (numRequiredNewLines > 0) {
 					appendNewLines(builder, numRequiredNewLines);
 					appendIndent(builder, indent);
@@ -1915,6 +1924,16 @@ public class FORMATTER {
 					}
 					break;
 				}
+				case MXMLTokenTypes.TOKEN_COMMENT: {
+					String tokenText = token.getText();
+					String trimmed = tokenText.substring(4, tokenText.length() - 3).trim();
+					if (!skipFormatting && FORMATTER_TAG_OFF.equals(trimmed)) {
+						skipFormatting = true;
+					} else if (skipFormatting && FORMATTER_TAG_ON.equals(trimmed)) {
+						skipFormatting = false;
+					}
+					break;
+				}
 			}
 
 			prevToken = token;
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestFormatterOff.java b/formatter/src/test/java/org/apache/royale/formatter/TestFormatterOff.java
index c0c8f9b..be1fd28 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestFormatterOff.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestFormatterOff.java
@@ -25,7 +25,7 @@ import org.junit.Test;
 
 public class TestFormatterOff extends BaseFormatterTests {
 	@Test
-	public void testFormatterOff() {
+	public void testAS3FormatterOff() {
 		FORMATTER formatter = new FORMATTER();
 		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
 		formatter.placeOpenBraceOnNewLine = true;
@@ -69,4 +69,45 @@ public class TestFormatterOff extends BaseFormatterTests {
 				// @formatter:on
 				result);
 	}
+
+	@Test
+	public void testMXMLFormatterOff() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = true;
+		formatter.insertSpaces = true;
+		formatter.tabSize = 2;
+		formatter.maxPreserveNewLines = 2;
+		String result = formatter.formatMXMLText(
+		// @formatter:off
+			"<mx:Application>\n" +
+			"\t<!-- @formatter:off -->\n" +
+			"\t<mx:Button/>\n" +
+			"\n" +
+			"\n" +
+			"\n" +
+			"\t<!-- @formatter:on -->\n" +
+			"\t<mx:Button/>\n" +
+			"\n" +
+			"\n" +
+			"\n" +
+			"</mx:Application>",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"<mx:Application>\n" +
+				"  <!-- @formatter:off -->\n" +
+				"\t<mx:Button/>\n" +
+				"\n" +
+				"\n" +
+				"\n" +
+				"\t<!-- @formatter:on -->\n" +
+				"  <mx:Button/>\n" +
+				"\n" +
+				"</mx:Application>",
+				// @formatter:on
+				result);
+	}
 }
\ No newline at end of file

[royale-compiler] 01/05: formatter: disable and re-enable formatting with 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 6e2657111e61d4b70502beafb3e5f26d561f0942
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Mon Nov 15 11:33:43 2021 -0800

    formatter: disable and re-enable formatting with comments
    
    Uses // @formatter:off and // @formatter:on
---
 .../org/apache/royale/formatter/FORMATTER.java     | 88 +++++++++++++++-------
 .../apache/royale/formatter/TestFormatterOff.java  | 72 ++++++++++++++++++
 2 files changed, 132 insertions(+), 28 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 dace35d..d4a8935 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -79,6 +79,8 @@ public class FORMATTER {
 	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*)");
+	private static final String FORMATTER_TAG_OFF = "@formatter:off";
+	private static final String FORMATTER_TAG_ON = "@formatter:on";
 
 	static enum ExitCode {
 		SUCCESS(0), PRINT_HELP(1), FAILED_WITH_PROBLEMS(2), FAILED_WITH_EXCEPTIONS(3), FAILED_WITH_CONFIG_PROBLEMS(4);
@@ -658,6 +660,7 @@ public class FORMATTER {
 		boolean blockOpenPending = false;
 		boolean indentedStatement = false;
 		boolean caseOrDefaultBlockOpenPending = false;
+		boolean skipFormatting = false;
 		List<BlockStackItem> blockStack = new ArrayList<BlockStackItem>();
 		int controlFlowParenStack = 0;
 		int ternaryStack = 0;
@@ -674,30 +677,34 @@ public class FORMATTER {
 		for (int i = 0; i < tokens.size(); i++) {
 			token = tokens.get(i);
 			if (token.getType() == TOKEN_TYPE_EXTRA) {
-				if (i == (tokens.size() - 1)) {
-					// if the last token is whitespace, include new lines
-					numRequiredNewLines = Math.max(0, countNewLinesInExtra(token));
-					appendNewLines(builder, numRequiredNewLines);
-					break;
-				}
-				if (!blockOpenPending) {
-					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
-							&& !(caseOrDefaultBlockOpenPending
-									&& prevTokenNotComment.getType() == ASTokenTypes.TOKEN_COLON)
-							&& !(prevTokenNotComment instanceof MetaDataPayloadToken)) {
-						boolean needsIndent = prevTokenNotComment.getType() != ASTokenTypes.TOKEN_BLOCK_OPEN
-								|| (!blockStack.isEmpty() && blockStack
-										.get(blockStack.size() - 1) instanceof ObjectLiteralBlockStackItem);
-						if (needsIndent) {
-							indentedStatement = true;
-							indent = increaseIndent(indent);
+				if (skipFormatting) {
+					builder.append(token.getText());
+				} else {
+					if (i == (tokens.size() - 1)) {
+						// if the last token is whitespace, include new lines
+						numRequiredNewLines = Math.max(0, countNewLinesInExtra(token));
+						appendNewLines(builder, numRequiredNewLines);
+						break;
+					}
+					if (!blockOpenPending) {
+						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
+								&& !(caseOrDefaultBlockOpenPending
+										&& prevTokenNotComment.getType() == ASTokenTypes.TOKEN_COLON)
+								&& !(prevTokenNotComment instanceof MetaDataPayloadToken)) {
+							boolean needsIndent = prevTokenNotComment.getType() != ASTokenTypes.TOKEN_BLOCK_OPEN
+									|| (!blockStack.isEmpty() && blockStack
+											.get(blockStack.size() - 1) instanceof ObjectLiteralBlockStackItem);
+							if (needsIndent) {
+								indentedStatement = true;
+								indent = increaseIndent(indent);
+							}
 						}
 					}
 				}
@@ -802,10 +809,23 @@ public class FORMATTER {
 					case ASTokenTypes.TOKEN_RESERVED_WORD_EACH:
 					case ASTokenTypes.TOKEN_RESERVED_WORD_EXTENDS:
 					case ASTokenTypes.TOKEN_RESERVED_WORD_IMPLEMENTS:
-					case ASTokenTypes.HIDDEN_TOKEN_MULTI_LINE_COMMENT:
+					case ASTokenTypes.HIDDEN_TOKEN_MULTI_LINE_COMMENT: {
+						// needs an extra space before the token
+						requiredSpace = true;
+						break;
+					}
 					case ASTokenTypes.HIDDEN_TOKEN_SINGLE_LINE_COMMENT: {
 						// needs an extra space before the token
 						requiredSpace = true;
+
+						String trimmed = token.getText().substring(2).trim();
+						if (!skipFormatting && FORMATTER_TAG_OFF.equals(trimmed)) {
+							skipFormatting = true;
+						} else if (skipFormatting && FORMATTER_TAG_ON.equals(trimmed)) {
+							skipFormatting = false;
+							numRequiredNewLines = 0;
+							requiredSpace = false;
+						}
 						break;
 					}
 					case ASTokenTypes.TOKEN_OPERATOR_EQUAL:
@@ -932,7 +952,7 @@ public class FORMATTER {
 					}
 				}
 			}
-			if (prevToken != null) {
+			if (!skipFormatting && prevToken != null) {
 				if (numRequiredNewLines > 0) {
 					appendNewLines(builder, numRequiredNewLines);
 					appendIndent(builder, indent);
@@ -953,7 +973,7 @@ public class FORMATTER {
 			}
 
 			// include the token's own text
-			builder.append(getTokenText(token, indent));
+			builder.append(getTokenText(token, indent, skipFormatting));
 
 			// characters that must appear after the token
 			if (token.getType() != ASTokenTypes.HIDDEN_TOKEN_SINGLE_LINE_COMMENT
@@ -1462,7 +1482,7 @@ public class FORMATTER {
 		return builder.toString();
 	}
 
-	private String getTokenText(IASToken token, int indent) {
+	private String getTokenText(IASToken token, int indent, boolean skipFormatting) {
 
 		if (token instanceof MetaDataPayloadToken) {
 			MetaDataPayloadToken metaPlayloadToken = (MetaDataPayloadToken) token;
@@ -1470,18 +1490,30 @@ public class FORMATTER {
 		} else {
 			switch (token.getType()) {
 				case ASTokenTypes.TOKEN_ASDOC_COMMENT: {
+					if (skipFormatting) {
+						return token.getText();
+					}
 					return formatASDocComment(token.getText(), indent);
 				}
 				case ASTokenTypes.HIDDEN_TOKEN_SINGLE_LINE_COMMENT: {
+					if (skipFormatting) {
+						return token.getText();
+					}
 					return formatSingleLineComment(token.getText());
 				}
 				case ASTokenTypes.HIDDEN_TOKEN_MULTI_LINE_COMMENT: {
+					if (skipFormatting) {
+						return token.getText();
+					}
 					return formatMultiLineComment(token.getText());
 				}
 				case ASTokenTypes.TOKEN_LITERAL_STRING: {
 					return formatLiteralString(token.getText());
 				}
 				case ASTokenTypes.TOKEN_SEMICOLON: {
+					if (skipFormatting) {
+						return token.isImplicit() ? "" : token.getText();
+					}
 					boolean skipSemicolon = Semicolons.REMOVE.equals(semicolons)
 							|| (Semicolons.IGNORE.equals(semicolons) && token.isImplicit());
 					if (!skipSemicolon) {
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestFormatterOff.java b/formatter/src/test/java/org/apache/royale/formatter/TestFormatterOff.java
new file mode 100644
index 0000000..c0c8f9b
--- /dev/null
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestFormatterOff.java
@@ -0,0 +1,72 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+package org.apache.royale.formatter;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class TestFormatterOff extends BaseFormatterTests {
+	@Test
+	public void testFormatterOff() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = true;
+		formatter.insertSpaces = true;
+		formatter.tabSize = 2;
+		formatter.maxPreserveNewLines = 2;
+		String result = formatter.formatActionScriptText(
+		// @formatter:off
+			"// @formatter:off\n" +
+			"for(var i:int=0;i<3;i++){\n" +
+			"\ttrace(i)//print to console\n" +
+			"\n" +
+			"\n" +
+			"\n" +
+			"}\n" +
+			"// @formatter:on\n" +
+			"for(var i:int=0;i<3;i++){\n" +
+			"\ttrace(i)//print to console\n" +
+			"\n" +
+			"\n" +
+			"\n" +
+			"}",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"// @formatter:off\n" +
+				"for(var i:int=0;i<3;i++){\n" +
+				"\ttrace(i)//print to console\n" +
+				"\n" +
+				"\n" +
+				"\n" +
+				"}\n" +
+				"// @formatter:on\n" +
+				"for (var i:int = 0; i < 3; i++)\n" +
+				"{\n" +
+				"  trace(i); // print to console\n" +
+				"\n" +
+				"}",
+				// @formatter:on
+				result);
+	}
+}
\ No newline at end of file

[royale-compiler] 04/05: formatter: handle space before /> in MXML

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 149dace067b9bcf7484b8c9be95080d74035db8c
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Mon Nov 15 14:58:43 2021 -0800

    formatter: handle space before /> in MXML
---
 formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java | 7 +++++--
 .../test/java/org/apache/royale/formatter/TestFormatterOff.java    | 6 +++---
 .../src/test/java/org/apache/royale/formatter/TestMXMLTag.java     | 2 +-
 3 files changed, 9 insertions(+), 6 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 8fda9a1..6a80272 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -1858,7 +1858,8 @@ public class FORMATTER {
 				}
 				case MXMLTokenTypes.TOKEN_CLOSE_TAG_START: {
 					if (nextToken != null && nextToken.getType() != MXMLTokenTypes.TOKEN_TAG_END
-							&& nextToken.getType() != MXMLTokenTypes.TOKEN_EMPTY_TAG_END) {
+							&& nextToken.getType() != MXMLTokenTypes.TOKEN_EMPTY_TAG_END
+							&& nextToken.getType() != TOKEN_TYPE_EXTRA) {
 						requiredSpace = true;
 					}
 					if (elementStack.isEmpty()) {
@@ -1877,7 +1878,9 @@ public class FORMATTER {
 					if (nextToken != null && nextToken.getType() != MXMLTokenTypes.TOKEN_TAG_END
 							&& nextToken.getType() != MXMLTokenTypes.TOKEN_EMPTY_TAG_END) {
 						attributeIndent = getAttributeIndent(token);
-						requiredSpace = true;
+						if(nextToken.getType() != TOKEN_TYPE_EXTRA) {
+							requiredSpace = true;
+						}
 					}
 					break;
 				}
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestFormatterOff.java b/formatter/src/test/java/org/apache/royale/formatter/TestFormatterOff.java
index be1fd28..27f0561 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestFormatterOff.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestFormatterOff.java
@@ -82,12 +82,12 @@ public class TestFormatterOff extends BaseFormatterTests {
 		// @formatter:off
 			"<mx:Application>\n" +
 			"\t<!-- @formatter:off -->\n" +
-			"\t<mx:Button/>\n" +
+			"\t<mx:Button />\n" +
 			"\n" +
 			"\n" +
 			"\n" +
 			"\t<!-- @formatter:on -->\n" +
-			"\t<mx:Button/>\n" +
+			"\t<mx:Button />\n" +
 			"\n" +
 			"\n" +
 			"\n" +
@@ -99,7 +99,7 @@ public class TestFormatterOff extends BaseFormatterTests {
 		// @formatter:off
 				"<mx:Application>\n" +
 				"  <!-- @formatter:off -->\n" +
-				"\t<mx:Button/>\n" +
+				"\t<mx:Button />\n" +
 				"\n" +
 				"\n" +
 				"\n" +
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestMXMLTag.java b/formatter/src/test/java/org/apache/royale/formatter/TestMXMLTag.java
index 20c85f7..0cc92e6 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestMXMLTag.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestMXMLTag.java
@@ -30,7 +30,7 @@ public class TestMXMLTag extends BaseFormatterTests {
 		formatter.insertSpaces = false;
 		String result = formatter.formatMXMLText(
 		// @formatter:off
-			"<s:Tag/>",
+			"<s:Tag />",
 			// @formatter:on
 			problems
 		);

[royale-compiler] 05/05: formatter: minor cleanup of off/on tags for AS3

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 9fb3b29369069dae30574548ce877c16ff3c362d
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Mon Nov 15 15:02:38 2021 -0800

    formatter: minor cleanup of off/on tags for AS3
---
 .../org/apache/royale/formatter/FORMATTER.java     | 24 +++++++++-------------
 .../apache/royale/formatter/TestFormatterOff.java  |  6 +++---
 2 files changed, 13 insertions(+), 17 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 6a80272..1f4d27a 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -810,23 +810,10 @@ public class FORMATTER {
 					case ASTokenTypes.TOKEN_RESERVED_WORD_EACH:
 					case ASTokenTypes.TOKEN_RESERVED_WORD_EXTENDS:
 					case ASTokenTypes.TOKEN_RESERVED_WORD_IMPLEMENTS:
-					case ASTokenTypes.HIDDEN_TOKEN_MULTI_LINE_COMMENT: {
-						// needs an extra space before the token
-						requiredSpace = true;
-						break;
-					}
+					case ASTokenTypes.HIDDEN_TOKEN_MULTI_LINE_COMMENT:
 					case ASTokenTypes.HIDDEN_TOKEN_SINGLE_LINE_COMMENT: {
 						// needs an extra space before the token
 						requiredSpace = true;
-
-						String trimmed = token.getText().substring(2).trim();
-						if (!skipFormatting && FORMATTER_TAG_OFF.equals(trimmed)) {
-							skipFormatting = true;
-						} else if (skipFormatting && FORMATTER_TAG_ON.equals(trimmed)) {
-							skipFormatting = false;
-							numRequiredNewLines = 0;
-							requiredSpace = false;
-						}
 						break;
 					}
 					case ASTokenTypes.TOKEN_OPERATOR_EQUAL:
@@ -1330,6 +1317,15 @@ public class FORMATTER {
 					}
 					case ASTokenTypes.HIDDEN_TOKEN_SINGLE_LINE_COMMENT: {
 						numRequiredNewLines = Math.max(numRequiredNewLines, 1);
+
+						String trimmed = token.getText().substring(2).trim();
+						if (!skipFormatting && FORMATTER_TAG_OFF.equals(trimmed)) {
+							skipFormatting = true;
+							appendNewLines(builder, 1);
+						} else if (skipFormatting && FORMATTER_TAG_ON.equals(trimmed)) {
+							skipFormatting = false;
+							numRequiredNewLines = 0;
+						}
 						break;
 					}
 					case ASTokenTypes.TOKEN_ASDOC_COMMENT:
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestFormatterOff.java b/formatter/src/test/java/org/apache/royale/formatter/TestFormatterOff.java
index 27f0561..84710e6 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestFormatterOff.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestFormatterOff.java
@@ -34,14 +34,14 @@ public class TestFormatterOff extends BaseFormatterTests {
 		formatter.maxPreserveNewLines = 2;
 		String result = formatter.formatActionScriptText(
 		// @formatter:off
-			"// @formatter:off\n" +
+			"\t// @formatter:off\n" +
 			"for(var i:int=0;i<3;i++){\n" +
 			"\ttrace(i)//print to console\n" +
 			"\n" +
 			"\n" +
 			"\n" +
 			"}\n" +
-			"// @formatter:on\n" +
+			"\t// @formatter:on\n" +
 			"for(var i:int=0;i<3;i++){\n" +
 			"\ttrace(i)//print to console\n" +
 			"\n" +
@@ -60,7 +60,7 @@ public class TestFormatterOff extends BaseFormatterTests {
 				"\n" +
 				"\n" +
 				"}\n" +
-				"// @formatter:on\n" +
+				"\t// @formatter:on\n" +
 				"for (var i:int = 0; i < 3; i++)\n" +
 				"{\n" +
 				"  trace(i); // print to console\n" +

[royale-compiler] 02/05: formatter: some missing braces

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 33e0b4ac55798c13845a67bfaebcd8354349c078
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Mon Nov 15 11:36:37 2021 -0800

    formatter: some missing braces
---
 .../org/apache/royale/formatter/FORMATTER.java     | 24 ++++++++++++++--------
 1 file changed, 16 insertions(+), 8 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 d4a8935..c379573 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -794,7 +794,7 @@ public class FORMATTER {
 						}
 						break;
 					}
-					case ASTokenTypes.TOKEN_SQUARE_CLOSE:
+					case ASTokenTypes.TOKEN_SQUARE_CLOSE: {
 						if (!blockStack.isEmpty()) {
 							BlockStackItem item = blockStack.get(blockStack.size() - 1);
 							if (item.token.getType() == ASTokenTypes.TOKEN_SQUARE_OPEN) {
@@ -803,6 +803,7 @@ public class FORMATTER {
 							}
 						}
 						break;
+					}
 					case ASTokenTypes.TOKEN_KEYWORD_AS:
 					case ASTokenTypes.TOKEN_KEYWORD_IS:
 					case ASTokenTypes.TOKEN_KEYWORD_IN:
@@ -1552,7 +1553,7 @@ public class FORMATTER {
 				case MetadataTokenTypes.TOKEN_ATTR_DEFAULT_VALUE:
 				case MetadataTokenTypes.TOKEN_ATTR_STATES:
 				case MetadataTokenTypes.TOKEN_ATTR_IMPLEMENTATION:
-				case MetadataTokenTypes.TOKEN_ATTR_OPERATOR_NS_QUALIFIER:
+				case MetadataTokenTypes.TOKEN_ATTR_OPERATOR_NS_QUALIFIER: {
 					if (needsComma) {
 						builder.append(",");
 						if (insertSpaceBetweenMetadataAttributes) {
@@ -1570,7 +1571,8 @@ public class FORMATTER {
 						i++;
 					}
 					break;
-				case MetadataTokenTypes.TOKEN_STRING:
+				}
+				case MetadataTokenTypes.TOKEN_STRING: {
 					if (needsComma) {
 						builder.append(",");
 						if (insertSpaceBetweenMetadataAttributes) {
@@ -1582,8 +1584,10 @@ public class FORMATTER {
 					builder.append("\"");
 					needsComma = true;
 					break;
-				default:
+				}
+				default: {
 					builder.append(metaToken.getText());
+				}
 			}
 		}
 		return builder.toString();
@@ -1926,26 +1930,30 @@ public class FORMATTER {
 		for (int i = startIndex; i < tokens.size(); i++) {
 			IMXMLToken token = tokens.get(i);
 			switch (token.getType()) {
-				case MXMLTokenTypes.TOKEN_TEXT:
+				case MXMLTokenTypes.TOKEN_TEXT: {
 					if (elementStack.size() == 1) {
 						return true;
 					}
 					break;
-				case MXMLTokenTypes.TOKEN_OPEN_TAG_START:
+				}
+				case MXMLTokenTypes.TOKEN_OPEN_TAG_START: {
 					elementStack.add(token);
 					break;
-				case MXMLTokenTypes.TOKEN_EMPTY_TAG_END:
+				}
+				case MXMLTokenTypes.TOKEN_EMPTY_TAG_END: {
 					elementStack.remove(elementStack.size() - 1);
 					if (elementStack.size() == 0) {
 						return false;
 					}
 					break;
-				case MXMLTokenTypes.TOKEN_CLOSE_TAG_START:
+				}
+				case MXMLTokenTypes.TOKEN_CLOSE_TAG_START: {
 					elementStack.remove(elementStack.size() - 1);
 					if (elementStack.size() == 0) {
 						return false;
 					}
 					break;
+				}
 			}
 		}
 		return false;