Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
paulk-asert committed Jan 29, 2024
1 parent 482a229 commit 714e6b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public static ArgumentListExpression args(final String... names) {
public static ArrayExpression arrayX(final ClassNode elementType, List<Expression> initExpressions) {
return new ArrayExpression(elementType, initExpressions);
}

public static ArrayExpression arrayX(final ClassNode elementType, List<Expression> initExpressions, List<Expression> sizeExpressions) {
return new ArrayExpression(elementType, initExpressions, sizeExpressions);
}

public static CastExpression asX(final ClassNode type, final Expression expression) {
return CastExpression.asExpression(type, expression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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)
Expand Down

0 comments on commit 714e6b6

Please sign in to comment.