Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 42280340b -> 436965d96


Make Parrot test util classes compileStatic

(cherry picked from commit adf7e92)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/436965d9
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/436965d9
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/436965d9

Branch: refs/heads/GROOVY_2_6_X
Commit: 436965d96de66c3c4043b6b485945404e1106d04
Parents: 4228034
Author: sunlan <sun...@apache.org>
Authored: Fri Apr 13 15:24:28 2018 +0800
Committer: sunlan <sun...@apache.org>
Committed: Fri Apr 13 15:56:53 2018 +0800

----------------------------------------------------------------------
 .../groovy/parser/antlr4/TestUtils.groovy       |  48 +++-
 .../antlr4/util/ASTComparatorCategory.groovy    | 251 ++++++++++++-------
 .../groovy/parser/antlr4/util/AstDumper.groovy  | 203 +++++++++++----
 .../test/resources/bugs/BUG-GROOVY-8426.groovy  |   6 +-
 4 files changed, 359 insertions(+), 149 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/436965d9/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy
----------------------------------------------------------------------
diff --git 
a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy
 
b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy
index 791655f..af2cb16 100644
--- 
a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy
+++ 
b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy
@@ -18,6 +18,8 @@
  */
 package org.apache.groovy.parser.antlr4
 
+import groovy.transform.CompileDynamic
+import groovy.transform.CompileStatic
 import groovy.util.logging.Log
 import org.apache.groovy.parser.AbstractParser
 import org.apache.groovy.parser.Antlr2Parser
@@ -25,8 +27,23 @@ import org.apache.groovy.parser.Antlr4Parser
 import org.apache.groovy.parser.antlr4.util.ASTComparatorCategory
 import org.apache.groovy.parser.antlr4.util.AstDumper
 import org.codehaus.groovy.antlr.AntlrParserPluginFactory
-import org.codehaus.groovy.ast.*
-import org.codehaus.groovy.ast.stmt.*
+import org.codehaus.groovy.ast.ConstructorNode
+import org.codehaus.groovy.ast.FieldNode
+import org.codehaus.groovy.ast.GenericsType
+import org.codehaus.groovy.ast.MethodNode
+import org.codehaus.groovy.ast.ModuleNode
+import org.codehaus.groovy.ast.PackageNode
+import org.codehaus.groovy.ast.Parameter
+import org.codehaus.groovy.ast.PropertyNode
+import org.codehaus.groovy.ast.stmt.AssertStatement
+import org.codehaus.groovy.ast.stmt.BreakStatement
+import org.codehaus.groovy.ast.stmt.ContinueStatement
+import org.codehaus.groovy.ast.stmt.ExpressionStatement
+import org.codehaus.groovy.ast.stmt.ForStatement
+import org.codehaus.groovy.ast.stmt.IfStatement
+import org.codehaus.groovy.ast.stmt.ReturnStatement
+import org.codehaus.groovy.ast.stmt.ThrowStatement
+import org.codehaus.groovy.ast.stmt.WhileStatement
 import org.codehaus.groovy.control.CompilerConfiguration
 import org.codehaus.groovy.syntax.Token
 
@@ -36,6 +53,8 @@ import java.util.zip.ZipFile
 /**
  * Utilities for test
  */
