Package org.codehaus.groovy.ast
Class GenericsType
java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.GenericsType
- All Implemented Interfaces:
NodeMetaDataHandler
Represents generic type information for parameterized types in Groovy/Java, including type variables,
wildcard types, and type bounds. Supports placeholders for type parameters, wildcards with upper/lower bounds,
and tracks resolution state for multi-phase compilation. Provides compatibility checking for generic type constraints.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents the name of aGenericsTypefor use as a map key or in generic type comparisons. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGenericsType(ClassNode basicType) Creates a simple generics type with no bounds for a concrete type.GenericsType(ClassNode type, ClassNode[] upperBounds, ClassNode lowerBound) Creates a generics type with optional upper and lower bounds. -
Method Summary
Modifier and TypeMethodDescriptionReturns the lower bound for this wildcard type (e.g., Bound in "? super Bound"), or null if this is not a lower-bounded wildcard.getName()Returns the name of this generic type.getType()Returns the underlyingClassNodefor this generic type.Returns the upper bounds for this wildcard or placeholder type (e.g.,Boundin? extends BoundorBound1 & Bound2inT extends Bound1 & Bound2), or null if this type has no upper bounds.booleanisCompatibleWith(ClassNode classNode) Determines if the provided type is compatible with this generic type specification.booleanReturns true if this generic type represents a type variable placeholder (e.g., T in <T>).booleanReturns true if this generic type has been resolved during compilation phases.booleanReturns true if this generic type represents a wildcard (e.g., ? or ? extends/super Bound).voidSets the name of this generic type.voidsetPlaceholder(boolean placeholder) Marks this generic type as a placeholder type variable.voidsetResolved(boolean resolved) Marks this generic type as resolved.voidSets the underlyingClassNodefor this generic type.voidsetWildcard(boolean wildcard) Marks this generic type as a wildcard.toString()Methods inherited from class org.codehaus.groovy.ast.ASTNode
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visitMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler
copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData
-
Field Details
-
EMPTY_ARRAY
-
-
Constructor Details
-
GenericsType
Creates a generics type with optional upper and lower bounds. The type is marked as a placeholder if the provided type is a generics placeholder. -
GenericsType
Creates a simple generics type with no bounds for a concrete type.- Parameters:
basicType- theClassNoderepresenting the concrete type (never null)
-
-
Method Details
-
getType
Returns the underlyingClassNodefor this generic type.- Returns:
- the type
-
setType
Sets the underlyingClassNodefor this generic type.- Parameters:
type- theClassNodeto set (never null)- Throws:
NullPointerException- if type is null
-
toString
-
getName
Returns the name of this generic type. For wildcard types, returns "?"; otherwise returns the type name.- Returns:
- the type name
-
setName
Sets the name of this generic type.- Parameters:
name- the type name (never null)- Throws:
NullPointerException- if name is null
-
isResolved
public boolean isResolved()Returns true if this generic type has been resolved during compilation phases.- Returns:
- true if resolved
-
setResolved
public void setResolved(boolean resolved) Marks this generic type as resolved. Setting to true also implicitly sets resolved=true.- Parameters:
resolved- true to mark as resolved
-
isPlaceholder
public boolean isPlaceholder()Returns true if this generic type represents a type variable placeholder (e.g., T in <T>).- Returns:
- true if this is a placeholder type variable
-
setPlaceholder
public void setPlaceholder(boolean placeholder) Marks this generic type as a placeholder type variable. Setting to true also sets resolved=true and clears the wildcard flag, since placeholders and wildcards are mutually exclusive.- Parameters:
placeholder- true to mark as a placeholder
-
isWildcard
public boolean isWildcard()Returns true if this generic type represents a wildcard (e.g., ? or ? extends/super Bound).- Returns:
- true if this is a wildcard type
-
setWildcard
public void setWildcard(boolean wildcard) Marks this generic type as a wildcard. Clears the placeholder flag if set, since wildcards and placeholders are mutually exclusive.- Parameters:
wildcard- true to mark as a wildcard
-
getLowerBound
Returns the lower bound for this wildcard type (e.g., Bound in "? super Bound"), or null if this is not a lower-bounded wildcard.- Returns:
- the lower bound
ClassNode, or null
-
getUpperBounds
Returns the upper bounds for this wildcard or placeholder type (e.g.,Boundin? extends BoundorBound1 & Bound2inT extends Bound1 & Bound2), or null if this type has no upper bounds.- Returns:
- array of upper bound
ClassNodes, or null
-
isCompatibleWith
Determines if the provided type is compatible with this generic type specification. The check is complete and recursive, including nested generic parameters. Accounts for wildcards, placeholders, bounds, and generic type covariance rules.- Parameters:
classNode- theClassNodeto check for compatibility- Returns:
- true if classNode satisfies this generic type specification
-