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

public abstract Class TraitComposer

extends Object
Class Inheritance
Imports
groovy.transform.CompileStatic, org.codehaus.groovy.ast.ASTNode, .AnnotationNode, .ClassHelper, .ClassNode, .FieldNode, .GenericsType, .MethodNode, .Parameter, .PropertyNode, org.codehaus.groovy.ast.expr.ArgumentListExpression, .ArrayExpression, .BinaryExpression, .CastExpression, .ClassExpression, .ConstantExpression, .Expression, .MethodCallExpression, .StaticMethodCallExpression, .VariableExpression, org.codehaus.groovy.ast.stmt.EmptyStatement, .ExpressionStatement, .Statement, org.codehaus.groovy.ast.tools.GeneralUtils, .GenericsUtils, org.codehaus.groovy.classgen.asm.BytecodeHelper, org.codehaus.groovy.control.CompilationUnit, .SourceUnit, org.codehaus.groovy.runtime.InvokerHelper, .MetaClassHelper, org.codehaus.groovy.syntax.SyntaxException, .Token, .Types, org.codehaus.groovy.transform.ASTTransformationCollectorCodeVisitor, org.codehaus.groovy.transform.sc.StaticCompileTransformation, org.codehaus.groovy.transform.stc.StaticTypesMarker, org.objectweb.asm.Opcodes, java.util.ArrayList, .Arrays, .Collections, .Iterator, .LinkedHashSet, .LinkedList, .List, .Map, .Optional

This class contains a static utility method doExtendTraits(org.codehaus.groovy.ast.ClassNode, org.codehaus.groovy.control.SourceUnit, org.codehaus.groovy.control.CompilationUnit) aimed at generating code for a classnode implementing a trait.
Since
2.3.0

Field Summary

Modifier and TypeField and Description
public static final ClassNode

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static void
applyTrait(final ClassNode trait, final ClassNode cNode, final TraitHelpersTuple helpers, SourceUnit unit)

private static void
checkTraitAllowed(final ClassNode bottomTrait, final SourceUnit unit)

private static ClassNode[]
copyExceptions(final ClassNode[] sourceExceptions)

private static Statement
createDelegatingForwarder(final MethodNode forwarderMethod, final ClassNode next)

private static SyntaxException
createException(ClassNode trait, ClassNode targetNode, MethodNode forwarder, MethodNode existingMethod)

private static void
createForwarderMethod(ClassNode trait, ClassNode targetNode, MethodNode helperMethod, MethodNode originalMethod, ClassNode helperClassNode, Map<String, ClassNode> genericsSpec, Parameter[] helperMethodParams, Parameter[] traitMethodParams, Parameter[] forwarderParams, ArgumentListExpression helperMethodArgList, SourceUnit unit)

private static Statement
createSuperFallback(final MethodNode forwarderMethod, final ClassNode returnType)

private static void
createSuperForwarder(ClassNode targetNode, MethodNode
a forwarder method
forwarder
,
final Map<String, ClassNode> genericsSpec)

Creates, if necessary, a super forwarder method, for stackable traits.

private static void
doCreateSuperForwarder(final ClassNode targetNode, final MethodNode forwarderMethod, final ClassNode[] interfacesToGenerateForwarderFor, final Map<String, ClassNode> genericsSpec)

Creates a method to dispatch to "super traits" in a "stackable" fashion.

public static void
doExtendTraits(final ClassNode
a class node
cNode
,
final SourceUnit
the source unit
unit
,
final CompilationUnit cu)

Given a class node, if this class node implements a trait, then generate all the appropriate code which delegates calls to the trait.

private static MethodNode
findExistingMethod(final ClassNode cNode, final MethodNode forwarder)

private static MethodNode
findExistingMethod(final ClassNode cNode, final String name, final Parameter[] params)

private static boolean
isExistingProperty(final String methodName, final ClassNode cNode, final Parameter[] params)

private static GenericsType[]
private static boolean
shouldSkipMethod(final ClassNode cNode, final String name, final Parameter[] params)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

COMPILESTATIC_CLASSNODEback to summary
public static final ClassNode COMPILESTATIC_CLASSNODE

Constructor Detail

TraitComposerback to summary
public TraitComposer()

Method Detail

applyTraitback to summary
private static void applyTrait(final ClassNode trait, final ClassNode cNode, final TraitHelpersTuple helpers, SourceUnit unit)
checkTraitAllowedback to summary
private static void checkTraitAllowed(final ClassNode bottomTrait, final SourceUnit unit)
copyExceptionsback to summary
private static ClassNode[] copyExceptions(final ClassNode[] sourceExceptions)
createDelegatingForwarderback to summary
private static Statement createDelegatingForwarder(final MethodNode forwarderMethod, final ClassNode next)
createExceptionback to summary
private static SyntaxException createException(ClassNode trait, ClassNode targetNode, MethodNode forwarder, MethodNode existingMethod)
createForwarderMethodback to summary
private static void createForwarderMethod(ClassNode trait, ClassNode targetNode, MethodNode helperMethod, MethodNode originalMethod, ClassNode helperClassNode, Map<String, ClassNode> genericsSpec, Parameter[] helperMethodParams, Parameter[] traitMethodParams, Parameter[] forwarderParams, ArgumentListExpression helperMethodArgList, SourceUnit unit)
createSuperFallbackback to summary
private static Statement createSuperFallback(final MethodNode forwarderMethod, final ClassNode returnType)
createSuperForwarderback to summary
private static void createSuperForwarder(ClassNode targetNode, MethodNode forwarder, final Map<String, ClassNode> genericsSpec)

Creates, if necessary, a super forwarder method, for stackable traits.

Parameters
forwarder:MethodNode

a forwarder method

doCreateSuperForwarderback to summary
private static void doCreateSuperForwarder(final ClassNode targetNode, final MethodNode forwarderMethod, final ClassNode[] interfacesToGenerateForwarderFor, final Map<String, ClassNode> genericsSpec)

Creates a method to dispatch to "super traits" in a "stackable" fashion. The generated method looks like this:

ReturnType trait$super$method(Class clazz, Arg1 arg1, Arg2 arg2, ...) {
    if (SomeTrait.is(A) return SomeOtherTrait$Trait$Helper.method(this, arg1, arg2)
    super.method(arg1,arg2)
}
doExtendTraitsback to summary
public static void doExtendTraits(final ClassNode cNode, final SourceUnit unit, final CompilationUnit cu)

Given a class node, if this class node implements a trait, then generate all the appropriate code which delegates calls to the trait. It is safe to call this method on a class node which does not implement a trait.

Parameters
cNode:ClassNode

a class node

unit:SourceUnit

the source unit

findExistingMethodback to summary
private static MethodNode findExistingMethod(final ClassNode cNode, final MethodNode forwarder)
findExistingMethodback to summary
private static MethodNode findExistingMethod(final ClassNode cNode, final String name, final Parameter[] params)
isExistingPropertyback to summary
private static boolean isExistingProperty(final String methodName, final ClassNode cNode, final Parameter[] params)
removeNonPlaceHoldersback to summary
private static GenericsType[] removeNonPlaceHolders(GenericsType[] oldTypes)
shouldSkipMethodback to summary
private static boolean shouldSkipMethod(final ClassNode cNode, final String name, final Parameter[] params)