Class JavaTypeDefinition
- java.lang.Object
-
- net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition
-
- All Implemented Interfaces:
TypeDefinition
public abstract class JavaTypeDefinition extends Object implements TypeDefinition
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
JavaTypeDefinition(TypeDefinitionType definitionType)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
equals(Object obj)
static JavaTypeDefinition
forClass(Class<?> clazz)
static JavaTypeDefinition
forClass(Class<?> clazz, JavaTypeDefinition... boundGenerics)
static JavaTypeDefinition
forClass(TypeDefinitionType type, Class<?> clazz, JavaTypeDefinition... boundGenerics)
static JavaTypeDefinition
forClass(TypeDefinitionType type, JavaTypeDefinition... intersectionTypes)
abstract JavaTypeDefinition
getAsSuper(Class<?> superClazz)
abstract JavaTypeDefinition
getComponentType()
Gets the component type of this type definition if it is an array type.TypeDefinitionType
getDefinitionType()
abstract JavaTypeDefinition
getElementType()
Gets the element type of this type definition if it is an array type.abstract JavaTypeDefinition
getEnclosingClass()
abstract Set<Class<?>>
getErasedSuperTypeSet()
abstract JavaTypeDefinition
getGenericType(int index)
abstract JavaTypeDefinition
getGenericType(String parameterName)
static int
getGenericTypeIndex(TypeVariable<?>[] typeParameters, String parameterName)
abstract JavaTypeDefinition
getJavaType(int index)
abstract int
getJavaTypeCount()
abstract Set<JavaTypeDefinition>
getSuperTypeSet()
protected abstract Set<JavaTypeDefinition>
getSuperTypeSet(Set<JavaTypeDefinition> destinationSet)
abstract Class<?>
getType()
Get the raw Class type of the definition.abstract int
getTypeParameterCount()
abstract int
hashCode()
abstract boolean
hasSameErasureAs(JavaTypeDefinition def)
abstract boolean
isArrayType()
abstract boolean
isClassOrInterface()
boolean
isExactType()
abstract boolean
isGeneric()
abstract boolean
isIntersectionType()
boolean
isLowerBound()
abstract boolean
isNullType()
abstract boolean
isPrimitive()
abstract boolean
isRawType()
Returns true if this type has type parameters and has not been parameterized, e.g.boolean
isUpperBound()
boolean
isWildcard()
abstract JavaTypeDefinition
resolveTypeDefinition(Type type)
abstract JavaTypeDefinition
resolveTypeDefinition(Type type, Method method, List<JavaTypeDefinition> methodTypeArgs)
protected abstract String
shallowString()
abstract String
toString()
abstract JavaTypeDefinition
withDimensions(int numDimensions)
Returns the type definition of the array type which has the given number of array dimensions, plus the dimensions of this type definition.
-
-
-
Constructor Detail
-
JavaTypeDefinition
protected JavaTypeDefinition(TypeDefinitionType definitionType)
-
-
Method Detail
-
forClass
public static JavaTypeDefinition forClass(TypeDefinitionType type, Class<?> clazz, JavaTypeDefinition... boundGenerics)
-
forClass
public static JavaTypeDefinition forClass(TypeDefinitionType type, JavaTypeDefinition... intersectionTypes)
-
forClass
public static JavaTypeDefinition forClass(Class<?> clazz)
-
forClass
public static JavaTypeDefinition forClass(Class<?> clazz, JavaTypeDefinition... boundGenerics)
-
getType
public abstract Class<?> getType()
Description copied from interface:TypeDefinition
Get the raw Class type of the definition.- Specified by:
getType
in interfaceTypeDefinition
- Returns:
- Raw Class type.
-
getEnclosingClass
public abstract JavaTypeDefinition getEnclosingClass()
-
isGeneric
public abstract boolean isGeneric()
-
getGenericTypeIndex
public static int getGenericTypeIndex(TypeVariable<?>[] typeParameters, String parameterName)
-
getGenericType
public abstract JavaTypeDefinition getGenericType(String parameterName)
-
getGenericType
public abstract JavaTypeDefinition getGenericType(int index)
-
resolveTypeDefinition
public abstract JavaTypeDefinition resolveTypeDefinition(Type type)
-
resolveTypeDefinition
public abstract JavaTypeDefinition resolveTypeDefinition(Type type, Method method, List<JavaTypeDefinition> methodTypeArgs)
-
isClassOrInterface
public abstract boolean isClassOrInterface()
-
isNullType
public abstract boolean isNullType()
-
isPrimitive
public abstract boolean isPrimitive()
-
hasSameErasureAs
public abstract boolean hasSameErasureAs(JavaTypeDefinition def)
-
getTypeParameterCount
public abstract int getTypeParameterCount()
-
isArrayType
public abstract boolean isArrayType()
-
getComponentType
public abstract JavaTypeDefinition getComponentType()
Gets the component type of this type definition if it is an array type. The component type of an array is the type is the same type as the array, with one less dimension, e.g. the component type ofint[][][]
isint[][]
.- Returns:
- The component type of this array type
- Throws:
IllegalStateException
- if this definition doesn't identify an array type- See Also:
getElementType()
-
getElementType
public abstract JavaTypeDefinition getElementType()
Gets the element type of this type definition if it is an array type. The component type of an array is the type is the same type as the array, stripped of all array dimensions, e.g. the element type ofint[][][]
isint
.- Returns:
- The element type of this array type, or this
type definition if
isArrayType()
returns false - See Also:
getComponentType()
-
withDimensions
public abstract JavaTypeDefinition withDimensions(int numDimensions)
Returns the type definition of the array type which has the given number of array dimensions, plus the dimensions of this type definition. Examples, assuming JavaTypeDefinition and Class are interchangeable (== is equality, not identity):int.class.withDimensions(3) == int[][][].class
int[].class.withDimensions(1) == int[][].class
c.withDimensions(0) == c
n > 0 => c.withDimensions(n).getComponentType() == c.withDimensions(n - 1)
- Parameters:
numDimensions
- Number of dimensions added to this type in the resulting array type- Returns:
- A new type definition, or this if numDimensions == 0
- Throws:
IllegalArgumentException
- if numDimensions < 0
-
getSuperTypeSet
public abstract Set<JavaTypeDefinition> getSuperTypeSet()
-
getSuperTypeSet
protected abstract Set<JavaTypeDefinition> getSuperTypeSet(Set<JavaTypeDefinition> destinationSet)
-
isRawType
public abstract boolean isRawType()
Returns true if this type has type parameters and has not been parameterized, e.g.List
instead ofList<T>
.
-
getAsSuper
public abstract JavaTypeDefinition getAsSuper(Class<?> superClazz)
-
isExactType
public final boolean isExactType()
-
isUpperBound
public final boolean isUpperBound()
-
isLowerBound
public final boolean isLowerBound()
-
isIntersectionType
public abstract boolean isIntersectionType()
-
isWildcard
public final boolean isWildcard()
-
getDefinitionType
public final TypeDefinitionType getDefinitionType()
-
getJavaType
public abstract JavaTypeDefinition getJavaType(int index)
-
getJavaTypeCount
public abstract int getJavaTypeCount()
-
shallowString
protected abstract String shallowString()
-
-