private MethodNode convertToMethodAction ( ClassNode classNode , MethodNode methodNode , SourceUnit source , GeneratorContext context ) { final ClassNode returnType = methodNode . getReturnType ( ) ; Parameter [ ] parameters = methodNode . getParameters ( ) ; for ( Parameter param : parameters ) { if ( param . hasInitialExpression ( ) ) { String paramName = param . getName ( ) ; String methodName = methodNode . getName ( ) ; String initialValue = param . getInitialExpression ( ) . getText ( ) ; String methodDeclaration = methodNode . getText ( ) ; String message = "Parameter [%s] to method [%s] has default value [%s]. " + "Default parameter values are not allowed in controller action methods. ([%s])" ; String formattedMessage = String . format ( message , paramName , methodName , initialValue , methodDeclaration ) ; GrailsASTUtils . error ( source , methodNode , formattedMessage ) ; } } MethodNode method = null ; if ( methodNode . getParameters ( ) . length > 0 ) { final BlockStatement methodCode = new BlockStatement ( ) ; final BlockStatement codeToHandleAllowedMethods = getCodeToHandleAllowedMethods ( classNode , methodNode . getName ( ) ) ; final Statement codeToCallOriginalMethod = addOriginalMethodCall ( methodNode , initializeActionParameters ( classNode , methodNode , methodNode . getName ( ) , parameters , source , context ) ) ; methodCode . addStatement ( codeToHandleAllowedMethods ) ; methodCode . addStatement ( codeToCallOriginalMethod ) ; method = new MethodNode ( methodNode . getName ( ) , Modifier . PUBLIC , returnType , ZERO_PARAMETERS , EMPTY_CLASS_ARRAY , methodCode ) ; GrailsASTUtils . copyAnnotations ( methodNode , method ) ; methodNode . addAnnotation ( DELEGATING_METHOD_ANNOATION ) ; annotateActionMethod ( classNode , parameters , method ) ; wrapMethodBodyWithExceptionHandling ( classNode , method ) ; } else { annotateActionMethod ( classNode , parameters , methodNode ) ; } wrapMethodBodyWithExceptionHandling ( classNode , methodNode ) ; return method ; }
Converts a method into a controller action . If the method accepts parameters a no - arg counterpart is created which delegates to the original .