Top Description Inners Fields Constructors Methods
org.codehaus.groovy.ast

public Class ClassHelper

extends Object
Class Inheritance
Imports
groovy.lang.Binding, .Closure, .GString, .GroovyInterceptable, .GroovyObject, .GroovyObjectSupport, .MetaClass, .Range, .Reference, .Script, .Tuple, .Tuple0, .Tuple1, .Tuple10, .Tuple11, .Tuple12, .Tuple13, .Tuple14, .Tuple15, .Tuple16, .Tuple2, .Tuple3, .Tuple4, .Tuple5, .Tuple6, .Tuple7, .Tuple8, .Tuple9, org.apache.groovy.util.Maps, org.codehaus.groovy.classgen.asm.util.TypeUtil, org.codehaus.groovy.runtime.GeneratedClosure, .GeneratedLambda, org.codehaus.groovy.transform.trait.Traits, org.codehaus.groovy.util.ManagedConcurrentMap, .ReferenceBundle, org.codehaus.groovy.vmplugin.VMPluginFactory, org.objectweb.asm.Opcodes, java.io.Serializable, java.lang.annotation.Annotation, .ElementType, java.lang.invoke.SerializedLambda, java.lang.ref.SoftReference, java.lang.reflect.Modifier, java.math.BigDecimal, .BigInteger, java.util.Iterator, .List, .Map, java.util.regex.Pattern

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final int
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
private static final Class<T>[]
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
protected static final ClassNode[]
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final String
public static final ClassNode
public static final ClassNode
private static final Map<ClassNode, ClassNode>
private static final String[]
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final ClassNode
public static final Class<T>[]
public static final ClassNode
private static final ClassNode[]
private static final int
public static final ClassNode
public static final ClassNode
private static final Map<ClassNode, ClassNode>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static MethodNode

Returns:

the method node if type is a SAM type, null otherwise
findSAM
(final ClassNode
a type for which to search for a single abstract method
type
)

Returns the single abstract method of a class node, if it is a SAM type, or null otherwise.

public static ClassNode
getNextSuperClass(final ClassNode source, final ClassNode target)

Returns a super class or interface for a given class depending on supplied target.

public static ClassNode
public static ClassNode
getWrapper(ClassNode
the ClassNode containing a possible primitive type
cn
)

Creates a ClassNode containing the wrapper of a ClassNode of primitive type.

private static boolean
public static boolean
public static boolean
public static boolean
isGeneratedFunction(final ClassNode type)

Checks if the type is a generated function, i.e. closure or lambda.

public static boolean
public static boolean

Returns:

true if the ClassNode is a primitive type
isPrimitiveType
(ClassNode
the ClassNode containing a possible primitive type
cn
)

Test to determine if a ClassNode is a primitive type.

public static boolean
isSAMType(final ClassNode type)

public static boolean

Returns:

