Package org.codehaus.groovy.ast.tools
Class GenericsUtils
- java.lang.Object
-
- org.codehaus.groovy.ast.tools.GenericsUtils
-
public class GenericsUtils extends java.lang.ObjectUtility methods to deal with generic types.
-
-
Field Summary
Fields Modifier and Type Field Description static GenericsType[]EMPTY_GENERICS_ARRAYstatic java.lang.StringJAVA_LANG_OBJECT
-
Constructor Summary
Constructors Constructor Description GenericsUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.util.Map<java.lang.String,ClassNode>addMethodGenerics(MethodNode current, java.util.Map<java.lang.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(java.util.Map<java.lang.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(java.util.Map<java.lang.String,ClassNode> genericsSpec, ClassNode type)static ClassNodecorrectToGenericsSpec(java.util.Map<java.lang.String,ClassNode> genericsSpec, GenericsType type)static MethodNodecorrectToGenericsSpec(java.util.Map<java.lang.String,ClassNode> genericsSpec, MethodNode mn)static ClassNodecorrectToGenericsSpecRecurse(java.util.Map<java.lang.String,ClassNode> genericsSpec, ClassNode type)static ClassNode[]correctToGenericsSpecRecurse(java.util.Map<java.lang.String,ClassNode> genericsSpec, ClassNode[] types)static ClassNodecorrectToGenericsSpecRecurse(java.util.Map<java.lang.String,ClassNode> genericsSpec, ClassNode type, java.util.List<java.lang.String> exclusions)static java.util.Map<java.lang.String,ClassNode>createGenericsSpec(ClassNode current)static java.util.Map<java.lang.String,ClassNode>createGenericsSpec(ClassNode current, java.util.Map<java.lang.String,ClassNode> oldSpec)static java.util.Map<java.lang.String,GenericsType>extractPlaceholders(ClassNode cn)static voidextractPlaceholders(ClassNode node, java.util.Map<java.lang.String,GenericsType> map)For a given classnode, fills in the supplied map with the parameterized types it defines.static voidextractSuperClassGenerics(ClassNode type, ClassNode target, java.util.Map<java.lang.String,ClassNode> spec)static ClassNodegetSuperClass(ClassNode type, ClassNode target)static ClassNodemakeClassSafe(java.lang.Class klass)static ClassNodemakeClassSafe0(ClassNode type, GenericsType... genericTypes)static ClassNodemakeClassSafeWithGenerics(java.lang.Class klass, ClassNode genericsType)static ClassNodemakeClassSafeWithGenerics(ClassNode type, GenericsType... genericTypes)static ClassNodenewClass(ClassNode type)static 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(java.lang.String option, SourceUnit sourceUnit, CompilationUnit compilationUnit, MethodNode mn, ASTNode usage)
-
-
-
Field Detail
-
EMPTY_GENERICS_ARRAY
public static final GenericsType[] EMPTY_GENERICS_ARRAY
-
JAVA_LANG_OBJECT
public static final java.lang.String JAVA_LANG_OBJECT
- See Also:
- Constant Field Values
-
-
Method Detail
-
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
public static GenericsType buildWildcardType(ClassNode... types)
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
public static java.util.Map<java.lang.String,GenericsType> extractPlaceholders(ClassNode cn)
-
extractPlaceholders
public static void extractPlaceholders(ClassNode node, java.util.Map<java.lang.String,GenericsType> map)
For a given classnode, fills in the supplied map with the parameterized types it defines.- Parameters:
node-map-
-
parameterizeInterfaceGenerics
@Deprecated public static ClassNode parameterizeInterfaceGenerics(ClassNode hint, ClassNode target)
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
public static ClassNode parameterizeType(ClassNode hint, ClassNode target)
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
-
makeClassSafe
public static ClassNode makeClassSafe(java.lang.Class klass)
-
makeClassSafeWithGenerics
public static ClassNode makeClassSafeWithGenerics(java.lang.Class klass, ClassNode genericsType)
-
makeClassSafe0
public static ClassNode makeClassSafe0(ClassNode type, GenericsType... genericTypes)
-
makeClassSafeWithGenerics
public static ClassNode makeClassSafeWithGenerics(ClassNode type, GenericsType... genericTypes)
-
correctToGenericsSpec
public static MethodNode correctToGenericsSpec(java.util.Map<java.lang.String,ClassNode> genericsSpec, MethodNode mn)
-
correctToGenericsSpecRecurse
public static ClassNode correctToGenericsSpecRecurse(java.util.Map<java.lang.String,ClassNode> genericsSpec, ClassNode type)
-
correctToGenericsSpecRecurse
public static ClassNode[] correctToGenericsSpecRecurse(java.util.Map<java.lang.String,ClassNode> genericsSpec, ClassNode[] types)
- Since:
- 2.4.1
-
correctToGenericsSpecRecurse
public static ClassNode correctToGenericsSpecRecurse(java.util.Map<java.lang.String,ClassNode> genericsSpec, ClassNode type, java.util.List<java.lang.String> exclusions)
-
correctToGenericsSpec
public static ClassNode correctToGenericsSpec(java.util.Map<java.lang.String,ClassNode> genericsSpec, GenericsType type)
-
correctToGenericsSpec
public static ClassNode correctToGenericsSpec(java.util.Map<java.lang.String,ClassNode> genericsSpec, ClassNode type)
-
createGenericsSpec
public static java.util.Map<java.lang.String,ClassNode> createGenericsSpec(ClassNode current)
-
createGenericsSpec
public static java.util.Map<java.lang.String,ClassNode> createGenericsSpec(ClassNode current, java.util.Map<java.lang.String,ClassNode> oldSpec)
-
addMethodGenerics
public static java.util.Map<java.lang.String,ClassNode> addMethodGenerics(MethodNode current, java.util.Map<java.lang.String,ClassNode> oldSpec)
-
extractSuperClassGenerics
public static void extractSuperClassGenerics(ClassNode type, ClassNode target, java.util.Map<java.lang.String,ClassNode> spec)
-
parseClassNodesFromString
public static ClassNode[] parseClassNodesFromString(java.lang.String option, SourceUnit sourceUnit, CompilationUnit compilationUnit, MethodNode mn, ASTNode usage)
-
applyGenericsContextToPlaceHolders
public static GenericsType[] applyGenericsContextToPlaceHolders(java.util.Map<java.lang.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
-
-