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 2022/07/14 23:12:19 UTC

[royale-compiler] branch develop updated (3eff216da -> 4c5c90491)

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 3eff216da Avoid null reference errors for scope which can occur with some xml-ish lookups.
     new aad583419 formatter: case or default that contains only a block does not increase indent of block
     new 33db4870e formatter: display problem severity
     new db4bc58ec formatter: handle disable place brace on new line for case or default that contains only a block does not increase indent of block
     new 9095032b9 StreamingASTokenizer: fixed issue where sourcePath variable was passed to original RawASTokenizer in setPath(), but not passed to a new RawASTokenizer created in setReader()
     new 2b6bf3e5e formatter: fix invalid error detected when source file starts with UTF BOM character
     new 4c5c90491 royaleunit-ant-tasks: added commandArgs attribute to <royaleunit/> element (closes #168)

The 6 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:
 compiler/src/assembly/scripts/{fdb => aslint}      |   2 +-
 .../src/assembly/scripts/{fdb.bat => aslint.bat}   |   2 +-
 .../internal/parsing/as/StreamingASTokenizer.java  |   1 +
 .../org/apache/royale/formatter/FORMATTER.java     |  95 +++++---
 .../royale/formatter/TestSwitchStatement.java      | 242 ++++++++++++++++++---
 .../commands/player/CustomPlayerCommand.java       |  23 +-
 .../commands/player/PlayerCommandFactory.java      |   3 +-
 .../royale/test/ant/tasks/RoyaleUnitTask.java      |  49 ++++-
 .../org/apache/royale/test/ant/tasks/TestRun.java  |   1 +
 .../ant/tasks/configuration/TaskConfiguration.java |   5 +
 .../tasks/configuration/TestRunConfiguration.java  |  16 ++
 11 files changed, 374 insertions(+), 65 deletions(-)
 copy compiler/src/assembly/scripts/{fdb => aslint} (98%)
 mode change 100755 => 100644
 copy compiler/src/assembly/scripts/{fdb.bat => aslint.bat} (95%)


[royale-compiler] 04/06: StreamingASTokenizer: fixed issue where sourcePath variable was passed to original RawASTokenizer in setPath(), but not passed to a new RawASTokenizer created in setReader()

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 9095032b93a41b82f8553d86644b9de1ac3e2508
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Jul 14 11:32:25 2022 -0700

    StreamingASTokenizer: fixed issue where sourcePath variable was passed to original RawASTokenizer in setPath(), but not passed to a new RawASTokenizer created in setReader()
---
 compiler/src/assembly/scripts/aslint               | 62 ++++++++++++++++++++++
 compiler/src/assembly/scripts/aslint.bat           | 26 +++++++++
 .../internal/parsing/as/StreamingASTokenizer.java  |  1 +
 3 files changed, 89 insertions(+)

diff --git a/compiler/src/assembly/scripts/aslint b/compiler/src/assembly/scripts/aslint
new file mode 100644
index 000000000..b23185ab8
--- /dev/null
+++ b/compiler/src/assembly/scripts/aslint
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+################################################################################
+##
+##  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.
+##
+################################################################################
+
+#
+# fasc shell script to launch compiler-asc.jar on OSX, Unix, or Cygwin.
+# In Windows Command Prompt, use fasc.bat instead.
+#
+
+if [ "x${ROYALE_COMPILER_HOME}" = "x" ]
+then
+    SCRIPT_HOME=`dirname "$0"`
+    ROYALE_COMPILER_HOME=${SCRIPT_HOME}/..
+else
+    echo Using Royale codebase: $ROYALE_COMPILER_HOME
+fi
+
+case `uname` in
+		CYGWIN*)
+			OS="Windows"
+		;;
+		*)
+			OS=Unix
+esac
+
+D32=''
+
+if [ $OS = "Windows" ]; then
+
+	ROYALE_COMPILER_HOME=`cygpath -m $ROYALE_COMPILER_HOME`
+
+elif [ $OS = "Unix" ]; then
+
+    check64="`java -version 2>&1 | grep -i 64-Bit`"
+    isOSX="`uname | grep -i Darwin`"
+    javaVersion="`java -version 2>&1 | awk -F '[ ".]+' 'NR==1 {print $3 "." $4}'`"
+    
+    if [ "$isOSX" != "" -a "$HOSTTYPE" = "x86_64" -a "$check64" != "" -a "$javaVersion" = "1.6" ]; then
+        D32='-d32'
+    fi
+fi
+
+VMARGS="-Xmx384m -Dsun.io.useCanonCaches=false "
+
+java $VMARGS $D32 $SETUP_SH_VMARGS -jar "${ROYALE_COMPILER_HOME}/lib/linter.jar" "$@"
diff --git a/compiler/src/assembly/scripts/aslint.bat b/compiler/src/assembly/scripts/aslint.bat
new file mode 100644
index 000000000..5bc7dc9da
--- /dev/null
+++ b/compiler/src/assembly/scripts/aslint.bat
@@ -0,0 +1,26 @@
+@echo off
+
+rem
+rem Licensed to the Apache Software Foundation (ASF) under one or more
+rem contributor license agreements.  See the NOTICE file distributed with
+rem this work for additional information regarding copyright ownership.
+rem The ASF licenses this file to You under the Apache License, Version 2.0
+rem (the "License"); you may not use this file except in compliance with
+rem the License.  You may obtain a copy of the License at
+rem
+rem     http://www.apache.org/licenses/LICENSE-2.0
+rem
+rem Unless required by applicable law or agreed to in writing, software
+rem distributed under the License is distributed on an "AS IS" BASIS,
+rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+rem See the License for the specific language governing permissions and
+rem limitations under the License.
+rem
+
+rem
+rem fasc.bat script to launch compiler-asc.jar in Windows Command Prompt.
+rem On OSX, Unix, or Cygwin, use the fasc shell script instead.
+rem
+
+@java -Dsun.io.useCanonCaches=false -Dapplication.home="%~dp0.." -Xms32m -Xmx512m -jar "%~dp0..\lib\linter.jar" %*
+
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/StreamingASTokenizer.java b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/StreamingASTokenizer.java
index efc9a53fc..52e923d2d 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/StreamingASTokenizer.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/StreamingASTokenizer.java
@@ -498,6 +498,7 @@ public class StreamingASTokenizer implements ASTokenTypes, IASTokenizer, Closeab
         tokenizer = new RawASTokenizer();
         tokenizer.yyreset(reader);
         tokenizer.setCollectComments(config.collectComments);
