Package org.codehaus.groovy.ast.tools
Class GenericsUtils
java.lang.Object
org.codehaus.groovy.ast.tools.GenericsUtils
Utility methods to deal with generic types.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddMethodGenerics(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 unreliablestatic GenericsType[]applyGenericsContextToPlaceHolders(Map<String, ClassNode> genericsSpec, GenericsType[] oldPlaceHolders) transforms generics types from an old context to a new context using the given spec.static GenericsTypebuildWildcardType(ClassNode... types) Generates a wildcard generic type in order to be used for checks against class nodes.static ClassNodecorrectToGenericsSpec(Map<String, ClassNode> genericsSpec, ClassNode type) static ClassNodecorrectToGenericsSpec(Map<String, ClassNode> genericsSpec, GenericsType type) static MethodNodecorrectToGenericsSpec(Map<String, ClassNode> genericsSpec, MethodNode mn) static ClassNodecorrectToGenericsSpecRecurse(Map<String, ClassNode> genericsSpec, ClassNode type) static ClassNode[]correctToGenericsSpecRecurse(Map<String, ClassNode> genericsSpec, ClassNode[] types) static ClassNodecorrectToGenericsSpecRecurse(Map<String, ClassNode> genericsSpec, ClassNode type, List<String> exclusions) createGenericsSpec(ClassNode current) createGenericsSpec(ClassNode current, Map<String, ClassNode> oldSpec) static Map<String, GenericsType> static voidextractPlaceholders(ClassNode node, Map<String, GenericsType> map) For a given classnode, fills in the supplied map with the parameterized types it defines.static voidstatic ClassNodegetSuperClass(ClassNode type, ClassNode target) static ClassNodemakeClassSafe(Class klass) static ClassNodemakeClassSafe0(ClassNode type, GenericsType... genericTypes) static ClassNodemakeClassSafeWithGenerics(Class klass, ClassNode genericsType) static ClassNodemakeClassSafeWithGenerics(ClassNode type, GenericsType... genericTypes) static ClassNodestatic ClassNodenonGeneric(ClassNode type) static ClassNodeparameterizeInterfaceGenerics(ClassNode hint, ClassNode target) Deprecated.Use #parameterizeType insteadstatic ClassNodeparameterizeType(ClassNode hint, ClassNode target) Interface class nodes retrieved fromClassNode.getInterfaces()orClassNode.getAllInterfaces()are returned with generic type arguments.static ClassNode[]parseClassNodesFromString(String option, SourceUnit sourceUnit, CompilationUnit compilationUnit, MethodNode mn, ASTNode usage)
-
Field Details
-
EMPTY_GENERICS_ARRAY
-
JAVA_LANG_OBJECT
- See Also:
-
-
Constructor Details
-
GenericsUtils
public GenericsUtils()
-
-
Method Details
-
alignGenericTypes
@Deprecated public static GenericsType[] alignGenericTypes(GenericsType[] redirectGenericTypes, GenericsType[] parameterizedTypes, GenericsType[] alignmentTarget) Deprecated.You shouldn't call this method because it is inherently unreliableGiven a parameterized type and a generic type information, aligns actual type parameters. For example, if a class uses generic type<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>
- Parameters:
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 to- Returns:
- aligned type arguments
-
buildWildcardType
Generates a wildcard generic type in order to be used for checks against class nodes. SeeGenericsType.isCompatibleWith(org.codehaus.groovy.ast.ClassNode).- Parameters:
types- the type to be used as the wildcard upper bound- Returns:
- a wildcard generics type
-
extractPlaceholders
-
extractPlaceholders
For a given classnode, fills in the supplied map with the parameterized types it defines.- Parameters:
node-map-
-
parameterizeInterfaceGenerics
Deprecated.Use #parameterizeType insteadInterface class nodes retrieved fromClassNode.getInterfaces()orClassNode.getAllInterfaces()are returned with generic type arguments. This method allows returning a parameterized interface given the parameterized class node which implements this interface.- Parameters:
hint- the class node where generics types are parameterizedtarget- the interface we want to parameterize generics types- Returns:
- a parameterized interface class node
-
parameterizeType
Interface class nodes retrieved fromClassNode.getInterfaces()orClassNode.getAllInterfaces()are returned with generic type arguments. This method allows returning a parameterized interface given the parameterized class node which implements this interface.- Parameters:
hint- the class node where generics types are parameterizedtarget- the interface we want to parameterize generics types- Returns:
- a parameterized interface class node
-
nonGeneric
-
newClass
-
makeClassSafe
-
makeClassSafeWithGenerics
-
makeClassSafe0
-
makeClassSafeWithGenerics
-
correctToGenericsSpec
-
correctToGenericsSpecRecurse
-
correctToGenericsSpecRecurse
public static ClassNode[] correctToGenericsSpecRecurse(Map<String, ClassNode> genericsSpec, ClassNode[] types) - Since:
- 2.4.1
-
correctToGenericsSpecRecurse
-
correctToGenericsSpec
public static ClassNode correctToGenericsSpec(Map<String, ClassNode> genericsSpec, GenericsType type) -
correctToGenericsSpec
-
createGenericsSpec
-
createGenericsSpec
-
addMethodGenerics
-
extractSuperClassGenerics
-
getSuperClass
-
parseClassNodesFromString
public static ClassNode[] parseClassNodesFromString(String option, SourceUnit sourceUnit, CompilationUnit compilationUnit, MethodNode mn, ASTNode usage) -
applyGenericsContextToPlaceHolders
public static GenericsType[] applyGenericsContextToPlaceHolders(Map<String, ClassNode> genericsSpec, GenericsType[] oldPlaceHolders) transforms generics types from an old context to a new context using the given spec. This method assumes all generics types will be placeholders. WARNING: The resulting generics types may or may not be placeholders after the transformation.- Parameters:
genericsSpec- the generics context information specoldPlaceHolders- the old placeholders- Returns:
- the new generics types
-