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 333c68745e5..02e40817cfe 100644 --- a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java +++ b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java @@ -3591,19 +3591,18 @@ public List visitArrayInitializer(final ArrayInitializerContext ctx) return Collections.emptyList(); } - ClassNode elementType = ctx.getNodeMetaData(ELEMENT_TYPE); + final ClassNode elementType = ctx.getNodeMetaData(ELEMENT_TYPE); try { visitingArrayInitializerCount += 1; var initExpressions = new ArrayList(); - for (int i = 0; i < ctx.getChildCount(); i += 1) { - var c = ctx.getChild(i); + for (var c : ctx.children) { if (c instanceof ArrayInitializerContext) { var arrayInitializer = (ArrayInitializerContext) c; ClassNode subType = elementType.getComponentType(); //if (subType == null) produce closure or throw exception arrayInitializer.putNodeMetaData(ELEMENT_TYPE, subType); var arrayExpression = configureAST(new ArrayExpression(subType, - this.visitArrayInitializer(arrayInitializer)), arrayInitializer); + this.visitArrayInitializer(arrayInitializer)), arrayInitializer); arrayExpression.setType(elementType); initExpressions.add(arrayExpression); } else if (c instanceof VariableInitializerContext) {