ClassHelper (Groovy 5.0.8)
Description: declaration: package: org.codehaus.groovy.ast, class: ClassHelper

Package org.codehaus.groovy.ast

# Class ClassHelper

java.lang.Object
org.codehaus.groovy.ast.ClassHelper

public class ClassHelper extends Object
Helper for `ClassNode` and classes handling them. Contains a set of pre-defined instances for the most used types and some code for cached node creation and basic handling.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final ClassNode`
  `Annotation_TYPE`
  `static final ClassNode`
  `AUTOCLOSEABLE_TYPE`
  `static final ClassNode`
  `BigDecimal_TYPE`
  `static final ClassNode`
  `BigInteger_TYPE`
  `static final ClassNode`
  `BINDING_TYPE`
  `static final ClassNode`
  `boolean_TYPE`
  `static final ClassNode`
  `Boolean_TYPE`
  `static final ClassNode`
  `byte_TYPE`
  `static final ClassNode`
  `Byte_TYPE`
  `static final ClassNode`
  `char_TYPE`
  `static final ClassNode`
  `Character_TYPE`
  `static final ClassNode`
  `CLASS_Type`
  `static final ClassNode`
  `CLONEABLE_TYPE`
  `static final ClassNode`
  `CLOSURE_TYPE`
  `static final ClassNode`
  `COLLECTION_TYPE`
  `static final ClassNode`
  `COMPARABLE_TYPE`
  `static final ClassNode`
  `DEPRECATED_TYPE`
  `static final ClassNode`
  `double_TYPE`
  `static final ClassNode`
  `Double_TYPE`
  `static final ClassNode`
  `DYNAMIC_TYPE`
  Deprecated.
  `static final ClassNode`
  `ELEMENT_TYPE_TYPE`
  `protected static final ClassNode[]`
  `EMPTY_TYPE_ARRAY`
  `static final ClassNode`
  `Enum_Type`
  `static final ClassNode`
  `float_TYPE`
  `static final ClassNode`
  `Float_TYPE`
  `static final ClassNode`
  `GENERATED_CLOSURE_Type`
  `static final ClassNode`
  `GENERATED_LAMBDA_TYPE`
  `static final ClassNode`
  `GROOVY_INTERCEPTABLE_TYPE`
  `static final ClassNode`
  `GROOVY_OBJECT_SUPPORT_TYPE`
  `static final ClassNode`
  `GROOVY_OBJECT_TYPE`
  `static final ClassNode`
  `GSTRING_TYPE`
  `static final ClassNode`
  `int_TYPE`
  `static final ClassNode`
  `Integer_TYPE`
  `static final ClassNode`
  `ITERABLE_TYPE`
  `static final ClassNode`
  `Iterator_TYPE`
  `static final ClassNode`
  `LIST_TYPE`
  `static final ClassNode`
  `long_TYPE`
  `static final ClassNode`
  `Long_TYPE`
  `static final ClassNode`
  `MAP_TYPE`
  `static final ClassNode`
  `METACLASS_TYPE`
  `static final ClassNode`
  `Number_TYPE`
  `static final String`
  `OBJECT`
  `static final ClassNode`
  `OBJECT_TYPE`
  `static final ClassNode`
  `OVERRIDE_TYPE`
  `static final ClassNode`
  `PATTERN_TYPE`
  `static final ClassNode`
  `RANGE_TYPE`
  `static final ClassNode`
  `REFERENCE_TYPE`
  `static final ClassNode`
  `SCRIPT_TYPE`
  `static final ClassNode`
  `SEALED_TYPE`
  `static final ClassNode`
  `SERIALIZABLE_TYPE`
  `static final ClassNode`
  `SERIALIZEDLAMBDA_TYPE`
  `static final ClassNode`
  `SET_TYPE`
  `static final ClassNode`
  `short_TYPE`
  `static final ClassNode`
  `Short_TYPE`
  `static final ClassNode`
  `STREAM_TYPE`
  `static final ClassNode`
  `STRING_TYPE`
  `static final ClassNode`
  `THROWABLE_TYPE`
  `static final Class[]`
  `TUPLE_CLASSES`
  `static final ClassNode`
  `TUPLE_TYPE`
  `static final ClassNode`
  `VOID_TYPE`
  `static final ClassNode`
  `void_WRAPPER_TYPE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ClassHelper()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static ClassNode`
  `dynamicType()`
  `static MethodNode`
  `findSAM(ClassNode type)`
  Returns the single abstract method of a class node, if it is a SAM type, or null otherwise.
  `static ClassNode`
  `getNextSuperClass(ClassNode source, ClassNode target)`
  Returns a super class or interface for a given class depending on supplied target.
  `static ClassNode`
  `getUnwrapper(ClassNode cn)`
  `static ClassNode`
  `getWrapper(ClassNode cn)`
  Creates a ClassNode containing the wrapper of a ClassNode of primitive type.
  `static boolean`
  `isBigDecimalType(ClassNode type)`
  `static boolean`
  `isBigIntegerType(ClassNode type)`
  `static boolean`
  `isCachedType(ClassNode type)`
  `static boolean`
  `isClassType(ClassNode type)`
  `static boolean`
  `isDynamicTyped(ClassNode type)`
  `static boolean`
  `isFunctionalInterface(ClassNode type)`
  `static boolean`
  `isGeneratedFunction(ClassNode type)`
  Checks if the type is a generated function, i.e.
  `static boolean`
  `isGroovyObjectType(ClassNode type)`
  `static boolean`
  `isGStringType(ClassNode type)`
  `static boolean`
  `isNumberType(ClassNode cn)`
  `static boolean`
  `isObjectType(ClassNode type)`
  `static boolean`
  `isPrimitiveBoolean(ClassNode type)`
  `static boolean`
  `isPrimitiveByte(ClassNode type)`
  `static boolean`
  `isPrimitiveChar(ClassNode type)`
  `static boolean`
  `isPrimitiveDouble(ClassNode type)`
  `static boolean`
  `isPrimitiveFloat(ClassNode type)`
  `static boolean`
  `isPrimitiveInt(ClassNode type)`
  `static boolean`
  `isPrimitiveLong(ClassNode type)`
  `static boolean`
  `isPrimitiveShort(ClassNode type)`
  `static boolean`
  `isPrimitiveType(ClassNode cn)`
  Test to determine if a ClassNode is a primitive type.
  `static boolean`
  `isPrimitiveVoid(ClassNode type)`
  `static boolean`
  `isSAMType(ClassNode type)`
  `static boolean`
  `isStaticConstantInitializerType(ClassNode cn)`
  Test to determine if a ClassNode is a type belongs to the list of types which are allowed to initialize constants directly in bytecode instead of using <cinit>
  `static boolean`
  `isStringType(ClassNode type)`
  `static boolean`
  `isWrapperBoolean(ClassNode type)`
  `static boolean`
  `isWrapperByte(ClassNode type)`
  `static boolean`
  `isWrapperCharacter(ClassNode type)`
  `static boolean`
  `isWrapperDouble(ClassNode type)`
  `static boolean`
  `isWrapperFloat(ClassNode type)`
  `static boolean`
  `isWrapperInteger(ClassNode type)`
  `static boolean`
  `isWrapperLong(ClassNode type)`
  `static boolean`
  `isWrapperShort(ClassNode type)`
  `static boolean`
  `isWrapperVoid(ClassNode type)`
  `static ClassNode`
  `make(Class c)`
  Creates a ClassNode using a given class.
  `static ClassNode[]`
  `make(Class[] classes)`
  Creates an array of ClassNodes using an array of classes.
  `static ClassNode`
  `make(Class c, boolean includeGenerics)`
  `static ClassNode`
  `make(String name)`
  Creates a ClassNode using a given class.
  `static ClassNode`
  `makeCached(Class c)`
  `static ClassNode`
  `makeReference()`
  `static ClassNode`
  `makeWithoutCaching(Class c)`
  `static ClassNode`
  `makeWithoutCaching(Class c, boolean includeGenerics)`
  `static ClassNode`
  `makeWithoutCaching(String name)`
  Creates a ClassNode using a given class.

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

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

- ## Field Details

  - ### TUPLE_CLASSES

    public static final Class[] TUPLE_CLASSES

  - ### OBJECT_TYPE

    public static final ClassNode OBJECT_TYPE

  - ### CLOSURE_TYPE

    public static final ClassNode CLOSURE_TYPE

  - ### GSTRING_TYPE

    public static final ClassNode GSTRING_TYPE

  - ### RANGE_TYPE

    public static final ClassNode RANGE_TYPE

  - ### PATTERN_TYPE

    public static final ClassNode PATTERN_TYPE

  - ### STRING_TYPE

    public static final ClassNode STRING_TYPE

  - ### SCRIPT_TYPE

    public static final ClassNode SCRIPT_TYPE

  - ### BINDING_TYPE

    public static final ClassNode BINDING_TYPE

  - ### THROWABLE_TYPE

    public static final ClassNode THROWABLE_TYPE

  - ### boolean_TYPE

    public static final ClassNode boolean_TYPE

  - ### char_TYPE

    public static final ClassNode char_TYPE

  - ### byte_TYPE

    public static final ClassNode byte_TYPE

  - ### int_TYPE

    public static final ClassNode int_TYPE

  - ### long_TYPE

    public static final ClassNode long_TYPE

  - ### short_TYPE

    public static final ClassNode short_TYPE

  - ### double_TYPE

    public static final ClassNode double_TYPE

  - ### float_TYPE

    public static final ClassNode float_TYPE

  - ### Byte_TYPE

    public static final ClassNode Byte_TYPE

  - ### Short_TYPE

    public static final ClassNode Short_TYPE

  - ### Integer_TYPE

    public static final ClassNode Integer_TYPE

  - ### Long_TYPE

    public static final ClassNode Long_TYPE

  - ### Character_TYPE

    public static final ClassNode Character_TYPE

  - ### Float_TYPE

    public static final ClassNode Float_TYPE

  - ### Double_TYPE

    public static final ClassNode Double_TYPE

  - ### Boolean_TYPE

    public static final ClassNode Boolean_TYPE

  - ### BigInteger_TYPE

    public static final ClassNode BigInteger_TYPE

  - ### BigDecimal_TYPE

    public static final ClassNode BigDecimal_TYPE

  - ### Number_TYPE

    public static final ClassNode Number_TYPE

  - ### VOID_TYPE

    public static final ClassNode VOID_TYPE

  - ### void_WRAPPER_TYPE

    public static final ClassNode void_WRAPPER_TYPE

  - ### METACLASS_TYPE

    public static final ClassNode METACLASS_TYPE

  - ### Iterator_TYPE

    public static final ClassNode Iterator_TYPE

  - ### Annotation_TYPE

    public static final ClassNode Annotation_TYPE

  - ### ELEMENT_TYPE_TYPE

    public static final ClassNode ELEMENT_TYPE_TYPE

  - ### AUTOCLOSEABLE_TYPE

    public static final ClassNode AUTOCLOSEABLE_TYPE

  - ### CLONEABLE_TYPE

    public static final ClassNode CLONEABLE_TYPE

  - ### SERIALIZABLE_TYPE

    public static final ClassNode SERIALIZABLE_TYPE

  - ### SERIALIZEDLAMBDA_TYPE

    public static final ClassNode SERIALIZEDLAMBDA_TYPE

  - ### SEALED_TYPE

    public static final ClassNode SEALED_TYPE

  - ### OVERRIDE_TYPE

    public static final ClassNode OVERRIDE_TYPE

  - ### DEPRECATED_TYPE

    public static final ClassNode DEPRECATED_TYPE

  - ### MAP_TYPE

    public static final ClassNode MAP_TYPE

  - ### SET_TYPE

    public static final ClassNode SET_TYPE

  - ### LIST_TYPE

    public static final ClassNode LIST_TYPE

  - ### Enum_Type

    public static final ClassNode Enum_Type

  - ### CLASS_Type

    public static final ClassNode CLASS_Type

  - ### TUPLE_TYPE

    public static final ClassNode TUPLE_TYPE

  - ### STREAM_TYPE

    public static final ClassNode STREAM_TYPE

  - ### ITERABLE_TYPE

    public static final ClassNode ITERABLE_TYPE

  - ### REFERENCE_TYPE

    public static final ClassNode REFERENCE_TYPE

  - ### COLLECTION_TYPE

    public static final ClassNode COLLECTION_TYPE

  - ### COMPARABLE_TYPE

    public static final ClassNode COMPARABLE_TYPE

  - ### GROOVY_OBJECT_TYPE

    public static final ClassNode GROOVY_OBJECT_TYPE

  - ### GENERATED_LAMBDA_TYPE

    public static final ClassNode GENERATED_LAMBDA_TYPE

  - ### GENERATED_CLOSURE_Type

    public static final ClassNode GENERATED_CLOSURE_Type

  - ### GROOVY_INTERCEPTABLE_TYPE

    public static final ClassNode GROOVY_INTERCEPTABLE_TYPE

  - ### GROOVY_OBJECT_SUPPORT_TYPE

    public static final ClassNode GROOVY_OBJECT_SUPPORT_TYPE

  - ### DYNAMIC_TYPE

    @Deprecated public static final ClassNode DYNAMIC_TYPE
    Deprecated.

  - ### EMPTY_TYPE_ARRAY

    protected static final ClassNode[] EMPTY_TYPE_ARRAY

  - ### OBJECT

    public static final String OBJECT
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### ClassHelper

    public ClassHelper()

- ## Method Details

  - ### dynamicType

    public static ClassNode dynamicType()

  - ### makeCached

    public static ClassNode makeCached(Class c)

  - ### make

    public static ClassNode[] make(Class[] classes)
    Creates an array of ClassNodes using an array of classes. For each of the given classes a new ClassNode will be created
    Parameters:
      `classes` - an array of classes used to create the ClassNodes
    Returns:
      an array of ClassNodes
    See Also:
      - `make(Class)`

  - ### make

    public static ClassNode make(Class c)
    Creates a ClassNode using a given class. A new ClassNode object is only created if the class is not one of the predefined ones
    Parameters:
      `c` - class used to create the ClassNode
    Returns:
      ClassNode instance created from the given class

  - ### make

    public static ClassNode make(Class c, boolean includeGenerics)

  - ### makeWithoutCaching

    public static ClassNode makeWithoutCaching(Class c)

  - ### makeWithoutCaching

    public static ClassNode makeWithoutCaching(Class c, boolean includeGenerics)

  - ### makeWithoutCaching

    public static ClassNode makeWithoutCaching(String name)
    Creates a ClassNode using a given class. Unlike make(String) this method will not use the cache to create the ClassNode. This means the ClassNode created from this method using the same name will have a different reference
    Parameters:
      `name` - of the class the ClassNode is representing
    See Also:
      - `make(String)`

  - ### make

    public static ClassNode make(String name)
    Creates a ClassNode using a given class. If the name is one of the predefined ClassNodes then the corresponding ClassNode instance will be returned. If the name is null or of length 0 the dynamic type is returned
    Parameters:
      `name` - of the class the ClassNode is representing

  - ### getWrapper

    public static ClassNode getWrapper(ClassNode cn)
    Creates a ClassNode containing the wrapper of a ClassNode of primitive type. Any ClassNode representing a primitive type should be created using the predefined types used in class. The method will check the parameter for known references of ClassNode representing a primitive type. If Reference is found, then a ClassNode will be contained that represents the wrapper class. For example for boolean, the wrapper class is java.lang.Boolean.

    If the parameter is no primitive type, the redirected ClassNode will be returned

    Parameters:
      `cn` - the ClassNode containing a possible primitive type
    See Also:
      - `make(Class)`
      - `make(String)`

  - ### getUnwrapper

    public static ClassNode getUnwrapper(ClassNode cn)

  - ### isPrimitiveType

    public static boolean isPrimitiveType(ClassNode cn)
    Test to determine if a ClassNode is a primitive type. Note: this only works for ClassNodes created using a predefined ClassNode
    Parameters:
      `cn` - the ClassNode containing a possible primitive type
    Returns:
      true if the ClassNode is a primitive type
    See Also:
      - `make(Class)`
      - `make(String)`

  - ### isStaticConstantInitializerType

    public static boolean isStaticConstantInitializerType(ClassNode cn)
    Test to determine if a ClassNode is a type belongs to the list of types which are allowed to initialize constants directly in bytecode instead of using <cinit>

    Note: this only works for ClassNodes created using a predefined ClassNode

    Parameters:
      `cn` - the ClassNode to be tested
    Returns:
      true if the ClassNode is of int, float, long, double or String type
    See Also:
      - `make(Class)`
      - `make(String)`

  - ### isNumberType

    public static boolean isNumberType(ClassNode cn)

  - ### makeReference

    public static ClassNode makeReference()

  - ### isCachedType

    public static boolean isCachedType(ClassNode type)

  - ### isDynamicTyped

    public static boolean isDynamicTyped(ClassNode type)

  - ### isPrimitiveBoolean

    public static boolean isPrimitiveBoolean(ClassNode type)

  - ### isPrimitiveChar

    public static boolean isPrimitiveChar(ClassNode type)

  - ### isPrimitiveByte

    public static boolean isPrimitiveByte(ClassNode type)

  - ### isPrimitiveInt

    public static boolean isPrimitiveInt(ClassNode type)

  - ### isPrimitiveLong

    public static boolean isPrimitiveLong(ClassNode type)

  - ### isPrimitiveShort

    public static boolean isPrimitiveShort(ClassNode type)

  - ### isPrimitiveDouble

    public static boolean isPrimitiveDouble(ClassNode type)

  - ### isPrimitiveFloat

    public static boolean isPrimitiveFloat(ClassNode type)

  - ### isPrimitiveVoid

    public static boolean isPrimitiveVoid(ClassNode type)

  - ### isWrapperBoolean

    public static boolean isWrapperBoolean(ClassNode type)

  - ### isWrapperCharacter

    public static boolean isWrapperCharacter(ClassNode type)

  - ### isWrapperByte

    public static boolean isWrapperByte(ClassNode type)

  - ### isWrapperInteger

    public static boolean isWrapperInteger(ClassNode type)

  - ### isWrapperLong

    public static boolean isWrapperLong(ClassNode type)

  - ### isWrapperShort

    public static boolean isWrapperShort(ClassNode type)

  - ### isWrapperDouble

    public static boolean isWrapperDouble(ClassNode type)

  - ### isWrapperFloat

    public static boolean isWrapperFloat(ClassNode type)

  - ### isWrapperVoid

    public static boolean isWrapperVoid(ClassNode type)

  - ### isBigIntegerType

    public static boolean isBigIntegerType(ClassNode type)

  - ### isBigDecimalType

    public static boolean isBigDecimalType(ClassNode type)

  - ### isStringType

    public static boolean isStringType(ClassNode type)

  - ### isGStringType

    public static boolean isGStringType(ClassNode type)

  - ### isObjectType

    public static boolean isObjectType(ClassNode type)

  - ### isGroovyObjectType

    public static boolean isGroovyObjectType(ClassNode type)

  - ### isClassType

    public static boolean isClassType(ClassNode type)

  - ### isSAMType

    public static boolean isSAMType(ClassNode type)

  - ### isFunctionalInterface

    public static boolean isFunctionalInterface(ClassNode type)

  - ### isGeneratedFunction

    public static boolean isGeneratedFunction(ClassNode type)
    Checks if the type is a generated function, i.e. closure or lambda.
    Since:
      3.0.0

  - ### findSAM

    public static MethodNode findSAM(ClassNode type)
    Returns the single abstract method of a class node, if it is a SAM type, or null otherwise.
    Parameters:
      `type` - a type for which to search for a single abstract method
    Returns:
      the method node if type is a SAM type, null otherwise

  - ### getNextSuperClass

    public static ClassNode getNextSuperClass(ClassNode source, ClassNode target)
    Returns a super class or interface for a given class depending on supplied target. If the target is not a super class or interface, then null will be returned. For a non-primitive array type -- if the target is also an array -- returns an array of the component type's super class or interface.