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/04 22:40:04 UTC
[royale-compiler] branch develop updated: formatter: fix new <*>[]
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
The following commit(s) were added to refs/heads/develop by this push:
new 4b92d86 formatter: fix new <*>[]
4b92d86 is described below
commit 4b92d864b8b8f3553fc8719f04ebfeccb46ca67d
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Nov 4 15:30:49 2021 -0700
formatter: fix new <*>[]
---
.../org/apache/royale/formatter/FORMATTER.java | 7 +-
.../apache/royale/formatter/TestNewStatement.java | 103 +++++++++++++++++++++
2 files changed, 108 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 738bb75..dace35d 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -1562,8 +1562,11 @@ public class FORMATTER {
}
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;
+ return prevToken != null && nextToken != null
+ && ((prevToken.getType() == ASTokenTypes.TOKEN_TYPED_COLLECTION_OPEN
+ && nextToken.getType() == ASTokenTypes.TOKEN_TYPED_COLLECTION_CLOSE)
+ || (prevToken.getType() == ASTokenTypes.TOKEN_TYPED_LITERAL_OPEN
+ && nextToken.getType() == ASTokenTypes.TOKEN_TYPED_LITERAL_CLOSE));
}
private boolean checkTokenBeforeUnaryOperator(IASToken token) {
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestNewStatement.java b/formatter/src/test/java/org/apache/royale/formatter/TestNewStatement.java
new file mode 100644
index 0000000..0b069fc
--- /dev/null
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestNewStatement.java
@@ -0,0 +1,103 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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;
+
+// for member variables of classes, see TestFieldDeclaration
+public class TestNewStatement extends BaseFormatterTests {
+ @Test
+ public void testWithClassNoParentheses() {
+ FORMATTER formatter = new FORMATTER();
+ formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+ formatter.placeOpenBraceOnNewLine = true;
+ formatter.insertSpaces = false;
+ String result = formatter.formatActionScriptText(
+ // @formatter:off
+ "new Sprite;",
+ // @formatter:on
+ problems
+ );
+ assertEquals(
+ // @formatter:off
+ "new Sprite;",
+ // @formatter:on
+ result);
+ }
+
+ @Test
+ public void testWithClassConstructorCall() {
+ FORMATTER formatter = new FORMATTER();
+ formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+ formatter.placeOpenBraceOnNewLine = true;
+ formatter.insertSpaces = false;
+ String result = formatter.formatActionScriptText(
+ // @formatter:off
+ "new Sprite();",
+ // @formatter:on
+ problems
+ );
+ assertEquals(
+ // @formatter:off
+ "new Sprite();",
+ // @formatter:on
+ result);
+ }
+
+ @Test
+ public void testWithVectorLiteral() {
+ FORMATTER formatter = new FORMATTER();
+ formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+ formatter.placeOpenBraceOnNewLine = true;
+ formatter.insertSpaces = false;
+ String result = formatter.formatActionScriptText(
+ // @formatter:off
+ "new <Sprite>[];",
+ // @formatter:on
+ problems
+ );
+ assertEquals(
+ // @formatter:off
+ "new <Sprite>[];",
+ // @formatter:on
+ result);
+ }
+
+ @Test
+ public void testWithVectorLiteralAnyType() {
+ FORMATTER formatter = new FORMATTER();
+ formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+ formatter.placeOpenBraceOnNewLine = true;
+ formatter.insertSpaces = false;
+ String result = formatter.formatActionScriptText(
+ // @formatter:off
+ "new <*>[];",
+ // @formatter:on
+ problems
+ );
+ assertEquals(
+ // @formatter:off
+ "new <*>[];",
+ // @formatter:on
+ result);
+ }
+}