Permalink
Browse files

GRAILS-9470 - minor improvement to how annotations are copied

  • Loading branch information...
1 parent 83b12f4 commit f1149e134712104df5133b0425dc6de04755dc48 @jeffbrown jeffbrown committed Oct 8, 2012
@@ -241,7 +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());
+ copyAnnotations(methodNode, method);
annotateActionMethod(parameters, method);
} else {
annotateActionMethod(parameters, methodNode);
@@ -250,6 +250,18 @@ private MethodNode convertToMethodAction(ClassNode classNode, MethodNode methodN
return method;
}
+ protected void copyAnnotations(final MethodNode from, final MethodNode to) {
+ final List<AnnotationNode> annotationsToCopy = from.getAnnotations();
+ for(final AnnotationNode node : annotationsToCopy) {
+ final AnnotationNode copyOfAnnotationNode = new AnnotationNode(node.getClassNode());
+ final Map<String, Expression> members = node.getMembers();
+ for(final Map.Entry<String, Expression> entry : members.entrySet()) {
+ copyOfAnnotationNode.addMember(entry.getKey(), entry.getValue());
+ }
+ to.addAnnotation(copyOfAnnotationNode);
+ }
+ }
+
private Statement addOriginalMethodCall(MethodNode methodNode, BlockStatement blockStatement) {
if (blockStatement == null) {

0 comments on commit f1149e1

Please sign in to comment.