+        tokenizer.setSourcePath(sourcePath);
         setSourcePositionAdjustment(offset, line, column);
     }
 


[royale-compiler] 01/06: formatter: case or default that contains only a block does not increase indent of block

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 aad583419ff2c2250a9c5770149a170a4e6467e0
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Jul 14 10:25:39 2022 -0700

    formatter: case or default that contains only a block does not increase indent of block
---
 .../org/apache/royale/formatter/FORMATTER.java     | 49 ++++++++++++++++++----
 .../royale/formatter/TestSwitchStatement.java      | 40 +++++++++---------
 2 files changed, 61 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 473ff7cb4..fc36d0989 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -91,11 +91,10 @@ public class FORMATTER {
 		}
 
 		final int code;
-        
-        int getCode()
-        {
-        	return code;
-        }
+
+		int getCode() {
+			return code;
+		}
 	}
 
 	/**
@@ -393,7 +392,8 @@ public class FORMATTER {
 		}
 	}
 
-	private String formatMXMLScriptElement(String filePath, int line, String text, Collection<ICompilerProblem> problems) {
+	private String formatMXMLScriptElement(String filePath, int line, String text,
+			Collection<ICompilerProblem> problems) {
 		String indent = "\t";
 		if (insertSpaces) {
 			indent = "";
@@ -761,7 +761,8 @@ public class FORMATTER {
 								indentedStatement = false;
 								indent = decreaseIndent(indent);
 							}
-							boolean oneLineBlock = nextToken != null && nextToken.getType() == ASTokenTypes.TOKEN_BLOCK_CLOSE;
+							boolean oneLineBlock = nextToken != null
+									&& nextToken.getType() == ASTokenTypes.TOKEN_BLOCK_CLOSE;
 							boolean needsNewLine = placeOpenBraceOnNewLine && (!collapseEmptyBlocks || !oneLineBlock);
 							if (needsNewLine) {
 								numRequiredNewLines = Math.max(numRequiredNewLines, 1);
@@ -1238,7 +1239,22 @@ public class FORMATTER {
 							if (inCaseOrDefaultClause) {
 								inCaseOrDefaultClause = false;
 								caseOrDefaultBlockOpenPending = true;
-								indent = increaseIndent(indent);
+								boolean nextIsBlock = nextTokenNotComment != null
+										&& nextTokenNotComment.getType() == ASTokenTypes.TOKEN_BLOCK_OPEN;
+								if (nextIsBlock) {
+									IASToken afterBlockClose = findTokenAfterBlock(nextTokenNotComment, tokens);
+									if (afterBlockClose != null) {
+										if (afterBlockClose.getType() == ASTokenTypes.TOKEN_BLOCK_CLOSE
+												|| afterBlockClose.getType() == ASTokenTypes.TOKEN_KEYWORD_CASE
+												|| afterBlockClose.getType() == ASTokenTypes.TOKEN_KEYWORD_DEFAULT) {
+											blockOpenPending = true;
+											blockStack.remove(blockStack.size() - 1);
+										}
+									}
+								}
+								if (!nextIsBlock || !blockOpenPending) {
+									indent = increaseIndent(indent);
+								}
 								if (nextToken != null && (nextToken
 										.getType() == ASTokenTypes.HIDDEN_TOKEN_SINGLE_LINE_COMMENT
 										|| nextToken.getType() == ASTokenTypes.HIDDEN_TOKEN_MULTI_LINE_COMMENT)) {
@@ -1408,6 +1424,23 @@ public class FORMATTER {
 		return builder.toString();
 	}
 
+	private IASToken findTokenAfterBlock(IASToken tokenBlockOpen, List<IASToken> tokens) {
+		List<IASToken> stack = new ArrayList<IASToken>();
+		int startIndex = tokens.indexOf(tokenBlockOpen) + 1;
+		for (int i = startIndex; i < tokens.size(); i++) {
+			IASToken current = tokens.get(i);
+			if (current.getType() == ASTokenTypes.TOKEN_BLOCK_OPEN) {
+				stack.add(current);
+			} else if (current.getType() == ASTokenTypes.TOKEN_BLOCK_CLOSE) {
+				if (stack.size() == 0) {
+					return getNextTokenSkipExtraAndComments(tokens, i + 1);
+				}
+				stack.remove(stack.size() - 1);
+			}
+		}
+		return null;
+	}
+
 	private int countNewLinesInExtra(IASToken tokenOrExtra) {
 		if (tokenOrExtra == null || tokenOrExtra.getType() != TOKEN_TYPE_EXTRA) {
 			return 0;
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestSwitchStatement.java b/formatter/src/test/java/org/apache/royale/formatter/TestSwitchStatement.java
index dffb1167b..d7cd956e7 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestSwitchStatement.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestSwitchStatement.java
@@ -146,8 +146,8 @@ public class TestSwitchStatement extends BaseFormatterTests {
 				"switch (condition)\n" +
 				"{\n" +
 				"\tcase condition:\n" +
-				"\t\t{\n" +
-				"\t\t}\n" +
+				"\t{\n" +
+				"\t}\n" +
 				"}",
 				// @formatter:on
 				result);
@@ -176,9 +176,9 @@ public class TestSwitchStatement extends BaseFormatterTests {
 				"switch (condition)\n" +
 				"{\n" +
 				"\tcase condition:\n" +
-				"\t\t{\n" +
-				"\t\t\tbreak;\n" +
-				"\t\t}\n" +
+				"\t{\n" +
+				"\t\tbreak;\n" +
+				"\t}\n" +
 				"}",
 				// @formatter:on
 				result);
@@ -295,8 +295,8 @@ public class TestSwitchStatement extends BaseFormatterTests {
 				"switch (condition)\n" +
 				"{\n" +
 				"\tdefault:\n" +
-				"\t\t{\n" +
-				"\t\t}\n" +
+				"\t{\n" +
+				"\t}\n" +
 				"}",
 				// @formatter:on
 				result);
@@ -325,9 +325,9 @@ public class TestSwitchStatement extends BaseFormatterTests {
 				"switch (condition)\n" +
 				"{\n" +
 				"\tdefault:\n" +
-				"\t\t{\n" +
-				"\t\t\tbreak;\n" +
-				"\t\t}\n" +
+				"\t{\n" +
+				"\t\tbreak;\n" +
+				"\t}\n" +
 				"}",
 				// @formatter:on
 				result);
@@ -549,8 +549,8 @@ public class TestSwitchStatement extends BaseFormatterTests {
 				"\tswitch (condition)\n" +
 				"\t{\n" +
 				"\t\tcase clause:\n" +
-				"\t\t\t{\n" +
-				"\t\t\t}\n" +
+				"\t\t{\n" +
+				"\t\t}\n" +
 				"\t}\n" +
 				"\tstatement;\n" +
 				"}",
@@ -585,9 +585,9 @@ public class TestSwitchStatement extends BaseFormatterTests {
 				"\tswitch (condition)\n" +
 				"\t{\n" +
 				"\t\tcase clause:\n" +
-				"\t\t\t{\n" +
-				"\t\t\t\tbreak;\n" +
-				"\t\t\t}\n" +
+				"\t\t{\n" +
+				"\t\t\tbreak;\n" +
+				"\t\t}\n" +
 				"\t}\n" +
 				"\tstatement;\n" +
 				"}",
@@ -654,8 +654,8 @@ public class TestSwitchStatement extends BaseFormatterTests {
 				"\tswitch (condition)\n" +
 				"\t{\n" +
 				"\t\tdefault:\n" +
-				"\t\t\t{\n" +
-				"\t\t\t}\n" +
+				"\t\t{\n" +
+				"\t\t}\n" +
 				"\t}\n" +
 				"\tstatement;\n" +
 				"}",
@@ -690,9 +690,9 @@ public class TestSwitchStatement extends BaseFormatterTests {
 				"\tswitch (condition)\n" +
 				"\t{\n" +
 				"\t\tdefault:\n" +
-				"\t\t\t{\n" +
-				"\t\t\t\tbreak;\n" +
-				"\t\t\t}\n" +
+				"\t\t{\n" +
+				"\t\t\tbreak;\n" +
+				"\t\t}\n" +
 				"\t}\n" +
 				"\tstatement;\n" +
 				"}",


[royale-compiler] 03/06: formatter: handle disable place brace on new line for case or default that contains only a block does not increase indent of block

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 db4bc58ec388cf2ec017d48ed5931f69a2910220
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Jul 14 10:54:41 2022 -0700

    formatter: handle disable place brace on new line for case or default that contains only a block does not increase indent of block
---
 .../org/apache/royale/formatter/FORMATTER.java     |  15 +-
 .../royale/formatter/TestSwitchStatement.java      | 202 ++++++++++++++++++++-
 2 files changed, 204 insertions(+), 13 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 8c6c75328..35c0d04a0 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -1250,19 +1250,20 @@ public class FORMATTER {
 												|| afterBlockClose.getType() == ASTokenTypes.TOKEN_KEYWORD_CASE
 												|| afterBlockClose.getType() == ASTokenTypes.TOKEN_KEYWORD_DEFAULT) {
 											blockOpenPending = true;
+											requiredSpace = true;
 											blockStack.remove(blockStack.size() - 1);
 										}
 									}
 								}
 								if (!nextIsBlock || !blockOpenPending) {
 									indent = increaseIndent(indent);
-								}
-								if (nextToken != null && (nextToken
-										.getType() == ASTokenTypes.HIDDEN_TOKEN_SINGLE_LINE_COMMENT
-										|| nextToken.getType() == ASTokenTypes.HIDDEN_TOKEN_MULTI_LINE_COMMENT)) {
-									requiredSpace = true;
-								} else {
-									numRequiredNewLines = Math.max(numRequiredNewLines, 1);
+									if (nextToken != null && (nextToken
+											.getType() == ASTokenTypes.HIDDEN_TOKEN_SINGLE_LINE_COMMENT
+											|| nextToken.getType() == ASTokenTypes.HIDDEN_TOKEN_MULTI_LINE_COMMENT)) {
+										requiredSpace = true;
+									} else {
+										numRequiredNewLines = Math.max(numRequiredNewLines, 1);
+									}
 								}
 							} else if (ternaryStack > 0) {
 								ternaryStack--;
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestSwitchStatement.java b/formatter/src/test/java/org/apache/royale/formatter/TestSwitchStatement.java
index d7cd956e7..2615958f7 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestSwitchStatement.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestSwitchStatement.java
@@ -125,7 +125,7 @@ public class TestSwitchStatement extends BaseFormatterTests {
 	}
 
 	@Test
-	public void testWithCaseClauseAndEmptyBlock() {
+	public void testWithCaseClauseAndEmptyBlockEnablePlaceOpenBraceOnNewLine() {
 		FORMATTER formatter = new FORMATTER();
 		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
 		formatter.placeOpenBraceOnNewLine = true;
@@ -154,7 +154,34 @@ public class TestSwitchStatement extends BaseFormatterTests {
 	}
 
 	@Test
-	public void testWithCaseClauseAndBlockWithStatement() {
+	public void testWithCaseClauseAndEmptyBlockDisablePlaceOpenBraceOnNewLine() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = false;
+		formatter.insertSpaces = false;
+		String result = formatter.formatActionScriptText(
+		// @formatter:off
+			"switch (condition)\n" +
+			"{\n" +
+			"\tcase condition:\n" +
+			"\t{\n" +
+			"\t}\n" +
+			"}",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"switch (condition) {\n" +
+				"\tcase condition: {\n" +
+				"\t}\n" +
+				"}",
+				// @formatter:on
+				result);
+	}
+
+	@Test
+	public void testWithCaseClauseAndBlockWithStatementEnablePlaceOpenBraceOnNewLine() {
 		FORMATTER formatter = new FORMATTER();
 		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
 		formatter.placeOpenBraceOnNewLine = true;
@@ -185,7 +212,36 @@ public class TestSwitchStatement extends BaseFormatterTests {
 	}
 
 	@Test
-	public void testWithCaseClauseAndStatementAfterBlock() {
+	public void testWithCaseClauseAndBlockWithStatementDisablePlaceOpenBraceOnNewLine() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = false;
+		formatter.insertSpaces = false;
+		String result = formatter.formatActionScriptText(
+		// @formatter:off
+			"switch (condition)\n" +
+			"{\n" +
+			"\tcase condition:\n" +
+			"\t{\n" +
+			"\t\tbreak;\n" +
+			"\t}\n" +
+			"}",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"switch (condition) {\n" +
+				"\tcase condition: {\n" +
+				"\t\tbreak;\n" +
+				"\t}\n" +
+				"}",
+				// @formatter:on
+				result);
+	}
+
+	@Test
+	public void testWithCaseClauseAndStatementAfterBlockEnablePlaceOpenBraceOnNewLine() {
 		FORMATTER formatter = new FORMATTER();
 		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
 		formatter.placeOpenBraceOnNewLine = true;
@@ -205,6 +261,9 @@ public class TestSwitchStatement extends BaseFormatterTests {
 		);
 		assertEquals(
 		// @formatter:off
+				// notice that the break statement is outside the curly braces,
+				// so the curly braces aren't considered a "body" for the case
+				// clause and they get indented an extra level.
 				"switch (condition)\n" +
 				"{\n" +
 				"\tcase condition:\n" +
@@ -217,6 +276,42 @@ public class TestSwitchStatement extends BaseFormatterTests {
 				result);
 	}
 
+	@Test
+	public void testWithCaseClauseAndStatementAfterBlockDisablePlaceOpenBraceOnNewLine() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = false;
+		formatter.insertSpaces = false;
+		String result = formatter.formatActionScriptText(
+		// @formatter:off
+			"switch (condition)\n" +
+			"{\n" +
+			"\tcase condition:\n" +
+			"\t{\n" +
+			"\t\tstatement;\n" +
+			"\t}\n" +
+			"\tbreak;\n" +
+			"}",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				// notice that the break statement is outside the curly braces,
+				// so the curly braces aren't considered a "body" for the case
+				// clause, and they get indented an extra level. the opening
+				// brace also doesn't appear on the same line as the case.
+				"switch (condition) {\n" +
+				"\tcase condition:\n" +
+				"\t\t{\n" +
+				"\t\t\tstatement;\n" +
+				"\t\t}\n" +
+				"\t\tbreak;\n" +
+				"}",
+				// @formatter:on
+				result);
+	}
+
 	@Test
 	public void testWithDefaultClauseAndStatement() {
 		FORMATTER formatter = new FORMATTER();
@@ -274,7 +369,7 @@ public class TestSwitchStatement extends BaseFormatterTests {
 	}
 
 	@Test
-	public void testWithDefaultClauseAndEmptyBlock() {
+	public void testWithDefaultClauseAndEmptyBlockEnablePlaceOpenBraceOnNewLine() {
 		FORMATTER formatter = new FORMATTER();
 		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
 		formatter.placeOpenBraceOnNewLine = true;
@@ -303,7 +398,34 @@ public class TestSwitchStatement extends BaseFormatterTests {
 	}
 
 	@Test
-	public void testWithDefaultClauseAndBlockWithStatement() {
+	public void testWithDefaultClauseAndEmptyBlockDisablePlaceOpenBraceOnNewLine() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = false;
+		formatter.insertSpaces = false;
+		String result = formatter.formatActionScriptText(
+		// @formatter:off
+			"switch (condition)\n" +
+			"{\n" +
+			"\tdefault:\n" +
+			"\t{\n" +
+			"\t}\n" +
+			"}",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"switch (condition) {\n" +
+				"\tdefault: {\n" +
+				"\t}\n" +
+				"}",
+				// @formatter:on
+				result);
+	}
+
+	@Test
+	public void testWithDefaultClauseAndBlockWithStatementEnablePlaceOpenBraceOnNewLine() {
 		FORMATTER formatter = new FORMATTER();
 		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
 		formatter.placeOpenBraceOnNewLine = true;
@@ -334,7 +456,36 @@ public class TestSwitchStatement extends BaseFormatterTests {
 	}
 
 	@Test
-	public void testWithDefaultClauseAndStatementAfterBlock() {
+	public void testWithDefaultClauseAndBlockWithStatementDisablePlaceOpenBraceOnNewLine() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = false;
+		formatter.insertSpaces = false;
+		String result = formatter.formatActionScriptText(
+		// @formatter:off
+			"switch (condition)\n" +
+			"{\n" +
+			"\tdefault:\n" +
+			"\t{\n" +
+			"\t\tbreak;\n" +
+			"\t}\n" +
+			"}",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"switch (condition) {\n" +
+				"\tdefault: {\n" +
+				"\t\tbreak;\n" +
+				"\t}\n" +
+				"}",
+				// @formatter:on
+				result);
+	}
+
+	@Test
+	public void testWithDefaultClauseAndStatementAfterBlockEnablePlaceOpenBraceOnNewLine() {
 		FORMATTER formatter = new FORMATTER();
 		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
 		formatter.placeOpenBraceOnNewLine = true;
@@ -354,6 +505,9 @@ public class TestSwitchStatement extends BaseFormatterTests {
 		);
 		assertEquals(
 		// @formatter:off
+				// notice that the break statement is outside the curly braces,
+				// so the curly braces aren't considered a "body" for the
+				// default clause and they get indented an extra level.
 				"switch (condition)\n" +
 				"{\n" +
 				"\tdefault:\n" +
@@ -366,6 +520,42 @@ public class TestSwitchStatement extends BaseFormatterTests {
 				result);
 	}
 
+	@Test
+	public void testWithDefaultClauseAndStatementAfterBlockDisablePlaceOpenBraceOnNewLine() {
+		FORMATTER formatter = new FORMATTER();
+		formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		formatter.placeOpenBraceOnNewLine = false;
+		formatter.insertSpaces = false;
+		String result = formatter.formatActionScriptText(
+		// @formatter:off
+			"switch (condition)\n" +
+			"{\n" +
+			"\tdefault:\n" +
+			"\t{\n" +
+			"\t\tstatement;\n" +
+			"\t}\n" +
+			"\tbreak;\n" +
+			"}",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				// notice that the break statement is outside the curly braces,
+				// so the curly braces aren't considered a "body" for the
+				// default clause and they get indented an extra level. the
+				// opening brace also doesn't appear on the same line as default.
+				"switch (condition) {\n" +
+				"\tdefault:\n" +
+				"\t\t{\n" +
+				"\t\t\tstatement;\n" +
+				"\t\t}\n" +
+				"\t\tbreak;\n" +
+				"}",
+				// @formatter:on
+				result);
+	}
+
 	@Test
 	public void testWithMultipleCaseClauses() {
 		FORMATTER formatter = new FORMATTER();


[royale-compiler] 02/06: formatter: display problem severity

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 33db4870e563dcaeb164f483b3097201ffb66028
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Jul 14 10:30:30 2022 -0700

    formatter: display problem severity
---
 .../org/apache/royale/formatter/FORMATTER.java     | 24 ++++++++++++----------
 1 file changed, 13 insertions(+), 11 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 fc36d0989..8c6c75328 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -130,7 +130,7 @@ public class FORMATTER {
 	public boolean mxmlAlignAttributes = false;
 	public boolean mxmlInsertNewLineBetweenAttributes = false;
 
-	private ProblemQuery problems;
+	private ProblemQuery problemQuery;
 	private List<File> inputFiles = new ArrayList<File>();
 	private boolean writeBackToInputFiles = false;
 	private boolean listChangedFiles = false;
@@ -139,11 +139,11 @@ public class FORMATTER {
 
 	public int execute(String[] args) {
 		ExitCode exitCode = ExitCode.SUCCESS;
-		problems = new ProblemQuery();
-		problems.setShowWarnings(false);
+		problemQuery = new ProblemQuery();
+		problemQuery.setShowWarnings(false);
 
 		try {
-			boolean continueFormatting = configure(args, problems);
+			boolean continueFormatting = configure(args, problemQuery);
 			if (continueFormatting) {
 				if (inputFiles.size() == 0) {
 					StringBuilder builder = new StringBuilder();
@@ -157,7 +157,7 @@ public class FORMATTER {
 					}
 					String filePath = FilenameNormalization.normalize("stdin.as");
 					String fileText = builder.toString();
-					String formattedText = formatFileText(filePath, fileText, problems.getProblems());
+					String formattedText = formatFileText(filePath, fileText, problemQuery.getProblems());
 					if (!fileText.equals(formattedText)) {
 						if (listChangedFiles) {
 							System.out.println(filePath);
@@ -170,7 +170,7 @@ public class FORMATTER {
 					for (File inputFile : inputFiles) {
 						String filePath = FilenameNormalization.normalize(inputFile.getAbsolutePath());
 						String fileText = FileUtils.readFileToString(inputFile, "utf8");
-						String formattedText = formatFileText(filePath, fileText, problems.getProblems());
+						String formattedText = formatFileText(filePath, fileText, problemQuery.getProblems());
 						if (!fileText.equals(formattedText)) {
 							if (listChangedFiles) {
 								System.out.println(filePath);
@@ -184,20 +184,22 @@ public class FORMATTER {
 						}
 					}
 				}
-			} else if (problems.hasFilteredProblems()) {
+			} else if (problemQuery.hasFilteredProblems()) {
 				exitCode = ExitCode.FAILED_WITH_CONFIG_PROBLEMS;
 			} else {
 				exitCode = ExitCode.PRINT_HELP;
 			}
 		} catch (Exception e) {
-			problems.add(new UnexpectedExceptionProblem(e));
+			problemQuery.add(new UnexpectedExceptionProblem(e));
 			System.err.println(e.getMessage());
 			exitCode = ExitCode.FAILED_WITH_EXCEPTIONS;
 		} finally {
-			if (problems.hasFilteredProblems()) {
-				final ProblemFormatter formatter = new WorkspaceProblemFormatter(new Workspace());
+			if (problemQuery.hasFilteredProblems()) {
+				final Workspace workspace = new Workspace();
+				final CompilerProblemCategorizer categorizer = new CompilerProblemCategorizer();
+				final ProblemFormatter formatter = new WorkspaceProblemFormatter(workspace, categorizer);
 				final ProblemPrinter printer = new ProblemPrinter(formatter);
-				printer.printProblems(problems.getFilteredProblems());
+				printer.printProblems(problemQuery.getFilteredProblems());
 			}
 		}
 		return exitCode.getCode();


[royale-compiler] 06/06: royaleunit-ant-tasks: added commandArgs attribute to element (closes #168)

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 4c5c9049188f0dee62aee4dc73f9c9e6f1e4582b
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Jul 14 15:13:00 2022 -0700

    royaleunit-ant-tasks: added commandArgs attribute to <royaleunit/> element (closes #168)
---
 .../commands/player/CustomPlayerCommand.java       | 23 ++++++++--
 .../commands/player/PlayerCommandFactory.java      |  3 +-
 .../royale/test/ant/tasks/RoyaleUnitTask.java      | 49 +++++++++++++++++++---
 .../org/apache/royale/test/ant/tasks/TestRun.java  |  1 +
 .../ant/tasks/configuration/TaskConfiguration.java |  5 +++
 .../tasks/configuration/TestRunConfiguration.java  | 16 +++++++
 6 files changed, 88 insertions(+), 9 deletions(-)

diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/CustomPlayerCommand.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/CustomPlayerCommand.java
index 830af6ecb..ebf6e80dd 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/CustomPlayerCommand.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/CustomPlayerCommand.java
@@ -28,6 +28,7 @@ public class CustomPlayerCommand implements PlayerCommand
 {
     private DefaultPlayerCommand proxiedCommand;
     private File executable;
+    private String[] executableArgs;
 
     public PlayerCommand getProxiedCommand()
     {
@@ -48,6 +49,16 @@ public class CustomPlayerCommand implements PlayerCommand
     {
         this.executable = executable;
     }
+
+    public String[] getExecutableArgs()
+    {
+        return executableArgs;
+    }
+    
+    public void setExecutableArgs(String[] executableArgs)
+    {
+        this.executableArgs = executableArgs;
+    }
     
     public void setProject(Project project)
     {
@@ -79,15 +90,21 @@ public class CustomPlayerCommand implements PlayerCommand
         proxiedCommand.getCommandLine().setExecutable(executable.getAbsolutePath());
         proxiedCommand.getCommandLine().clearArgs();
         
+        int customArgsCount = executableArgs != null ? executableArgs.length : 0;
+        String[] args = new String[customArgsCount + 1];
+        if (executableArgs != null)
+        {
+            System.arraycopy(executableArgs, 0, args, 0, executableArgs.length);
+        }
         if(getUrl() != null)
         {    	  
-           proxiedCommand.getCommandLine().addArguments(new String[]{getUrl()});
+            args[args.length - 1] = getUrl();
         } 
         else 
         {  
-           proxiedCommand.getCommandLine().addArguments(new String[]{getFileToExecute().getAbsolutePath()});
+            args[args.length - 1] = getFileToExecute().getAbsolutePath();
         }
-
+        proxiedCommand.getCommandLine().addArguments(args);
     }
     
     public Process launch() throws IOException
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/PlayerCommandFactory.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/PlayerCommandFactory.java
index 696126276..8c3264f2f 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/PlayerCommandFactory.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/PlayerCommandFactory.java
@@ -35,7 +35,7 @@ public class PlayerCommandFactory
      * @param localTrusted
      * @return Desired player command with platform defaults possibly wrapped in a custom command
      */
