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>
,java.lang.Cloneable
- Direct Known Subclasses:
AnnotationDeclaration
,ClassOrInterfaceDeclaration
,EnumDeclaration
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.
-
-
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 Modifier and Type Field Description private NodeList<BodyDeclaration<?>>
members
private NodeList<Modifier>
modifiers
private SimpleName
name
-
Fields inherited from class com.github.javaparser.ast.Node
ABSOLUTE_BEGIN_LINE, ABSOLUTE_END_LINE, NODE_BY_BEGIN_POSITION, prettyPrinterNoCommentsConfiguration, SYMBOL_RESOLVER_KEY
-
-
Constructor Summary
Constructors Constructor Description TypeDeclaration()
TypeDeclaration(NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<BodyDeclaration<?>> members)
TypeDeclaration(NodeList<Modifier> modifiers, java.lang.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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description T
addMember(BodyDeclaration<?> decl)
Adds the given declaration to the specified type.TypeDeclaration
asTypeDeclaration()
TypeDeclaration<?>
clone()
java.util.List<CallableDeclaration<?>>
getCallablesWithSignature(CallableDeclaration.Signature signature)
java.util.Optional<java.lang.String>
getFullyQualifiedName()
Returns the fully qualified name of this type, derived only from information available in this compilation unit.NodeList<BodyDeclaration<?>>
getMembers()
TypeDeclarationMetaModel
getMetaModel()
NodeList<Modifier>
getModifiers()
Return the modifiers of this type declaration.SimpleName
getName()
void
ifTypeDeclaration(java.util.function.Consumer<TypeDeclaration> action)
boolean
isNestedType()
boolean
isTopLevelType()
boolean
isTypeDeclaration()
boolean
remove(Node node)
boolean
replace(Node node, Node replacementNode)
abstract ResolvedReferenceTypeDeclaration
resolve()
T
setMembers(NodeList<BodyDeclaration<?>> members)
T
setModifiers(NodeList<Modifier> modifiers)
T
setName(SimpleName name)
java.util.Optional<TypeDeclaration>
toTypeDeclaration()
-
Methods inherited from class com.github.javaparser.ast.body.BodyDeclaration
asAnnotationDeclaration, asAnnotationMemberDeclaration, asCallableDeclaration, asClassOrInterfaceDeclaration, asConstructorDeclaration, asEnumConstantDeclaration, asEnumDeclaration, asFieldDeclaration, asInitializerDeclaration, asMethodDeclaration, getAnnotations, ifAnnotationDeclaration, ifAnnotationMemberDeclaration, ifCallableDeclaration, ifClassOrInterfaceDeclaration, ifConstructorDeclaration, ifEnumConstantDeclaration, ifEnumDeclaration, ifFieldDeclaration, ifInitializerDeclaration, ifMethodDeclaration, isAnnotationDeclaration, isAnnotationMemberDeclaration, isCallableDeclaration, isClassOrInterfaceDeclaration, isConstructorDeclaration, isEnumConstantDeclaration, isEnumDeclaration, isFieldDeclaration, isInitializerDeclaration, isMethodDeclaration, setAnnotations, toAnnotationDeclaration, toAnnotationMemberDeclaration, toCallableDeclaration, toClassOrInterfaceDeclaration, toConstructorDeclaration, toEnumConstantDeclaration, toEnumDeclaration, toFieldDeclaration, toInitializerDeclaration, toMethodDeclaration
-
Methods inherited from class com.github.javaparser.ast.Node
addOrphanComment, containsData, customInitialization, equals, findAll, findAll, findCompilationUnit, findFirst, findFirst, findFirst, findRootNode, getAllContainedComments, getChildNodes, getChildNodesByType, getComment, getData, getDataKeys, getNodesByType, getOrphanComments, getParentNode, getParentNodeForChildren, getParsed, getRange, getSymbolResolver, getTokenRange, getToStringPrettyPrinterConfiguration, hashCode, isAncestorOf, isRegistered, notifyPropertyChange, register, register, registerForSubtree, remove, removeComment, removeData, removeForced, removeOrphanComment, replace, setAsParentNodeOf, setAsParentNodeOf, setBlockComment, setComment, setData, setLineComment, setParentNode, setParsed, setRange, setTokenRange, setToStringPrettyPrinterConfiguration, 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, 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
-
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
-
-
-
-
Field Detail
-
name
private SimpleName name
-
members
private NodeList<BodyDeclaration<?>> members
-
-
Constructor Detail
-
TypeDeclaration
public 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 Detail
-
addMember
public T addMember(BodyDeclaration<?> decl)
Adds the given declaration to the specified type.- Specified by:
addMember
in interfaceNodeWithMembers<T extends TypeDeclaration<?>>
- Parameters:
decl
- member declaration
-
getMembers
public NodeList<BodyDeclaration<?>> 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
public NodeList<Modifier> getModifiers()
Return the modifiers of this type declaration.- Specified by:
getModifiers
in interfaceNodeWithModifiers<T extends TypeDeclaration<?>>
- Returns:
- modifiers
- See Also:
Modifier
-
setMembers
public T setMembers(NodeList<BodyDeclaration<?>> members)
- Specified by:
setMembers
in interfaceNodeWithMembers<T extends TypeDeclaration<?>>
-
setModifiers
public T setModifiers(NodeList<Modifier> modifiers)
- Specified by:
setModifiers
in interfaceNodeWithModifiers<T extends TypeDeclaration<?>>
-
setName
public T setName(SimpleName name)
- Specified by:
setName
in interfaceNodeWithSimpleName<T extends TypeDeclaration<?>>
-
getName
public SimpleName getName()
- Specified by:
getName
in interfaceNodeWithSimpleName<T extends TypeDeclaration<?>>
-
remove
public boolean remove(Node node)
- Overrides:
remove
in classBodyDeclaration<T extends TypeDeclaration<?>>
-
isTopLevelType
public boolean isTopLevelType()
- Returns:
- is this type's parent a CompilationUnit?
-
getCallablesWithSignature
public java.util.List<CallableDeclaration<?>> getCallablesWithSignature(CallableDeclaration.Signature signature)
- Returns:
- methods or constructors whose signatures match the passed signature.
-
getFullyQualifiedName
public java.util.Optional<java.lang.String> 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 not contained in a compilation unit, it will return Optional.empty().- See Also:
LocalClassDeclarationStmt
-
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
public TypeDeclaration<?> clone()
- Overrides:
clone
in classBodyDeclaration<T extends TypeDeclaration<?>>
-
getMetaModel
public TypeDeclarationMetaModel getMetaModel()
- Overrides:
getMetaModel
in classBodyDeclaration<T extends TypeDeclaration<?>>
- Returns:
- get JavaParser specific node introspection information.
-
replace
public boolean replace(Node node, Node replacementNode)
- Overrides:
replace
in classBodyDeclaration<T extends TypeDeclaration<?>>
-
isTypeDeclaration
public boolean isTypeDeclaration()
- Overrides:
isTypeDeclaration
in classBodyDeclaration<T extends TypeDeclaration<?>>
-
asTypeDeclaration
public TypeDeclaration asTypeDeclaration()
- Overrides:
asTypeDeclaration
in classBodyDeclaration<T extends TypeDeclaration<?>>
-
ifTypeDeclaration
public void ifTypeDeclaration(java.util.function.Consumer<TypeDeclaration> action)
- Overrides:
ifTypeDeclaration
in classBodyDeclaration<T extends TypeDeclaration<?>>
-
toTypeDeclaration
public java.util.Optional<TypeDeclaration> toTypeDeclaration()
- Overrides:
toTypeDeclaration
in classBodyDeclaration<T extends TypeDeclaration<?>>
-
resolve
public abstract ResolvedReferenceTypeDeclaration resolve()
-
-