[Java] Class GenericsUtils

  • org.codehaus.groovy.ast.tools.GenericsUtils

Utility methods to deal with generic types.

Field Summary

Fields
Modifiers Name Description
static GenericsType[] EMPTY_GENERICS_ARRAY
static String JAVA_LANG_OBJECT

Methods Summary

Methods
Type Params Return Type Name and description
static Map<String, ClassNode> addMethodGenerics(MethodNode current, Map<String, ClassNode> oldSpec)
static GenericsType[] alignGenericTypes(GenericsType[] redirectGenericTypes, GenericsType[] parameterizedTypes, GenericsType[] alignmentTarget)
Given a parameterized type and a generic type information, aligns actual type parameters.
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 MethodNode correctToGenericsSpec(Map<String, ClassNode> genericsSpec, MethodNode mn)
static ClassNode correctToGenericsSpec(Map<String, ClassNode> genericsSpec, GenericsType type)
static ClassNode correctToGenericsSpec(Map<String, ClassNode> genericsSpec, ClassNode type)
static ClassNode correctToGenericsSpecRecurse(Map<String, ClassNode> genericsSpec, ClassNode type)
static ClassNode[] correctToGenericsSpecRecurse(Map<String, ClassNode> genericsSpec, ClassNode[] types)
@since 2.4.1
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<String, GenericsType> extractPlaceholders(ClassNode cn)
static void extractPlaceholders(ClassNode node, Map<String, 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 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 ClassNode newClass(ClassNode type)
static ClassNode nonGeneric(ClassNode type)
static ClassNode parameterizeInterfaceGenerics(ClassNode hint, ClassNode target)
Interface class nodes retrieved from ClassNode.getInterfaces or ClassNode.getAllInterfaces are returned with generic type arguments.
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)

Inherited Methods Summary

Inherited Methods
Methods inherited from class Name
class Object wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Field Detail

public static final GenericsType[] EMPTY_GENERICS_ARRAY

public static final String JAVA_LANG_OBJECT

Method Detail

public static Map<String, ClassNode> addMethodGenerics(MethodNode current, Map<String, ClassNode> oldSpec)

@Deprecated public static GenericsType[] alignGenericTypes(GenericsType[] redirectGenericTypes, GenericsType[] parameterizedTypes, GenericsType[] alignmentTarget)

Given 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>
deprecated:
You shouldn't call this method because it is inherently unreliable
Parameters:
redirectGenericTypes - the type arguments or the redirect class node
parameterizedTypes - the actual type arguments used on this class node
alignmentTarget - the generic type arguments to which we want to align to
Returns:
aligned type arguments

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 spec
oldPlaceHolders - the old placeholders
Returns:
the new generics types

public static GenericsType buildWildcardType(ClassNode... types)

Generates a wildcard generic type in order to be used for checks against class nodes. See GenericsType#isCompatibleWith(org.codehaus.groovy.ast.ClassNode).

Parameters:
types - the type to be used as the wildcard upper bound
Returns:
a wildcard generics type

public static MethodNode correctToGenericsSpec(Map<String, ClassNode> genericsSpec, MethodNode mn)

public static ClassNode correctToGenericsSpec(Map<String, ClassNode> genericsSpec, GenericsType type)

public static ClassNode correctToGenericsSpec(Map<String, ClassNode> genericsSpec, ClassNode type)

public static ClassNode correctToGenericsSpecRecurse(Map<String, ClassNode> genericsSpec, ClassNode type)

public static ClassNode[] correctToGenericsSpecRecurse(Map<String, ClassNode> genericsSpec, ClassNode[] types)

Since:
2.4.1

public static ClassNode correctToGenericsSpecRecurse(Map<String, ClassNode> genericsSpec, ClassNode type, List<String> exclusions)

@SuppressWarnings("unchecked") public static Map<String, ClassNode> createGenericsSpec(ClassNode current)

public static Map<String, ClassNode> createGenericsSpec(ClassNode current, Map<String, ClassNode> oldSpec)

public static Map<String, GenericsType> extractPlaceholders(ClassNode cn)

public static void extractPlaceholders(ClassNode node, Map<String, GenericsType> map)

For a given classnode, fills in the supplied map with the parameterized types it defines.

Parameters:
node
map

public static void extractSuperClassGenerics(ClassNode type, ClassNode target, Map<String, ClassNode> spec)

public static ClassNode getSuperClass(ClassNode type, ClassNode target)

public static ClassNode makeClassSafe(Class klass)

public static ClassNode makeClassSafe0(ClassNode type, GenericsType... genericTypes)

public static ClassNode makeClassSafeWithGenerics(Class klass, ClassNode genericsType)

public static ClassNode makeClassSafeWithGenerics(ClassNode type, GenericsType... genericTypes)

public static ClassNode newClass(ClassNode type)

public static ClassNode nonGeneric(ClassNode type)

@Deprecated public static ClassNode parameterizeInterfaceGenerics(ClassNode hint, ClassNode target)

Interface class nodes retrieved from 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.

deprecated:
Use #parameterizeType instead
Parameters:
hint - the class node where generics types are parameterized
target - the interface we want to parameterize generics types
Returns:
a parameterized interface class node

public static ClassNode parameterizeType(ClassNode hint, ClassNode target)

Interface class nodes retrieved from 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.

Parameters:
hint - the class node where generics types are parameterized
target - the interface we want to parameterize generics types
Returns:
a parameterized interface class node

public static ClassNode[] parseClassNodesFromString(String option, SourceUnit sourceUnit, CompilationUnit compilationUnit, MethodNode mn, ASTNode usage)

© 2003-2020 The Apache Software Foundation
Licensed under the Apache license.
https://docs.groovy-lang.org/2.4.21/html/gapi/org/codehaus/groovy/ast/tools/GenericsUtils.html