-    public static PlayerCommand createPlayer(OperatingSystem os, String player, File customCommand, boolean localTrusted)
+    public static PlayerCommand createPlayer(OperatingSystem os, String player, File customCommand, String[] customCommandArgs, boolean localTrusted)
     {
         PlayerCommand newInstance = null;
 
@@ -73,6 +73,7 @@ public class PlayerCommandFactory
             CustomPlayerCommand customInstance = new CustomPlayerCommand();
             customInstance.setProxiedCommand(defaultInstance);
             customInstance.setExecutable(customCommand);
+            customInstance.setExecutableArgs(customCommandArgs);
             newInstance = customInstance;
         }
         else
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/RoyaleUnitTask.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/RoyaleUnitTask.java
index d01e03a5d..9f4f73f61 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/RoyaleUnitTask.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/RoyaleUnitTask.java
@@ -16,16 +16,25 @@
  */
 package org.apache.royale.test.ant.tasks;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.royale.test.ant.tasks.configuration.TaskConfiguration;
+import org.apache.royale.test.ant.tasks.types.LoadConfig;
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DynamicAttribute;
 import org.apache.tools.ant.DynamicElement;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.types.FileSet;
-import org.apache.royale.test.ant.tasks.configuration.TaskConfiguration;
-import org.apache.royale.test.ant.tasks.types.LoadConfig;
 
