This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
     new 0a7f52833c less meta data
0a7f52833c is described below

commit 0a7f52833c6663b3a79c21247e503ed293e49e53
Author: Eric Milles <eric.mil...@thomsonreuters.com>
AuthorDate: Tue Aug 29 11:47:00 2023 -0500

    less meta data
---
 .../apache/groovy/parser/antlr4/AstBuilder.java    | 94 ++++++++--------------
 1 file changed, 34 insertions(+), 60 deletions(-)

diff --git a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java 
b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 66d97c0ae9..1297b6b622 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -695,16 +695,9 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
      */
     @Override
     public List<CatchStatement> visitCatchClause(final CatchClauseContext ctx) 
{
-        // FIXME Groovy will ignore variableModifier of parameter in the catch 
clause
-        // In order to make the new parser behave same with the old one, we do 
not process variableModifier*
-
         return this.visitCatchType(ctx.catchType()).stream()
                 .map(e -> configureAST(
                         new CatchStatement(
-                                // FIXME The old parser does not set location 
info for the parameter of the catch clause.
-                                // we could make it better
-                                //this.configureAST(new Parameter(e, 
this.visitIdentifier(ctx.identifier())), ctx.Identifier()),
-
                                 new Parameter(e, 
this.visitIdentifier(ctx.identifier())),
                                 this.visitBlock(ctx.block())),
                         ctx))
@@ -811,7 +804,6 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
 
                     return statementList;
                 });
-
     }
 
     @Override
@@ -1101,14 +1093,12 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
                     }
 
                     switch (tuple.getV1().getType()) {
-                        case CASE: {
+                        case CASE:
                             if (!asBoolean(statementList)) {
                                 firstLabelHolder.add(tuple.getV1());
                             }
-
-                            for (int i = 0, n = tuple.getV2().size(); i < n; 
i++) {
+                            for (int i = 0, n = tuple.getV2().size(); i < n; i 
+= 1) {
                                 Expression expr = tuple.getV2().get(i);
-
                                 statementList.add(
                                         configureAST(
                                                 new CaseStatement(
@@ -1120,17 +1110,10 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
                                                 ),
                                                 firstLabelHolder.get(0)));
                             }
-
                             break;
-                        }
                         case DEFAULT: {
-                            codeBlock.putNodeMetaData(IS_SWITCH_DEFAULT, true);
-
-                            statementList.add(
-                                    // this.configureAST(codeBlock, 
tuple.getKey())
-                                    codeBlock
-                            );
-
+                            codeBlock.putNodeMetaData(IS_SWITCH_DEFAULT, 
Boolean.TRUE);
+                            statementList.add(codeBlock);
                             break;
                         }
                     }
@@ -1328,7 +1311,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
                                 .collect(Collectors.toList()));
                 sealedAnnotationNode.setMember("permittedSubclasses", 
permittedSubclassesListExpression);
                 configureAST(sealedAnnotationNode, ctx.PERMITS());
-                sealedAnnotationNode.setNodeMetaData("permits", true);
+                sealedAnnotationNode.setNodeMetaData("permits", Boolean.TRUE);
             }
             classNode.addAnnotation(sealedAnnotationNode);
         } else if (isNonSealed) {
@@ -1969,12 +1952,6 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
     }
 
     private DeclarationListStatement 
