Top Description Inners Fields Constructors Methods
org.codehaus.groovy.transform

public Class LogASTTransformation

extends AbstractASTTransformation
implements CompilationUnitAware
Class Inheritance
All Implemented Interfaces
groovy.transform.CompilationUnitAware
Annotations
@GroovyASTTransformation
phase:SEMANTIC_ANALYSIS
Imports
groovy.lang.GroovyClassLoader, .GroovyRuntimeException, groovy.transform.CompilationUnitAware, org.codehaus.groovy.GroovyBugError, org.codehaus.groovy.ast.ASTNode, .AnnotatedNode, .AnnotationNode, .ClassCodeExpressionTransformer, .ClassHelper, .ClassNode, .DynamicVariable, .FieldNode, org.codehaus.groovy.ast.expr.ClosureExpression, .ConstantExpression, .Expression, .MethodCallExpression, .TupleExpression, .VariableExpression, org.codehaus.groovy.ast.stmt.BlockStatement, org.codehaus.groovy.classgen.VariableScopeVisitor, org.codehaus.groovy.control.CompilationUnit, .CompilePhase, .SourceUnit, org.codehaus.groovy.runtime.DefaultGroovyMethods, java.lang.reflect.Method, .Modifier

This class provides an AST Transformation to add a log field to a class.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
public abstract static class
public static interface
LogASTTransformation.LoggingStrategy

A LoggingStrategy defines how to wire a new logger instance into an existing class.

public static interface
LogASTTransformation.LoggingStrategyV2

A LoggingStrategy defines how to wire a new logger instance into an existing class.

Field Summary

Modifier and TypeField and Description
private CompilationUnit
public static final String
public static final String
DEFAULT_CATEGORY_NAME

This is just a dummy value used because String annotations values can not be null.

Inherited from org.codehaus.groovy.transform.AbstractASTTransformation:
RETENTION_CLASSNODEsourceUnit

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static LogASTTransformation.LoggingStrategy
createLoggingStrategy(final AnnotationNode logAnnotation, final ClassLoader classLoader, final ClassLoader xformLoader)

private static String
lookupCategoryName(final AnnotationNode logAnnotation)

private int
lookupLogFieldModifiers(final AnnotatedNode targetClass, final AnnotationNode logAnnotation)

private static String
lookupLogFieldName(final AnnotationNode logAnnotation)

public void
public void
visit(final ASTNode[]
The ASTnodes when the call was triggered. Element 0 is the AnnotationNode that triggered this annotation to be activated. Element 1 is the AnnotatedNode decorated, such as a MethodNode or ClassNode. For global transformations it is usually safe to ignore this parameter.
nodes
,
final SourceUnit
The source unit being compiled. The source unit may contain several classes. For global transformations, information about the AST can be retrieved from this object.
sourceUnit
)

Implements org.codehaus.groovy.transform.ASTTransformation.visit.

The method is invoked when an AST Transformation is active.
Inherited from org.codehaus.groovy.transform.AbstractASTTransformation:
addErrorcheckIncludeExcludecheckIncludeExcludecheckIncludeExcludeUndefinedAwarecheckIncludeExcludeUndefinedAwarecheckNotInterfacecheckPropertyListcheckPropertyListcheckPropertyListcopyAnnotatedNodeAnnotationscopyAnnotatedNodeAnnotationsdeemedInternalNamegetAnnotationNamegetClassListgetMemberClassListgetMemberClassValuegetMemberClassValuegetMemberIntValuegetMemberListgetMemberStringListgetMemberStringValuegetMemberStringValuegetMemberValuehasAnnotationinitmemberHasValuenonGenericshouldSkipshouldSkipshouldSkipOnDescriptorshouldSkipOnDescriptorUndefinedAwareshouldSkipUndefinedAwareshouldSkipUndefinedAwaretokenize

Field Detail

compilationUnitback to summary
private CompilationUnit compilationUnit
DEFAULT_ACCESS_MODIFIERback to summary
public static final String DEFAULT_ACCESS_MODIFIER
DEFAULT_CATEGORY_NAMEback to summary
public static final String DEFAULT_CATEGORY_NAME

This is just a dummy value used because String annotations values can not be null. It will be replaced by the fully qualified class name of the annotated class.

Constructor Detail

LogASTTransformationback to summary
public LogASTTransformation()

Method Detail