-public class RoyaleUnitTask extends Task implements DynamicElement
+public class RoyaleUnitTask extends Task implements DynamicElement, DynamicAttribute
 {
+	private static final Pattern COMMAND_ARGS_PATTERN = Pattern.compile(
+			"([\\-+]([^\\s]+\\+?=)(('([^'])*')|(\"([^\"])*\")|([^\\s\"',]+))(,(('([^'])*')|(\"([^\"])*\")|([^\\s\"']+)))*)|('([^'])*')|(\"([^\"])*\")|([^\\s\"']+)");
+
     private TaskConfiguration configuration;
 
     public RoyaleUnitTask()
@@ -142,6 +151,11 @@ public class RoyaleUnitTask extends Task implements DynamicElement
         configuration.setCommand(executableFilePath);
     }
 
+    public void setCommandArgs(String[] customArgs)
+    {
+        configuration.setCommandArgs(customArgs);
+    }
+
     public void setHeadless(boolean headless)
     {
         configuration.setHeadless(headless);
@@ -204,11 +218,36 @@ public class RoyaleUnitTask extends Task implements DynamicElement
             LoadConfig loadconfig = new LoadConfig();
             configuration.setLoadConfig(loadconfig);
             return loadconfig;
-        } 
+        }
         else
         {
-            throw new BuildException( "The <royaleUnit> type doesn't support the " + arg0 + "nested element");
+            throw new BuildException( "The <royaleUnit> type doesn't support the " + arg0 + " nested element");
         }
     }
 
