Package: org.grails.compiler.web

## [Java] Class ControllerActionTransformer

- org.grails.compiler.web.ControllerActionTransformer

- All Implemented Interfaces and Traits:
    AnnotatedClassInjector, GrailsArtefactClassInjector, groovy.transform.CompilationUnitAware

      @AstTransformer
      public class ControllerActionTransformer
      extends java.lang.Object

  Enhances controller classes by converting closures actions to method actions and binding request parameters to action arguments.

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static org.codehaus.groovy.ast.AnnotationNode` | `ACTION_ANNOTATION_NODE` |
    `static java.util.regex.Pattern` | `CONTROLLER_PATTERN` |
    `static java.lang.String` | `CONVERT_CLOSURES_KEY` |
    `static org.codehaus.groovy.ast.AnnotationNode` | `DELEGATING_METHOD_ANNOATION` |
    `static java.lang.String` | `EXCEPTION_HANDLER_META_DATA_FIELD_NAME` |
    `static java.lang.String` | `VOID_TYPE` |

  - ### Constructor Summary

    Constructors
    Constructor and description
    `ControllerActionTransformer ()`

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected void` | `addMethodToInvokeClosure(org.codehaus.groovy.ast.ClassNode controllerClassNode, org.codehaus.groovy.ast.PropertyNode closureProperty, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)`
    `` | `protected void` | `annotateActionMethod(org.codehaus.groovy.ast.ClassNode controllerClassNode, org.codehaus.groovy.ast.Parameter[] parameters, org.codehaus.groovy.ast.MethodNode methodNode)`
    `` | `java.lang.String[]` | `getArtefactTypes()`
    `` | `protected org.codehaus.groovy.ast.stmt.BlockStatement` | `getCodeToHandleAllowedMethods(org.codehaus.groovy.ast.ClassNode controllerClass, java.lang.String methodName)`
    `` | `protected java.util.Collection<org.codehaus.groovy.ast.MethodNode>` | `getExceptionHandlerMethods(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.control.SourceUnit sourceUnit)`
    `` | `protected org.codehaus.groovy.ast.expr.Expression` | `getRejectValueExpression(org.codehaus.groovy.ast.ClassNode classNode, java.lang.String methodParamName)`
    `` | `protected org.codehaus.groovy.ast.stmt.BlockStatement` | `initializeActionParameters(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.ASTNode actionNode, java.lang.String actionName, org.codehaus.groovy.ast.Parameter[] actionParameters, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)`
    `` | `protected void` | `initializeAndValidateCommandObjectParameter(org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.ClassNode controllerNode, org.codehaus.groovy.ast.ClassNode commandObjectNode, org.codehaus.groovy.ast.ASTNode actionNode, java.lang.String actionName, java.lang.String paramName, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)`
    `` | `protected void` | `initializeCommandObjectParameter(org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.ClassNode commandObjectNode, java.lang.String paramName, org.codehaus.groovy.control.SourceUnit source)`
    `` | `protected void` | `initializeMethodParameter(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.ASTNode actionNode, java.lang.String actionName, org.codehaus.groovy.ast.Parameter param, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)`
    `` | `protected void` | `initializePrimitiveOrTypeWrapperParameter(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.Parameter param, java.lang.String requestParameterName)`
    `` | `protected void` | `initializeStringParameter(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.Parameter param, java.lang.String requestParameterName)`
    `` | `protected boolean` | `methodShouldBeConfiguredAsControllerAction(org.codehaus.groovy.ast.MethodNode method)` @param method a potential controller action method
    `` | `void` | `performInjection(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context, org.codehaus.groovy.ast.ClassNode classNode)`
    `` | `void` | `performInjection(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.ast.ClassNode classNode)`
    `` | `void` | `performInjectionOnAnnotatedClass(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context, org.codehaus.groovy.ast.ClassNode classNode)`
    `` | `void` | `performInjectionOnAnnotatedClass(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.ast.ClassNode classNode)`
    `` | `void` | `setCompilationUnit(org.codehaus.groovy.control.CompilationUnit compilationUnit)`
    `` | `boolean` | `shouldInject(java.net.URL url)`
    `` | `protected void` | `transformClosureToMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.expr.ClosureExpression closureAction, org.codehaus.groovy.ast.PropertyNode property, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)`
    `` | `protected void` | `wrapMethodBodyWithExceptionHandling(org.codehaus.groovy.ast.ClassNode controllerClassNode, org.codehaus.groovy.ast.MethodNode methodNode)` This will wrap the method body in a try catch block which does something like this:
         try {
             // original method body here
         } catch (Exception $caughtException) {
             Method $method = getExceptionHandlerMethod($caughtException.getClass())
             if($method) {
                 return $method.invoke(this, $caughtException)
             } else {
                 throw $caughtException
             }
         }

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Field Detail

    - #### public static final org.codehaus.groovy.ast.AnnotationNode ACTION_ANNOTATION_NODE

    - #### public static java.util.regex.Pattern CONTROLLER_PATTERN

    - #### public static final java.lang.String CONVERT_CLOSURES_KEY

    - #### public static final org.codehaus.groovy.ast.AnnotationNode DELEGATING_METHOD_ANNOATION

    - #### public static final java.lang.String EXCEPTION_HANDLER_META_DATA_FIELD_NAME

    - #### public static final java.lang.String VOID_TYPE

  - ### Constructor Detail

    - #### public ControllerActionTransformer()

  - ### Method Detail

    - #### protected void addMethodToInvokeClosure(org.codehaus.groovy.ast.ClassNode controllerClassNode, org.codehaus.groovy.ast.PropertyNode closureProperty, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)

    - #### protected void annotateActionMethod(org.codehaus.groovy.ast.ClassNode controllerClassNode, org.codehaus.groovy.ast.Parameter[] parameters, org.codehaus.groovy.ast.MethodNode methodNode)

    - #### public java.lang.String[] getArtefactTypes()

    - #### protected org.codehaus.groovy.ast.stmt.BlockStatement getCodeToHandleAllowedMethods(org.codehaus.groovy.ast.ClassNode controllerClass, java.lang.String methodName)

    - #### protected java.util.Collection<org.codehaus.groovy.ast.MethodNode> getExceptionHandlerMethods(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.control.SourceUnit sourceUnit)

    - #### protected org.codehaus.groovy.ast.expr.Expression getRejectValueExpression(org.codehaus.groovy.ast.ClassNode classNode, java.lang.String methodParamName)

    - #### protected org.codehaus.groovy.ast.stmt.BlockStatement initializeActionParameters(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.ASTNode actionNode, java.lang.String actionName, org.codehaus.groovy.ast.Parameter[] actionParameters, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)

    - #### protected void initializeAndValidateCommandObjectParameter(org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.ClassNode controllerNode, org.codehaus.groovy.ast.ClassNode commandObjectNode, org.codehaus.groovy.ast.ASTNode actionNode, java.lang.String actionName, java.lang.String paramName, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)

    - #### protected void initializeCommandObjectParameter(org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.ClassNode commandObjectNode, java.lang.String paramName, org.codehaus.groovy.control.SourceUnit source)

    - #### protected void initializeMethodParameter(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.ASTNode actionNode, java.lang.String actionName, org.codehaus.groovy.ast.Parameter param, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)

    - #### protected void initializePrimitiveOrTypeWrapperParameter(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.Parameter param, java.lang.String requestParameterName)

    - #### protected void initializeStringParameter(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.Parameter param, java.lang.String requestParameterName)

    - #### protected boolean methodShouldBeConfiguredAsControllerAction(org.codehaus.groovy.ast.MethodNode method)

      Parameters:
        `method` - a potential controller action method
      Returns:
        true if the method should be configured as a controller action, false otherwise

    - #### public void performInjection(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context, org.codehaus.groovy.ast.ClassNode classNode)

    - #### public void performInjection(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.ast.ClassNode classNode)

    - #### @java.lang.Override public void performInjectionOnAnnotatedClass(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context, org.codehaus.groovy.ast.ClassNode classNode)

    - #### @java.lang.Override public void performInjectionOnAnnotatedClass(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.ast.ClassNode classNode)

    - #### @java.lang.Override public void setCompilationUnit(org.codehaus.groovy.control.CompilationUnit compilationUnit)

    - #### public boolean shouldInject(java.net.URL url)

    - #### protected void transformClosureToMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.expr.ClosureExpression closureAction, org.codehaus.groovy.ast.PropertyNode property, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)

    - #### protected void wrapMethodBodyWithExceptionHandling(org.codehaus.groovy.ast.ClassNode controllerClassNode, org.codehaus.groovy.ast.MethodNode methodNode)

      This will wrap the method body in a try catch block which does something like this:

           try {
               // original method body here
           } catch (Exception $caughtException) {
               Method $method = getExceptionHandlerMethod($caughtException.getClass())
               if($method) {
                   return $method.invoke(this, $caughtException)
               } else {
                   throw $caughtException
               }
           }

      Parameters:
        `methodNode` - the method to add the try catch block to