Class ResolvedReferenceType
- java.lang.Object
-
- com.github.javaparser.resolution.types.ResolvedReferenceType
-
- All Implemented Interfaces:
ResolvedTypeParameterValueProvider
,ResolvedTypeParametrized
,ResolvedType
- Direct Known Subclasses:
ReferenceTypeImpl
public abstract class ResolvedReferenceType extends java.lang.Object implements ResolvedType, ResolvedTypeParametrized, ResolvedTypeParameterValueProvider
A ReferenceType like a class, an interface or an enum. Note that this type can contain also the values specified for the type parameters.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
JAVA_LANG_ENUM
protected static java.lang.String
JAVA_LANG_OBJECT
protected ResolvedReferenceTypeDeclaration
typeDeclaration
protected ResolvedTypeParametersMap
typeParametersMap
-
Constructor Summary
Constructors Constructor Description ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration)
ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration, java.util.List<ResolvedType> typeArguments)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ResolvedReferenceType
asReferenceType()
private ResolvedReferenceType
asResolvedReferenceType(java.lang.Object o)
protected boolean
compareConsideringTypeParameters(ResolvedReferenceType other)
private boolean
compareConsideringVariableTypeParameters(ResolvedType referenceType, ResolvedTypeVariable typeVariable)
protected abstract ResolvedReferenceType
create(ResolvedReferenceTypeDeclaration typeDeclaration)
protected ResolvedReferenceType
create(ResolvedReferenceTypeDeclaration typeDeclaration, ResolvedTypeParametersMap typeParametersMap)
protected abstract ResolvedReferenceType
create(ResolvedReferenceTypeDeclaration typeDeclaration, java.util.List<ResolvedType> typeParameters)
private static java.util.List<ResolvedType>
deriveParams(ResolvedReferenceTypeDeclaration typeDeclaration)
abstract ResolvedReferenceType
deriveTypeParameters(ResolvedTypeParametersMap typeParametersMap)
java.lang.String
describe()
boolean
equals(java.lang.Object o)
ResolvedType
erasure()
private java.util.List<ResolvedType>
erasureOfParamaters(ResolvedTypeParametersMap typeParametersMap)
abstract java.util.List<ResolvedReferenceType>
getAllAncestors()
Return all ancestors, that means all superclasses and interfaces.abstract java.util.List<ResolvedReferenceType>
getAllAncestors(java.util.function.Function<ResolvedReferenceTypeDeclaration,java.util.List<ResolvedReferenceType>> traverser)
Return all ancestors, that means all superclasses and interfaces.java.util.List<ResolvedReferenceType>
getAllClassesAncestors()
java.util.List<ResolvedFieldDeclaration>
getAllFieldsVisibleToInheritors()
Fields which are visible to inheritors.java.util.List<ResolvedReferenceType>
getAllInterfacesAncestors()
java.util.List<ResolvedMethodDeclaration>
getAllMethods()
Get a list of all the methods available on this type.java.util.List<ResolvedMethodDeclaration>
getAllMethodsVisibleToInheritors()
abstract java.util.Set<ResolvedFieldDeclaration>
getDeclaredFields()
Fields declared on this type.abstract java.util.Set<MethodUsage>
getDeclaredMethods()
Methods declared on this type.abstract java.util.List<ResolvedReferenceType>
getDirectAncestors()
Return direct ancestors, that means the superclasses and interfaces implemented directly.java.util.Optional<ResolvedType>
getFieldType(java.lang.String name)
The type of the field could be different from the one in the corresponding FieldDeclaration because type variables would be solved.java.util.Optional<ResolvedType>
getGenericParameterByName(java.lang.String name)
Get the type associated with the type parameter with the given name.java.lang.String
getId()
Id of the declaration.java.lang.String
getQualifiedName()
Qualified name of the declaration.java.util.Optional<ResolvedReferenceTypeDeclaration>
getTypeDeclaration()
Corresponding TypeDeclarationjava.util.List<Pair<ResolvedTypeParameterDeclaration,ResolvedType>>
getTypeParametersMap()
Get the values for all type parameters declared on this type.int
hashCode()
boolean
hasName()
Has the TypeDeclaration a name? Anonymous classes do not have one.abstract boolean
isAssignableBy(ResolvedType other)
This method checks if ThisType t = new OtherType() would compile.protected boolean
isCorrespondingBoxingType(java.lang.String typeName)
boolean
isJavaLangEnum()
boolean
isJavaLangObject()
We don't make this _ex_plicit in the data representation because that would affect codegen and make everything generate like<T extends Object>
instead of<T>
private boolean
isJavaObject(ResolvedType rt)
private boolean
isLazyType(java.lang.Object type)
boolean
isRawType()
boolean
isReferenceType()
Can this be seen as a ReferenceTypeUsage? In other words: is this a reference to a class, an interface or an enum?boolean
isUnboxable()
boolean
isUnboxableTo(ResolvedPrimitiveType primitiveType)
ResolvedType
replaceTypeVariables(ResolvedTypeParameterDeclaration tpToReplace, ResolvedType replaced, java.util.Map<ResolvedTypeParameterDeclaration,ResolvedType> inferredTypes)
Replace all variables referring to the given TypeParameter with the given value.java.lang.String
toDescriptor()
abstract ResolvedType
toRawType()
java.lang.String
toString()
java.util.Optional<ResolvedPrimitiveType>
toUnboxedType()
abstract ResolvedType
transformTypeParameters(ResolvedTypeTransformer transformer)
Execute a transformation on all the type parameters of this element.ResolvedTypeParametersMap
typeParametersMap()
java.util.List<ResolvedType>
typeParametersValues()
Get the values for all type parameters declared on this type.java.util.Optional<ResolvedType>
typeParamValue(ResolvedTypeParameterDeclaration typeParameterDeclaration)
Calculate the value for the given type parameter.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.javaparser.resolution.types.ResolvedType
arrayLevel, asArrayType, asConstraintType, asPrimitive, asTypeParameter, asTypeVariable, asUnionType, asWildcard, isArray, isConstraint, isInferenceVariable, isNull, isNumericType, isPrimitive, isReference, isTypeVariable, isUnionType, isVoid, isWildcard, mention, replaceTypeVariables, solveGenericTypes
-
Methods inherited from interface com.github.javaparser.resolution.types.parametrization.ResolvedTypeParameterValueProvider
useThisTypeParametersOnTheGivenType
-
-
-
-
Field Detail
-
JAVA_LANG_ENUM
protected static java.lang.String JAVA_LANG_ENUM
-
JAVA_LANG_OBJECT
protected static java.lang.String JAVA_LANG_OBJECT
-
typeDeclaration
protected ResolvedReferenceTypeDeclaration typeDeclaration
-
typeParametersMap
protected ResolvedTypeParametersMap typeParametersMap
-
-
Constructor Detail
-
ResolvedReferenceType
public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration)
-
ResolvedReferenceType
public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration, java.util.List<ResolvedType> typeArguments)
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
isLazyType
private boolean isLazyType(java.lang.Object type)
-
asResolvedReferenceType
private ResolvedReferenceType asResolvedReferenceType(java.lang.Object o)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
isReferenceType
public final boolean isReferenceType()
Description copied from interface:ResolvedType
Can this be seen as a ReferenceTypeUsage? In other words: is this a reference to a class, an interface or an enum?- Specified by:
isReferenceType
in interfaceResolvedType
-
asReferenceType
public ResolvedReferenceType asReferenceType()
- Specified by:
asReferenceType
in interfaceResolvedType
-
describe
public java.lang.String describe()
- Specified by:
describe
in interfaceResolvedType
-
transformTypeParameters
public abstract ResolvedType transformTypeParameters(ResolvedTypeTransformer transformer)
Execute a transformation on all the type parameters of this element.
-
replaceTypeVariables
public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToReplace, ResolvedType replaced, java.util.Map<ResolvedTypeParameterDeclaration,ResolvedType> inferredTypes)
Description copied from interface:ResolvedType
Replace all variables referring to the given TypeParameter with the given value. By replacing these values I could also infer some type equivalence. Those would be collected in the given map.- Specified by:
replaceTypeVariables
in interfaceResolvedType
-
isAssignableBy
public abstract boolean isAssignableBy(ResolvedType other)
This method checks if ThisType t = new OtherType() would compile.- Specified by:
isAssignableBy
in interfaceResolvedType
-
getAllAncestors
public abstract java.util.List<ResolvedReferenceType> getAllAncestors()
Return all ancestors, that means all superclasses and interfaces. This list should always include Object (unless this is a reference to Object). The type typeParametersValues should be expressed in terms of this type typeParametersValues. The default order of presenting ancestors corresponds to a search in depth.For example, given:
class Foo<A, B> {} class Bar<C> extends Foo<C, String> {}
a call to getAllAncestors on a reference to Bar having type parameter Boolean should include Foo<Boolean, String>.
-
getAllAncestors
public abstract java.util.List<ResolvedReferenceType> getAllAncestors(java.util.function.Function<ResolvedReferenceTypeDeclaration,java.util.List<ResolvedReferenceType>> traverser)
Return all ancestors, that means all superclasses and interfaces. This list should always include Object (unless this is a reference to Object). The type typeParametersValues should be expressed in terms of this type typeParametersValues.
-
getDirectAncestors
public abstract java.util.List<ResolvedReferenceType> getDirectAncestors()
Return direct ancestors, that means the superclasses and interfaces implemented directly. This list should include Object if the class has no other superclass or the interface is not extending another interface. There is an exception for Object itself.
-
getAllInterfacesAncestors
public final java.util.List<ResolvedReferenceType> getAllInterfacesAncestors()
-
getAllClassesAncestors
public final java.util.List<ResolvedReferenceType> getAllClassesAncestors()
-
getGenericParameterByName
public java.util.Optional<ResolvedType> getGenericParameterByName(java.lang.String name)
Get the type associated with the type parameter with the given name. It returns Optional.empty unless the type declaration declares a type parameter with the given name.- Specified by:
getGenericParameterByName
in interfaceResolvedTypeParameterValueProvider
-
typeParametersValues
public java.util.List<ResolvedType> typeParametersValues()
Get the values for all type parameters declared on this type. The list can be empty for raw types.
-
getTypeParametersMap
public java.util.List<Pair<ResolvedTypeParameterDeclaration,ResolvedType>> getTypeParametersMap()
Get the values for all type parameters declared on this type. In case of raw types the values correspond to TypeVariables.
-
typeParametersMap
public ResolvedTypeParametersMap typeParametersMap()
- Specified by:
typeParametersMap
in interfaceResolvedTypeParametrized
-
getTypeDeclaration
public final java.util.Optional<ResolvedReferenceTypeDeclaration> getTypeDeclaration()
Corresponding TypeDeclaration
-
getFieldType
public java.util.Optional<ResolvedType> getFieldType(java.lang.String name)
The type of the field could be different from the one in the corresponding FieldDeclaration because type variables would be solved.
-
hasName
public boolean hasName()
Has the TypeDeclaration a name? Anonymous classes do not have one.
-
getQualifiedName
public java.lang.String getQualifiedName()
Qualified name of the declaration.
-
getId
public java.lang.String getId()
Id of the declaration. It corresponds to the qualified name, unless for local classes.
-
getDeclaredMethods
public abstract java.util.Set<MethodUsage> getDeclaredMethods()
Methods declared on this type.
-
getDeclaredFields
public abstract java.util.Set<ResolvedFieldDeclaration> getDeclaredFields()
Fields declared on this type.
-
isRawType
public boolean isRawType()
-
typeParamValue
public java.util.Optional<ResolvedType> typeParamValue(ResolvedTypeParameterDeclaration typeParameterDeclaration)
Description copied from interface:ResolvedTypeParameterValueProvider
Calculate the value for the given type parameter. It could be inherited.- Specified by:
typeParamValue
in interfaceResolvedTypeParameterValueProvider
-
toRawType
public abstract ResolvedType toRawType()
- Returns:
- A copy of the current reference type, without type parameters.
-
getAllMethods
public java.util.List<ResolvedMethodDeclaration> getAllMethods()
Get a list of all the methods available on this type. This list includes methods declared in this type and methods inherited. This list includes methods of all sort of visibility. However it does not include methods that have been overwritten.
-
getAllFieldsVisibleToInheritors
public java.util.List<ResolvedFieldDeclaration> getAllFieldsVisibleToInheritors()
Fields which are visible to inheritors. They include all inherited fields which are visible to this type plus all declared fields which are not private.
-
getAllMethodsVisibleToInheritors
public java.util.List<ResolvedMethodDeclaration> getAllMethodsVisibleToInheritors()
-
create
protected abstract ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration, java.util.List<ResolvedType> typeParameters)
-
create
protected ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration, ResolvedTypeParametersMap typeParametersMap)
-
create
protected abstract ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration)
-
isCorrespondingBoxingType
protected boolean isCorrespondingBoxingType(java.lang.String typeName)
-
compareConsideringTypeParameters
protected boolean compareConsideringTypeParameters(ResolvedReferenceType other)
-
compareConsideringVariableTypeParameters
private boolean compareConsideringVariableTypeParameters(ResolvedType referenceType, ResolvedTypeVariable typeVariable)
-
deriveParams
private static java.util.List<ResolvedType> deriveParams(ResolvedReferenceTypeDeclaration typeDeclaration)
-
deriveTypeParameters
public abstract ResolvedReferenceType deriveTypeParameters(ResolvedTypeParametersMap typeParametersMap)
-
isJavaLangObject
public boolean isJavaLangObject()
We don't make this _ex_plicit in the data representation because that would affect codegen and make everything generate like<T extends Object>
instead of<T>
- Returns:
- true, if this represents
java.lang.Object
- See Also:
ResolvedReferenceTypeDeclaration.isJavaLangObject()
, https://github.com/javaparser/javaparser/issues/2044
-
isJavaLangEnum
public boolean isJavaLangEnum()
- Returns:
- true, if this represents
java.lang.Enum
- See Also:
ResolvedReferenceTypeDeclaration.isJavaLangEnum()
-
isUnboxable
public boolean isUnboxable()
-
isUnboxableTo
public boolean isUnboxableTo(ResolvedPrimitiveType primitiveType)
-
toUnboxedType
public java.util.Optional<ResolvedPrimitiveType> toUnboxedType()
-
erasure
public ResolvedType erasure()
- Specified by:
erasure
in interfaceResolvedType
-
erasureOfParamaters
private java.util.List<ResolvedType> erasureOfParamaters(ResolvedTypeParametersMap typeParametersMap)
-
isJavaObject
private boolean isJavaObject(ResolvedType rt)
-
toDescriptor
public java.lang.String toDescriptor()
- Specified by:
toDescriptor
in interfaceResolvedType
-
-