public abstract class Traits
extends Object
A collection of utility methods used to deal with traits.
| Modifiers | Name | Description |
|---|---|---|
@interface |
Traits.Implemented |
Internal annotation used to indicate which methods in a trait interface have a default implementation. |
@interface |
Traits.TraitBridge |
Internal annotation used to indicate that a method is a bridge method to a trait default implementation. |
| Modifiers | Name | Description |
|---|---|---|
static ClassNode |
GENERATED_PROXY_CLASSNODE |
Class node for GeneratedGroovyProxy. |
static ClassNode |
IMPLEMENTED_CLASSNODE |
Class node for Implemented. |
static ClassNode |
SELFTYPE_CLASSNODE |
Class node for SelfType. |
static String |
STATIC_THIS_OBJECT |
Synthetic parameter name for the current static trait receiver. |
static String |
THIS_OBJECT |
Synthetic parameter name for the current trait receiver. |
static ClassNode |
TRAITBRIDGE_CLASSNODE |
Class node for TraitBridge. |
static Class<Trait> |
TRAIT_CLASS |
Runtime annotation type that marks Groovy traits. |
static ClassNode |
TRAIT_CLASSNODE |
Class node for Trait. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static LinkedHashSet<ClassNode> |
collectAllInterfacesReverseOrder(ClassNode cNode, LinkedHashSet<ClassNode> interfaces)Collects all interfaces of a class node, but reverses the order of the declaration of direct interfaces of this class node. |
|
public static LinkedHashSet<ClassNode> |
collectSelfTypes(ClassNode receiver, LinkedHashSet<ClassNode> selfTypes)Collects all the self types that a type should extend or implement, given the traits is implements. |
|
public static LinkedHashSet<ClassNode> |
collectSelfTypes(ClassNode receiver, LinkedHashSet<ClassNode> selfTypes, boolean checkInterfaces, boolean checkSuperClass)Collects all the self types that a type should extend or implement, given the traits is implements. |
|
public static String[] |
decomposeSuperCallName(String methodName)Returns the trait and method names derived from super-trait name scheme or null if the method name doesn't correspond to a trait method. |
|
public static ClassNode |
findFieldHelper(ClassNode trait)Returns the generated instance field helper class for a trait. |
|
public static ClassNode |
findHelper(ClassNode trait)Returns the generated helper class for a trait. |
|
public static ClassNode |
findStaticFieldHelper(ClassNode trait)Returns the generated static field helper class for a trait. |
|
public static List<ClassNode> |
findTraits(ClassNode cNode)Find all traits associated with the given type. |
<T> |
public static T |
getAsType(Object self, Class<T> clazz)Converts a class implementing some trait into a target class. |
|
public static Method |
getBridgeMethodTarget(Method someMethod)Reflection API to find the method corresponding to the default implementation of a trait, given a bridge method. |
|
public static boolean |
hasDefaultImplementation(MethodNode method)Indicates whether a method in a trait interface has a default implementation. |
|
public static boolean |
hasDefaultImplementation(Method method)Indicates whether a method in a trait interface has a default implementation. |
|
public static boolean |
isAnnotatedWithTrait(ClassNode cNode)Returns true if the specified class node is annotated with the Trait interface. |
|
public static boolean |
isBridgeMethod(Method someMethod)Reflection API to indicate whether some method is a bridge method to the default implementation of a trait. |
|
public static boolean |
isTrait(ClassNode cNode)Returns true if the specified class node is a trait. |
|
public static boolean |
isTrait(Class<?> clazz)Returns true if the specified class is a trait. |
Class node for GeneratedGroovyProxy.
Class node for Implemented.
Synthetic parameter name for the current static trait receiver.
Synthetic parameter name for the current trait receiver.
Class node for TraitBridge.
Collects all interfaces of a class node, but reverses the order of the declaration of direct interfaces of this class node. This is used to make sure a trait implementing A,B where both A and B have the same method will take the method from B (latest), aligning the behavior with categories.
cNode - a class nodeinterfaces - ordered set of interfacesCollects all the self types that a type should extend or implement, given the traits is implements. Collects from interfaces and superclasses too.
receiver - a class node that may implement a traitselfTypes - a set where the self types will be putselfTypes collectionCollects all the self types that a type should extend or implement, given the traits is implements.
receiver - a class node that may implement a traitselfTypes - a set where the self types will be putcheckInterfaces - should the interfaces that the node implements be collected toocheckSuperClass - should we collect from the superclass tooselfTypes collection Returns the trait and method names derived from super-trait name scheme
or null if the method name doesn't correspond to a trait method.
Returns the generated instance field helper class for a trait.
trait - the trait class nodenull if none existsReturns the generated helper class for a trait.
trait - the trait class nodeReturns the generated static field helper class for a trait.
trait - the trait class nodenull if none existsFind all traits associated with the given type.
cNode - the given classnodeConverts a class implementing some trait into a target class. If the trait is a dynamic proxy and that the target class is assignable to the target object of the proxy, then the target object is returned. Otherwise, falls back to DefaultGroovyMethods.asType
self - an object to be coerced to some classclazz - the class to be coerced toReflection API to find the method corresponding to the default implementation of a trait, given a bridge method.
someMethod - a methodIndicates whether a method in a trait interface has a default implementation.
method - a method nodeIndicates whether a method in a trait interface has a default implementation.
method - a method nodeReturns true if the specified class node is annotated with the Trait interface.
cNode - a class nodeReflection API to indicate whether some method is a bridge method to the default implementation of a trait.
someMethod - a methodtrue if the method bridges to a trait default implementationReturns true if the specified class node is a trait.
cNode - a class node to testReturns true if the specified class is a trait.
clazz - a class to test