ControllerActionTransformer (Grails 6.0.0)

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
      implements AnnotatedClassInjector, GrailsArtefactClassInjector, groovy.transform.CompilationUnitAware

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static org.codehaus.groovy.ast.AnnotationNode` | `ACTION_ANNOTATION_NODE` |
    `private static java.lang.String` | `ACTION_MEMBER_TARGET` |
    `private static java.lang.String` | `ALLOWED_METHODS_HANDLED_ATTRIBUTE_NAME` |
    `static java.util.regex.Pattern` | `CONTROLLER_PATTERN` |
    `static java.lang.String` | `CONVERT_CLOSURES_KEY` |
    `static org.codehaus.groovy.ast.AnnotationNode` | `DELEGATING_METHOD_ANNOATION` |
    `private static org.codehaus.groovy.ast.expr.TupleExpression` | `EMPTY_TUPLE` |
    `static java.lang.String` | `EXCEPTION_HANDLER_META_DATA_FIELD_NAME` |
    `private static org.codehaus.groovy.ast.ClassNode` | `OBJECT_CLASS` |
    `private static java.util.List<org.codehaus.groovy.ast.ClassNode>` | `PRIMITIVE_CLASS_NODES` |
    `private static java.util.Map<org.codehaus.groovy.ast.ClassNode, java.lang.String>` | `TYPE_WRAPPER_CLASS_TO_CONVERSION_METHOD_NAME` |
    `static java.lang.String` | `VOID_TYPE` |
    `private org.codehaus.groovy.control.CompilationUnit` | `compilationUnit` |
    `private java.lang.Boolean` | `converterEnabled` |

  - ### 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)`
    `` | `private org.codehaus.groovy.ast.stmt.Statement` | `addOriginalMethodCall(org.codehaus.groovy.ast.MethodNode methodNode, org.codehaus.groovy.ast.stmt.BlockStatement blockStatement)`
    `` | `protected void` | `annotateActionMethod(org.codehaus.groovy.ast.ClassNode controllerClassNode, org.codehaus.groovy.ast.Parameter[] parameters, org.codehaus.groovy.ast.MethodNode methodNode)`
    `` | `public java.lang.Object` | `call(java.lang.Object object)`
    `` | `private org.codehaus.groovy.ast.MethodNode` | `convertToMethodAction(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.MethodNode methodNode, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)` Converts a method into a controller action.
    `` | `private boolean` | `doesModulePathIncludeSubstring(org.codehaus.groovy.ast.ModuleNode moduleNode, java.lang.String substring)` Checks to see if a Module is defined at a path which includes the specified substring
    `` | `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)`
    `` | `private boolean` | `isCommandObjectAction(org.codehaus.groovy.ast.Parameter[] params)`
    `` | `private boolean` | `isExceptionHandlingMethod(org.codehaus.groovy.ast.MethodNode methodNode)`
    `` | `protected boolean` | `methodShouldBeConfiguredAsControllerAction(org.codehaus.groovy.ast.MethodNode method)` Parameters: `method` - a potential controller action method
    `` | `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)`
    `` | `public void` | `performInjectionOnAnnotatedClass(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context, org.codehaus.groovy.ast.ClassNode classNode)`
    `` | `public void` | `performInjectionOnAnnotatedClass(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.ast.ClassNode classNode)`
    `` | `private void` | `processClosures(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)`
    `` | `private void` | `processMethods(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)`
    `` | `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
             }
         }

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long), java.lang.Object#wait(long, int), 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

    - #### private static final java.lang.String ACTION_MEMBER_TARGET

    - #### private static final java.lang.String ALLOWED_METHODS_HANDLED_ATTRIBUTE_NAME

    - #### 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

    - #### private static final org.codehaus.groovy.ast.expr.TupleExpression EMPTY_TUPLE

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

    - #### private static final org.codehaus.groovy.ast.ClassNode OBJECT_CLASS

    - #### private static java.util.List<org.codehaus.groovy.ast.ClassNode> PRIMITIVE_CLASS_NODES

    - #### @java.lang.SuppressWarnings({"unchecked"}) private static final java.util.Map<org.codehaus.groovy.ast.ClassNode, java.lang.String> TYPE_WRAPPER_CLASS_TO_CONVERSION_METHOD_NAME

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

    - #### private org.codehaus.groovy.control.CompilationUnit compilationUnit

    - #### private java.lang.Boolean converterEnabled

  - ### 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)

    - #### private org.codehaus.groovy.ast.stmt.Statement addOriginalMethodCall(org.codehaus.groovy.ast.MethodNode methodNode, org.codehaus.groovy.ast.stmt.BlockStatement blockStatement)

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

    - #### @java.lang.Override public java.lang.Object call(java.lang.Object object)

    - #### private org.codehaus.groovy.ast.MethodNode convertToMethodAction(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.MethodNode methodNode, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)

      Converts a method into a controller action. If the method accepts parameters, a no-arg counterpart is created which delegates to the original.

      Parameters:
        `classNode` - The controller class
        `methodNode` - The method to be converted
      Returns:
        The no-arg wrapper method, or null if none was created.

    - #### private boolean doesModulePathIncludeSubstring(org.codehaus.groovy.ast.ModuleNode moduleNode, java.lang.String substring)

      Checks to see if a Module is defined at a path which includes the specified substring

      Parameters:
        `moduleNode` - a ModuleNode
        `substring` - The substring to search for
      Returns:
        true if moduleNode is defined at a path which includes the specified substring

    - #### 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)

    - #### private boolean isCommandObjectAction(org.codehaus.groovy.ast.Parameter[] params)

    - #### private boolean isExceptionHandlingMethod(org.codehaus.groovy.ast.MethodNode methodNode)

    - #### 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)

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

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

    - #### @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