diff --git a/grails-plugin-controllers/src/main/groovy/org/grails/compiler/web/ControllerActionTransformer.java b/grails-plugin-controllers/src/main/groovy/org/grails/compiler/web/ControllerActionTransformer.java index 3cbc4ecd8a7..096547ad9e6 100644 --- a/grails-plugin-controllers/src/main/groovy/org/grails/compiler/web/ControllerActionTransformer.java +++ b/grails-plugin-controllers/src/main/groovy/org/grails/compiler/web/ControllerActionTransformer.java @@ -29,7 +29,6 @@ import grails.web.controllers.ControllerMethod; import groovy.lang.Closure; import groovy.transform.CompilationUnitAware; -import org.apache.groovy.ast.tools.AnnotatedNodeUtils; import org.apache.groovy.ast.tools.ClassNodeUtils; import org.codehaus.groovy.ast.ASTNode; import org.codehaus.groovy.ast.AnnotationNode; @@ -98,6 +97,7 @@ import java.util.Map; import java.util.regex.Pattern; +import static org.codehaus.groovy.ast.tools.GeneralUtils.*; import static org.grails.compiler.injection.GrailsASTUtils.applyDefaultMethodTarget; import static org.grails.compiler.injection.GrailsASTUtils.applyMethodTarget; import static org.grails.compiler.injection.GrailsASTUtils.buildGetMapExpression; @@ -843,16 +843,11 @@ protected void initializeAndValidateCommandObjectParameter(final BlockStatement protected void initializeCommandObjectParameter(final BlockStatement wrapper, final ClassNode commandObjectNode, final String paramName, SourceUnit source) { - - final ArgumentListExpression initializeCommandObjectArguments = new ArgumentListExpression(); - initializeCommandObjectArguments.addExpression(new ClassExpression(commandObjectNode)); - initializeCommandObjectArguments.addExpression(new ConstantExpression(paramName)); - final MethodCallExpression initializeCommandObjectMethodCall = new MethodCallExpression(new VariableExpression("this"), "initializeCommandObject", initializeCommandObjectArguments); + final ArgumentListExpression initializeCommandObjectArguments = args(classX(commandObjectNode), constX(paramName)); + final MethodCallExpression initializeCommandObjectMethodCall = callThisX("initializeCommandObject", initializeCommandObjectArguments); applyDefaultMethodTarget(initializeCommandObjectMethodCall, commandObjectNode); - - final Expression assignCommandObjectToParameter = new BinaryExpression(new VariableExpression(paramName), Token.newSymbol(Types.EQUALS, 0, 0), initializeCommandObjectMethodCall); - - wrapper.addStatement(new ExpressionStatement(assignCommandObjectToParameter)); + final Expression assignCommandObjectToParameter = declX(localVarX(paramName), initializeCommandObjectMethodCall); + wrapper.addStatement(stmt(assignCommandObjectToParameter)); } /** diff --git a/grails-test-suite-web/src/test/groovy/org/grails/web/commandobjects/CommandObjectsSpec.groovy b/grails-test-suite-web/src/test/groovy/org/grails/web/commandobjects/CommandObjectsSpec.groovy index a7c14fe59c7..f65f884d599 100644 --- a/grails-test-suite-web/src/test/groovy/org/grails/web/commandobjects/CommandObjectsSpec.groovy +++ b/grails-test-suite-web/src/test/groovy/org/grails/web/commandobjects/CommandObjectsSpec.groovy @@ -316,6 +316,13 @@ class TestController { [command: co] } + private seeIssue13486() { + // the presence of this local variable could break + // the compile-time generated no-arg methodActionWithDate() + // see https://github.com/grails/grails-core/issues/13486 + String co + } + def methodActionWithArtist(Artist a) { [artist: a] }