Skip to content

Commit fed687f

Browse files
committed
Add object initializers instead of creating the statement manually
1 parent cfea820 commit fed687f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

grails-plugin-controllers/src/main/groovy/org/grails/compiler/web/ControllerActionTransformer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,12 +746,12 @@ protected void initializeAndValidateCommandObjectParameter(final BlockStatement
746746
TraitInjectionUtils.injectTrait(compilationUnit, source, commandObjectNode, Validateable.class);
747747

748748
List<ConstructorNode> declaredConstructors = commandObjectNode.getDeclaredConstructors();
749-
if(declaredConstructors.isEmpty()) {
749+
List<Statement> objectInitializerStatements = commandObjectNode.getObjectInitializerStatements();
750+
if(declaredConstructors.isEmpty() && !objectInitializerStatements.isEmpty()) {
750751
BlockStatement constructorLogic = new BlockStatement();
751752
ConstructorNode constructorNode = new ConstructorNode(Modifier.PUBLIC, constructorLogic);
752-
ClassNode helper = Traits.findHelper(ClassHelper.make(Validateable.class));
753753
commandObjectNode.addConstructor(constructorNode);
754-
constructorLogic.addStatement(new ExpressionStatement(new StaticMethodCallExpression(helper, "$init$", VariableExpression.THIS_EXPRESSION)));
754+
constructorLogic.addStatements(objectInitializerStatements);
755755
}
756756
argumentIsValidateable = true;
757757
} else if (doesModulePathIncludeSubstring(commandObjectModule,

0 commit comments

Comments
 (0)