org.codehaus.groovy.transform.trait

## Class Traits

- java.lang.Object
- - org.codehaus.groovy.transform.trait.Traits

-     public abstract class Traits
      extends java.lang.Object

  A collection of utility methods used to deal with traits.
  Since:
    2.3.0
  Author:
    Cédric Champeau

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `Traits.Implemented` Internal annotation used to indicate which methods in a trait interface have a default implementation.
    `static interface` | `Traits.TraitBridge` Internal annotation used to indicate that a method is a bridge method to a trait default implementation.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static ClassNode` | `GENERATED_PROXY_CLASSNODE`
    `static ClassNode` | `IMPLEMENTED_CLASSNODE`
    `static ClassNode` | `SELFTYPE_CLASSNODE`
    `static java.lang.String` | `STATIC_THIS_OBJECT`
    `static java.lang.String` | `THIS_OBJECT`
    `static java.lang.Class` | `TRAIT_CLASS`
    `static ClassNode` | `TRAIT_CLASSNODE`
    `static ClassNode` | `TRAITBRIDGE_CLASSNODE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Traits()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.util.LinkedHashSet<ClassNode>` | `collectAllInterfacesReverseOrder(ClassNode cNode, java.util.LinkedHashSet<ClassNode> interfaces)` Collects all interfaces of a class node, but reverses the order of the declaration of direct interfaces of this class node.
    `static java.util.LinkedHashSet<ClassNode>` | `collectSelfTypes(ClassNode receiver, java.util.LinkedHashSet<ClassNode> selfTypes)` Collects all the self types that a type should extend or implement, given the traits is implements.
    `static java.util.LinkedHashSet<ClassNode>` | `collectSelfTypes(ClassNode receiver, java.util.LinkedHashSet<ClassNode> selfTypes, boolean checkInterfaces, boolean checkSuper)` Collects all the self types that a type should extend or implement, given the traits is implements.
    `static java.lang.String[]` | `decomposeSuperCallName(java.lang.String origName)` Returns the name of a method without the super trait specific prefix.
    `static ClassNode` | `findFieldHelper(ClassNode trait)`
    `static ClassNode` | `findHelper(ClassNode trait)`
    `static <T> T` | `getAsType(java.lang.Object self, java.lang.Class<T> clazz)` Converts a class implementing some trait into a target class.
    `static java.lang.reflect.Method` | `getBridgeMethodTarget(java.lang.reflect.Method someMethod)` Reflection API to find the method corresponding to the default implementation of a trait, given a bridge method.
    `static boolean` | `hasDefaultImplementation(java.lang.reflect.Method method)` Indicates whether a method in a trait interface has a default implementation.
    `static boolean` | `hasDefaultImplementation(MethodNode method)` Indicates whether a method in a trait interface has a default implementation.
    `static boolean` | `isAnnotatedWithTrait(ClassNode cNode)` Returns true if the specified class node is annotated with the `Trait` interface.
    `static boolean` | `isBridgeMethod(java.lang.reflect.Method someMethod)` Reflection API to indicate whether some method is a bridge method to the default implementation of a trait.
    `static boolean` | `isTrait(java.lang.Class clazz)` Returns true if the specified class is a trait.
    `static boolean` | `isTrait(ClassNode cNode)` Returns true if the specified class node is a trait.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### IMPLEMENTED_CLASSNODE

          public static final ClassNode IMPLEMENTED_CLASSNODE

    - #### TRAITBRIDGE_CLASSNODE

          public static final ClassNode TRAITBRIDGE_CLASSNODE

    - #### TRAIT_CLASS

          public static final java.lang.Class TRAIT_CLASS

    - #### TRAIT_CLASSNODE

          public static final ClassNode TRAIT_CLASSNODE

    - #### GENERATED_PROXY_CLASSNODE

          public static final ClassNode GENERATED_PROXY_CLASSNODE

    - #### SELFTYPE_CLASSNODE

          public static final ClassNode SELFTYPE_CLASSNODE

    - #### THIS_OBJECT

          public static final java.lang.String THIS_OBJECT

      See Also:
        Constant Field Values

    - #### STATIC_THIS_OBJECT

          public static final java.lang.String STATIC_THIS_OBJECT

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Traits

          public Traits()

  - ### Method Detail

    - #### findHelper

          public static ClassNode findHelper(ClassNode trait)

    - #### findFieldHelper

          public static ClassNode findFieldHelper(ClassNode trait)

    - #### isTrait

          public static boolean isTrait(ClassNode cNode)

      Returns true if the specified class node is a trait.
      Parameters:
        `cNode` - a class node to test
      Returns:
        true if the classnode represents a trait

    - #### isTrait

          public static boolean isTrait(java.lang.Class clazz)

      Returns true if the specified class is a trait.
      Parameters:
        `clazz` - a class to test
      Returns:
        true if the classnode represents a trait

    - #### isAnnotatedWithTrait

          public static boolean isAnnotatedWithTrait(ClassNode cNode)

      Returns true if the specified class node is annotated with the `Trait` interface.
      Parameters:
        `cNode` - a class node
      Returns:
        true if the specified class node is annotated with the `Trait` interface.

    - #### hasDefaultImplementation

          public static boolean hasDefaultImplementation(MethodNode method)

      Indicates whether a method in a trait interface has a default implementation.
      Parameters:
        `method` - a method node
      Returns:
        true if the method has a default implementation in the trait

    - #### hasDefaultImplementation

          public static boolean hasDefaultImplementation(java.lang.reflect.Method method)

      Indicates whether a method in a trait interface has a default implementation.
      Parameters:
        `method` - a method node
      Returns:
        true if the method has a default implementation in the trait

    - #### isBridgeMethod

          public static boolean isBridgeMethod(java.lang.reflect.Method someMethod)

      Reflection API to indicate whether some method is a bridge method to the default implementation of a trait.
      Parameters:
        `someMethod` - a method node
      Returns:
        null if it is not a method implemented in a trait. If it is, returns the method from the trait class.

    - #### getBridgeMethodTarget

          public static java.lang.reflect.Method getBridgeMethodTarget(java.lang.reflect.Method someMethod)

      Reflection API to find the method corresponding to the default implementation of a trait, given a bridge method.
      Parameters:
        `someMethod` - a method node
      Returns:
        null if it is not a method implemented in a trait. If it is, returns the method from the trait class.

    - #### getAsType

          public static <T> T getAsType(java.lang.Object self,
                                        java.lang.Class<T> clazz)

      Converts 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(java.lang.Object, Class)`
      Parameters:
        `self` - an object to be coerced to some class
        `clazz` - the class to be coerced to
      Returns:
        the object coerced to the target class, or the proxy instance if it is compatible with the target class.

    - #### decomposeSuperCallName

          public static java.lang.String[] decomposeSuperCallName(java.lang.String origName)

      Returns the name of a method without the super trait specific prefix. If the method name doesn't correspond to a super trait method call, the result will be null.
      Parameters:
        `origName` - the name of a method
      Returns:
        null if the name doesn't start with the super trait prefix, otherwise the name without the prefix

    - #### collectAllInterfacesReverseOrder

          public static java.util.LinkedHashSet<ClassNode> collectAllInterfacesReverseOrder(ClassNode cNode,
                                                                                            java.util.LinkedHashSet<ClassNode> interfaces)

      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.
      Parameters:
        `cNode` - a class node
        `interfaces` - ordered set of interfaces

    - #### collectSelfTypes

          public static java.util.LinkedHashSet<ClassNode> collectSelfTypes(ClassNode receiver,
                                                                            java.util.LinkedHashSet<ClassNode> selfTypes)

      Collects all the self types that a type should extend or implement, given the traits is implements. Collects from interfaces and superclasses too.
      Parameters:
        `receiver` - a class node that may implement a trait
        `selfTypes` - a collection where the list of self types will be written
      Returns:
        the selfTypes collection itself
      Since:
        2.4.0

    - #### collectSelfTypes

          public static java.util.LinkedHashSet<ClassNode> collectSelfTypes(ClassNode receiver,
                                                                            java.util.LinkedHashSet<ClassNode> selfTypes,
                                                                            boolean checkInterfaces,
                                                                            boolean checkSuper)

      Collects all the self types that a type should extend or implement, given the traits is implements.
      Parameters:
        `receiver` - a class node that may implement a trait
        `selfTypes` - a collection where the list of self types will be written
        `checkInterfaces` - should the interfaces that the node implements be collected too
        `checkSuper` - should we collect from the superclass too
      Returns:
        the selfTypes collection itself
      Since:
        2.4.0