createLoggingStrategyback to summary
private static LogASTTransformation.LoggingStrategy createLoggingStrategy(final AnnotationNode logAnnotation, final ClassLoader classLoader, final ClassLoader xformLoader)
lookupCategoryNameback to summary
private static String lookupCategoryName(final AnnotationNode logAnnotation)
lookupLogFieldModifiersback to summary
private int lookupLogFieldModifiers(final AnnotatedNode targetClass, final AnnotationNode logAnnotation)
lookupLogFieldNameback to summary
private static String lookupLogFieldName(final AnnotationNode logAnnotation)
setCompilationUnitback to summary
public void setCompilationUnit(final CompilationUnit compilationUnit)

Implements groovy.transform.CompilationUnitAware.setCompilationUnit.

Annotations
@Override
visitback to summary
public void visit(final ASTNode[] nodes, final SourceUnit sourceUnit)

Implements org.codehaus.groovy.transform.ASTTransformation.visit.

Doc from org.codehaus.groovy.transform.ASTTransformation.visit.

The method is invoked when an AST Transformation is active. For local transformations, it is invoked once each time the local annotation is encountered. For global transformations, it is invoked once for every source unit, which is typically a source file.

Parameters
nodes:ASTNode[]

The ASTnodes when the call was triggered. Element 0 is the AnnotationNode that triggered this annotation to be activated. Element 1 is the AnnotatedNode decorated, such as a MethodNode or ClassNode. For global transformations it is usually safe to ignore this parameter.

sourceUnit:SourceUnit

The source unit being compiled. The source unit may contain several classes. For global transformations, information about the AST can be retrieved from this object.

Annotations
@Override
org.codehaus.groovy.transform back to summary

public abstract Class LogASTTransformation.AbstractLoggingStrategy

extends Object
implements LoggingStrategy
Class Inheritance
  • java.lang.Object
  • org.codehaus.groovy.transform.LogASTTransformation.AbstractLoggingStrategy
All Implemented Interfaces
org.codehaus.groovy.transform.LogASTTransformation.LoggingStrategy
Known Direct Subclasses
org.codehaus.groovy.transform.LogASTTransformation.AbstractLoggingStrategyV2

Field Summary

Modifier and TypeField and Description
protected final GroovyClassLoader

Constructor Summary

AccessConstructor and Description
protected
protected

Method Summary

Modifier and TypeMethod and Description
protected ClassNode
classNode(final String name)

public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loaderback to summary
protected final GroovyClassLoader loader

Constructor Detail

AbstractLoggingStrategyback to summary
protected AbstractLoggingStrategy(final GroovyClassLoader loader)
AbstractLoggingStrategyback to summary
protected AbstractLoggingStrategy()

Method Detail

classNodeback to summary
protected ClassNode classNode(final String name)
getCategoryNameback to summary
public String getCategoryName(final ClassNode classNode, final String categoryName)

Implements org.codehaus.groovy.transform.LogASTTransformation.LoggingStrategy.getCategoryName.

Annotations
@Override
org.codehaus.groovy.transform back to summary

public abstract Class LogASTTransformation.AbstractLoggingStrategyV2

extends AbstractLoggingStrategy
implements LoggingStrategyV2
Class Inheritance
All Implemented Interfaces
org.codehaus.groovy.transform.LogASTTransformation.LoggingStrategyV2, org.codehaus.groovy.transform.LogASTTransformation.LoggingStrategy
Known Direct Subclasses
groovy.util.logging.Commons.CommonsLoggingStrategy, groovy.util.logging.Log.JavaUtilLoggingStrategy, groovy.util.logging.Log4j.Log4jLoggingStrategy, groovy.util.logging.Log4j2.Log4j2LoggingStrategy, groovy.util.logging.Slf4j.Slf4jLoggingStrategy

Field Summary

Inherited from org.codehaus.groovy.transform.LogASTTransformation.AbstractLoggingStrategy:
loader

Constructor Summary

AccessConstructor and Description
protected
protected

Method Summary

Modifier and TypeMethod and Description
public FieldNode
addLoggerFieldToClass(final ClassNode
the class that was originally annotated with the Log transformation.
classNode
,
final String
the name of the logger field
fieldName
,
final String
the name of the logging category
categoryName
)

Implements org.codehaus.groovy.transform.LogASTTransformation.LoggingStrategy.addLoggerFieldToClass.

In this method, you are given a ClassNode, a field name and a category name, and you must add a new Field onto the class.
Inherited from org.codehaus.groovy.transform.LogASTTransformation.AbstractLoggingStrategy:
classNodegetCategoryName

Constructor Detail

AbstractLoggingStrategyV2back to summary
protected AbstractLoggingStrategyV2(final GroovyClassLoader loader)
AbstractLoggingStrategyV2back to summary
protected AbstractLoggingStrategyV2()

