public class GenericsUtils extends Object
Modifier and Type | Field and Description |
---|---|
static GenericsType[] |
EMPTY_GENERICS_ARRAY |
static String |
JAVA_LANG_OBJECT |
Constructor and Description |
---|
GenericsUtils() |
Modifier and Type | Method and Description |
---|---|
static Map<String,ClassNode> |
addMethodGenerics(MethodNode current,
Map<String,ClassNode> oldSpec) |
static GenericsType[] |
alignGenericTypes(GenericsType[] redirectGenericTypes,
GenericsType[] parameterizedTypes,
GenericsType[] alignmentTarget)
Deprecated.
You shouldn't call this method because it is inherently unreliable
|
static GenericsType[] |
applyGenericsContextToPlaceHolders(Map<String,ClassNode> genericsSpec,
GenericsType[] oldPlaceHolders)
transforms generics types from an old context to a new context using the given spec.
|
static GenericsType |
buildWildcardType(ClassNode... types)
Generates a wildcard generic type in order to be used for checks against class nodes.
|
static void |
clearParameterizedTypeCache()
Clear the parameterized type cache
It is useful to IDE as the type being compiled are continuously being edited/altered, see GROOVY-8675
|
static ClassNode |
correctToGenericsSpec(Map<String,ClassNode> genericsSpec,
ClassNode type) |
static ClassNode |
correctToGenericsSpec(Map<String,ClassNode> genericsSpec,
GenericsType type) |
static MethodNode |
correctToGenericsSpec(Map<String,ClassNode> genericsSpec,
MethodNode mn) |
static ClassNode |
correctToGenericsSpecRecurse(Map<String,ClassNode> genericsSpec,
ClassNode type) |
static ClassNode[] |
correctToGenericsSpecRecurse(Map<String,ClassNode> genericsSpec,
ClassNode[] types) |
static ClassNode |
correctToGenericsSpecRecurse(Map<String,ClassNode> genericsSpec,
ClassNode type,
List<String> exclusions) |
static Map<String,ClassNode> |
createGenericsSpec(ClassNode current) |
static Map<String,ClassNode> |
createGenericsSpec(ClassNode current,
Map<String,ClassNode> oldSpec) |
static Map<GenericsType.GenericsTypeName,GenericsType> |
extractPlaceholders(ClassNode cn) |
static void |
extractPlaceholders(ClassNode node,
Map<GenericsType.GenericsTypeName,GenericsType> map)
For a given classnode, fills in the supplied map with the parameterized
types it defines.
|
static void |
extractSuperClassGenerics(ClassNode type,
ClassNode target,
Map<String,ClassNode> spec) |
static ClassNode |
findActualTypeByGenericsPlaceholderName(String placeholderName,
Map<GenericsType,GenericsType> genericsPlaceholderAndTypeMap)
Get the actual type according to the placeholder name
|
static ClassNode |
findParameterizedType(ClassNode genericsClass,
ClassNode actualType)
Get the parameterized type by search the whole class hierarchy according to generics class and actual receiver.
|
static ClassNode |
findParameterizedTypeFromCache(ClassNode genericsClass,
ClassNode actualType)
Try to get the parameterized type from the cache.
|
static ClassNode |
getSuperClass(ClassNode type,
ClassNode target) |
static ClassNode |
makeClassSafe(Class klass) |
static ClassNode |
makeClassSafe0(ClassNode type,
GenericsType... genericTypes) |
static ClassNode |
makeClassSafeWithGenerics(Class klass,
ClassNode genericsType) |
static ClassNode |
makeClassSafeWithGenerics(ClassNode type,
GenericsType... genericTypes) |
static Map<GenericsType,GenericsType> |
makeDeclaringAndActualGenericsTypeMap(ClassNode declaringClass,
ClassNode actualReceiver)
map declaring generics type to actual generics type, e.g.
|
static Map<GenericsType,GenericsType> |
makeDeclaringAndActualGenericsTypeMapOfExactType(ClassNode declaringClass,
ClassNode actualReceiver)
Backported from 3.0.0
The method is similar with
makeDeclaringAndActualGenericsTypeMap(ClassNode, ClassNode) ,
The main difference is that the method will try to map all placeholders found to the relevant exact types,
but the other will not try even if the parameterized type has placeholders |
static ClassNode |
newClass(ClassNode type) |
static ClassNode |
nonGeneric(ClassNode type) |
static ClassNode |
parameterizeInterfaceGenerics(ClassNode hint,
ClassNode target)
Deprecated.
Use #parameterizeType instead
|
static ClassNode |
parameterizeType(ClassNode hint,
ClassNode target)
Interface class nodes retrieved from
ClassNode.getInterfaces()
or ClassNode.getAllInterfaces() are returned with generic type
arguments. |
static ClassNode[] |
parseClassNodesFromString(String option,
SourceUnit sourceUnit,
CompilationUnit compilationUnit,
MethodNode mn,
ASTNode usage) |
static String |
toGenericTypesString(GenericsType[] genericsTypes) |
public static final GenericsType[] EMPTY_GENERICS_ARRAY
public static final String JAVA_LANG_OBJECT
@Deprecated public static GenericsType[] alignGenericTypes(GenericsType[] redirectGenericTypes, GenericsType[] parameterizedTypes, GenericsType[] alignmentTarget)
<T,U,V>(redirectGenericTypes), is used with actual type parameters
<java.lang.String, U,V>, then a class or interface using generic types
<T,V>will be aligned to
<java.lang.String,V>
redirectGenericTypes
- the type arguments or the redirect class nodeparameterizedTypes
- the actual type arguments used on this class nodealignmentTarget
- the generic type arguments to which we want to align topublic static GenericsType buildWildcardType(ClassNode... types)
GenericsType.isCompatibleWith(org.codehaus.groovy.ast.ClassNode)
.types
- the type to be used as the wildcard upper boundpublic static Map<GenericsType.GenericsTypeName,GenericsType> extractPlaceholders(ClassNode cn)
public static void extractPlaceholders(ClassNode node, Map<GenericsType.GenericsTypeName,GenericsType> map)
node
- the class node to checkmap
- the generics type information collectorpublic static String toGenericTypesString(GenericsType[] genericsTypes)
@Deprecated public static ClassNode parameterizeInterfaceGenerics(ClassNode hint, ClassNode target)
ClassNode.getInterfaces()
or ClassNode.getAllInterfaces()
are returned with generic type
arguments. This method allows returning a parameterized interface given the parameterized class
node which implements this interface.hint
- the class node where generics types are parameterizedtarget
- the interface we want to parameterize generics typespublic static ClassNode parameterizeType(ClassNode hint, ClassNode target)
ClassNode.getInterfaces()
or ClassNode.getAllInterfaces()
are returned with generic type
arguments. This method allows returning a parameterized interface given the parameterized class
node which implements this interface.hint
- the class node where generics types are parameterizedtarget
- the interface we want to parameterize generics typespublic static ClassNode makeClassSafeWithGenerics(Class klass, ClassNode genericsType)
public static ClassNode makeClassSafe0(ClassNode type, GenericsType... genericTypes)
public static ClassNode makeClassSafeWithGenerics(ClassNode type, GenericsType... genericTypes)
public static MethodNode correctToGenericsSpec(Map<String,ClassNode> genericsSpec, MethodNode mn)
public static ClassNode correctToGenericsSpecRecurse(Map<String,ClassNode> genericsSpec, ClassNode type)
public static ClassNode[] correctToGenericsSpecRecurse(Map<String,ClassNode> genericsSpec, ClassNode[] types)
public static ClassNode correctToGenericsSpecRecurse(Map<String,ClassNode> genericsSpec, ClassNode type, List<String> exclusions)
public static ClassNode correctToGenericsSpec(Map<String,ClassNode> genericsSpec, GenericsType type)
public static ClassNode correctToGenericsSpec(Map<String,ClassNode> genericsSpec, ClassNode type)
public static Map<String,ClassNode> createGenericsSpec(ClassNode current, Map<String,ClassNode> oldSpec)
public static Map<String,ClassNode> addMethodGenerics(MethodNode current, Map<String,ClassNode> oldSpec)
public static void extractSuperClassGenerics(ClassNode type, ClassNode target, Map<String,ClassNode> spec)
public static ClassNode[] parseClassNodesFromString(String option, SourceUnit sourceUnit, CompilationUnit compilationUnit, MethodNode mn, ASTNode usage)
public static GenericsType[] applyGenericsContextToPlaceHolders(Map<String,ClassNode> genericsSpec, GenericsType[] oldPlaceHolders)
genericsSpec
- the generics context information specoldPlaceHolders
- the old placeholderspublic static ClassNode findParameterizedTypeFromCache(ClassNode genericsClass, ClassNode actualType)
findParameterizedType(ClassNode, ClassNode)
public static ClassNode findParameterizedType(ClassNode genericsClass, ClassNode actualType)
findParameterizedTypeFromCache(ClassNode, ClassNode)
is strongly recommended for better performance.genericsClass
- the generics classactualType
- the actual typepublic static void clearParameterizedTypeCache()
public static Map<GenericsType,GenericsType> makeDeclaringAndActualGenericsTypeMap(ClassNode declaringClass, ClassNode actualReceiver)
public static Map<GenericsType,GenericsType> makeDeclaringAndActualGenericsTypeMapOfExactType(ClassNode declaringClass, ClassNode actualReceiver)
makeDeclaringAndActualGenericsTypeMap(ClassNode, ClassNode)
,
The main difference is that the method will try to map all placeholders found to the relevant exact types,
but the other will not try even if the parameterized type has placeholdersdeclaringClass
- the generics class node declaring the generics typesactualReceiver
- the sub-class class nodepublic static ClassNode findActualTypeByGenericsPlaceholderName(String placeholderName, Map<GenericsType,GenericsType> genericsPlaceholderAndTypeMap)
placeholderName
- the placeholder name, e.g. T, EgenericsPlaceholderAndTypeMap
- the result of makeDeclaringAndActualGenericsTypeMap(ClassNode, ClassNode)