Permalink
Browse files

GRAILS-9470 - Improve annotation handling for action methods

If a controller action method accepts arguments and has annotations applied to it, those annotations should also be applied to the generated no-arg action method.
  • Loading branch information...
jeffbrown committed Oct 8, 2012
1 parent 7241873 commit 83b12f4d73f48c8aed5adc8e8411eee45f455bdd
@@ -241,6 +241,7 @@ private MethodNode convertToMethodAction(ClassNode classNode, MethodNode methodN
EMPTY_CLASS_ARRAY,
addOriginalMethodCall(methodNode, initializeActionParameters(
classNode, methodNode, methodNode.getName(), parameters, source, context)));
+ method.addAnnotations(methodNode.getAnnotations());
annotateActionMethod(parameters, method);
} else {
annotateActionMethod(parameters, methodNode);
@@ -2,6 +2,7 @@ package org.codehaus.groovy.grails.compiler.web
import grails.util.BuildSettings
import grails.util.GrailsWebUtil
+import grails.web.Action
import org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext
import org.codehaus.groovy.grails.compiler.injection.ClassInjector
@@ -57,6 +58,39 @@ class ControllerActionTransformerSpec extends Specification {
controller.getClass().getMethod("action", [] as Class[]) != null
}
+ void 'Test that user applied annotations are applied to generated action methods'() {
+ given:
+ def cls = gcl.parseClass('''
+ class SomeController {
+ @Deprecated
+ def action1(){}
+ @Deprecated
+ def action2(String paramName){}
+}
+''')
+
+ when:
+ def action1NoArgMethod = cls.getMethod('action1')
+
+ then:
+ action1NoArgMethod.getAnnotation(Action)
+ action1NoArgMethod.getAnnotation(Deprecated)
+
+ when:
+ def action2MethodWithStringArg = cls.getMethod('action2', [String] as Class[])
+
+ then:
+ !action2MethodWithStringArg.getAnnotation(Action)
+ action2MethodWithStringArg.getAnnotation(Deprecated)
+
+ when:
+ def action2NoArgMethod = cls.getMethod('action2')
+
+ then:
+ action2NoArgMethod.getAnnotation(Action)
+ action2NoArgMethod.getAnnotation(Deprecated)
+ }
+
void 'Test action overiding'() {
given:
def superControllerClass = gcl.parseClass('''

0 comments on commit 83b12f4

Please sign in to comment.