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

public Class TraitASTTransformation

extends AbstractASTTransformation
implements CompilationUnitAware
Class Inheritance
All Implemented Interfaces
groovy.transform.CompilationUnitAware
Annotations
@GroovyASTTransformation
phase:SEMANTIC_ANALYSIS
Imports
groovy.transform.CompilationUnitAware, org.codehaus.groovy.ast.ASTNode, .AnnotatedNode, .AnnotationNode, .ClassCodeExpressionTransformer, .ClassHelper, .ClassNode, .FieldNode, .GenericsType, .GroovyClassVisitor, .InnerClassNode, .MethodNode, .Parameter, .PropertyNode, org.codehaus.groovy.ast.expr.BinaryExpression, .Expression, .MethodCallExpression, .VariableExpression, org.codehaus.groovy.ast.stmt.BlockStatement, .ExpressionStatement, .Statement, org.codehaus.groovy.ast.tools.GeneralUtils, .GenericsUtils, org.codehaus.groovy.classgen.GeneratorContext, .VariableScopeVisitor, .Verifier, org.codehaus.groovy.control.CompilationUnit, .CompilePhase, .SourceUnit, org.codehaus.groovy.runtime.InvokerHelper, org.codehaus.groovy.syntax.SyntaxException, org.codehaus.groovy.transform.ASTTransformationCollectorCodeVisitor, .AbstractASTTransformation, .GroovyASTTransformation, java.util.ArrayList, .Collection, .HashSet, .Iterator, .LinkedList, .List, .Set

Handles generation of code for the traits (trait keyword is equivalent to using the @Trait annotation). A class annotated with @Trait will generate, instead:

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private CompilationUnit
public static final String
private static final ClassNode
private static final ClassNode
public static final String
private SourceUnit
Inherited from org.codehaus.groovy.transform.AbstractASTTransformation:
RETENTION_CLASSNODE

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
private void
private void
private static void
copyClassAnnotations(final ClassNode
the trait class node
cNode
,
final ClassNode
the helper class node
helper
)

Copies annotation from the trait to the helper, excluding the trait annotation itself.

private ClassNode
private static MethodNode
createInitMethod(final boolean isStatic, final ClassNode cNode, final ClassNode helper)

private static ClassNode
createReceiverType(final boolean isStatic, final ClassNode rawType)

private static Parameter
createSelfParameter(final ClassNode traitClass, boolean isStatic)

private static List<AnnotationNode>
private static void
private static void
private BlockStatement
getBlockStatement(final MethodNode targetMethod, final Statement code)

private static boolean
methodNeedsReplacement(final ClassNode cNode, final MethodNode mNode)

private Statement
processBody(final VariableExpression thisObject, final Statement code, final ClassNode trait, final ClassNode traitHelper, final ClassNode fieldHelper, final Collection<String> knownFields)

private void
processField(final FieldNode field, final MethodNode initializer, final MethodNode staticInitializer, final ClassNode fieldHelper, final ClassNode helper, final ClassNode staticFieldHelper, final ClassNode trait, final Set<String> knownFields)

private MethodNode
processMethod(final ClassNode traitClass, final ClassNode traitHelperClass, final MethodNode methodNode, final ClassNode fieldHelper, final Collection<String> knownFields)

private static void
processProperty(final ClassNode cNode, final PropertyNode node)

Mostly copied from the Verifier class but does *not* generate bytecode.

private void
private void
private void
private void
resolveScope(final ClassNode cNode)

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.
source
)

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
DO_DYNAMICback to summary
public static final String DO_DYNAMIC
INVOKERHELPER_CLASSNODEback to summary
private static final ClassNode INVOKERHELPER_CLASSNODE
OVERRIDE_CLASSNODEback to summary
private static final ClassNode OVERRIDE_CLASSNODE
POST_TYPECHECKING_REPLACEMENTback to summary
public static final String POST_TYPECHECKING_REPLACEMENT
sourceUnitback to summary
private SourceUnit sourceUnit

Hides org.codehaus.groovy.transform.AbstractASTTransformation.sourceUnit.

Constructor Detail

TraitASTTransformationback to summary
public TraitASTTransformation()

Method Detail

checkExtendsClauseback to summary
private void checkExtendsClause(final ClassNode cNode)
checkInnerClassesback to summary
private void checkInnerClasses(final ClassNode cNode)
checkNoConstructorback to summary
private void checkNoConstructor(final ClassNode cNode)
copyClassAnnotationsback to summary
private static void copyClassAnnotations(final ClassNode cNode, final ClassNode helper)

Copies annotation from the trait to the helper, excluding the trait annotation itself.

Parameters
cNode:ClassNode

the trait class node

helper:ClassNode

the helper class node

