Interface ResolvedReferenceTypeDeclaration
-
- All Superinterfaces:
AssociableToAST,ResolvedDeclaration,ResolvedTypeDeclaration,ResolvedTypeParametrizable
- All Known Subinterfaces:
ResolvedAnnotationDeclaration,ResolvedClassDeclaration,ResolvedEnumDeclaration,ResolvedInterfaceDeclaration,ResolvedRecordDeclaration
public interface ResolvedReferenceTypeDeclaration extends ResolvedTypeDeclaration, ResolvedTypeParametrizable
- Author:
- Federico Tomassetti
-
-
Field Summary
Fields Modifier and Type Field Description static Function<ResolvedReferenceTypeDeclaration,List<ResolvedReferenceType>>breadthFirstFuncstatic Function<ResolvedReferenceTypeDeclaration,List<ResolvedReferenceType>>depthFirstFuncstatic StringJAVA_IO_SERIALIZABLEstatic StringJAVA_LANG_COMPARABLEstatic StringJAVA_LANG_ENUMstatic StringJAVA_LANG_OBJECTstatic StringJAVA_LANG_RECORD
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default ResolvedReferenceTypeDeclarationasReferenceType()default booleancanBeAssignedTo(ResolvedReferenceTypeDeclaration other)Can we assign instances of the type defined by this declaration to variables having the type defined by the given type?default Optional<ResolvedTypeParameterDeclaration>findTypeParameter(String name)Find the closest TypeParameterDeclaration with the given name.default List<ResolvedReferenceType>getAllAncestors()The list of all the ancestors of the current declaration, direct and indirect.default List<ResolvedReferenceType>getAllAncestors(Function<ResolvedReferenceTypeDeclaration,List<ResolvedReferenceType>> traverser)The list of all the ancestors of the current declaration, direct and indirect.List<ResolvedFieldDeclaration>getAllFields()Return a list of all fields, either declared in this declaration or inherited.Set<MethodUsage>getAllMethods()Return a list of all the methods declared of this type declaration, either declared or inherited.default List<ResolvedFieldDeclaration>getAllNonStaticFields()Return a list of all the non static fields, either declared or inherited.default List<ResolvedFieldDeclaration>getAllStaticFields()Return a list of all the static fields, either declared or inherited.default List<ResolvedReferenceType>getAncestors()Resolves the types of all direct ancestors (i.e., the directly extended class and the directly implemented interfaces) and returns the list of ancestors as a list of resolved reference types.List<ResolvedReferenceType>getAncestors(boolean acceptIncompleteList)Resolves the types of all direct ancestors (i.e., the directly extended class and the directly implemented interfaces) and returns the list of ancestors as a list of resolved reference types.List<ResolvedConstructorDeclaration>getConstructors()default Optional<ResolvedAnnotationDeclaration>getDeclaredAnnotation(String name)Returns the resolved annotation corresponding to the specified name and declared in this type declaration.default Set<ResolvedAnnotationDeclaration>getDeclaredAnnotations()Return a collection of all annotations declared in this type declaration.default List<ResolvedFieldDeclaration>getDeclaredFields()Return a list of all the fields declared in this type.Set<ResolvedMethodDeclaration>getDeclaredMethods()Return a list of all the methods declared in this type declaration.default ResolvedFieldDeclarationgetField(String name)Note that the type of the field should be expressed using the type variables of this particular type.default ResolvedFieldDeclarationgetVisibleField(String name)Consider only field or inherited field which is not private.default List<ResolvedFieldDeclaration>getVisibleFields()Return a list of all fields declared and the inherited ones which are not private.default booleanhasAnnotation(String qualifiedName)Has the type at least one annotation declared or inherited having the specified qualified name?booleanhasDirectlyAnnotation(String qualifiedName)Has the type at least one annotation declared having the specified qualified name?default booleanhasField(String name)Has this type a field with the given name?default booleanhasVisibleField(String name)Either a declared field or inherited field which is not private.booleanisAssignableBy(ResolvedReferenceTypeDeclaration other)Can we assign instances of the given type to variables having the type defined by this declaration?booleanisAssignableBy(ResolvedType type)Can we assign instances of the given type to variables having the type defined by this declaration?booleanisFunctionalInterface()This means that the type has a functional method.default booleanisInheritedAnnotation(String name)Returns true if the specified annotation is inheritable.default booleanisJavaLangEnum()default booleanisJavaLangObject()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>default booleanisJavaLangRecord()default booleanisReferenceType()Is this the declaration of a reference type?-
Methods inherited from interface com.github.javaparser.resolution.declarations.AssociableToAST
toAst, toAst
-
Methods inherited from interface com.github.javaparser.resolution.declarations.ResolvedDeclaration
asEnumConstant, asField, asMethod, asParameter, asTypePattern, getName, hasName, isEnumConstant, isField, isMethod, isParameter, isTypePattern, isVariable
-
Methods inherited from interface com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration
asAnnotation, asClass, asEnum, asInterface, asRecord, asType, asTypeParameter, containerType, getClassName, getId, getInternalType, getPackageName, getQualifiedName, hasInternalType, internalTypes, isAnnotation, isAnonymousClass, isClass, isEnum, isInterface, isRecord, isType, isTypeParameter
-
Methods inherited from interface com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable
getTypeParameters, isGeneric
-
-
-
-
Field Detail
-
JAVA_LANG_ENUM
static final String JAVA_LANG_ENUM
-
JAVA_LANG_COMPARABLE
static final String JAVA_LANG_COMPARABLE
-
JAVA_IO_SERIALIZABLE
static final String JAVA_IO_SERIALIZABLE
-
JAVA_LANG_OBJECT
static final String JAVA_LANG_OBJECT
-
JAVA_LANG_RECORD
static final String JAVA_LANG_RECORD
- See Also:
- Constant Field Values
-
depthFirstFunc
static final Function<ResolvedReferenceTypeDeclaration,List<ResolvedReferenceType>> depthFirstFunc
-
breadthFirstFunc
static final Function<ResolvedReferenceTypeDeclaration,List<ResolvedReferenceType>> breadthFirstFunc
-
-
Method Detail
-
asReferenceType
default ResolvedReferenceTypeDeclaration asReferenceType()
- Specified by:
asReferenceTypein interfaceResolvedTypeDeclaration
-
isReferenceType
default boolean isReferenceType()
Description copied from interface:ResolvedTypeDeclarationIs this the declaration of a reference type?- Specified by:
isReferenceTypein interfaceResolvedTypeDeclaration
-
getAncestors
default List<ResolvedReferenceType> getAncestors()
Resolves the types of all direct ancestors (i.e., the directly extended class and the directly implemented interfaces) and returns the list of ancestors as a list of resolved reference types.In case any ancestor cannot be resolved, an
UnsolvedSymbolExceptionis thrown. In order to obtain a list of only the resolvable direct ancestors, usegetAncestors(boolean)and pass the valuetrue.Note that an ancestor can be parametrized types with values specified. For example:
class A implements Comparable<String> {}
In this case the ancestor is Comparable<String>
- Returns:
- The list of resolved ancestors.
- Throws:
UnsolvedSymbolException- if some ancestor could not be resolved.
-
getAncestors
List<ResolvedReferenceType> getAncestors(boolean acceptIncompleteList)
Resolves the types of all direct ancestors (i.e., the directly extended class and the directly implemented interfaces) and returns the list of ancestors as a list of resolved reference types.If
acceptIncompleteListisfalse, then anUnsolvedSymbolExceptionis thrown if any ancestor cannot be resolved. Otherwise, a list of only the resolvable direct ancestors is returned.- Parameters:
acceptIncompleteList- When set tofalse, this method throws anUnsolvedSymbolExceptionif one or more ancestor could not be resolved. When set totrue, this method does not throw anUnsolvedSymbolException, but the list of returned ancestors may be incomplete in case one or more ancestor could not be resolved.- Returns:
- The list of resolved ancestors.
- Throws:
UnsolvedSymbolException- if some ancestor could not be resolved andacceptIncompleteListis set tofalse.
-
getAllAncestors
default List<ResolvedReferenceType> getAllAncestors()
The list of all the ancestors of the current declaration, direct and indirect. This list does not contains duplicates with the exact same type parameters. For example if A inherits from B, and B inherits from C and implements D, and C inherits from E By default the traversal is depth first
-
getAllAncestors
default List<ResolvedReferenceType> getAllAncestors(Function<ResolvedReferenceTypeDeclaration,List<ResolvedReferenceType>> traverser)
The list of all the ancestors of the current declaration, direct and indirect. This list does not contains duplicates with the exact same type parameters. For example if A inherits from B, and B inherits from C and implements D, and C inherits from E Apply the specified traversal
-
getField
default ResolvedFieldDeclaration getField(String name)
Note that the type of the field should be expressed using the type variables of this particular type. Consider for example:class Foo
{ E field; } class Bar extends Foo
{ } When calling getField("field") on Foo I should get a FieldDeclaration with type E, while calling it on Bar I should get a FieldDeclaration with type String.
-
getVisibleField
default ResolvedFieldDeclaration getVisibleField(String name)
Consider only field or inherited field which is not private.
-
hasField
default boolean hasField(String name)
Has this type a field with the given name?
-
hasVisibleField
default boolean hasVisibleField(String name)
Either a declared field or inherited field which is not private.
-
getAllFields
List<ResolvedFieldDeclaration> getAllFields()
Return a list of all fields, either declared in this declaration or inherited.
-
getVisibleFields
default List<ResolvedFieldDeclaration> getVisibleFields()
Return a list of all fields declared and the inherited ones which are not private.
-
getAllNonStaticFields
default List<ResolvedFieldDeclaration> getAllNonStaticFields()
Return a list of all the non static fields, either declared or inherited.
-
getAllStaticFields
default List<ResolvedFieldDeclaration> getAllStaticFields()
Return a list of all the static fields, either declared or inherited.
-
getDeclaredFields
default List<ResolvedFieldDeclaration> getDeclaredFields()
Return a list of all the fields declared in this type.
-
getDeclaredMethods
Set<ResolvedMethodDeclaration> getDeclaredMethods()
Return a list of all the methods declared in this type declaration.
-
getAllMethods
Set<MethodUsage> getAllMethods()
Return a list of all the methods declared of this type declaration, either declared or inherited. Note that it should not include overridden methods.
-
isAssignableBy
boolean isAssignableBy(ResolvedType type)
Can we assign instances of the given type to variables having the type defined by this declaration?
-
canBeAssignedTo
default boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other)
Can we assign instances of the type defined by this declaration to variables having the type defined by the given type?
-
isAssignableBy
boolean isAssignableBy(ResolvedReferenceTypeDeclaration other)
Can we assign instances of the given type to variables having the type defined by this declaration?
-
hasDirectlyAnnotation
boolean hasDirectlyAnnotation(String qualifiedName)
Has the type at least one annotation declared having the specified qualified name?
-
hasAnnotation
default boolean hasAnnotation(String qualifiedName)
Has the type at least one annotation declared or inherited having the specified qualified name? By default, the subclasses do not inherit the annotation declared on the parent class. However, there is a way to propagate particular annotations throughout the class hierarchy using the @Inherited annotation.
-
isInheritedAnnotation
default boolean isInheritedAnnotation(String name)
Returns true if the specified annotation is inheritable.
-
getDeclaredAnnotation
default Optional<ResolvedAnnotationDeclaration> getDeclaredAnnotation(String name)
Returns the resolved annotation corresponding to the specified name and declared in this type declaration.
-
getDeclaredAnnotations
default Set<ResolvedAnnotationDeclaration> getDeclaredAnnotations()
Return a collection of all annotations declared in this type declaration.
-
isFunctionalInterface
boolean isFunctionalInterface()
This means that the type has a functional method. Conceptually, a functional interface has exactly one abstract method. Typically these classes has the FunctionInterface annotation but this is not mandatory.
-
findTypeParameter
default Optional<ResolvedTypeParameterDeclaration> findTypeParameter(String name)
Description copied from interface:ResolvedTypeParametrizableFind the closest TypeParameterDeclaration with the given name. It first look on this element itself and then on the containers.- Specified by:
findTypeParameterin interfaceResolvedTypeParametrizable
-
getConstructors
List<ResolvedConstructorDeclaration> getConstructors()
-
isJavaLangObject
default 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:
ResolvedReferenceType.isJavaLangObject(), https://github.com/javaparser/javaparser/issues/2044
-
isJavaLangEnum
default boolean isJavaLangEnum()
- Returns:
- true, if this represents
java.lang.Enum - See Also:
ResolvedReferenceType.isJavaLangEnum()
-
isJavaLangRecord
default boolean isJavaLangRecord()
- Returns:
- true if this represents
java.lang.Record - See Also:
ResolvedReferenceType.isJavaLangRecord()
-
-