true if the ClassNode is of int, float, long, double or String type
isStaticConstantInitializerType
(ClassNode
the ClassNode to be tested
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

public static ClassNode[]

Returns:

an array of ClassNodes
make
(Class<T>[]
an array of classes used to create the ClassNodes
classes
)

Creates an array of ClassNodes using an array of classes.

public static ClassNode

Returns:

ClassNode instance created from the given class
make
(Class<T>
class used to create the ClassNode
c
)

Creates a ClassNode using a given class.

public static ClassNode
make(Class<T> c, boolean includeGenerics)

public static ClassNode
make(String
of the class the ClassNode is representing
name
)

Creates a ClassNode using a given class.

public static ClassNode
public static ClassNode
public static ClassNode
public static ClassNode
makeWithoutCaching(Class<T> c, boolean includeGenerics)

public static ClassNode
makeWithoutCaching(String
of the class the ClassNode is representing
name
)

Creates a ClassNode using a given class.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ABSTRACT_STATIC_PRIVATEback to summary
private static final int ABSTRACT_STATIC_PRIVATE
Annotation_TYPEback to summary
public static final ClassNode Annotation_TYPE
AUTOCLOSEABLE_TYPEback to summary
public static final ClassNode AUTOCLOSEABLE_TYPE
BigDecimal_TYPEback to summary
public static final ClassNode BigDecimal_TYPE
BigInteger_TYPEback to summary
public static final ClassNode BigInteger_TYPE
BINDING_TYPEback to summary
public static final ClassNode BINDING_TYPE
boolean_TYPEback to summary
public static final ClassNode boolean_TYPE
Boolean_TYPEback to summary
public static final ClassNode Boolean_TYPE
byte_TYPEback to summary
public static final ClassNode byte_TYPE
Byte_TYPEback to summary
public static final ClassNode Byte_TYPE
char_TYPEback to summary
public static final ClassNode char_TYPE
Character_TYPEback to summary
public static final ClassNode Character_TYPE
CLASS_Typeback to summary
public static final ClassNode CLASS_Type
classesback to summary
private static final Class<T>[] classes
CLOSURE_TYPEback to summary
public static final ClassNode CLOSURE_TYPE
COMPARABLE_TYPEback to summary
public static final ClassNode COMPARABLE_TYPE
double_TYPEback to summary
public static final ClassNode double_TYPE
Double_TYPEback to summary
public static final ClassNode Double_TYPE
DYNAMIC_TYPEback to summary
public static final ClassNode DYNAMIC_TYPE
ELEMENT_TYPE_TYPEback to summary
public static final ClassNode ELEMENT_TYPE_TYPE
EMPTY_TYPE_ARRAYback to summary
protected static final ClassNode[] EMPTY_TYPE_ARRAY
Enum_Typeback to summary
public static final ClassNode Enum_Type
float_TYPEback to summary
public static final ClassNode float_TYPE
Float_TYPEback to summary
public static final ClassNode Float_TYPE
GENERATED_CLOSURE_Typeback to summary
public static final ClassNode GENERATED_CLOSURE_Type
GENERATED_LAMBDA_TYPEback to summary
public static final ClassNode GENERATED_LAMBDA_TYPE
GROOVY_INTERCEPTABLE_TYPEback to summary
public static final ClassNode GROOVY_INTERCEPTABLE_TYPE
GROOVY_OBJECT_SUPPORT_TYPEback to summary
public static final ClassNode GROOVY_OBJECT_SUPPORT_TYPE
GROOVY_OBJECT_TYPEback to summary
public static final ClassNode GROOVY_OBJECT_TYPE
GSTRING_TYPEback to summary
public static final ClassNode GSTRING_TYPE
int_TYPEback to summary
public static final ClassNode int_TYPE
Integer_TYPEback to summary
public static final ClassNode Integer_TYPE
Iterator_TYPEback to summary
public static final ClassNode Iterator_TYPE
LIST_TYPEback to summary
public static final ClassNode LIST_TYPE
long_TYPEback to summary
public static final ClassNode long_TYPE
Long_TYPEback to summary
public static final ClassNode Long_TYPE
MAP_TYPEback to summary
public static final ClassNode MAP_TYPE
METACLASS_TYPEback to summary
public static final ClassNode METACLASS_TYPE
Number_TYPEback to summary
public static final ClassNode Number_TYPE
OBJECTback to summary
public static final String OBJECT
OBJECT_TYPEback to summary
public static final ClassNode OBJECT_TYPE
PATTERN_TYPEback to summary
public static final ClassNode PATTERN_TYPE
PRIMITIVE_TYPE_TO_WRAPPER_TYPE_MAPback to summary
private static final Map<ClassNode, ClassNode> PRIMITIVE_TYPE_TO_WRAPPER_TYPE_MAP
primitiveClassNamesback to summary
private static final String[] primitiveClassNames
RANGE_TYPEback to summary
public static final ClassNode RANGE_TYPE
REFERENCE_TYPEback to summary
public static final ClassNode REFERENCE_TYPE
SCRIPT_TYPEback to summary
public static final ClassNode SCRIPT_TYPE
SERIALIZABLE_TYPEback to summary
public static final ClassNode SERIALIZABLE_TYPE
SERIALIZEDLAMBDA_TYPEback to summary
public static final ClassNode SERIALIZEDLAMBDA_TYPE
short_TYPEback to summary
public static final ClassNode short_TYPE
Short_TYPEback to summary
public static final ClassNode Short_TYPE
STRING_TYPEback to summary
public static final ClassNode STRING_TYPE
THROWABLE_TYPEback to summary
public static final ClassNode THROWABLE_TYPE
TUPLE_CLASSESback to summary
public static final Class<T>[] TUPLE_CLASSES
TUPLE_TYPEback to summary
public static final ClassNode TUPLE_TYPE
typesback to summary
private static final ClassNode[] types
VISIBILITYback to summary
private static final int VISIBILITY
VOID_TYPEback to summary
public static final ClassNode VOID_TYPE
void_WRAPPER_TYPEback to summary
public static final ClassNode void_WRAPPER_TYPE
WRAPPER_TYPE_TO_PRIMITIVE_TYPE_MAPback to summary
private static final Map<ClassNode, ClassNode> WRAPPER_TYPE_TO_PRIMITIVE_TYPE_MAP

Constructor Detail

ClassHelperback to summary
public ClassHelper()

Method Detail

findSAMback to summary
public static MethodNode findSAM(final ClassNode type)

Returns the single abstract method of a class node, if it is a SAM type, or null otherwise.

Parameters
type:ClassNode

a type for which to search for a single abstract method

Returns:MethodNode

the method node if type is a SAM type, null otherwise

getNextSuperClassback to summary
public static ClassNode getNextSuperClass(final ClassNode source, final 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.

getUnwrapperback to summary
public static ClassNode getUnwrapper(ClassNode cn)
getWrapperback to summary
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:ClassNode

the ClassNode containing a possible primitive type

See Also
make(Class), make(String)
hasUsableImplementationback to summary
private static boolean hasUsableImplementation(ClassNode c, MethodNode m)
isCachedTypeback to summary
public static boolean isCachedType(ClassNode type)
isFunctionalInterfaceback to summary
public static boolean isFunctionalInterface(final ClassNode type)
isGeneratedFunctionback to summary
public static boolean isGeneratedFunction(final ClassNode type)

Checks if the type is a generated function, i.e. closure or lambda.

Since
3.0.0
isNumberTypeback to summary
public static boolean isNumberType(ClassNode cn)
isPrimitiveTypeback to summary
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:ClassNode

the ClassNode containing a possible primitive type

Returns:boolean

true if the ClassNode is a primitive type

See Also
make(Class), make(String)
isSAMTypeback to summary
public static boolean isSAMType(final ClassNode type)
isStaticConstantInitializerTypeback to summary
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:ClassNode

the ClassNode to be tested

Returns:boolean

true if the ClassNode is of int, float, long, double or String type

See Also
make(Class), make(String)
makeback to summary
public static ClassNode[] make(Class<T>[] 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:Class<T>[]

an array of classes used to create the ClassNodes

Returns:ClassNode[]

an array of ClassNodes

See Also
make(Class)
makeback to summary
public static ClassNode make(Class<T> 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<T>

class used to create the ClassNode

Returns:ClassNode

ClassNode instance created from the given class

makeback to summary
public static ClassNode make(Class<T> c, boolean includeGenerics)
makeback to summary
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:String

of the class the ClassNode is representing

makeCachedback to summary
public static ClassNode makeCached(Class<T> c)
makeReferenceback to summary
public static ClassNode makeReference()
makeWithoutCachingback to summary
public static ClassNode makeWithoutCaching(Class<T> c)
makeWithoutCachingback to summary
public static ClassNode makeWithoutCaching(Class<T> c, boolean includeGenerics)
makeWithoutCachingback to summary
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:String

of the class the ClassNode is representing

See Also
make(String)
org.codehaus.groovy.ast back to summary

pack-priv Class ClassHelper.ClassHelperCache

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv static ManagedConcurrentMap<Class<T>, SoftReference<ClassNode>>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classCacheback to summary
pack-priv static ManagedConcurrentMap<Class<T>, SoftReference<ClassNode>> classCache

Constructor Detail

ClassHelperCacheback to summary
pack-priv ClassHelperCache()