Interface ASTTypeDeclaration
-
- All Superinterfaces:
Annotatable,ASTBodyDeclaration,ASTTopLevelDeclaration,GenericNode<JavaNode>,JavadocCommentOwner,JavaNode,JjtreeNode<JavaNode>,ModifierOwner,Node,Reportable,SymbolDeclaratorNode,TextAvailableNode,TypeNode,TypeParamOwnerNode
- All Known Implementing Classes:
ASTAnnotationTypeDeclaration,ASTAnonymousClassDeclaration,ASTClassDeclaration,ASTEnumDeclaration,ASTRecordDeclaration
public interface ASTTypeDeclaration extends TypeNode, ModifierOwner, TypeParamOwnerNode, ASTBodyDeclaration, ASTTopLevelDeclaration, JavadocCommentOwner
Groups class, enum, record, annotation and interface declarations under a common supertype.TypeDeclaration ::=
ClassDeclaration|AnonymousClassDeclaration|EnumDeclaration|AnnotationTypeDeclaration|RecordDeclarationNote: In PMD 6, there was a node with this name (ASTTypeDeclaration) which was a top-level wrapper node around type declarations. This node has been removed in PMD 7 and the name has been reused.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.sourceforge.pmd.lang.java.ast.ModifierOwner
ModifierOwner.Visibility
-
-
Field Summary
-
Fields inherited from interface net.sourceforge.pmd.lang.ast.Node
COORDS_COMPARATOR
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description @NonNull StringgetBinaryName()Returns the binary name of this type declaration.default ASTTypeBodygetBody()Returns the body of this type declaration.@Nullable StringgetCanonicalName()Returns the canonical name of this class, if it exists.default NodeStream<ASTBodyDeclaration>getDeclarations()Retrieves the member declarations (fields, methods, classes, etc.) from the body of this type declaration.default <T extends ASTBodyDeclaration>
NodeStream<T>getDeclarations(Class<? extends T> klass)Returns the declarations of a particular type.default NodeStream<ASTEnumConstant>getEnumConstants()Returns the enum constants declared by this enum.default NodeStream<ASTExecutableDeclaration>getOperations()Returns the operations declared in this class (methods and constructors).default StringgetPackageName()Returns the name of the package in which this class is declared.default @Nullable ASTRecordComponentListgetRecordComponents()Returns the record components declared by this class.@NonNull StringgetSimpleName()Returns the simple name of this type declaration.default @NonNull NodeStream<ASTClassType>getSuperInterfaceTypeNodes()Returns the list of interfaces implemented by this class, or extended by this interface.@NonNull JClassSymbolgetSymbol()Returns the symbol this node declares.@NonNull JClassTypegetTypeMirror()Returns the generic type declaration of the declared type.default booleanisAbstract()Returns true if this is an abstract type.default booleanisAnnotation()Returns true if this is an annotation type declaration.default booleanisAnonymous()Returns true if this is an anonymous class declaration.default booleanisEnum()Returns true if this is an enum class declaration.default booleanisFinal()default booleanisInterface()Returns true if this is an interface type declaration (including annotation types).default booleanisLocal()Returns true if the class is declared inside a block other than the body of another class, or the top level.default booleanisNested()Returns true if this type declaration is nested inside an interface, class or annotation.default booleanisRecord()Returns true if this is an record class declaration.default booleanisRegularClass()Returns true if this is a regular class declaration (not an enum, not a record, not an interface or annotation).default booleanisRegularInterface()Returns true if this is a regular interface declaration (not an annotation).default booleanisStatic()Returns true if this type is static.default booleanisTopLevel()Returns true if this type is declared at the top-level of a file.-
Methods inherited from interface net.sourceforge.pmd.lang.java.ast.Annotatable
getAnnotation, isAnnotationPresent, isAnnotationPresent, isAnyAnnotationPresent
-
Methods inherited from interface net.sourceforge.pmd.lang.ast.impl.GenericNode
ancestors, ancestorsOrSelf, asStream, children, descendants, descendantsOrSelf, getChild, getFirstChild, getLastChild, getNextSibling, getParent, getPreviousSibling
-
Methods inherited from interface net.sourceforge.pmd.lang.java.ast.JavadocCommentOwner
getJavadocComment
-
Methods inherited from interface net.sourceforge.pmd.lang.java.ast.JavaNode
getEnclosingType, getRoot, getSymbolTable, getTypeSystem
-
Methods inherited from interface net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeNode
getFirstToken, getLastToken, tokens
-
Methods inherited from interface net.sourceforge.pmd.lang.java.ast.ModifierOwner
getDeclaredAnnotations, getEffectiveVisibility, getModifiers, getVisibility, hasExplicitModifiers, hasModifiers, hasVisibility
-
Methods inherited from interface net.sourceforge.pmd.lang.ast.Node
acceptVisitor, ancestors, children, compareLocation, descendants, firstChild, getAstInfo, getBeginColumn, getBeginLine, getEndColumn, getEndLine, getImage, getIndexInParent, getLanguageVersion, getNumChildren, getReportLocation, getTextDocument, getUserMap, getXPathAttributesIterator, getXPathNodeName, hasImageEqualTo, isFindBoundary
-
Methods inherited from interface net.sourceforge.pmd.lang.ast.TextAvailableNode
getOriginalText, getText, getTextRegion
-
Methods inherited from interface net.sourceforge.pmd.lang.java.ast.TypeNode
getTypeMirror
-
Methods inherited from interface net.sourceforge.pmd.lang.java.ast.TypeParamOwnerNode
getTypeParameters
-
-
-
-
Method Detail
-
getSymbol
@NonNull JClassSymbol getSymbol()
Description copied from interface:SymbolDeclaratorNodeReturns the symbol this node declares.- Specified by:
getSymbolin interfaceSymbolDeclaratorNode- Specified by:
getSymbolin interfaceTypeParamOwnerNode
-
getTypeMirror
@NonNull JClassType getTypeMirror()
Returns the generic type declaration of the declared type. Note that for anonymous classes, this returns a class type whose symbol is the actual anonymous class. Egnew Runnable() { void foo() { } void run() { } }would present both methods, ie not just be aRunnable. TheASTConstructorCallwould have typeRunnablethough, not the anonymous class.- Specified by:
getTypeMirrorin interfaceTypeNode- Returns:
- The type mirror. Never returns null; if the type is unresolved, returns
TypeSystem.UNKNOWN.
-
getSimpleName
@NonNull String getSimpleName()
Returns the simple name of this type declaration. Returns the empty string if this is an anonymous class declaration.
-
getPackageName
default String getPackageName()
Returns the name of the package in which this class is declared.
-
getBinaryName
@NonNull String getBinaryName()
Returns the binary name of this type declaration. This is likeClass.getName().
-
getCanonicalName
@Nullable String getCanonicalName()
Returns the canonical name of this class, if it exists. Otherwise returns null. This is likeClass.getCanonicalName().A canonical name exists if all enclosing types have a canonical name, and this is neither a local class nor an anonymous class. For example:
So non-local/anonymous classes declared somewhere in a local/anonymous class also have no locpackage p; public class A { // p.A class M { // p.A.M { class Local { // null, local class class M2 {} // null, member of a local class } new Local() { // null, anonymous class class M2 {} // null, member of an anonymous class }; } } }
-
isAbstract
default boolean isAbstract()
Returns true if this is an abstract type. Interfaces and annotations types are implicitly abstract.
-
isStatic
default boolean isStatic()
Returns true if this type is static. Only inner types can be static.
-
isFinal
default boolean isFinal()
-
getEnumConstants
default NodeStream<ASTEnumConstant> getEnumConstants()
Returns the enum constants declared by this enum. If this is not an enum declaration, returns an empty stream.
-
getRecordComponents
default @Nullable ASTRecordComponentList getRecordComponents()
Returns the record components declared by this class. If this is not a record declaration, returns null.
-
getDeclarations
default NodeStream<ASTBodyDeclaration> getDeclarations()
Retrieves the member declarations (fields, methods, classes, etc.) from the body of this type declaration.
-
getDeclarations
default <T extends ASTBodyDeclaration> NodeStream<T> getDeclarations(Class<? extends T> klass)
Returns the declarations of a particular type.- Type Parameters:
T- Type of the declarations- Parameters:
klass- Type of the declarations
-
getOperations
default NodeStream<ASTExecutableDeclaration> getOperations()
Returns the operations declared in this class (methods and constructors).
-
getBody
default ASTTypeBody getBody()
Returns the body of this type declaration.
-
isNested
default boolean isNested()
Returns true if this type declaration is nested inside an interface, class or annotation.
-
isLocal
default boolean isLocal()
Returns true if the class is declared inside a block other than the body of another class, or the top level. Anonymous classes are not considered local. Only class declarations can be local. Local classes cannot be static.
-
isTopLevel
default boolean isTopLevel()
Returns true if this type is declared at the top-level of a file.
-
isAnonymous
default boolean isAnonymous()
Returns true if this is an anonymous class declaration.
-
isEnum
default boolean isEnum()
Returns true if this is an enum class declaration.
-
isRecord
default boolean isRecord()
Returns true if this is an record class declaration.
-
isInterface
default boolean isInterface()
Returns true if this is an interface type declaration (including annotation types). This is consistent withClass.isInterface().
-
isRegularClass
default boolean isRegularClass()
Returns true if this is a regular class declaration (not an enum, not a record, not an interface or annotation). Note that egJClassSymbol.isClass()counts records and enums in, just likeisInterface()counts annotations in.
-
isRegularInterface
default boolean isRegularInterface()
Returns true if this is a regular interface declaration (not an annotation). Note thatisInterface()counts annotations in.
-
isAnnotation
default boolean isAnnotation()
Returns true if this is an annotation type declaration.
-
getSuperInterfaceTypeNodes
default @NonNull NodeStream<ASTClassType> getSuperInterfaceTypeNodes()
Returns the list of interfaces implemented by this class, or extended by this interface. Returns null if no such list is declared.
-
-