Search in sources :

Example 1 with FreshRuntime

use of grails.test.runtime.FreshRuntime in project grails-core by grails.

the class DirtiesRuntimeTransformation method visit.

@Override
public void visit(final ASTNode[] astNodes, final SourceUnit source) {
    if (!(astNodes[0] instanceof AnnotationNode) || !(astNodes[1] instanceof MethodNode)) {
        throw new RuntimeException("Internal error: wrong types: $node.class / $parent.class");
    }
    final MethodNode methodNode = (MethodNode) astNodes[1];
    final ClassNode declaringClassNode = methodNode.getDeclaringClass();
    if (declaringClassNode != null) {
        final List<AnnotationNode> annotations = declaringClassNode.getAnnotations(ClassHelper.make(FreshRuntime.class));
        if (annotations != null && annotations.size() > 0) {
            final String message = "The [" + methodNode.getName() + "] method in [" + declaringClassNode.getName() + "] is marked with @DirtiesRuntime.  " + "There is no need to mark a test method with @DirtiesRuntime " + "inside of a test class which is marked with @FreshRuntime.";
            GrailsASTUtils.warning(source, methodNode, message);
        }
    }
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) MethodNode(org.codehaus.groovy.ast.MethodNode) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) FreshRuntime(grails.test.runtime.FreshRuntime)

Aggregations

FreshRuntime (grails.test.runtime.FreshRuntime)1 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)1 ClassNode (org.codehaus.groovy.ast.ClassNode)1 MethodNode (org.codehaus.groovy.ast.MethodNode)1