Package com.github.javaparser.ast.body
Class TypeDeclaration<T extends TypeDeclaration<?>>
java.lang.Object
com.github.javaparser.ast.Node
com.github.javaparser.ast.body.BodyDeclaration<T>
com.github.javaparser.ast.body.TypeDeclaration<T>
- All Implemented Interfaces:
NodeWithAccessModifiers<T>
,NodeWithPrivateModifier<T>
,NodeWithProtectedModifier<T>
,NodeWithPublicModifier<T>
,NodeWithStaticModifier<T>
,NodeWithStrictfpModifier<T>
,NodeWithAnnotations<T>
,NodeWithJavadoc<T>
,NodeWithMembers<T>
,NodeWithModifiers<T>
,NodeWithRange<Node>
,NodeWithSimpleName<T>
,NodeWithTokenRange<Node>
,Observable
,Visitable
,HasParentNode<Node>
,Cloneable
- Direct Known Subclasses:
AnnotationDeclaration
,ClassOrInterfaceDeclaration
,EnumDeclaration
,RecordDeclaration
public abstract class TypeDeclaration<T extends TypeDeclaration<?>>
extends BodyDeclaration<T>
implements NodeWithSimpleName<T>, NodeWithJavadoc<T>, NodeWithMembers<T>, NodeWithAccessModifiers<T>, NodeWithStaticModifier<T>, NodeWithStrictfpModifier<T>
A base class for all types of type declarations.
- Author:
- Julio Vilmar Gesser
-
Nested Class Summary
Nested classes/interfaces inherited from class com.github.javaparser.ast.Node
Node.BreadthFirstIterator, Node.DirectChildrenIterator, Node.ObserverRegistrationMode, Node.ParentsVisitor, Node.Parsedness, Node.PostOrderIterator, Node.PreOrderIterator, Node.TreeTraversal
-
Field Summary
Fields inherited from class com.github.javaparser.ast.Node
ABSOLUTE_BEGIN_LINE, ABSOLUTE_END_LINE, LINE_SEPARATOR_KEY, NODE_BY_BEGIN_POSITION, PHANTOM_KEY, prettyPrinterNoCommentsConfiguration, PRINTER_KEY, SYMBOL_RESOLVER_KEY
-
Constructor Summary
ConstructorDescriptionTypeDeclaration(NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<BodyDeclaration<?>> members)
TypeDeclaration(NodeList<Modifier> modifiers, String name)
TypeDeclaration(TokenRange tokenRange, NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<BodyDeclaration<?>> members)
This constructor is used by the parser and is considered private. -
Method Summary
Modifier and TypeMethodDescriptionaddMember(BodyDeclaration<?> decl)
Adds the given declaration to the specified type.clone()
Returns the fully qualified name of this type, derived only from information available in this compilation unit.Return the modifiers of this type declaration.getName()
void
ifTypeDeclaration(Consumer<TypeDeclaration> action)
boolean
boolean
boolean
boolean
boolean
abstract ResolvedReferenceTypeDeclaration
resolve()
setMembers(NodeList<BodyDeclaration<?>> members)
setModifiers(NodeList<Modifier> modifiers)
setName(SimpleName name)
Methods inherited from class com.github.javaparser.ast.body.BodyDeclaration
asAnnotationDeclaration, asAnnotationMemberDeclaration, asCallableDeclaration, asClassOrInterfaceDeclaration, asCompactConstructorDeclaration, asConstructorDeclaration, asEnumConstantDeclaration, asEnumDeclaration, asFieldDeclaration, asInitializerDeclaration, asMethodDeclaration, asRecordDeclaration, getAnnotations, ifAnnotationDeclaration, ifAnnotationMemberDeclaration, ifCallableDeclaration, ifClassOrInterfaceDeclaration, ifCompactConstructorDeclaration, ifConstructorDeclaration, ifEnumConstantDeclaration, ifEnumDeclaration, ifFieldDeclaration, ifInitializerDeclaration, ifMethodDeclaration, ifRecordDeclaration, isAnnotationDeclaration, isAnnotationMemberDeclaration, isCallableDeclaration, isClassOrInterfaceDeclaration, isCompactConstructorDeclaration, isConstructorDeclaration, isEnumConstantDeclaration, isEnumDeclaration, isFieldDeclaration, isInitializerDeclaration, isMethodDeclaration, isRecordDeclaration, setAnnotations, toAnnotationDeclaration, toAnnotationMemberDeclaration, toCallableDeclaration, toClassOrInterfaceDeclaration, toCompactConstructorDeclaration, toConstructorDeclaration, toEnumConstantDeclaration, toEnumDeclaration, toFieldDeclaration, toInitializerDeclaration, toMethodDeclaration, toRecordDeclaration
Methods inherited from class com.github.javaparser.ast.Node
addOrphanComment, containsData, createDefaultPrinter, createDefaultPrinter, customInitialization, equals, findAll, findAll, findAll, findCompilationUnit, findFirst, findFirst, findFirst, findRootNode, getAllContainedComments, getChildNodes, getChildNodesByType, getComment, getData, getDataKeys, getDefaultPrinterConfiguration, getLineEndingStyle, getLineEndingStyleOrDefault, getNodesByType, getOrphanComments, getParentNode, getParentNodeForChildren, getParsed, getPrinter, getPrinter, getRange, getSymbolResolver, getTokenRange, hashCode, hasScope, isAncestorOf, isPhantom, isRegistered, notifyPropertyChange, register, register, registerForSubtree, remove, removeComment, removeData, removeForced, removeOrphanComment, replace, setAsParentNodeOf, setAsParentNodeOf, setBlockComment, setComment, setData, setLineComment, setParentNode, setParsed, setRange, setTokenRange, stream, stream, toString, toString, tryAddImportToParentCompilationUnit, unregister, walk, walk, walk
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.github.javaparser.HasParentNode
findAncestor, findAncestor, hasParentNode, isDescendantOf
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithAnnotations
addAndGetAnnotation, addAndGetAnnotation, addAnnotation, addAnnotation, addAnnotation, addMarkerAnnotation, addMarkerAnnotation, addSingleMemberAnnotation, addSingleMemberAnnotation, addSingleMemberAnnotation, addSingleMemberAnnotation, getAnnotation, getAnnotationByClass, getAnnotationByName, isAnnotationPresent, isAnnotationPresent, setAnnotation, tryAddImportToParentCompilationUnit
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithJavadoc
getComment, getJavadoc, getJavadocComment, hasJavaDocComment, removeJavaDocComment, setComment, setJavadocComment, setJavadocComment, setJavadocComment, setJavadocComment
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithMembers
addConstructor, addField, addField, addField, addFieldWithInitializer, addFieldWithInitializer, addFieldWithInitializer, addInitializer, addMethod, addPrivateField, addPrivateField, addPrivateField, addProtectedField, addProtectedField, addProtectedField, addPublicField, addPublicField, addPublicField, addStaticInitializer, getConstructorByParameterTypes, getConstructorByParameterTypes, getConstructors, getDefaultConstructor, getFieldByName, getFields, getMember, getMethods, getMethodsByName, getMethodsByParameterTypes, getMethodsByParameterTypes, getMethodsBySignature, isEmpty, setMember, tryAddImportToParentCompilationUnit
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithModifiers
addModifier, getAccessSpecifier, hasModifier, removeModifier, setModifier, setModifiers
Methods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithPrivateModifier
isPrivate, setPrivate
Methods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithProtectedModifier
isProtected, setProtected
Methods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithPublicModifier
isPublic, setPublic
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithRange
containsWithin, containsWithinRange, getBegin, getEnd, hasRange
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithSimpleName
getNameAsExpression, getNameAsString, setName
Methods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithStaticModifier
isStatic, setStatic
Methods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithStrictfpModifier
isStrictfp, setStrictfp
-
Constructor Details
-
TypeDeclaration
public TypeDeclaration() -
TypeDeclaration
-
TypeDeclaration
public TypeDeclaration(NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<BodyDeclaration<?>> members) -
TypeDeclaration
public TypeDeclaration(TokenRange tokenRange, NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<BodyDeclaration<?>> members)This constructor is used by the parser and is considered private.
-
-
Method Details
-
addMember
Adds the given declaration to the specified type.- Specified by:
addMember
in interfaceNodeWithMembers<T extends TypeDeclaration<?>>
- Parameters:
decl
- member declaration
-
getMembers
- Specified by:
getMembers
in interfaceNodeWithMembers<T extends TypeDeclaration<?>>
- Returns:
- all members inside the braces of this node, like fields, methods, nested types, etc.
-
getModifiers
Return the modifiers of this type declaration.- Specified by:
getModifiers
in interfaceNodeWithModifiers<T extends TypeDeclaration<?>>
- Returns:
- modifiers
- See Also:
Modifier
-
setMembers
- Specified by:
setMembers
in interfaceNodeWithMembers<T extends TypeDeclaration<?>>
-
setModifiers
- Specified by:
setModifiers
in interfaceNodeWithModifiers<T extends TypeDeclaration<?>>
-
setName
- Specified by:
setName
in interfaceNodeWithSimpleName<T extends TypeDeclaration<?>>
-
getName
- Specified by:
getName
in interfaceNodeWithSimpleName<T extends TypeDeclaration<?>>
-
remove
- Overrides:
remove
in classBodyDeclaration<T extends TypeDeclaration<?>>
-
isTopLevelType
public boolean isTopLevelType()- Returns:
- is this type's parent a CompilationUnit?
-
getCallablesWithSignature
public List<CallableDeclaration<?>> getCallablesWithSignature(CallableDeclaration.Signature signature)- Returns:
- methods or constructors whose signatures match the passed signature.
-
getFullyQualifiedName
Returns the fully qualified name of this type, derived only from information available in this compilation unit. (So no symbol solving happens.) If the declared type is a local class declaration, it will return Optional.empty(). If the declared type is a local record declaration, it will return Optional.empty(). If the declared type is not contained in a compilation unit, it will return Optional.empty(). -
isNestedType
public boolean isNestedType()- Returns:
- is this type's parent a TypeDeclaration? NOTE: many people are confused over terminology. Refer to https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html .
-
clone
- Overrides:
clone
in classBodyDeclaration<T extends TypeDeclaration<?>>
-
getMetaModel
- Overrides:
getMetaModel
in classBodyDeclaration<T extends TypeDeclaration<?>>
- Returns:
- get JavaParser specific node introspection information.
-
replace
- Overrides:
replace
in classBodyDeclaration<T extends TypeDeclaration<?>>
-
isTypeDeclaration
public boolean isTypeDeclaration()- Overrides:
isTypeDeclaration
in classBodyDeclaration<T extends TypeDeclaration<?>>
-
asTypeDeclaration
- Overrides:
asTypeDeclaration
in classBodyDeclaration<T extends TypeDeclaration<?>>
-
ifTypeDeclaration
- Overrides:
ifTypeDeclaration
in classBodyDeclaration<T extends TypeDeclaration<?>>
-
toTypeDeclaration
- Overrides:
toTypeDeclaration
in classBodyDeclaration<T extends TypeDeclaration<?>>
-
resolve
-