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);
}
Aggregations