+
+@CompileStatic
 @Log
 class TestUtils {
     public static final String DEFAULT_RESOURCES_PATH = 
'subprojects/parser-antlr4/src/test/resources';
@@ -49,6 +68,7 @@ class TestUtils {
         return doTest(path, addIgnore(ignoreClazzList, 
ASTComparatorCategory.LOCATION_IGNORE_LIST))
     }
 
+    @CompileDynamic
     static doTest(String path, conf) {
         AbstractParser antlr4Parser = new Antlr4Parser()
         AbstractParser antlr2Parser = new Antlr2Parser()
@@ -81,6 +101,7 @@ class TestUtils {
     }
     */
 
+    @CompileDynamic
     static unzipAndTest(String path, String entryName, conf, Map<String, 
String> replacementsMap=[:]) {
         AbstractParser antlr4Parser = new Antlr4Parser()
         AbstractParser antlr2Parser = new Antlr2Parser()
@@ -114,6 +135,7 @@ class TestUtils {
         shouldFail(path, addIgnore(ignoreClazzList, 
ASTComparatorCategory.LOCATION_IGNORE_LIST), toCheckNewParserOnly)
     }
 
+    @CompileDynamic
     static shouldFail(String path, conf, boolean toCheckNewParserOnly = false) 
{
         AbstractParser antlr4Parser = new Antlr4Parser()
         AbstractParser antlr2Parser = new Antlr2Parser()
@@ -136,6 +158,7 @@ class TestUtils {
         }
     }
 
+    @CompileDynamic
     static unzipAndFail(String path, String entryName, conf, Map<String, 
String> replacementsMap=[:], boolean toCheckNewParserOnly = false) {
         AbstractParser antlr4Parser = new Antlr4Parser()
         AbstractParser antlr2Parser = new Antlr2Parser()
@@ -164,8 +187,7 @@ class TestUtils {
         }
     }
 
-
-    static assertAST(ast1, ast2, conf) {
+    static assertAST(ModuleNode ast1, ModuleNode ast2, conf) {
         assert null != ast1 && null != ast2
 
         ASTComparatorCategory.apply(conf) {
@@ -187,14 +209,14 @@ class TestUtils {
         return [result, end - begin];
     }
 
-    static addIgnore(Class aClass, ArrayList<String> ignore, Map<Class, 
List<String>> c = null) {
-        c = c ?: ASTComparatorCategory.DEFAULT_CONFIGURATION.clone() as 
Map<Class, List<String>>;
+    static addIgnore(Class aClass, List<String> ignore, Map<Class, 
List<String>> c = null) {
+        c = c ?: new HashMap<>(ASTComparatorCategory.DEFAULT_CONFIGURATION) as 
Map<Class, List<String>>;
         c[aClass].addAll(ignore)
         return c
     }
 
-    static addIgnore(Collection<Class> aClass, ArrayList<String> ignore, 
Map<Class, List<String>> c = null) {
-        c = c ?: ASTComparatorCategory.DEFAULT_CONFIGURATION.clone() as 
Map<Class, List<String>>;
+    static addIgnore(Collection<Class> aClass, List<String> ignore, Map<Class, 
List<String>> c = null) {
+        c = c ?: new HashMap<>(ASTComparatorCategory.DEFAULT_CONFIGURATION) as 
Map<Class, List<String>>;
         aClass.each { c[it].addAll(ignore) }
         return c
     }
@@ -229,7 +251,7 @@ class TestUtils {
     }
 
     static doRunAndTestAntlr4(String path) {
-        assert executeScript(path)
+        assert executeScript(path);
     }
 
     static doRunAndTestAntlr2(String path) {
@@ -240,7 +262,7 @@ class TestUtils {
         executeScript(createAntlr4Shell(), "$RESOURCES_PATH/$path")
     }
 
-    static executeScript(gsh, String path) {
+    static executeScript(GroovyShell gsh, String path) {
         def file = new File(path);
         def content = file.text;
 
@@ -254,19 +276,19 @@ class TestUtils {
         }
     }
 
-    static createAntlr4Shell() {
+    static GroovyShell createAntlr4Shell() {
         CompilerConfiguration configuration = new 
CompilerConfiguration(CompilerConfiguration.DEFAULT)
         configuration.pluginFactory = new Antlr4PluginFactory()
 
         return new GroovyShell(configuration);
     }
 
-    static createAntlr2Shell() {
+    static GroovyShell createAntlr2Shell() {
         CompilerConfiguration configuration = new 
CompilerConfiguration(CompilerConfiguration.DEFAULT)
         configuration.pluginFactory = new AntlrParserPluginFactory()
 
         return new GroovyShell(configuration);
     }
 
-    public static final List COMMON_IGNORE_CLASS_LIST = 
Collections.unmodifiableList([AssertStatement, BreakStatement, ConstructorNode, 
ContinueStatement, ExpressionStatement, FieldNode, ForStatement, GenericsType, 
IfStatement, MethodNode, PackageNode, Parameter, PropertyNode, ReturnStatement, 
ThrowStatement, Token, WhileStatement]);
+    public static final List COMMON_IGNORE_CLASS_LIST = 
Collections.unmodifiableList([AssertStatement, BreakStatement, ConstructorNode, 
ContinueStatement, ExpressionStatement, FieldNode, ForStatement, GenericsType, 
IfStatement, MethodNode, PackageNode, Parameter, PropertyNode, ReturnStatement, 
ThrowStatement, Token, WhileStatement] as List);
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/436965d9/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/util/ASTComparatorCategory.groovy
----------------------------------------------------------------------
diff --git 
a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/util/ASTComparatorCategory.groovy
 
b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/util/ASTComparatorCategory.groovy
index 19123f9..0480004 100644
--- 
a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/util/ASTComparatorCategory.groovy
+++ 
b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/util/ASTComparatorCategory.groovy
@@ -18,14 +18,90 @@
  */
 package org.apache.groovy.parser.antlr4.util
 
+import groovy.transform.CompileDynamic
+import groovy.transform.CompileStatic
 import groovy.util.logging.Log
-import org.codehaus.groovy.ast.*
-import org.codehaus.groovy.ast.expr.*
-import org.codehaus.groovy.ast.stmt.*
+import org.codehaus.groovy.ast.AnnotationNode
+import org.codehaus.groovy.ast.ClassNode
+import org.codehaus.groovy.ast.CompileUnit
+import org.codehaus.groovy.ast.ConstructorNode
+import org.codehaus.groovy.ast.DynamicVariable
+import org.codehaus.groovy.ast.EnumConstantClassNode
+import org.codehaus.groovy.ast.FieldNode
+import org.codehaus.groovy.ast.GenericsType
+import org.codehaus.groovy.ast.ImportNode
+import org.codehaus.groovy.ast.InnerClassNode
+import org.codehaus.groovy.ast.InterfaceHelperClassNode
+import org.codehaus.groovy.ast.MethodNode
+import org.codehaus.groovy.ast.MixinNode
+import org.codehaus.groovy.ast.ModuleNode
+import org.codehaus.groovy.ast.PackageNode
+import org.codehaus.groovy.ast.Parameter
+import org.codehaus.groovy.ast.PropertyNode
+import org.codehaus.groovy.ast.Variable
+import org.codehaus.groovy.ast.VariableScope
+import org.codehaus.groovy.ast.expr.AnnotationConstantExpression
+import org.codehaus.groovy.ast.expr.ArgumentListExpression
+import org.codehaus.groovy.ast.expr.ArrayExpression
+import org.codehaus.groovy.ast.expr.AttributeExpression
+import org.codehaus.groovy.ast.expr.BinaryExpression
+import org.codehaus.groovy.ast.expr.BitwiseNegationExpression
+import org.codehaus.groovy.ast.expr.BooleanExpression
+import org.codehaus.groovy.ast.expr.CastExpression
+import org.codehaus.groovy.ast.expr.ClassExpression
+import org.codehaus.groovy.ast.expr.ClosureExpression
+import org.codehaus.groovy.ast.expr.ClosureListExpression
+import org.codehaus.groovy.ast.expr.ConstantExpression
+import org.codehaus.groovy.ast.expr.ConstructorCallExpression
+import org.codehaus.groovy.ast.expr.DeclarationExpression
+import org.codehaus.groovy.ast.expr.ElvisOperatorExpression
+import org.codehaus.groovy.ast.expr.EmptyExpression
+import org.codehaus.groovy.ast.expr.ExpressionTransformer
+import org.codehaus.groovy.ast.expr.FieldExpression
+import org.codehaus.groovy.ast.expr.GStringExpression
+import org.codehaus.groovy.ast.expr.ListExpression
+import org.codehaus.groovy.ast.expr.MapEntryExpression
+import org.codehaus.groovy.ast.expr.MapExpression
+import org.codehaus.groovy.ast.expr.MethodCall
+import org.codehaus.groovy.ast.expr.MethodCallExpression
+import org.codehaus.groovy.ast.expr.MethodPointerExpression
+import org.codehaus.groovy.ast.expr.NamedArgumentListExpression
+import org.codehaus.groovy.ast.expr.NotExpression
+import org.codehaus.groovy.ast.expr.PostfixExpression
+import org.codehaus.groovy.ast.expr.PrefixExpression
+import org.codehaus.groovy.ast.expr.PropertyExpression
+import org.codehaus.groovy.ast.expr.RangeExpression
+import org.codehaus.groovy.ast.expr.SpreadExpression
+import org.codehaus.groovy.ast.expr.SpreadMapExpression
+import org.codehaus.groovy.ast.expr.StaticMethodCallExpression
+import org.codehaus.groovy.ast.expr.TernaryExpression
+import org.codehaus.groovy.ast.expr.TupleExpression
+import org.codehaus.groovy.ast.expr.UnaryMinusExpression
+import org.codehaus.groovy.ast.expr.UnaryPlusExpression
+import org.codehaus.groovy.ast.expr.VariableExpression
+import org.codehaus.groovy.ast.stmt.AssertStatement
+import org.codehaus.groovy.ast.stmt.BlockStatement
+import org.codehaus.groovy.ast.stmt.BreakStatement
+import org.codehaus.groovy.ast.stmt.CaseStatement
+import org.codehaus.groovy.ast.stmt.CatchStatement
+import org.codehaus.groovy.ast.stmt.ContinueStatement
+import org.codehaus.groovy.ast.stmt.DoWhileStatement
+import org.codehaus.groovy.ast.stmt.EmptyStatement
+import org.codehaus.groovy.ast.stmt.ExpressionStatement
+import org.codehaus.groovy.ast.stmt.ForStatement
+import org.codehaus.groovy.ast.stmt.IfStatement
+import org.codehaus.groovy.ast.stmt.LoopingStatement
+import org.codehaus.groovy.ast.stmt.ReturnStatement
+import org.codehaus.groovy.ast.stmt.SwitchStatement
+import org.codehaus.groovy.ast.stmt.SynchronizedStatement
+import org.codehaus.groovy.ast.stmt.ThrowStatement
+import org.codehaus.groovy.ast.stmt.TryCatchStatement
+import org.codehaus.groovy.ast.stmt.WhileStatement
 import org.codehaus.groovy.syntax.Token
 
 import java.util.logging.Level
 
+@CompileStatic
 @Log @SuppressWarnings("GroovyUnusedDeclaration")
 class ASTComparatorCategory {
     static { log.level = Level.WARNING }
@@ -36,94 +112,95 @@ class ASTComparatorCategory {
      *  Keeps all checked object pairs and their comparison result.
      *  Will be cleared at {@link #apply(groovy.lang.Closure)} method }
      */
-    static objects = [:] as Map<List<Object>, Boolean>
+    static Map<List<Object>, Boolean> objects = [:] as Map<List<Object>, 
Boolean>
     static String lastName
 
     static Map<Class, List<String>> DEFAULT_CONFIGURATION = [
-            (ClassNode): (['module', "declaredMethodsMap", 
"plainNodeReference", "typeClass", "allInterfaces", 
"orAddStaticConstructorNode", "allDeclaredMethods", "unresolvedSuperClass", 
"innerClasses" ] + LOCATION_IGNORE_LIST) as List<String>,
-            (ConstructorNode): ['declaringClass'],
-            (DynamicVariable): [],
-            (EnumConstantClassNode): ["typeClass"],
-            (FieldNode): ["owner", "declaringClass", "initialValueExpression", 
"assignToken"],
-            (GenericsType): [],
-            (ImportNode): LOCATION_IGNORE_LIST,
-            (InnerClassNode): (['module', "declaredMethodsMap", 
"plainNodeReference", "typeClass", "allInterfaces", 
"orAddStaticConstructorNode", "allDeclaredMethods", "unresolvedSuperClass", 
"innerClasses" ] + LOCATION_IGNORE_LIST) as List<String>,
-            (InterfaceHelperClassNode): [],
-            (MethodNode): ["text", "declaringClass"],
-            (MixinNode): [],
-            (ModuleNode): ["context"],
-            (PackageNode): [],
-            (Parameter): [],
-            (PropertyNode): ['declaringClass', 'initialValueExpression', 
"assignToken"],
-            (Variable): [],
-            (VariableScope): ["clazzScope", "parent", 
"declaredVariablesIterator"],
-            (Token): ["root", "startColumn"],
-            (AnnotationNode): (["text"] + LOCATION_IGNORE_LIST) as 
List<String>,
-            (AssertStatement): ["text"],
-            (BlockStatement): ["columnNumber", "lineNumber", 
"lastColumnNumber", "lastLineNumber", "text"],
-            (BreakStatement): ["text"],
-            (CaseStatement): ["text"],
-            (CatchStatement): (["text"] + LOCATION_IGNORE_LIST) as 
List<String>,
-            (ContinueStatement): ["text"],
-            (DoWhileStatement): ["text"],
-            (EmptyStatement): ["text"],
-            (ExpressionStatement): ["text"],
-            (ForStatement): ["text"],
-            (IfStatement): ["text"],
-            (LoopingStatement): ["text"],
-            (ReturnStatement): ["text"],
-            (SwitchStatement): ["columnNumber", "lineNumber", 
"lastColumnNumber", "lastLineNumber", "text"],
-            (SynchronizedStatement): ["text"],
-            (ThrowStatement): ["text"],
-            (TryCatchStatement): (["text"] + LOCATION_IGNORE_LIST) as 
List<String>,
-            (WhileStatement): ["text"],
+            (ClassNode)                   : (['module', "declaredMethodsMap", 
"plainNodeReference", "typeClass", "allInterfaces", 
"orAddStaticConstructorNode", "allDeclaredMethods", "unresolvedSuperClass", 
"innerClasses" ] + LOCATION_IGNORE_LIST) as List<String>,
+            (ConstructorNode)             : ['declaringClass'],
+            (DynamicVariable)             : [],
+            (EnumConstantClassNode)       : ["typeClass"],
+            (FieldNode)                   : ["owner", "declaringClass", 
"initialValueExpression", "assignToken"],
+            (GenericsType)                : [],
+            (ImportNode)                  : LOCATION_IGNORE_LIST,
+            (InnerClassNode)              : (['module', "declaredMethodsMap", 
"plainNodeReference", "typeClass", "allInterfaces", 
"orAddStaticConstructorNode", "allDeclaredMethods", "unresolvedSuperClass", 
"innerClasses" ] + LOCATION_IGNORE_LIST) as List<String>,
+            (InterfaceHelperClassNode)    : [],
+            (MethodNode)                  : ["text", "declaringClass"],
+            (MixinNode)                   : [],
+            (ModuleNode)                  : ["context"],
+            (PackageNode)                 : [],
+            (Parameter)                   : [],
+            (PropertyNode)                : ['declaringClass', 
'initialValueExpression', "assignToken"],
+            (Variable)                    : [],
+            (VariableScope)               : ["clazzScope", "parent", 
"declaredVariablesIterator"],
+            (Token)                       : ["root", "startColumn"],
+            (AnnotationNode)              : (["text"] + LOCATION_IGNORE_LIST) 
as List<String>,
+            (AssertStatement)             : ["text"],
+            (BlockStatement)              : ["columnNumber", "lineNumber", 
"lastColumnNumber", "lastLineNumber", "text"],
+            (BreakStatement)              : ["text"],
+            (CaseStatement)               : ["text"],
+            (CatchStatement)              : (["text"] + LOCATION_IGNORE_LIST) 
as List<String>,
+            (ContinueStatement)           : ["text"],
+            (DoWhileStatement)            : ["text"],
+            (EmptyStatement)              : ["text"],
+            (ExpressionStatement)         : ["text"],
+            (ForStatement)                : ["text"],
+            (IfStatement)                 : ["text"],
+            (LoopingStatement)            : ["text"],
+            (ReturnStatement)             : ["text"],
+            (SwitchStatement)             : ["columnNumber", "lineNumber", 
"lastColumnNumber", "lastLineNumber", "text"],
+            (SynchronizedStatement)       : ["text"],
+            (ThrowStatement)              : ["text"],
+            (TryCatchStatement)           : (["text"] + LOCATION_IGNORE_LIST) 
as List<String>,
+            (WhileStatement)              : ["text"],
             (AnnotationConstantExpression): EXPRESSION_IGNORE_LIST,
-            (ArgumentListExpression): EXPRESSION_IGNORE_LIST,
-            (ArrayExpression): EXPRESSION_IGNORE_LIST,
-            (AttributeExpression): EXPRESSION_IGNORE_LIST,
-            (BinaryExpression): EXPRESSION_IGNORE_LIST,
-            (BitwiseNegationExpression): EXPRESSION_IGNORE_LIST,
-            (BooleanExpression): EXPRESSION_IGNORE_LIST,
-            (CastExpression): EXPRESSION_IGNORE_LIST,
-            (ClassExpression): EXPRESSION_IGNORE_LIST,
-            (ClosureExpression): EXPRESSION_IGNORE_LIST,
-            (ClosureListExpression): EXPRESSION_IGNORE_LIST,
-            (ConstantExpression): EXPRESSION_IGNORE_LIST,
-            (ConstructorCallExpression): EXPRESSION_IGNORE_LIST,
-            (DeclarationExpression): ["text", "columnNumber", "lineNumber", 
"lastColumnNumber", "lastLineNumber"],
-            (ElvisOperatorExpression): EXPRESSION_IGNORE_LIST,
-            (EmptyExpression): EXPRESSION_IGNORE_LIST,
-            (ExpressionTransformer): EXPRESSION_IGNORE_LIST,
-            (FieldExpression): EXPRESSION_IGNORE_LIST,
-            (GStringExpression): EXPRESSION_IGNORE_LIST,
-            (ListExpression): EXPRESSION_IGNORE_LIST,
-            (MapEntryExpression): EXPRESSION_IGNORE_LIST,
-            (MapExpression): EXPRESSION_IGNORE_LIST,
-            (MethodCall): EXPRESSION_IGNORE_LIST,
-            (MethodCallExpression): EXPRESSION_IGNORE_LIST,
-            (MethodPointerExpression): EXPRESSION_IGNORE_LIST,
-            (NamedArgumentListExpression): EXPRESSION_IGNORE_LIST,
-            (NotExpression): EXPRESSION_IGNORE_LIST,
-            (PostfixExpression): EXPRESSION_IGNORE_LIST,
-            (PrefixExpression): EXPRESSION_IGNORE_LIST,
-            (PropertyExpression): EXPRESSION_IGNORE_LIST,
-            (RangeExpression): EXPRESSION_IGNORE_LIST,
-            (SpreadExpression): EXPRESSION_IGNORE_LIST,
-            (SpreadMapExpression): EXPRESSION_IGNORE_LIST,
-            (StaticMethodCallExpression): EXPRESSION_IGNORE_LIST,
-            (TernaryExpression): EXPRESSION_IGNORE_LIST,
-            (TupleExpression): EXPRESSION_IGNORE_LIST,
-            (UnaryMinusExpression): EXPRESSION_IGNORE_LIST,
-            (UnaryPlusExpression): EXPRESSION_IGNORE_LIST,
-            (VariableExpression): EXPRESSION_IGNORE_LIST,
-    ];
+            (ArgumentListExpression)      : EXPRESSION_IGNORE_LIST,
+            (ArrayExpression)             : EXPRESSION_IGNORE_LIST,
+            (AttributeExpression)         : EXPRESSION_IGNORE_LIST,
+            (BinaryExpression)            : EXPRESSION_IGNORE_LIST,
+            (BitwiseNegationExpression)   : EXPRESSION_IGNORE_LIST,
+            (BooleanExpression)           : EXPRESSION_IGNORE_LIST,
+            (CastExpression)              : EXPRESSION_IGNORE_LIST,
+            (ClassExpression)             : EXPRESSION_IGNORE_LIST,
+            (ClosureExpression)           : EXPRESSION_IGNORE_LIST,
+            (ClosureListExpression)       : EXPRESSION_IGNORE_LIST,
+            (ConstantExpression)          : EXPRESSION_IGNORE_LIST,
+            (ConstructorCallExpression)   : EXPRESSION_IGNORE_LIST,
+            (DeclarationExpression)       : ["text", "columnNumber", 
"lineNumber", "lastColumnNumber", "lastLineNumber"],
+            (ElvisOperatorExpression)     : EXPRESSION_IGNORE_LIST,
+            (EmptyExpression)             : EXPRESSION_IGNORE_LIST,
+            (ExpressionTransformer)       : EXPRESSION_IGNORE_LIST,
+            (FieldExpression)             : EXPRESSION_IGNORE_LIST,
+            (GStringExpression)           : EXPRESSION_IGNORE_LIST,
+            (ListExpression)              : EXPRESSION_IGNORE_LIST,
+            (MapEntryExpression)          : EXPRESSION_IGNORE_LIST,
+            (MapExpression)               : EXPRESSION_IGNORE_LIST,
+            (MethodCall)                  : EXPRESSION_IGNORE_LIST,
+            (MethodCallExpression)        : EXPRESSION_IGNORE_LIST,
+            (MethodPointerExpression)     : EXPRESSION_IGNORE_LIST,
+            (NamedArgumentListExpression) : EXPRESSION_IGNORE_LIST,
+            (NotExpression)               : EXPRESSION_IGNORE_LIST,
+            (PostfixExpression)           : EXPRESSION_IGNORE_LIST,
+            (PrefixExpression)            : EXPRESSION_IGNORE_LIST,
+            (PropertyExpression)          : EXPRESSION_IGNORE_LIST,
+            (RangeExpression)             : EXPRESSION_IGNORE_LIST,
+            (SpreadExpression)            : EXPRESSION_IGNORE_LIST,
+            (SpreadMapExpression)         : EXPRESSION_IGNORE_LIST,
+            (StaticMethodCallExpression)  : EXPRESSION_IGNORE_LIST,
+            (TernaryExpression)           : EXPRESSION_IGNORE_LIST,
+            (TupleExpression)             : EXPRESSION_IGNORE_LIST,
+            (UnaryMinusExpression)        : EXPRESSION_IGNORE_LIST,
+            (UnaryPlusExpression)         : EXPRESSION_IGNORE_LIST,
+            (VariableExpression)          : EXPRESSION_IGNORE_LIST,
+    ] as Map<Class, List<String>>
 
     static Map<Class, List<String>> COLLECTION_PROPERTY_CONFIGURATION = [
             (ModuleNode): ["classes", "name"]
-    ]
+    ] as Map<Class, List<String>>
 
     static Map<Class, List<String>> configuration = DEFAULT_CONFIGURATION;
 
+    @CompileDynamic
     static void apply(config = DEFAULT_CONFIGURATION, Closure cl) {
         configuration = config
         objects.clear()
@@ -138,8 +215,8 @@ class ASTComparatorCategory {
      * @param b
      * @return
      */
+    @CompileDynamic
     static reflexiveEquals(a, b, ignore = []) {
-
         if (a.getClass() != b.getClass()) {
             log.warning(" !!!! DIFFERENCE WAS FOUND! ${a.getClass()} != 
${b.getClass()}")
             return false;
@@ -161,7 +238,8 @@ class ASTComparatorCategory {
         if (a.is(b))
             return true
 
-        def difference = a.metaClass.properties.find { MetaBeanProperty p ->
+        def difference = a.metaClass.properties.find { MetaProperty mp  ->
+            MetaBeanProperty p = (MetaBeanProperty) mp
             if (!p.getter)
                 return false
 
@@ -194,7 +272,7 @@ class ASTComparatorCategory {
         }
 
         if (difference)
-            log.warning(" !!!! DIFFERENCE WAS FOUND! 
[${a.metaClass.hasProperty(a, 'text') ? a.text : '<NO 
TEXT>'}][${a.class}][${difference.name}]:: ${ a."$difference.name" } != ${ 
b."$difference.name" }")
+            log.warning(" !!!! DIFFERENCE WAS FOUND! 
[${extractText(a)}][${a.class}][${difference.name}]:: ${ a."$difference.name" } 
!= ${ b."$difference.name" }")
         else
             log.info(" ==== Exit ${ a.getClass() } ${ a.hashCode() } ====== ")
 
@@ -204,6 +282,11 @@ class ASTComparatorCategory {
         res
     }
 
+    @CompileDynamic
+    static String extractText(obj) {
+        return obj.metaClass.hasProperty(obj, 'text') ? obj.text : '<NO TEXT>'
+    }
+
     
////////////////////////////////////////////////////////////////////////////////////////////////////
     // Just a bunch of copypasted methods. Maybe will wrote AST transformation 
for them.
     
////////////////////////////////////////////////////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/groovy/blob/436965d9/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/util/AstDumper.groovy
----------------------------------------------------------------------
diff --git 
a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/util/AstDumper.groovy
 
b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/util/AstDumper.groovy
index a8c937c..e0c3114 100644
--- 
a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/util/AstDumper.groovy
+++ 
b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/util/AstDumper.groovy
@@ -18,9 +18,77 @@
  */
 package org.apache.groovy.parser.antlr4.util
 
-import org.codehaus.groovy.ast.*
-import org.codehaus.groovy.ast.expr.*
-import org.codehaus.groovy.ast.stmt.*
+import groovy.transform.CompileStatic
+import org.codehaus.groovy.ast.ASTNode
+import org.codehaus.groovy.ast.AnnotationNode
+import org.codehaus.groovy.ast.ClassHelper
+import org.codehaus.groovy.ast.ClassNode
+import org.codehaus.groovy.ast.ConstructorNode
+import org.codehaus.groovy.ast.FieldNode
+import org.codehaus.groovy.ast.GenericsType
+import org.codehaus.groovy.ast.GroovyClassVisitor
+import org.codehaus.groovy.ast.GroovyCodeVisitor
+import org.codehaus.groovy.ast.ImportNode
+import org.codehaus.groovy.ast.MethodNode
+import org.codehaus.groovy.ast.ModuleNode
+import org.codehaus.groovy.ast.PackageNode
+import org.codehaus.groovy.ast.Parameter
+import org.codehaus.groovy.ast.PropertyNode
+import org.codehaus.groovy.ast.expr.ArgumentListExpression
+import org.codehaus.groovy.ast.expr.ArrayExpression
+import org.codehaus.groovy.ast.expr.AttributeExpression
+import org.codehaus.groovy.ast.expr.BinaryExpression
+import org.codehaus.groovy.ast.expr.BitwiseNegationExpression
+import org.codehaus.groovy.ast.expr.BooleanExpression
+import org.codehaus.groovy.ast.expr.CastExpression
+import org.codehaus.groovy.ast.expr.ClassExpression
+import org.codehaus.groovy.ast.expr.ClosureExpression
+import org.codehaus.groovy.ast.expr.ClosureListExpression
+import org.codehaus.groovy.ast.expr.ConstantExpression
+import org.codehaus.groovy.ast.expr.ConstructorCallExpression
+import org.codehaus.groovy.ast.expr.DeclarationExpression
+import org.codehaus.groovy.ast.expr.ElvisOperatorExpression
+import org.codehaus.groovy.ast.expr.EmptyExpression
+import org.codehaus.groovy.ast.expr.Expression
+import org.codehaus.groovy.ast.expr.FieldExpression
+import org.codehaus.groovy.ast.expr.GStringExpression
+import org.codehaus.groovy.ast.expr.LambdaExpression
+import org.codehaus.groovy.ast.expr.ListExpression
+import org.codehaus.groovy.ast.expr.MapEntryExpression
+import org.codehaus.groovy.ast.expr.MapExpression
+import org.codehaus.groovy.ast.expr.MethodCallExpression
+import org.codehaus.groovy.ast.expr.MethodPointerExpression
+import org.codehaus.groovy.ast.expr.NotExpression
+import org.codehaus.groovy.ast.expr.PostfixExpression
+import org.codehaus.groovy.ast.expr.PrefixExpression
+import org.codehaus.groovy.ast.expr.PropertyExpression
+import org.codehaus.groovy.ast.expr.RangeExpression
+import org.codehaus.groovy.ast.expr.SpreadExpression
+import org.codehaus.groovy.ast.expr.SpreadMapExpression
+import org.codehaus.groovy.ast.expr.StaticMethodCallExpression
+import org.codehaus.groovy.ast.expr.TernaryExpression
+import org.codehaus.groovy.ast.expr.TupleExpression
+import org.codehaus.groovy.ast.expr.UnaryMinusExpression
+import org.codehaus.groovy.ast.expr.UnaryPlusExpression
+import org.codehaus.groovy.ast.expr.VariableExpression
+import org.codehaus.groovy.ast.stmt.AssertStatement
+import org.codehaus.groovy.ast.stmt.BlockStatement
+import org.codehaus.groovy.ast.stmt.BreakStatement
+import org.codehaus.groovy.ast.stmt.CaseStatement
+import org.codehaus.groovy.ast.stmt.CatchStatement
+import org.codehaus.groovy.ast.stmt.ContinueStatement
+import org.codehaus.groovy.ast.stmt.DoWhileStatement
+import org.codehaus.groovy.ast.stmt.EmptyStatement
+import org.codehaus.groovy.ast.stmt.ExpressionStatement
+import org.codehaus.groovy.ast.stmt.ForStatement
+import org.codehaus.groovy.ast.stmt.IfStatement
+import org.codehaus.groovy.ast.stmt.ReturnStatement
+import org.codehaus.groovy.ast.stmt.Statement
+import org.codehaus.groovy.ast.stmt.SwitchStatement
+import org.codehaus.groovy.ast.stmt.SynchronizedStatement
+import org.codehaus.groovy.ast.stmt.ThrowStatement
+import org.codehaus.groovy.ast.stmt.TryCatchStatement
+import org.codehaus.groovy.ast.stmt.WhileStatement
 import org.codehaus.groovy.classgen.BytecodeExpression
 import org.codehaus.groovy.classgen.GeneratorContext
 import org.codehaus.groovy.classgen.Verifier
@@ -37,6 +105,7 @@ import java.lang.reflect.Modifier
  * @author  <a href="mailto:realblue...@hotmail.com";>Daniel.Sun</a>
  * Created on    2016/08/16
  */
+@CompileStatic
 class AstDumper {
     private ModuleNode ast;
 
@@ -55,7 +124,7 @@ class AstDumper {
         try {
             AstNodeToScriptVisitor visitor = new AstNodeToScriptVisitor(out, 
true, true);
 
-            new LinkedList<ClassNode>(this.ast?.classes ?: []).sort { c1, c2 
-> c1.name <=> c2.name }?.each {
+            new LinkedList<ClassNode>((List) this.ast?.classes ?: []).sort { 
c1, c2 -> c1.name <=> c2.name }?.each {
                 visitor.call(new SourceUnit((String) null, (ReaderSource) 
null, null, null, null) {
                     @Override
                     public ModuleNode getAST() {
@@ -82,6 +151,7 @@ class AstDumper {
  *
  * @author Hamlet D'Arcy
  */
+@CompileStatic
 class AstNodeToScriptVisitor extends CompilationUnit.PrimaryClassNodeOperation 
implements GroovyCodeVisitor, GroovyClassVisitor {
 
     private final Writer _out
@@ -233,7 +303,8 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
         }
 
         visitModifiers(node.modifiers)
-        print "class $node.name"
+        if (node.isInterface()) print node.name
+        else print "class $node.name"
         visitGenerics node?.genericsTypes
         boolean first = true
         node.unresolvedInterfaces?.each {
@@ -257,6 +328,8 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
             printDoubleBreak()
             node?.declaredConstructors?.each { visitConstructor(it) }
             printLineBreak()
+            visitObjectInitializerBlocks(node)
+            printLineBreak()
             node?.methods?.each { visitMethod(it) }
         }
         print '}'
@@ -264,6 +337,19 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
         classNameStack.pop()
     }
 
+    private void visitObjectInitializerBlocks(ClassNode node) {
+        for (Statement stmt : node.getObjectInitializerStatements()) {
+            print '{'
+            printLineBreak()
+            indented {
+                stmt.visit(this)
+            }
+            printLineBreak()
+            print '}'
+            printDoubleBreak()
+        }
+    }
+
     private void visitGenerics(GenericsType[] generics) {
 
         if (generics) {
@@ -368,40 +454,10 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
         printDoubleBreak()
     }
 
-    private def visitModifiers(int modifiers) {
-        if (Modifier.isAbstract(modifiers)) {
-            print 'abstract '
-        }
-        if (Modifier.isFinal(modifiers)) {
-            print 'final '
-        }
-        if (Modifier.isInterface(modifiers)) {
-            print 'interface '
-        }
-        if (Modifier.isNative(modifiers)) {
-            print 'native '
-        }
-        if (Modifier.isPrivate(modifiers)) {
-            print 'private '
-        }
-        if (Modifier.isProtected(modifiers)) {
-            print 'protected '
-        }
-        if (Modifier.isPublic(modifiers)) {
-            print 'public '
-        }
-        if (Modifier.isStatic(modifiers)) {
-            print 'static '
-        }
-        if (Modifier.isSynchronized(modifiers)) {
-            print 'synchronized '
-        }
-        if (Modifier.isTransient(modifiers)) {
-            print 'transient '
-        }
-        if (Modifier.isVolatile(modifiers)) {
-            print 'volatile '
-        }
+    private void visitModifiers(int modifiers) {
+        String mods = Modifier.toString(modifiers)
+        mods = mods ? mods + ' ' : mods
+        print mods
     }
 
     @Override
@@ -424,7 +480,7 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
             // GROOVY-5150: final constants may be initialized directly
             print ' = '
             if (ClassHelper.STRING_TYPE == type) {
-                print "'"+node.initialValueExpression.text.replaceAll("'", 
"\\\\'")+"'"
+                print "'" + node.initialValueExpression.text.replaceAll("'", 
"\\\\'") + "'"
             } else if (ClassHelper.char_TYPE == type) {
                 print "'${node.initialValueExpression.text}'"
             } else {
@@ -460,9 +516,22 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
 
     @Override
     void visitBlockStatement(BlockStatement block) {
-        block?.statements?.each {
-            it.visit(this)
+        if (printStatementLabels(block)) {
+            print '{'
+            printLineBreak()
+            indented {
+                block?.statements?.each {
+                    it.visit(this)
+                    printLineBreak()
+                }
+            }
+            print '}'
             printLineBreak()
+        } else {
+            block?.statements?.each {
+                it.visit(this)
+                printLineBreak()
+            }
         }
         if (!_out.toString().endsWith('\n')) {
             printLineBreak()
@@ -471,7 +540,7 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
 
     @Override
     void visitForLoop(ForStatement statement) {
-
+        printStatementLabels(statement)
         print 'for ('
         if (statement?.variable != ForStatement.FOR_LOOP_DUMMY) {
             visitParameters([statement.variable])
@@ -494,6 +563,7 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
 
     @Override
     void visitIfElse(IfStatement ifElse) {
+        printStatementLabels(ifElse)
         print 'if ('
         ifElse?.booleanExpression?.visit this
         print ') {'
@@ -529,6 +599,7 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
 
     @Override
     void visitSwitch(SwitchStatement statement) {
+        printStatementLabels(statement)
         print 'switch ('
         statement?.expression?.visit this
         print ') {'
@@ -561,12 +632,18 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
     @Override
     void visitBreakStatement(BreakStatement statement) {
         print 'break'
+        if (statement?.label) {
+            print ' ' + statement.label
+        }
         printLineBreak()
     }
 
     @Override
     void visitContinueStatement(ContinueStatement statement) {
         print 'continue'
+        if (statement?.label) {
+            print ' ' + statement.label
+        }
         printLineBreak()
     }
 
@@ -662,6 +739,11 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
         print '}'
     }
 
+    //@Override
+    void visitLambdaExpression(LambdaExpression expression) {
+        visitClosureExpression(expression)
+    }
+
     @Override
     void visitLambdaExpression(LambdaExpression expression) {
         visitClosureExpression(expression)
@@ -693,7 +775,7 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
         }
         print '.'
         if (expression?.property instanceof ConstantExpression) {
-            visitConstantExpression(expression?.property, true)
+            visitConstantExpression((ConstantExpression) expression?.property, 
true)
         } else {
             expression?.property?.visit this
         }
@@ -738,7 +820,7 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
         // handle multiple assignment expressions
         if (expression?.leftExpression instanceof ArgumentListExpression) {
             print 'def '
-            visitArgumentlistExpression expression?.leftExpression, true
+            visitArgumentlistExpression((ArgumentListExpression) 
expression?.leftExpression, true)
             print " $expression.operation.text "
             expression.rightExpression.visit this
 
@@ -796,7 +878,6 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
     /**
      * Prints out the type, safely handling arrays.
      * @param classNode
-     *      classnode
      */
     void visitType(ClassNode classNode) {
         def name = classNode.name
@@ -837,14 +918,13 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
     }
 
 
-
     @Override
     void visitMapExpression(MapExpression expression) {
         print '['
         if (expression?.mapEntryExpressions?.size() == 0) {
             print ':'
         } else {
-            visitExpressionsAndCommaSeparate(expression?.mapEntryExpressions)
+            visitExpressionsAndCommaSeparate((List) 
expression?.mapEntryExpressions)
         }
         print ']'
     }
@@ -869,6 +949,7 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
 
     @Override
     void visitTryCatchFinally(TryCatchStatement statement) {
+        printStatementLabels(statement)
         print 'try {'
         printLineBreak()
         indented {
@@ -898,6 +979,7 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
 
     @Override
     void visitSynchronizedStatement(SynchronizedStatement statement) {
+        printStatementLabels(statement)
         print 'synchronized ('
         statement?.expression?.visit this
         print ') {'
@@ -929,6 +1011,7 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
 
     @Override
     void visitWhileLoop(WhileStatement statement) {
+        printStatementLabels(statement)
         print 'while ('
         statement?.booleanExpression?.visit this
         print ') {'
@@ -943,6 +1026,7 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
 
     @Override
     void visitDoWhileLoop(DoWhileStatement statement) {
+        printStatementLabels(statement)
         print 'do {'
         printLineBreak()
         indented {
@@ -1017,7 +1101,7 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
                 print ', '
             }
             first = false
-            it.visit this
+            ((ASTNode) it).visit this
         }
     }
 
@@ -1026,5 +1110,24 @@ class AstNodeToScriptVisitor extends 
CompilationUnit.PrimaryClassNodeOperation i
         print '*:'
         expression?.expression?.visit this
     }
-}
 
+    /**
+     * Prints all labels for the given statement.  The labels will be printed 
on a single
+     * line and line break will be added.
+     *
+     * @param statement for which to print labels
+     * @return {@code true} if the statement had labels to print, else {@code 
false}
+     */
+    private boolean printStatementLabels(Statement statement) {
+        List<String> labels = statement?.statementLabels
+        if (labels == null || labels.isEmpty()) {
+            return false
+        }
+        for (String label : labels) {
+            print label + ':'
+            printLineBreak()
+        }
+        return true
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/436965d9/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8426.groovy
----------------------------------------------------------------------
diff --git 
a/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8426.groovy 
b/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8426.groovy
index aa0e4d4..917e8cb 100644
--- a/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8426.groovy
+++ b/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8426.groovy
@@ -17,14 +17,16 @@
  *  under the License.
  */
 
+
+import groovy.transform.CompileDynamic
 import org.codehaus.groovy.ast.ClassNode
 import org.codehaus.groovy.ast.MethodNode
 import org.codehaus.groovy.ast.builder.AstBuilder
 import org.codehaus.groovy.ast.stmt.BlockStatement
 import static org.codehaus.groovy.control.CompilePhase.CONVERSION
 
-
- class Groovy8426Test {
+@CompileDynamic
+class Groovy8426Test {
     void testMethodBlockStatement() {
         def result = new AstBuilder().buildFromString CONVERSION, false, '''
             def method() {

Reply via email to