public abstract class ClassOrInterfaceType extends ReferenceType
This abstract class corresponds to this grammar production in the JLS:
ClassOrInterfaceType: ClassType InterfaceTypeInterfaceType is syntactically the same as ClassType. Therefore,
ClassType
and InterfaceType
do not exist as subclasses of this class, Rather, the subclasses of this type
distinguish between types with parameters (ParameterizedType
), and types without (NonParameterizedType
).Modifier and Type | Field and Description |
---|---|
private static boolean |
debug
Set to true to enable debug output to standard out.
|
protected @Nullable ClassOrInterfaceType |
enclosingType
The enclosing type.
|
Constructor and Description |
---|
ClassOrInterfaceType() |
Modifier and Type | Method and Description |
---|---|
abstract ClassOrInterfaceType |
applyCaptureConversion()
Applies a capture conversion to this type.
|
(package private) ClassOrInterfaceType |
applyCaptureConversion(ClassOrInterfaceType type)
Applies capture conversion to the enclosing type of this type and adds the result as the
enclosing class of the given type.
|
boolean |
equals(@Nullable java.lang.Object obj) |
static ClassOrInterfaceType |
forClass(java.lang.Class<?> classType)
Translates a
Class object that represents a class or interface into a ClassOrInterfaceType object. |
static ClassOrInterfaceType |
forType(java.lang.reflect.Type type)
Creates a
ClassOrInterfaceType object for a given java.lang.reflect.Type
reference. |
java.util.Collection<ClassOrInterfaceType> |
getAllSupertypesInclusive()
Return all supertypes of this type, including itself.
|
java.lang.String |
getBinaryName()
Returns the binary name of this type, including type arguments if this is a parameterized type
(so, it isn't really a binary name).
|
@Nullable java.lang.String |
getCanonicalName()
Returns the name of this type as the "canonical name" of the underlying runtime class.
|
java.lang.String |
getFqName()
Returns the fully-qualified name of this type, including type arguments if this is a
parameterized type.
|
java.util.List<ClassOrInterfaceType> |
getImmediateSupertypes()
Return the immediate supertypes of this type.
|
@Nullable Substitution |
getInstantiatingSubstitution(ReferenceType goalType)
Computes a substitution that can be applied to the type variables of the generic goal type to
instantiate operations of this type, possibly inherited from from the goal type.
|
abstract java.util.List<ClassOrInterfaceType> |
getInterfaces()
Returns the interface types directly implemented by this class or interface type.
|
@Nullable InstantiatedType |
getMatchingSupertype(GenericClassType goalType)
Finds the parameterized type that is a supertype of this class that also matches the given
generic class.
|
@Nullable java.lang.Package |
getPackage()
Returns the package of the runtime class of this type.
|
(package private) java.lang.String |
getPackagePrefix()
Return the package part of a type name, including the final period.
|
abstract NonParameterizedType |
getRawtype()
Returns the non-parameterized form of this class type.
|
java.lang.String |
getSimpleName()
Returns the name of this class type.
|
abstract ClassOrInterfaceType |
getSuperclass()
Return the type for the superclass for this class.
|
java.util.Collection<ClassOrInterfaceType> |
getSuperTypes()
Return the set of all of the supertypes of this type.
|
java.util.List<TypeArgument> |
getTypeArguments()
Returns the type arguments for this type.
|
java.util.List<TypeVariable> |
getTypeParameters()
Returns the list of type parameters for this type.
|
java.lang.String |
getUnqualifiedBinaryName()
Returns the name of this type without package name, but with type arguments if parameterized,
and enclosing class if a member class.
|
boolean |
hasCaptureVariable()
Indicates whether this
ReferenceType has a capture variable. |
int |
hashCode() |
boolean |
hasWildcard()
Indicates whether this type has a wildcard anywhere within it.
|
abstract boolean |
isAbstract()
Indicate whether this class is abstract.
|
boolean |
isClassOrInterfaceType()
Indicate whether this type is a class or interface type.
|
boolean |
isGeneric(boolean ignoreWildcards)
Indicate whether this type is generic.
|
boolean |
isInstantiationOf(ReferenceType otherType)
Indicates whether this type is an instantiation of a more general type.
|
boolean |
isMemberClass()
Indicate whether this class is a member of another class.
|
boolean |
isNestedClass()
Indicate whether this class is a nested class.
|
boolean |
isParameterized()
Indicate whether this type is a parameterized type.
|
abstract boolean |
isStatic()
Indicates whether this class is static.
|
boolean |
isSubtypeOf(Type otherType)
Test whether this type is a subtype of the given type according to transitive closure of
definition of the direct supertype relation in section 4.10.2
of JLS for JavaSE 8.
|
abstract ClassOrInterfaceType |
substitute(Substitution substitution)
Applies a substitution to a
ReferenceType . |
(package private) ClassOrInterfaceType |
substitute(Substitution substitution,
ClassOrInterfaceType type)
Applies the substitution to the enclosing type of this type and adds the result as the
enclosing class of the given type.
|
getInstantiatingSubstitutionforTypeVariable, isAssignableFrom, isCaptureVariable, isReferenceType
compareTo, forFullyQualifiedName, forName, forValue, getRuntimeClass, getTypeforFullyQualifiedName, isArray, isAssignableFromTypeOf, isBoxedPrimitive, isClass, isEnum, isGeneric, isInterface, isNonreceiverType, isObject, isPrimitive, isRawtype, isString, isVariable, isVoid, runtimeClassIs, toString
private static boolean debug
protected @Nullable ClassOrInterfaceType enclosingType
public static ClassOrInterfaceType forClass(java.lang.Class<?> classType)
Class
object that represents a class or interface into a ClassOrInterfaceType
object. If the object has parameters, then delegates to ParameterizedType.forClass(Class)
. Otherwise, creates a NonParameterizedType
object
from the given object.classType
- the class type to translateClassOrInterfaceType
object created from the given class typepublic static ClassOrInterfaceType forType(java.lang.reflect.Type type)
ClassOrInterfaceType
object for a given java.lang.reflect.Type
reference. If type is a java.lang.reflect.ParameterizedType
, then calls ParameterizedType.forType(java.lang.reflect.Type)
. Otherwise, if type is a Class
object, calls forClass(Class)
.type
- the type referenceClassOrInterfaceType
object for the given typepublic boolean equals(@Nullable java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public abstract ClassOrInterfaceType substitute(Substitution substitution)
ReferenceType
. If the type is parameterized then replaces
type variables that occur, otherwise returns this type.
This abstract method forces typing of substitutions applied to ReferenceType
objects
without an explicit cast.
This abstract method allows substitutions to be applied to ClassOrInterfaceType
objects without casting.
substitute
in class ReferenceType
substitution
- the type substitutionfinal ClassOrInterfaceType substitute(Substitution substitution, ClassOrInterfaceType type)
substitution
- the substitution to apply to the enclosing typetype
- the type to which resulting enclosing type is to be added; will be side-effectedpublic abstract ClassOrInterfaceType applyCaptureConversion()
Type
applyCaptureConversion
in class ReferenceType
final ClassOrInterfaceType applyCaptureConversion(ClassOrInterfaceType type)
type
- this type with capture conversion applied; will be side-effectedpublic java.lang.String getSimpleName()
getSimpleName
in class Type
public @Nullable java.lang.String getCanonicalName()
Type
Type.getFqName()
except for types with type arguments. For java.util.List<T>
returns "java.util.List"
. Returns null
when Class<?>.getCanonicalName()
does for the underlying Class<?>
object (e.g., the type is
a local or anonymous class, or array type where the component type that has no canonical name).getCanonicalName
in class Type
public java.lang.String getFqName()
Type
java.util.List<T>
return "java.util.List<T>"
.public java.lang.String getBinaryName()
Type
java.util.List<T>
return "java.util.List<T>"
.getBinaryName
in class Type
public java.lang.String getUnqualifiedBinaryName()
Type
java.util.List<T>
would return
"List<T>"
.getUnqualifiedBinaryName
in class Type
public abstract java.util.List<ClassOrInterfaceType> getInterfaces()
Class.getGenericInterfaces()
. If no interfaces are
implemented, then returns the empty list.public @Nullable java.lang.Package getPackage()
java.lang.String getPackagePrefix()
public abstract NonParameterizedType getRawtype()
getRawtype
in class Type
public @Nullable InstantiatedType getMatchingSupertype(GenericClassType goalType)
class C<T> implements Comparator<T>
and class A
extends C<String>
, then when applied to A
, this method would return C<String>
when given C<T>
, and Comparator<String>
when given Comparator<E>
.
Returns null if there is no such type.
Performs a depth-first search of the supertype relation for this type. If the goal type is an interface, then searches the interfaces of this type first.
goalType
- the generic class typepublic @Nullable Substitution getInstantiatingSubstitution(ReferenceType goalType)
ReferenceType
If there is no unifying substitution, returns null
.
getInstantiatingSubstitution
in class ReferenceType
goalType
- the generic type for which a substitution is neededpublic abstract ClassOrInterfaceType getSuperclass()
Object
type if this type has no superclasspublic java.util.Collection<ClassOrInterfaceType> getSuperTypes()
public java.util.List<ClassOrInterfaceType> getImmediateSupertypes()
public java.util.Collection<ClassOrInterfaceType> getAllSupertypesInclusive()
public abstract boolean isAbstract()
public boolean isGeneric(boolean ignoreWildcards)
Type
public boolean isInstantiationOf(ReferenceType otherType)
For a general ReferenceType
, this is only true if the other type is the same, or the
other type is a type variable for which this type satisfies the bounds. Other cases are handled
by the overriding implementations isInstantiationOf(ReferenceType)
, InstantiatedType.isInstantiationOf(ReferenceType)
, and TypeVariable.isInstantiationOf(ReferenceType)
.
For a ClassOrInterfaceType
that is a member class, if otherType
is also a
member class, then the enclosing type of this type must instantiate the enclosing type of
otherType
.
isInstantiationOf
in class ReferenceType
otherType
- the general reference typepublic final boolean isNestedClass()
public final boolean isMemberClass()
public boolean isParameterized()
Type
C<T1,...,Tk>
that instantiates a generic class C<F1,...,Fk>
.
If inputType.isParameterized returns true, there are two possibilities: inputType
instanceof InstantiatedType
, or inputType is a member class and the enclosing type is a
parameterized type
isParameterized
in class Type
public abstract boolean isStatic()
public boolean isSubtypeOf(Type otherType)
isSubtypeOf
in class ReferenceType
otherType
- the possible supertypeReferenceType.isAssignableFrom(Type)
,
isSubtypeOf(Type)
public boolean hasWildcard()
Type
hasWildcard
in class Type
public boolean hasCaptureVariable()
Type
ReferenceType
has a capture variable.hasCaptureVariable
in class Type
public java.util.List<TypeArgument> getTypeArguments()
public java.util.List<TypeVariable> getTypeParameters()
ReferenceType
ArrayType
(such as E[]
), and subclasses of ParameterizedType
.getTypeParameters
in class ReferenceType
public boolean isClassOrInterfaceType()
Type
isClassOrInterfaceType
in class Type