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 d56e53b StreamingASTokenizer: fix issue where metadata was not
recognized after comments
d56e53b is described below
commit d56e53b576ce7502c1bccdc857ff7c9eec538b8e
Author: Josh Tynjala <[email protected]>
AuthorDate: Thu Nov 4 13:27:32 2021 -0700
StreamingASTokenizer: fix issue where metadata was not recognized after
comments
This wasn't noticed before because comments are usually omitted from the
token stream. However, comments are kept for the formatter, so it exposed the
issue, and the behavior should match asdoc comments, which were not omitted
before either.
---
.../internal/parsing/as/StreamingASTokenizer.java | 2 ++
.../org/apache/royale/formatter/TestMetadata.java | 42 ++++++++++++++++++++++
2 files changed, 44 insertions(+)
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 93b67f5..efc9a53 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
@@ -1391,6 +1391,8 @@ public class StreamingASTokenizer implements
ASTokenTypes, IASTokenizer, Closeab
{
switch (lastToken.getType())
{
+ case HIDDEN_TOKEN_SINGLE_LINE_COMMENT:
+ case HIDDEN_TOKEN_MULTI_LINE_COMMENT:
case TOKEN_ASDOC_COMMENT:
case TOKEN_SEMICOLON:
case TOKEN_ATTRIBUTE:
diff --git
a/formatter/src/test/java/org/apache/royale/formatter/TestMetadata.java
b/formatter/src/test/java/org/apache/royale/formatter/TestMetadata.java
index d678533..ffc1cdb 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestMetadata.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestMetadata.java
@@ -229,4 +229,46 @@ public class TestMetadata extends BaseFormatterTests {
// @formatter:on
result);
}
+
+ @Test
+ public void testAfterSingleLineComment() {
+ FORMATTER formatter = new FORMATTER();
+ formatter.insertSpaceBeforeAndAfterBinaryOperators = true;
+ formatter.placeOpenBraceOnNewLine = true;
+ formatter.insertSpaces = false;
+ String result = formatter.formatActionScriptText(
+ // @formatter:off
+ "// comment\n" +
+ "[UnknownMetaTag(attr1=\"one\")]\n",
+ // @formatter:on
+ problems
+ );
+ assertEquals(
+ // @formatter:off
+ "// comment\n" +
+ "[UnknownMetaTag(attr1=\"one\")]\n",
+ // @formatter:on
+ result);
+ }
+
+ @Test
+ public void testAfterMultiLineComment() {
+ FORMATTER formatter = new FORMATTER();
+ formatter.insertSpaceBeforeAndAfterBinaryOperators = true;
+ formatter.placeOpenBraceOnNewLine = true;
+ formatter.insertSpaces = false;
+ String result = formatter.formatActionScriptText(
+ // @formatter:off
+ "/* comment */\n" +
+ "[UnknownMetaTag(attr1=\"one\")]\n",
+ // @formatter:on
+ problems
+ );
+ assertEquals(
+ // @formatter:off
+ "/* comment */\n" +
+ "[UnknownMetaTag(attr1=\"one\")]\n",
+ // @formatter:on
+ result);
+ }
}