+	private String[] parseCommandArgs(String combined)
+    {
+		List<String> result = new ArrayList<String>();
+		Matcher matcher = COMMAND_ARGS_PATTERN.matcher(combined);
+		while (matcher.find())
+    {
+			String option = matcher.group();
+			result.add(option);
+		}
+        return result.toArray(new String[0]);
+	}
+
+    public void setDynamicAttribute(String arg0, String arg1)
+           throws BuildException {
+       if("commandargs".equals(arg0))
+       {
+            String[] commandArgs = parseCommandArgs(arg1);
+            configuration.setCommandArgs(commandArgs);
+       }
+       else
+       {	
+            throw new BuildException( "The <royaleUnit> type doesn't support the " + arg0 + " attribute");
+       }
+   }
+
 }
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/TestRun.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/TestRun.java
index 531474b4d..d46e03beb 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/TestRun.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/TestRun.java
@@ -104,6 +104,7 @@ public class TestRun
                 configuration.getOs(), 
                 configuration.getPlayer(), 
                 configuration.getCommand(), 
+                configuration.getCommandArgs(),
                 configuration.isLocalTrusted());
         
         command.setProject(project);
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TaskConfiguration.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TaskConfiguration.java
index 790ea140a..69edba135 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TaskConfiguration.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TaskConfiguration.java
@@ -93,6 +93,11 @@ public class TaskConfiguration
             testRunConfiguration.setCommand(project.resolveFile(commandPath));
         }
     }
