Search in sources :

Example 1 with LogASTTransformation

use of org.codehaus.groovy.transform.LogASTTransformation in project grails-core by grails.

the class LoggingTransformer method performInjectionOnAnnotatedClass.

@Override
public void performInjectionOnAnnotatedClass(SourceUnit source, ClassNode classNode) {
    if (classNode.getNodeMetaData(Slf4j.class) != null)
        return;
    String packageName = Slf4j.class.getPackage().getName();
    // if already annotated skip
    for (AnnotationNode annotationNode : classNode.getAnnotations()) {
        if (annotationNode.getClassNode().getPackageName().equals(packageName)) {
            return;
        }
    }
    FieldNode logField = classNode.getField("log");
    if (logField != null) {
        if (!Modifier.isPrivate(logField.getModifiers())) {
            return;
        }
    }
    if (classNode.getSuperClass().getName().equals("grails.boot.config.GrailsAutoConfiguration")) {
        return;
    }
    AnnotationNode annotationNode = new AnnotationNode(ClassHelper.make(Slf4j.class));
    LogASTTransformation logASTTransformation = new LogASTTransformation();
    logASTTransformation.setCompilationUnit(new CompilationUnit(new GroovyClassLoader(getClass().getClassLoader())));
    logASTTransformation.visit(new ASTNode[] { annotationNode, classNode }, source);
    classNode.putNodeMetaData(Slf4j.class, annotationNode);
}
Also used : CompilationUnit(org.codehaus.groovy.control.CompilationUnit) GroovyClassLoader(groovy.lang.GroovyClassLoader) LogASTTransformation(org.codehaus.groovy.transform.LogASTTransformation) Slf4j(groovy.util.logging.Slf4j)

Aggregations

GroovyClassLoader (groovy.lang.GroovyClassLoader)1 Slf4j (groovy.util.logging.Slf4j)1 CompilationUnit (org.codehaus.groovy.control.CompilationUnit)1 LogASTTransformation (org.codehaus.groovy.transform.LogASTTransformation)1