|
20 | 20 | import static org.grails.compiler.injection.GrailsASTUtils.buildGetMapExpression; |
21 | 21 | import static org.grails.compiler.injection.GrailsASTUtils.buildGetPropertyExpression; |
22 | 22 | import static org.grails.compiler.injection.GrailsASTUtils.buildSetPropertyExpression; |
| 23 | +import static org.grails.compiler.injection.GrailsASTUtils.hasAnnotation; |
| 24 | +import static org.grails.compiler.injection.GrailsASTUtils.hasParameters; |
| 25 | +import static org.grails.compiler.injection.GrailsASTUtils.removeAnnotation; |
23 | 26 | import grails.artefact.Artefact; |
24 | 27 | import grails.artefact.controller.support.AllowedMethodsHelper; |
25 | 28 | import grails.compiler.DelegatingMethod; |
|
37 | 40 | import groovy.lang.Closure; |
38 | 41 |
|
39 | 42 | import java.io.File; |
| 43 | +import java.lang.annotation.Annotation; |
40 | 44 | import java.lang.reflect.Method; |
41 | 45 | import java.lang.reflect.Modifier; |
42 | 46 | import java.net.URL; |
@@ -233,6 +237,10 @@ private boolean isExceptionHandlingMethod(MethodNode methodNode) { |
233 | 237 | return isExceptionHandler; |
234 | 238 | } |
235 | 239 |
|
| 240 | + private boolean isTraitMethod(MethodNode methodNode) { |
| 241 | + return GrailsASTUtils.hasAnnotation(methodNode, Traits.TraitBridge.class); |
| 242 | + } |
| 243 | + |
236 | 244 | private void processMethods(ClassNode classNode, SourceUnit source, |
237 | 245 | GeneratorContext context) { |
238 | 246 |
|
@@ -295,14 +303,10 @@ public Object call(Object object) { |
295 | 303 | */ |
296 | 304 | protected boolean methodShouldBeConfiguredAsControllerAction(final MethodNode method) { |
297 | 305 | int minLineNumber = 0; |
298 | | - // Methods inherited from traits marked with @Action that take a parameter: |
299 | | - // Remove the @Action annotation so they will be processed to create the no-arg method |
300 | | - if (method.getAnnotations(ClassHelper.make(Traits.TraitBridge.class)).size() > 0) { |
301 | | - List<AnnotationNode> annotations = method.getAnnotations(ACTION_ANNOTATION_NODE.getClassNode()); |
302 | | - if (annotations.size() > 0 && method.getParameters().length > 0) { |
303 | | - method.getAnnotations().removeAll(annotations); |
304 | | - --minLineNumber; |
305 | | - } |
| 306 | + if (isTraitMethod(method) && hasAnnotation(method, Action.class) && hasParameters(method)) { |
| 307 | + removeAnnotation(method, Action.class); |
| 308 | + //Trait methods have a line number of -1 |
| 309 | + --minLineNumber; |
306 | 310 | } |
307 | 311 | return !method.isStatic() && |
308 | 312 | method.isPublic() && |
|
0 commit comments