Method Detail

addLoggerFieldToClassback to summary
public FieldNode addLoggerFieldToClass(final ClassNode classNode, final String fieldName, final String categoryName)

Implements org.codehaus.groovy.transform.LogASTTransformation.LoggingStrategy.addLoggerFieldToClass.

Doc from org.codehaus.groovy.transform.LogASTTransformation.LoggingStrategy.addLoggerFieldToClass.

In this method, you are given a ClassNode, a field name and a category name, and you must add a new Field onto the class. Return the result of the ClassNode.addField operations.

Parameters
classNode:ClassNode

the class that was originally annotated with the Log transformation.

fieldName:String

the name of the logger field

categoryName:String

the name of the logging category

Returns:FieldNode

the FieldNode instance that was created and added to the class

Annotations
@Override
org.codehaus.groovy.transform back to summary

public Interface LogASTTransformation.LoggingStrategy

Known Direct Subinterfaces
org.codehaus.groovy.transform.LogASTTransformation.LoggingStrategyV2
Known Direct Implementers
org.codehaus.groovy.transform.LogASTTransformation.AbstractLoggingStrategy

A LoggingStrategy defines how to wire a new logger instance into an existing class. It is meant to be used with the @Log family of annotations to allow you to write your own Log annotation provider.

Method Summary

Modifier and TypeMethod and Description
public FieldNode

Returns:

the FieldNode instance that was created and added to the class
addLoggerFieldToClass
(ClassNode
the class that was originally annotated with the Log transformation.
classNode
,
String
the name of the logger field
fieldName
,
String
the name of the logging category
categoryName
)

In this method, you are given a ClassNode, a field name and a category name, and you must add a new Field onto the class.

public String
getCategoryName(ClassNode classNode, String categoryName)

public boolean
isLoggingMethod(String methodName)

public Expression
wrapLoggingMethodCall(Expression logVariable, String methodName, Expression originalExpression)

Method Detail

addLoggerFieldToClassback to summary
public FieldNode addLoggerFieldToClass(ClassNode classNode, String fieldName, String categoryName)

In this method, you are given a ClassNode, a field name and a category name, and you must add a new Field onto the class. Return the result of the ClassNode.addField operations.

Parameters
classNode:ClassNode

the class that was originally annotated with the Log transformation.

fieldName:String

the name of the logger field

categoryName:String

the name of the logging category

Returns:FieldNode

the FieldNode instance that was created and added to the class

getCategoryNameback to summary
public String getCategoryName(ClassNode classNode, String categoryName)
isLoggingMethodback to summary
public boolean isLoggingMethod(String methodName)
wrapLoggingMethodCallback to summary
public Expression wrapLoggingMethodCall(Expression logVariable, String methodName, Expression originalExpression)
org.codehaus.groovy.transform back to summary

public Interface LogASTTransformation.LoggingStrategyV2

extends LoggingStrategy
Known Direct Implementers
org.codehaus.groovy.transform.LogASTTransformation.AbstractLoggingStrategyV2

A LoggingStrategy defines how to wire a new logger instance into an existing class. It is meant to be used with the @Log family of annotations to allow you to write your own Log annotation provider.

Method Summary

Modifier and TypeMethod and Description
public FieldNode

Returns:

the FieldNode instance that was created and added to the class
addLoggerFieldToClass
(ClassNode
the class that was originally annotated with the Log transformation.
classNode
,
String
the name of the logger field
fieldName
,
String
the name of the logging category
categoryName
,
int
the modifiers (private, final, et. al.) of the logger field
fieldModifiers
)

In this method, you are given a ClassNode, a field name and a category name, and you must add a new Field onto the class.

Inherited from org.codehaus.groovy.transform.LogASTTransformation.LoggingStrategy:
addLoggerFieldToClassgetCategoryNameisLoggingMethodwrapLoggingMethodCall

Method Detail

addLoggerFieldToClassback to summary
public FieldNode addLoggerFieldToClass(ClassNode classNode, String fieldName, String categoryName, int fieldModifiers)

In this method, you are given a ClassNode, a field name and a category name, and you must add a new Field onto the class. Return the result of the ClassNode.addField operations.

Parameters
classNode:ClassNode

the class that was originally annotated with the Log transformation.

fieldName:String

the name of the logger field

categoryName:String

the name of the logging category

fieldModifiers:int

the modifiers (private, final, et. al.) of the logger field

Returns:FieldNode

the FieldNode instance that was created and added to the class