+
+    public void setCommandArgs(String[] commandArgs)
+    {
+        testRunConfiguration.setCommandArgs(commandArgs);
+    }
     
     public void setDisplay(int display)
     {
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TestRunConfiguration.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TestRunConfiguration.java
index c5951c589..b60f8e59d 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TestRunConfiguration.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TestRunConfiguration.java
@@ -17,6 +17,7 @@
 package org.apache.royale.test.ant.tasks.configuration;
 
 import java.io.File;
+import java.util.Arrays;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.royale.test.ant.LoggingUtil;
@@ -29,6 +30,7 @@ public class TestRunConfiguration implements StepConfiguration
 
     private String player;
     private File command = null;
+    private String[] commandArgs = null;
     private int display = 99;
     private boolean failOnTestFailure = false;
     private String failureProperty = "royaleunit.failed";
@@ -54,6 +56,16 @@ public class TestRunConfiguration implements StepConfiguration
         this.command = command;
     }
     
+    public String[] getCommandArgs()
+    {
+        return commandArgs;
+    }
+
+    public void setCommandArgs(String[] commandArgs)
+    {
+        this.commandArgs = commandArgs;
+    }
+    
     public boolean isCustomCommand()
     {
         return command != null;
@@ -268,6 +280,10 @@ public class TestRunConfiguration implements StepConfiguration
         if(isCustomCommand())
         {
             LoggingUtil.log("\tcommand: [" + command + "]");
+            if (commandArgs != null)
+            {
+                LoggingUtil.log("\tcommandArgs: [" + Arrays.toString(commandArgs) + "]");
+            }
         }
         
         LoggingUtil.log("\tport: [" + port + "]");


[royale-compiler] 05/06: formatter: fix invalid error detected when source file starts with UTF BOM character

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 2b6bf3e5e65c818e96caa67241b426fe6a610728
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Jul 14 11:35:42 2022 -0700

    formatter: fix invalid error detected when source file starts with UTF BOM character
---
 .../src/main/java/org/apache/royale/formatter/FORMATTER.java     | 9 ++++++---
 1 file changed, 6 insertions(+), 3 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 35c0d04a0..a512c0987 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -41,6 +41,7 @@ import org.apache.royale.compiler.clients.problems.ProblemQuery;
 import org.apache.royale.compiler.clients.problems.WorkspaceProblemFormatter;
 import org.apache.royale.compiler.common.VersionInfo;
 import org.apache.royale.compiler.exceptions.ConfigurationException;
+import org.apache.royale.compiler.filespecs.FileSpecification;
 import org.apache.royale.compiler.internal.config.localization.LocalizationManager;
 import org.apache.royale.compiler.internal.parsing.as.ASParser;
 import org.apache.royale.compiler.internal.parsing.as.ASToken;
@@ -169,7 +170,8 @@ public class FORMATTER {
 				} else {
 					for (File inputFile : inputFiles) {
 						String filePath = FilenameNormalization.normalize(inputFile.getAbsolutePath());
-						String fileText = FileUtils.readFileToString(inputFile, "utf8");
+						FileSpecification fileSpec = new FileSpecification(filePath);
+						String fileText = IOUtils.toString(fileSpec.createReader());
 						String formattedText = formatFileText(filePath, fileText, problemQuery.getProblems());
 						if (!fileText.equals(formattedText)) {
 							if (listChangedFiles) {
@@ -206,8 +208,9 @@ public class FORMATTER {
 	}
 
 	public String formatFile(File file, Collection<ICompilerProblem> problems) throws IOException {
-		String fileText = FileUtils.readFileToString(file, "utf8");
-		String filePath = file.getAbsolutePath();
+		String filePath = FilenameNormalization.normalize(file.getAbsolutePath());
+		FileSpecification fileSpec = new FileSpecification(filePath);
+		String fileText = IOUtils.toString(fileSpec.createReader());
 		return formatFileText(filePath, fileText, problems);
 	}