From 714e6b628d2b0b4408af45000007e41cc1fca860 Mon Sep 17 00:00:00 2001 From: Paul King Date: Mon, 29 Jan 2024 14:38:25 +1000 Subject: [PATCH] minor refactor --- .../java/org/codehaus/groovy/ast/tools/GeneralUtils.java | 5 +++++ .../groovy/transform/RecordTypeASTTransformation.java | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java index 1a09bf80d6e..e4b4838f7f9 100644 --- a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java +++ b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java @@ -135,6 +135,11 @@ public static ArgumentListExpression args(final String... names) { public static ArrayExpression arrayX(final ClassNode elementType, List initExpressions) { return new ArrayExpression(elementType, initExpressions); } + + public static ArrayExpression arrayX(final ClassNode elementType, List initExpressions, List sizeExpressions) { + return new ArrayExpression(elementType, initExpressions, sizeExpressions); + } + public static CastExpression asX(final ClassNode type, final Expression expression) { return CastExpression.asExpression(type, expression); } diff --git a/src/main/java/org/codehaus/groovy/transform/RecordTypeASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/RecordTypeASTTransformation.java index 61d601bf217..8c304c2c153 100644 --- a/src/main/java/org/codehaus/groovy/transform/RecordTypeASTTransformation.java +++ b/src/main/java/org/codehaus/groovy/transform/RecordTypeASTTransformation.java @@ -85,6 +85,7 @@ import static org.codehaus.groovy.ast.ClassHelper.make; import static org.codehaus.groovy.ast.ClassHelper.makeWithoutCaching; import static org.codehaus.groovy.ast.tools.GeneralUtils.args; +import static org.codehaus.groovy.ast.tools.GeneralUtils.arrayX; import static org.codehaus.groovy.ast.tools.GeneralUtils.assignS; import static org.codehaus.groovy.ast.tools.GeneralUtils.bytecodeX; import static org.codehaus.groovy.ast.tools.GeneralUtils.callThisX; @@ -323,7 +324,7 @@ private void createBeanInfoClass(ClassNode cNode) { BlockStatement block = new BlockStatement(); VariableExpression p = varX("p", PROPERTY_DESCRIPTOR_ARRAY_TYPE); block.addStatement( - declS(p, new ArrayExpression(PROPERTY_DESCRIPTOR_TYPE, Collections.emptyList(), List.of(constX(pList.size())))) + declS(p, arrayX(PROPERTY_DESCRIPTOR_TYPE, Collections.emptyList(), List.of(constX(pList.size())))) ); for (int i = 0; i < pList.size(); i++) { String name = pList.get(i).getName(); @@ -334,10 +335,10 @@ private void createBeanInfoClass(ClassNode cNode) { block.addStatement(returnS(p)); beanInfoClass.addMethod("getPropertyDescriptors", ACC_PUBLIC, PROPERTY_DESCRIPTOR_ARRAY_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, block); beanInfoClass.addMethod("getEventSetDescriptors", ACC_PUBLIC, EVENT_SET_DESCRIPTOR_ARRAY_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, returnS( - new ArrayExpression(EVENT_SET_DESCRIPTOR_TYPE, Collections.emptyList(), List.of(constX(0))) + arrayX(EVENT_SET_DESCRIPTOR_TYPE, Collections.emptyList(), List.of(constX(0))) )); beanInfoClass.addMethod("getMethodDescriptors", ACC_PUBLIC, METHOD_DESCRIPTOR_ARRAY_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, returnS( - new ArrayExpression(METHOD_DESCRIPTOR_TYPE, Collections.emptyList(), List.of(constX(0))) + arrayX(METHOD_DESCRIPTOR_TYPE, Collections.emptyList(), List.of(constX(0))) )); beanInfoClass.addMethod("getDefaultPropertyIndex", ACC_PUBLIC, int_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, returnS( constX(-1)