Class JavaParserRecordDeclaration
- java.lang.Object
-
- com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration
-
- com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserRecordDeclaration
-
- All Implemented Interfaces:
AssociableToAST,HasAccessSpecifier,ResolvedDeclaration,ResolvedRecordDeclaration,ResolvedReferenceTypeDeclaration,ResolvedTypeDeclaration,ResolvedTypeParametrizable,MethodResolutionCapability,MethodUsageResolutionCapability,SymbolResolutionCapability
public class JavaParserRecordDeclaration extends AbstractTypeDeclaration implements ResolvedRecordDeclaration, MethodResolutionCapability, MethodUsageResolutionCapability, SymbolResolutionCapability
Heavily based on JavaParserClassDeclaration
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJavaParserRecordDeclaration.CanonicalRecordConstructorstatic classJavaParserRecordDeclaration.ImplicitGetterMethod
-
Field Summary
Fields Modifier and Type Field Description private JavaParserTypeAdapter<RecordDeclaration>javaParserTypeAdapterprivate TypeSolvertypeSolverprivate RecordDeclarationwrappedNode-
Fields inherited from interface com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration
breadthFirstFunc, depthFirstFunc, JAVA_IO_SERIALIZABLE, JAVA_LANG_COMPARABLE, JAVA_LANG_ENUM, JAVA_LANG_OBJECT, JAVA_LANG_RECORD
-
-
Constructor Summary
Constructors Constructor Description JavaParserRecordDeclaration(RecordDeclaration wrappedNode, TypeSolver typeSolver)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description AccessSpecifieraccessSpecifier()The access specifier of this element.booleancanBeAssignedTo(ResolvedReferenceTypeDeclaration other)Can we assign instances of the type defined by this declaration to variables having the type defined by the given type?java.util.Optional<ResolvedReferenceTypeDeclaration>containerType()Get the ReferenceTypeDeclaration enclosing this declaration.private booleancontainsCanonicalConstructor(java.util.List<ResolvedConstructorDeclaration> constructors)booleanequals(java.lang.Object o)java.util.List<ResolvedFieldDeclaration>getAllFields()This method returns both the ResolvedFieldDeclarations for the explicit static fields declared in the record and non-static private fields corresponding to the record parameters.java.util.List<ResolvedReferenceType>getAllInterfaces()Return all the interfaces implemented by this class, either directly or indirectly, including the interfaces extended by interfaces it implements.java.util.List<ResolvedReferenceType>getAllSuperClasses()Get all superclasses, with all the type typeParametersValues expressed as functions of the type typeParametersValues of this declaration.java.util.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.java.lang.StringgetClassName()The class(es) wrapping this type.java.util.List<ResolvedConstructorDeclaration>getConstructors()List of constructors available for the class.ContextgetContext()Deprecated.java.util.Set<ResolvedAnnotationDeclaration>getDeclaredAnnotations()Return a collection of all annotations declared in this type declaration.java.util.Set<ResolvedMethodDeclaration>getDeclaredMethods()This method returns both the explicit methods declared in the record and the implicit getter methods for the record parameters.java.util.List<ResolvedReferenceType>getInterfaces()Return all the interfaces implemented directly by this class.java.lang.StringgetName()Should return the name or return null if the name is not available.java.lang.StringgetPackageName()The package name of the type.java.lang.StringgetQualifiedName()The fully qualified name of the type declared.java.util.Optional<ResolvedReferenceType>getSuperClass()This is a ReferenceTypeUsage because it could contain type typeParametersValues.java.util.List<ResolvedTypeParameterDeclaration>getTypeParameters()The list of type parameters defined on this element.ResolvedTypegetUsage(Node node)RecordDeclarationgetWrappedNode()Returns the JavaParser node associated with this JavaParserClassDeclaration.booleanhasDirectlyAnnotation(java.lang.String canonicalName)Has the type at least one annotation declared having the specified qualified name?inthashCode()java.util.Set<ResolvedReferenceTypeDeclaration>internalTypes()Get the list of types defined inside the current type.private booleanisAncestor(ResolvedReferenceType candidateAncestor, java.lang.String ownQualifiedName)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?SymbolReference<ResolvedMethodDeclaration>solveMethod(java.lang.String name, java.util.List<ResolvedType> parameterTypes)SymbolReference<ResolvedMethodDeclaration>solveMethod(java.lang.String name, java.util.List<ResolvedType> argumentsTypes, boolean staticOnly)java.util.Optional<MethodUsage>solveMethodAsUsage(java.lang.String name, java.util.List<ResolvedType> argumentTypes, Context invocationContext, java.util.List<ResolvedType> typeParameters)SymbolReference<? extends ResolvedValueDeclaration>solveSymbol(java.lang.String name, TypeSolver typeSolver)SymbolReference<ResolvedTypeDeclaration>solveType(java.lang.String name)Deprecated.java.util.Optional<Node>toAst()If the declaration is associated to an AST node return it, otherwise it return empty.private ResolvedReferenceTypetoReferenceType(ClassOrInterfaceType classOrInterfaceType)java.lang.StringtoString()-
Methods inherited from class com.github.javaparser.symbolsolver.logic.AbstractTypeDeclaration
getAllMethods, isFunctionalInterface, isRecordType
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.javaparser.resolution.declarations.AssociableToAST
toAst
-
Methods inherited from interface com.github.javaparser.resolution.declarations.ResolvedDeclaration
asEnumConstant, asField, asMethod, asParameter, asTypePattern, hasName, isEnumConstant, isField, isMethod, isParameter, isTypePattern, isVariable
-
Methods inherited from interface com.github.javaparser.resolution.declarations.ResolvedRecordDeclaration
asRecord, isRecord
-
Methods inherited from interface com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration
asReferenceType, findTypeParameter, getAllAncestors, getAllAncestors, getAllMethods, getAllNonStaticFields, getAllStaticFields, getAncestors, getDeclaredAnnotation, getDeclaredFields, getField, getVisibleField, getVisibleFields, hasAnnotation, hasField, hasVisibleField, isFunctionalInterface, isInheritedAnnotation, isJavaLangEnum, isJavaLangObject, isJavaLangRecord, isReferenceType
-
Methods inherited from interface com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration
asAnnotation, asClass, asEnum, asInterface, asType, asTypeParameter, getId, getInternalType, hasInternalType, isAnnotation, isAnonymousClass, isClass, isEnum, isInterface, isType, isTypeParameter
-
Methods inherited from interface com.github.javaparser.resolution.declarations.ResolvedTypeParametrizable
isGeneric
-
-
-
-
Field Detail
-
typeSolver
private TypeSolver typeSolver
-
wrappedNode
private RecordDeclaration wrappedNode
-
javaParserTypeAdapter
private JavaParserTypeAdapter<RecordDeclaration> javaParserTypeAdapter
-
-
Constructor Detail
-
JavaParserRecordDeclaration
public JavaParserRecordDeclaration(RecordDeclaration wrappedNode, TypeSolver typeSolver)
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getAllFields
public java.util.List<ResolvedFieldDeclaration> getAllFields()
This method returns both the ResolvedFieldDeclarations for the explicit static fields declared in the record and non-static private fields corresponding to the record parameters. This is done to make the fields of a record consistent across the various models (since the record parameters are considered fields by the Java compiler and runtime).- Specified by:
getAllFieldsin interfaceResolvedReferenceTypeDeclaration
-
solveMethod
public SymbolReference<ResolvedMethodDeclaration> solveMethod(java.lang.String name, java.util.List<ResolvedType> parameterTypes)
-
solveMethodAsUsage
public java.util.Optional<MethodUsage> solveMethodAsUsage(java.lang.String name, java.util.List<ResolvedType> argumentTypes, Context invocationContext, java.util.List<ResolvedType> typeParameters)
- Specified by:
solveMethodAsUsagein interfaceMethodUsageResolutionCapability
-
getContext
@Deprecated public Context getContext()
Deprecated.This method is deprecated because the context is an implementation detail that should not be exposed. Ideally this method should become private. For this reason all further usages of this method are discouraged.
-
getUsage
public ResolvedType getUsage(Node node)
-
getName
public java.lang.String getName()
Description copied from interface:ResolvedDeclarationShould return the name or return null if the name is not available.- Specified by:
getNamein interfaceResolvedDeclaration
-
getSuperClass
public java.util.Optional<ResolvedReferenceType> getSuperClass()
Description copied from interface:ResolvedRecordDeclarationThis is a ReferenceTypeUsage because it could contain type typeParametersValues. For example:class A extends B<Integer, String>.Note that only the Object class should not have a superclass and therefore return empty.
- Specified by:
getSuperClassin interfaceResolvedRecordDeclaration
-
getInterfaces
public java.util.List<ResolvedReferenceType> getInterfaces()
Description copied from interface:ResolvedRecordDeclarationReturn all the interfaces implemented directly by this class. It does not include the interfaces implemented by superclasses or extended by the interfaces implemented.- Specified by:
getInterfacesin interfaceResolvedRecordDeclaration
-
getAllSuperClasses
public java.util.List<ResolvedReferenceType> getAllSuperClasses()
Description copied from interface:ResolvedRecordDeclarationGet all superclasses, with all the type typeParametersValues expressed as functions of the type typeParametersValues of this declaration.- Specified by:
getAllSuperClassesin interfaceResolvedRecordDeclaration
-
getAllInterfaces
public java.util.List<ResolvedReferenceType> getAllInterfaces()
Description copied from interface:ResolvedRecordDeclarationReturn all the interfaces implemented by this class, either directly or indirectly, including the interfaces extended by interfaces it implements.Get all interfaces, with all the type typeParametersValues expressed as functions of the type typeParametersValues of this declaration.
- Specified by:
getAllInterfacesin interfaceResolvedRecordDeclaration
-
getConstructors
public java.util.List<ResolvedConstructorDeclaration> getConstructors()
Description copied from interface:ResolvedRecordDeclarationList of constructors available for the class. This list should also include the default constructor.- Specified by:
getConstructorsin interfaceResolvedRecordDeclaration- Specified by:
getConstructorsin interfaceResolvedReferenceTypeDeclaration
-
containsCanonicalConstructor
private boolean containsCanonicalConstructor(java.util.List<ResolvedConstructorDeclaration> constructors)
-
hasDirectlyAnnotation
public boolean hasDirectlyAnnotation(java.lang.String canonicalName)
Description copied from interface:ResolvedReferenceTypeDeclarationHas the type at least one annotation declared having the specified qualified name?- Specified by:
hasDirectlyAnnotationin interfaceResolvedReferenceTypeDeclaration
-
getDeclaredAnnotations
public java.util.Set<ResolvedAnnotationDeclaration> getDeclaredAnnotations()
Description copied from interface:ResolvedReferenceTypeDeclarationReturn a collection of all annotations declared in this type declaration.- Specified by:
getDeclaredAnnotationsin interfaceResolvedReferenceTypeDeclaration
-
getPackageName
public java.lang.String getPackageName()
Description copied from interface:ResolvedTypeDeclarationThe package name of the type.- Specified by:
getPackageNamein interfaceResolvedTypeDeclaration
-
getClassName
public java.lang.String getClassName()
Description copied from interface:ResolvedTypeDeclarationThe class(es) wrapping this type.- Specified by:
getClassNamein interfaceResolvedTypeDeclaration
-
getQualifiedName
public java.lang.String getQualifiedName()
Description copied from interface:ResolvedTypeDeclarationThe fully qualified name of the type declared.- Specified by:
getQualifiedNamein interfaceResolvedTypeDeclaration
-
isAssignableBy
public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other)
Description copied from interface:ResolvedReferenceTypeDeclarationCan we assign instances of the given type to variables having the type defined by this declaration?- Specified by:
isAssignableByin interfaceResolvedReferenceTypeDeclaration
-
isAssignableBy
public boolean isAssignableBy(ResolvedType type)
Description copied from interface:ResolvedReferenceTypeDeclarationCan we assign instances of the given type to variables having the type defined by this declaration?- Specified by:
isAssignableByin interfaceResolvedReferenceTypeDeclaration
-
canBeAssignedTo
public boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other)
Description copied from interface:ResolvedReferenceTypeDeclarationCan we assign instances of the type defined by this declaration to variables having the type defined by the given type?- Specified by:
canBeAssignedToin interfaceResolvedReferenceTypeDeclaration
-
solveType
@Deprecated public SymbolReference<ResolvedTypeDeclaration> solveType(java.lang.String name)
Deprecated.Resolution should move out of declarations, so that they are pure declarations and the resolution should work for JavaParser, Reflection and Javassist classes in the same way and not be specific to the three implementations.
-
solveMethod
public SymbolReference<ResolvedMethodDeclaration> solveMethod(java.lang.String name, java.util.List<ResolvedType> argumentsTypes, boolean staticOnly)
- Specified by:
solveMethodin interfaceMethodResolutionCapability
-
solveSymbol
public SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(java.lang.String name, TypeSolver typeSolver)
- Specified by:
solveSymbolin interfaceSymbolResolutionCapability- Parameters:
name- Field / symbol name.typeSolver- Symbol solver to resolve type usage.- Returns:
- Symbol reference of the resolved value.
-
getAncestors
public java.util.List<ResolvedReferenceType> getAncestors(boolean acceptIncompleteList)
Description copied from interface:ResolvedReferenceTypeDeclarationResolves 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.- Specified by:
getAncestorsin interfaceResolvedReferenceTypeDeclaration- 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.
-
isAncestor
private boolean isAncestor(ResolvedReferenceType candidateAncestor, java.lang.String ownQualifiedName)
-
getDeclaredMethods
public java.util.Set<ResolvedMethodDeclaration> getDeclaredMethods()
This method returns both the explicit methods declared in the record and the implicit getter methods for the record parameters. This is done for consistency across the various models.- Specified by:
getDeclaredMethodsin interfaceResolvedReferenceTypeDeclaration
-
getTypeParameters
public java.util.List<ResolvedTypeParameterDeclaration> getTypeParameters()
Description copied from interface:ResolvedTypeParametrizableThe list of type parameters defined on this element.- Specified by:
getTypeParametersin interfaceResolvedTypeParametrizable
-
getWrappedNode
public RecordDeclaration getWrappedNode()
Returns the JavaParser node associated with this JavaParserClassDeclaration.- Returns:
- A visitable JavaParser node wrapped by this object.
-
accessSpecifier
public AccessSpecifier accessSpecifier()
Description copied from interface:HasAccessSpecifierThe access specifier of this element.- Specified by:
accessSpecifierin interfaceHasAccessSpecifier
-
toAst
public java.util.Optional<Node> toAst()
Description copied from interface:AssociableToASTIf the declaration is associated to an AST node return it, otherwise it return empty. Declaration based on source code have an AST node associated while others don't. Example of other declarations are declarations coming from reflection or JARs. You may wonder how this method is different from the various getWrappedNode. The difference is that toAst is present in all Resolved* declarations (such as ResolvedAnnotationDeclaration), while getWrappedNode is present only on the subclasses of the Resolved* declarations that derive from JP AST nodes (such as JavaParserClassDeclaration). Therefore one which has a Resolved* declaration need to do a downcast before being able to use getWrappedNode. Now, this means that toAst could potentially replace getWrappedNode (but not the other way around!). However toAst return an Optional, which is less convenient than getting the direct node. Also, toAst sometimes have to return a more generic node. This is the case for subclasses of ResolvedClassDeclaration. In those cases toAst return a Node. Why? Because both anonymous class declarations and standard class declarations are subclasses of that. In one case the underlying AST node is an ObjectCreationExpr, while in the other case it is ClassOrInterfaceDeclaration. In these cases getWrappedNode is particularly nice because it returns the right type of AST node, not just a Node.- Specified by:
toAstin interfaceAssociableToAST
-
internalTypes
public java.util.Set<ResolvedReferenceTypeDeclaration> internalTypes()
Description copied from interface:ResolvedTypeDeclarationGet the list of types defined inside the current type.- Specified by:
internalTypesin interfaceResolvedTypeDeclaration
-
containerType
public java.util.Optional<ResolvedReferenceTypeDeclaration> containerType()
Description copied from interface:ResolvedTypeDeclarationGet the ReferenceTypeDeclaration enclosing this declaration.- Specified by:
containerTypein interfaceResolvedTypeDeclaration
-
toReferenceType
private ResolvedReferenceType toReferenceType(ClassOrInterfaceType classOrInterfaceType)
-
-