createHelperClassback to summary
private ClassNode createHelperClass(final ClassNode cNode)
createInitMethodback to summary
private static MethodNode createInitMethod(final boolean isStatic, final ClassNode cNode, final ClassNode helper)
createReceiverTypeback to summary
private static ClassNode createReceiverType(final boolean isStatic, final ClassNode rawType)
createSelfParameterback to summary
private static Parameter createSelfParameter(final ClassNode traitClass, boolean isStatic)
filterAnnotationsback to summary
private static List<AnnotationNode> filterAnnotations(final List<AnnotationNode> annotations)
generateMethodsWithDefaultArgsback to summary
private static void generateMethodsWithDefaultArgs(final ClassNode cNode)
generatePropertyMethodsback to summary
private static void generatePropertyMethods(final ClassNode cNode)
getBlockStatementback to summary
private BlockStatement getBlockStatement(final MethodNode targetMethod, final Statement code)
methodNeedsReplacementback to summary
private static boolean methodNeedsReplacement(final ClassNode cNode, final MethodNode mNode)
processBodyback to summary
private Statement processBody(final VariableExpression thisObject, final Statement code, final ClassNode trait, final ClassNode traitHelper, final ClassNode fieldHelper, final Collection<String> knownFields)
processFieldback to summary
private void processField(final FieldNode field, final MethodNode initializer, final MethodNode staticInitializer, final ClassNode fieldHelper, final ClassNode helper, final ClassNode staticFieldHelper, final ClassNode trait, final Set<String> knownFields)
processMethodback to summary
private MethodNode processMethod(final ClassNode traitClass, final ClassNode traitHelperClass, final MethodNode methodNode, final ClassNode fieldHelper, final Collection<String> knownFields)
processPropertyback to summary
private static void processProperty(final ClassNode cNode, final PropertyNode node)

Mostly copied from the Verifier class but does *not* generate bytecode.

registerASTTransformationsback to summary
private void registerASTTransformations(final ClassNode helper)
replaceExtendsByImplementsback to summary
private void replaceExtendsByImplements(final ClassNode cNode)
resolveHelperClassIfNecessaryback to summary
private void resolveHelperClassIfNecessary(final ClassNode helperClassNode)
resolveScopeback to summary
private void resolveScope(final ClassNode cNode)
setCompilationUnitback to summary
public void setCompilationUnit(final CompilationUnit unit)

Implements groovy.transform.CompilationUnitAware.setCompilationUnit.

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

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.

source: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.trait back to summary

private Class TraitASTTransformation.DefaultArgsMethodsAdder

extends Verifier
Class Inheritance

Field Summary

Inherited from org.codehaus.groovy.classgen.Verifier:
__TIMESTAMP__TIMESTAMP__DEFAULT_PARAMETER_GENERATEDINITIAL_EXPRESSIONSTATIC_METACLASS_BOOLSWAP_INIT

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
addDefaultParameterMethods(final ClassNode node)

Overrides org.codehaus.groovy.classgen.Verifier.addDefaultParameterMethods.

Creates a new method for each combination of default parameter expressions.
Inherited from org.codehaus.groovy.classgen.Verifier:
addClosureCodeaddConstructoraddCovariantMethodsaddDefaultConstructoraddDefaultParameterConstructorsaddDefaultParametersaddDefaultParametersaddFieldInitializationaddGroovyObjectInterfaceAndMethodsaddInitializationaddInitializationaddMethodaddMethod$$bridgeaddPropertyMethodaddReturnIfNeededaddTimeStampcapitalizecreateGetterBlockcreateSetterBlockgetClassNodegetFinalVariablesCallbackgetMethodNodegetTimestampgetTimestampFromFieldNamesetClassNodetransformToPrimitiveConstantIfPossiblevisitClassvisitConstructorvisitFieldvisitGenericTypevisitMethodvisitProperty

Constructor Detail

DefaultArgsMethodsAdderback to summary
private DefaultArgsMethodsAdder()

Method Detail

addDefaultParameterMethodsback to summary
public void addDefaultParameterMethods(final ClassNode node)

Overrides org.codehaus.groovy.classgen.Verifier.addDefaultParameterMethods.

Doc from org.codehaus.groovy.classgen.Verifier.addDefaultParameterMethods.

Creates a new method for each combination of default parameter expressions.

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

private Class TraitASTTransformation.PostTypeCheckingExpressionReplacer

extends ClassCodeExpressionTransformer
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final SourceUnit

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected SourceUnit
public Expression
Inherited from org.codehaus.groovy.ast.ClassCodeExpressionTransformer:
setSourcePositionvisitAnnotationvisitAssertStatementvisitCaseStatementvisitConstructorOrMethodvisitDoWhileLoopvisitExpressionStatementvisitFieldvisitForLoopvisitIfElsevisitPropertyvisitReturnStatementvisitSwitchvisitSynchronizedStatementvisitThrowStatementvisitWhileLoop

Field Detail

sourceUnitback to summary
private final SourceUnit sourceUnit

Constructor Detail

PostTypeCheckingExpressionReplacerback to summary
pack-priv PostTypeCheckingExpressionReplacer(final SourceUnit sourceUnit)

Method Detail

getSourceUnitback to summary
protected SourceUnit getSourceUnit()

Implements abstract org.codehaus.groovy.ast.ClassCodeVisitorSupport.getSourceUnit.

Annotations
@Override
transformback to summary
public Expression transform(final Expression exp)

Overrides org.codehaus.groovy.ast.ClassCodeExpressionTransformer.transform.

Implements org.codehaus.groovy.ast.expr.ExpressionTransformer.transform.

Doc from org.codehaus.groovy.ast.expr.ExpressionTransformer.transform.

Transforms the given expression into another expression

Annotations
@Override