Skip to content

Commit a20f2d4

Browse files
Improve how command objects are initialized
This is an improvement on 3827c7a. This is related to apache/grails-data-mapping#580.
1 parent 3827c7a commit a20f2d4

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

grails-core/src/main/groovy/org/codehaus/groovy/grails/compiler/injection/GrailsASTUtils.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -873,16 +873,6 @@ public static boolean hasAnnotation(final ClassNode classNode, final Class<? ext
873873
return !classNode.getAnnotations(new ClassNode(annotationClass)).isEmpty();
874874
}
875875

876-
/**
877-
* Returns true if classNode is marked with annotationClass
878-
* @param methodNode A MethodNode to inspect
879-
* @param annotationClass an annotation to look for
880-
* @return true if methodNode is marked with annotationClass, otherwise false
881-
*/
882-
public static boolean hasAnnotation(final MethodNode methodNode, final Class<? extends Annotation> annotationClass) {
883-
return !methodNode.getAnnotations(new ClassNode(annotationClass)).isEmpty();
884-
}
885-
886876
/**
887877
* @param classNode a ClassNode to search
888878
* @param annotationsToLookFor Annotations to look for

grails-plugin-controllers/src/main/groovy/org/codehaus/groovy/grails/compiler/web/ControllerActionTransformer.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static org.codehaus.groovy.grails.compiler.injection.GrailsASTUtils.buildGetPropertyExpression;
2222
import static org.codehaus.groovy.grails.compiler.injection.GrailsASTUtils.buildSetPropertyExpression;
2323
import grails.artefact.Artefact;
24-
import grails.transaction.Transactional;
2524
import grails.util.BuildSettings;
2625
import grails.util.CollectionUtils;
2726
import grails.validation.ASTValidateableHelper;
@@ -403,16 +402,14 @@ protected void populateMethodWithCommandObjectInitializationCode(final ClassNode
403402

404403
protected MethodNode getMethodToIncludeCommandObjectInitializationCode(final MethodNode methodNode) {
405404
MethodNode node = methodNode;
406-
if(GrailsASTUtils.hasAnnotation(methodNode, Transactional.class)) {
407-
final ClassNode declaringClass = methodNode.getDeclaringClass();
408-
final String txHandlingMethodName = TransactionalTransform.getTransactionHandlingMethodName(methodNode);
409-
final Parameter[] originalMethodParameters = methodNode.getParameters();
410-
final Parameter[] txHandlingMethodParams = new Parameter[originalMethodParameters.length + 1];
411-
System.arraycopy(originalMethodParameters, 0, txHandlingMethodParams, 0, originalMethodParameters.length);
412-
txHandlingMethodParams[txHandlingMethodParams.length-1] = new Parameter(ClassHelper.make(TransactionStatus.class), "transactionStatus");
413-
if(declaringClass.hasMethod(txHandlingMethodName, txHandlingMethodParams)) {
414-
node = declaringClass.getMethod(txHandlingMethodName, txHandlingMethodParams);
415-
}
405+
final ClassNode declaringClass = methodNode.getDeclaringClass();
406+
final String txHandlingMethodName = TransactionalTransform.getTransactionHandlingMethodName(methodNode);
407+
final Parameter[] originalMethodParameters = methodNode.getParameters();
408+
final Parameter[] txHandlingMethodParams = new Parameter[originalMethodParameters.length + 1];
409+
System.arraycopy(originalMethodParameters, 0, txHandlingMethodParams, 0, originalMethodParameters.length);
410+
txHandlingMethodParams[txHandlingMethodParams.length - 1] = new Parameter(ClassHelper.make(TransactionStatus.class), "transactionStatus");
411+
if (declaringClass.hasMethod(txHandlingMethodName, txHandlingMethodParams)) {
412+
node = declaringClass.getMethod(txHandlingMethodName, txHandlingMethodParams);
416413
}
417414
return node;
418415
}

0 commit comments

Comments
 (0)