createMultiAssignmentDeclarationListStatement(final VariableDeclarationContext 
ctx, final ModifierManager modifierManager) {
-        /*
-        if (!modifierManager.contains(DEF)) {
-            throw createParsingFailedException("keyword def is required to 
declare tuple, e.g. def (int a, int b) = [1, 2]", ctx);
-        }
-        */
-
         return configureAST(
                 new DeclarationListStatement(
                         configureAST(
@@ -2500,13 +2477,13 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
             GenericsType[] genericsTypes = 
this.visitNonWildcardTypeArguments(ctx.nonWildcardTypeArguments());
 
             if (asBoolean(ctx.DOT())) {
-                boolean isSafeChain = this.isTrue(baseExpr, 
PATH_EXPRESSION_BASE_EXPR_SAFE_CHAIN);
+                boolean isSafeChain = isTrue(baseExpr, 
PATH_EXPRESSION_BASE_EXPR_SAFE_CHAIN);
                 return this.createDotExpression(ctx, baseExpr, namePartExpr, 
genericsTypes, isSafeChain);
             } else if (asBoolean(ctx.SAFE_DOT())) {
                 return this.createDotExpression(ctx, baseExpr, namePartExpr, 
genericsTypes, true);
             } else if (asBoolean(ctx.SAFE_CHAIN_DOT())) { // e.g. obj??.a  OR 
obj??.@a
                 Expression expression = createDotExpression(ctx, baseExpr, 
namePartExpr, genericsTypes, true);
-                
expression.putNodeMetaData(PATH_EXPRESSION_BASE_EXPR_SAFE_CHAIN, true);
+                
expression.putNodeMetaData(PATH_EXPRESSION_BASE_EXPR_SAFE_CHAIN, Boolean.TRUE);
                 return expression;
             } else if (asBoolean(ctx.METHOD_POINTER())) { // e.g. obj.&m
                 return configureAST(new MethodPointerExpression(baseExpr, 
namePartExpr), ctx);
@@ -2519,7 +2496,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
                     return configureAST(attributeExpression, ctx);
                 } else { // e.g. obj*.p
                     PropertyExpression propertyExpression = new 
PropertyExpression(baseExpr, namePartExpr, true);
-                    
propertyExpression.putNodeMetaData(PATH_EXPRESSION_BASE_EXPR_GENERICS_TYPES, 
genericsTypes);
+                    if (genericsTypes != null) 
propertyExpression.putNodeMetaData(PATH_EXPRESSION_BASE_EXPR_GENERICS_TYPES, 
genericsTypes);
                     propertyExpression.setSpreadSafe(true);
                     return configureAST(propertyExpression, ctx);
                 }
@@ -2530,7 +2507,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
             return configureAST(this.visitCreator(creatorContext), ctx);
         } else if (asBoolean(ctx.indexPropertyArgs())) { // e.g. list[1, 3, 5]
             Tuple2<Token, Expression> tuple = 
this.visitIndexPropertyArgs(ctx.indexPropertyArgs());
-            boolean isSafeChain = this.isTrue(baseExpr, 
PATH_EXPRESSION_BASE_EXPR_SAFE_CHAIN);
+            boolean isSafeChain = isTrue(baseExpr, 
PATH_EXPRESSION_BASE_EXPR_SAFE_CHAIN);
             return configureAST(
                     new BinaryExpression(baseExpr, 
createGroovyToken(tuple.getV1()), tuple.getV2(), isSafeChain || 
asBoolean(ctx.indexPropertyArgs().SAFE_INDEX())),
                     ctx);
@@ -2602,7 +2579,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
 
             if (baseExpr instanceof VariableExpression // e.g. m()
                     || baseExpr instanceof GStringExpression // e.g. "$m"()
-                    || (baseExpr instanceof ConstantExpression && 
this.isTrue(baseExpr, IS_STRING))) { // e.g. "m"()
+                    || (baseExpr instanceof ConstantExpression && 
isTrue(baseExpr, IS_STRING))) { // e.g. "m"()
                 String baseExprText = baseExpr.getText();
                 if (THIS_STR.equals(baseExprText) || 
SUPER_STR.equals(baseExprText)) { // e.g. this(...), super(...)
                     // class declaration is not allowed in the closure,
@@ -2695,7 +2672,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
 
             if (baseExpr instanceof VariableExpression // e.g. m { }
                     || baseExpr instanceof GStringExpression // e.g. "$m" { }
-                    || (baseExpr instanceof ConstantExpression && 
this.isTrue(baseExpr, IS_STRING))) { // e.g. "m" { }
+                    || (baseExpr instanceof ConstantExpression && 
isTrue(baseExpr, IS_STRING))) { // e.g. "m" { }
                 MethodCallExpression methodCallExpression =
                         this.createMethodCallExpression(
                                 baseExpr,
@@ -2728,7 +2705,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
             return configureAST(new AttributeExpression(baseExpr, 
namePartExpr, safe), ctx);
         } else { // e.g. obj.p  OR  obj?.p
             PropertyExpression propertyExpression = new 
PropertyExpression(baseExpr, namePartExpr, safe);
-            
propertyExpression.putNodeMetaData(PATH_EXPRESSION_BASE_EXPR_GENERICS_TYPES, 
genericsTypes);
+            if (genericsTypes != null) 
propertyExpression.putNodeMetaData(PATH_EXPRESSION_BASE_EXPR_GENERICS_TYPES, 
genericsTypes);
             return configureAST(propertyExpression, ctx);
         }
     }
@@ -3178,7 +3155,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
 
     @Override
     public Expression visitConditionalExprAlt(final ConditionalExprAltContext 
ctx) {
-        ctx.fb.putNodeMetaData(IS_INSIDE_CONDITIONAL_EXPRESSION, true);
+        ctx.fb.putNodeMetaData(IS_INSIDE_CONDITIONAL_EXPRESSION, Boolean.TRUE);
 
         if (asBoolean(ctx.ELVIS())) { // e.g. a == 6 ?: 0
             return configureAST(
@@ -3186,7 +3163,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
                     ctx);
         }
 
-        ctx.tb.putNodeMetaData(IS_INSIDE_CONDITIONAL_EXPRESSION, true);
+        ctx.tb.putNodeMetaData(IS_INSIDE_CONDITIONAL_EXPRESSION, Boolean.TRUE);
 
         return configureAST(
                 new TernaryExpression(
@@ -3623,15 +3600,13 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
     }
 
     private void validateExpressionListElement(final 
ExpressionListElementContext ctx, final Expression expression) {
-        if (!(expression instanceof MethodCallExpression && isTrue(expression, 
IS_COMMAND_EXPRESSION))) {
-            return;
-        }
-
-        // statements like `foo(String a)` is invalid
-        MethodCallExpression methodCallExpression = (MethodCallExpression) 
expression;
-        String methodName = methodCallExpression.getMethodAsString();
-        if (methodCallExpression.isImplicitThis() && 
Character.isUpperCase(methodName.codePointAt(0)) || 
isPrimitiveType(methodName)) {
-            throw createParsingFailedException("Invalid method declaration", 
ctx);
+        if (expression instanceof MethodCallExpression && isTrue(expression, 
IS_COMMAND_EXPRESSION)) {
+            // statements like `foo(String a)` is invalid
+            MethodCallExpression methodCallExpression = (MethodCallExpression) 
expression;
+            String methodName = methodCallExpression.getMethodAsString();
+            if (methodCallExpression.isImplicitThis() && 
Character.isUpperCase(methodName.codePointAt(0)) || 
isPrimitiveType(methodName)) {
+                throw createParsingFailedException("Invalid method 
declaration", ctx);
+            }
         }
     }
 
@@ -4067,7 +4042,8 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
         ClassNode classNode = null;
 
         if (asBoolean(ctx.classOrInterfaceType())) {
-            
ctx.classOrInterfaceType().putNodeMetaData(IS_INSIDE_INSTANCEOF_EXPR, 
ctx.getNodeMetaData(IS_INSIDE_INSTANCEOF_EXPR));
+            if (isTrue(ctx, IS_INSIDE_INSTANCEOF_EXPR))
+                
ctx.classOrInterfaceType().putNodeMetaData(IS_INSIDE_INSTANCEOF_EXPR, 
Boolean.TRUE);
             classNode = 
this.visitClassOrInterfaceType(ctx.classOrInterfaceType());
         } else if (asBoolean(ctx.primitiveType())) {
             classNode = this.visitPrimitiveType(ctx.primitiveType());
@@ -4094,10 +4070,12 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
     public ClassNode visitClassOrInterfaceType(final 
ClassOrInterfaceTypeContext ctx) {
         ClassNode classNode;
         if (asBoolean(ctx.qualifiedClassName())) {
-            
ctx.qualifiedClassName().putNodeMetaData(IS_INSIDE_INSTANCEOF_EXPR, 
ctx.getNodeMetaData(IS_INSIDE_INSTANCEOF_EXPR));
+            if (isTrue(ctx, IS_INSIDE_INSTANCEOF_EXPR))
+                
ctx.qualifiedClassName().putNodeMetaData(IS_INSIDE_INSTANCEOF_EXPR, 
Boolean.TRUE);
             classNode = this.visitQualifiedClassName(ctx.qualifiedClassName());
         } else {
-            
ctx.qualifiedStandardClassName().putNodeMetaData(IS_INSIDE_INSTANCEOF_EXPR, 
ctx.getNodeMetaData(IS_INSIDE_INSTANCEOF_EXPR));
+            if (isTrue(ctx, IS_INSIDE_INSTANCEOF_EXPR))
+                
ctx.qualifiedStandardClassName().putNodeMetaData(IS_INSIDE_INSTANCEOF_EXPR, 
Boolean.TRUE);
             classNode = 
this.visitQualifiedStandardClassName(ctx.qualifiedStandardClassName());
         }
 
@@ -4395,11 +4373,11 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
 
     private ClassNode createClassNode(final GroovyParserRuleContext ctx) {
         ClassNode result = makeClassNode(ctx.getText());
-
-        if (!isTrue(ctx, IS_INSIDE_INSTANCEOF_EXPR)) { // type in the 
"instanceof" expression should not have proxy to redirect to it
+        if (isTrue(ctx, IS_INSIDE_INSTANCEOF_EXPR)) {
+            // type in the "instanceof" expression shouldn't have redirect
+        } else {
             result = this.proxyClassNode(result);
         }
-
         return configureAST(result, ctx);
     }
 
@@ -4410,7 +4388,6 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
 
         ClassNode cn = ClassHelper.makeWithoutCaching(classNode.getName());
         cn.setRedirect(classNode);
-
         return cn;
     }
 
@@ -4515,12 +4492,9 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
                             PathElementContext pathElementContext = 
(PathElementContext) e;
                             
pathElementContext.putNodeMetaData(PATH_EXPRESSION_BASE_EXPR, r);
                             Expression expression = 
this.visitPathElement(pathElementContext);
-
-                            boolean isSafeChain = isTrue((Expression) r, 
PATH_EXPRESSION_BASE_EXPR_SAFE_CHAIN);
-                            if (isSafeChain) {
-                                
expression.putNodeMetaData(PATH_EXPRESSION_BASE_EXPR_SAFE_CHAIN, true);
+                            if (isTrue((Expression) r, 
PATH_EXPRESSION_BASE_EXPR_SAFE_CHAIN)) {
+                                
expression.putNodeMetaData(PATH_EXPRESSION_BASE_EXPR_SAFE_CHAIN, Boolean.TRUE);
                             }
-
                             return expression;
                         }
                 );
@@ -4707,8 +4681,8 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
         return 
lexer.getInputStream().getText(Interval.of(context.getStart().getStartIndex(), 
context.getStop().getStopIndex()));
     }
 
-    private boolean isTrue(final NodeMetaDataHandler nodeMetaDataHandler, 
final String key) {
-        return Boolean.TRUE.equals(nodeMetaDataHandler.getNodeMetaData(key));
+    private static boolean isTrue(final NodeMetaDataHandler obj, final String 
key) {
+        return Boolean.TRUE.equals(obj.getNodeMetaData(key));
     }
 
     private CompilationFailedException createParsingFailedException(final 
String msg, final GroovyParserRuleContext ctx) {

Reply via email to