Package com.github.javaparser.ast.body
Class ClassOrInterfaceDeclaration
- java.lang.Object
-
- com.github.javaparser.ast.Node
-
- com.github.javaparser.ast.body.BodyDeclaration<T>
-
- com.github.javaparser.ast.body.TypeDeclaration<ClassOrInterfaceDeclaration>
-
- com.github.javaparser.ast.body.ClassOrInterfaceDeclaration
-
- All Implemented Interfaces:
NodeWithAbstractModifier<ClassOrInterfaceDeclaration>
,NodeWithAccessModifiers<ClassOrInterfaceDeclaration>
,NodeWithFinalModifier<ClassOrInterfaceDeclaration>
,NodeWithPrivateModifier<ClassOrInterfaceDeclaration>
,NodeWithProtectedModifier<ClassOrInterfaceDeclaration>
,NodeWithPublicModifier<ClassOrInterfaceDeclaration>
,NodeWithStaticModifier<ClassOrInterfaceDeclaration>
,NodeWithStrictfpModifier<ClassOrInterfaceDeclaration>
,NodeWithAnnotations<ClassOrInterfaceDeclaration>
,NodeWithExtends<ClassOrInterfaceDeclaration>
,NodeWithImplements<ClassOrInterfaceDeclaration>
,NodeWithJavadoc<ClassOrInterfaceDeclaration>
,NodeWithMembers<ClassOrInterfaceDeclaration>
,NodeWithModifiers<ClassOrInterfaceDeclaration>
,NodeWithRange<Node>
,NodeWithSimpleName<ClassOrInterfaceDeclaration>
,NodeWithTokenRange<Node>
,NodeWithTypeParameters<ClassOrInterfaceDeclaration>
,Observable
,Visitable
,HasParentNode<Node>
,Cloneable
public final class ClassOrInterfaceDeclaration extends TypeDeclaration<ClassOrInterfaceDeclaration> implements NodeWithImplements<ClassOrInterfaceDeclaration>, NodeWithExtends<ClassOrInterfaceDeclaration>, NodeWithTypeParameters<ClassOrInterfaceDeclaration>, NodeWithAbstractModifier<ClassOrInterfaceDeclaration>, NodeWithFinalModifier<ClassOrInterfaceDeclaration>
A definition of a class or interface.class X { ... }
- Author:
- Julio Vilmar Gesser
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.github.javaparser.ast.Node
Node.ObserverRegistrationMode, Node.Parsedness
-
-
Field Summary
-
Fields inherited from class com.github.javaparser.ast.Node
ABSOLUTE_BEGIN_LINE, ABSOLUTE_END_LINE, NODE_BY_BEGIN_POSITION, prettyPrinterNoCommentsConfiguration
-
-
Constructor Summary
Constructors Constructor Description ClassOrInterfaceDeclaration()
ClassOrInterfaceDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, boolean isInterface, SimpleName name, NodeList<TypeParameter> typeParameters, NodeList<ClassOrInterfaceType> extendedTypes, NodeList<ClassOrInterfaceType> implementedTypes, NodeList<BodyDeclaration<?>> members)
This constructor is used by the parser and is considered private.ClassOrInterfaceDeclaration(EnumSet<Modifier> modifiers, boolean isInterface, String name)
ClassOrInterfaceDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, boolean isInterface, SimpleName name, NodeList<TypeParameter> typeParameters, NodeList<ClassOrInterfaceType> extendedTypes, NodeList<ClassOrInterfaceType> implementedTypes, NodeList<BodyDeclaration<?>> members)
-
Method Summary
-
Methods inherited from class com.github.javaparser.ast.body.TypeDeclaration
addMember, getCallablesWithSignature, getMembers, getModifiers, getName, isNestedType, isTopLevelType, setMembers, setModifiers, setName
-
Methods inherited from class com.github.javaparser.ast.body.BodyDeclaration
getAnnotations, setAnnotations
-
Methods inherited from class com.github.javaparser.ast.Node
addOrphanComment, customInitialization, equals, getAllContainedComments, getChildNodes, getChildNodesByType, getComment, getData, getNodesByType, getOrphanComments, getParentNode, getParentNodeForChildren, getParsed, getRange, getTokenRange, hasComment, hashCode, isRegistered, notifyPropertyChange, register, register, registerForSubtree, remove, removeComment, removeForced, removeOrphanComment, replace, setAsParentNodeOf, setAsParentNodeOf, setBlockComment, setComment, setData, setLineComment, setParentNode, setParsed, setRange, setTokenRange, toString, toString, tryAddImportToParentCompilationUnit, unregister
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.javaparser.HasParentNode
getAncestorOfType
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAbstractModifier
isAbstract, setAbstract
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithAnnotations
addAndGetAnnotation, addAndGetAnnotation, addAnnotation, addAnnotation, addAnnotation, addMarkerAnnotation, addMarkerAnnotation, addSingleMemberAnnotation, addSingleMemberAnnotation, addSingleMemberAnnotation, getAnnotation, getAnnotationByClass, getAnnotationByName, isAnnotationPresent, isAnnotationPresent, setAnnotation, tryAddImportToParentCompilationUnit
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithExtends
addExtendedType, addExtendedType, addExtendedType, addExtends, addExtends, getExtendedTypes, setExtendedType, tryAddImportToParentCompilationUnit
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier
isFinal, setFinal
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithImplements
addImplementedType, addImplementedType, addImplementedType, addImplements, addImplements, getImplementedTypes, setImplementedType, tryAddImportToParentCompilationUnit
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithJavadoc
getComment, getJavadoc, getJavadocComment, hasJavaDocComment, removeJavaDocComment, setComment, setJavadocComment, setJavadocComment, setJavadocComment
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithMembers
addField, addField, addField, addInitializer, addMethod, addPrivateField, addPrivateField, addProtectedField, addProtectedField, addPublicField, addPublicField, addStaticInitializer, getFieldByName, getFields, getMember, getMethods, getMethodsByName, getMethodsByParameterTypes, getMethodsByParameterTypes, getMethodsBySignature, setMember, tryAddImportToParentCompilationUnit
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithModifiers
addModifier, getModifiers, 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, getBegin, getEnd, isPositionedAfter, isPositionedBefore
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithSimpleName
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
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters
addTypeParameter, getTypeParameter, isGeneric, setTypeParameter
-
-
-
-
Constructor Detail
-
ClassOrInterfaceDeclaration
public ClassOrInterfaceDeclaration()
-
ClassOrInterfaceDeclaration
public ClassOrInterfaceDeclaration(EnumSet<Modifier> modifiers, boolean isInterface, String name)
-
ClassOrInterfaceDeclaration
public ClassOrInterfaceDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, boolean isInterface, SimpleName name, NodeList<TypeParameter> typeParameters, NodeList<ClassOrInterfaceType> extendedTypes, NodeList<ClassOrInterfaceType> implementedTypes, NodeList<BodyDeclaration<?>> members)
-
ClassOrInterfaceDeclaration
@Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") public ClassOrInterfaceDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, boolean isInterface, SimpleName name, NodeList<TypeParameter> typeParameters, NodeList<ClassOrInterfaceType> extendedTypes, NodeList<ClassOrInterfaceType> implementedTypes, NodeList<BodyDeclaration<?>> members)
This constructor is used by the parser and is considered private.
-
-
Method Detail
-
accept
public <R,A> R accept(GenericVisitor<R,A> v, A arg)
Description copied from interface:Visitable
Accept method for visitor support.- Specified by:
accept
in interfaceVisitable
- Type Parameters:
R
- the type of the return value of the visitorA
- the type the user argument passed to the visitor- Parameters:
v
- the visitor implementationarg
- the argument passed to the visitor (of type A)- Returns:
- the result of the visit (of type R)
-
accept
public <A> void accept(VoidVisitor<A> v, A arg)
Description copied from interface:Visitable
Accept method for visitor support.
-
getExtendedTypes
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public NodeList<ClassOrInterfaceType> getExtendedTypes()
- Specified by:
getExtendedTypes
in interfaceNodeWithExtends<ClassOrInterfaceDeclaration>
-
getImplementedTypes
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public NodeList<ClassOrInterfaceType> getImplementedTypes()
- Specified by:
getImplementedTypes
in interfaceNodeWithImplements<ClassOrInterfaceDeclaration>
-
getTypeParameters
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public NodeList<TypeParameter> getTypeParameters()
- Specified by:
getTypeParameters
in interfaceNodeWithTypeParameters<ClassOrInterfaceDeclaration>
-
isInterface
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public boolean isInterface()
-
setExtendedTypes
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public ClassOrInterfaceDeclaration setExtendedTypes(NodeList<ClassOrInterfaceType> extendedTypes)
- Specified by:
setExtendedTypes
in interfaceNodeWithExtends<ClassOrInterfaceDeclaration>
-
setImplementedTypes
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public ClassOrInterfaceDeclaration setImplementedTypes(NodeList<ClassOrInterfaceType> implementedTypes)
- Specified by:
setImplementedTypes
in interfaceNodeWithImplements<ClassOrInterfaceDeclaration>
-
setInterface
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public ClassOrInterfaceDeclaration setInterface(boolean isInterface)
-
setTypeParameters
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public ClassOrInterfaceDeclaration setTypeParameters(NodeList<TypeParameter> typeParameters)
- Specified by:
setTypeParameters
in interfaceNodeWithTypeParameters<ClassOrInterfaceDeclaration>
-
getDefaultConstructor
public Optional<ConstructorDeclaration> getDefaultConstructor()
Try to find aConstructorDeclaration
with no parameters by its name- Returns:
- the methods found (multiple in case of polymorphism)
-
addConstructor
public ConstructorDeclaration addConstructor(Modifier... modifiers)
Adds a constructor to this- Parameters:
modifiers
- the modifiers likeModifier.PUBLIC
- Returns:
- the
MethodDeclaration
created
-
getConstructors
public List<ConstructorDeclaration> getConstructors()
Find all constructors for this class.- Returns:
- the constructors found. This list is immutable.
-
getConstructorByParameterTypes
public Optional<ConstructorDeclaration> getConstructorByParameterTypes(String... paramTypes)
Try to find aMethodDeclaration
by its parameters types- Parameters:
paramTypes
- the types of parameters like "Map<Integer,String>","int" to match
void foo(Map<Integer,String> myMap,int number)- Returns:
- the methods found (multiple in case of overloading)
-
getConstructorByParameterTypes
public Optional<ConstructorDeclaration> getConstructorByParameterTypes(Class<?>... paramTypes)
Try to find aMethodDeclaration
by its parameters types- Parameters:
paramTypes
- the types of parameters like "Map<Integer,String>","int" to match
void foo(Map<Integer,String> myMap,int number)- Returns:
- the methods found (multiple in case of overloading)
-
getNodeLists
@Generated("com.github.javaparser.generator.core.node.GetNodeListsGenerator") public List<NodeList<?>> getNodeLists()
Description copied from class:Node
The list of NodeLists owned by this node.- Overrides:
getNodeLists
in classTypeDeclaration<ClassOrInterfaceDeclaration>
-
remove
@Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") public boolean remove(Node node)
- Overrides:
remove
in classTypeDeclaration<ClassOrInterfaceDeclaration>
-
isLocalClassDeclaration
public boolean isLocalClassDeclaration()
- Returns:
- is this class's parent a LocalClassDeclarationStmt ?
-
isInnerClass
public boolean isInnerClass()
- Returns:
- is this an inner class? NOTE: many people are confused over terminology. Refer to https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html .
-
clone
@Generated("com.github.javaparser.generator.core.node.CloneGenerator") public ClassOrInterfaceDeclaration clone()
- Overrides:
clone
in classTypeDeclaration<ClassOrInterfaceDeclaration>
-
getMetaModel
@Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") public ClassOrInterfaceDeclarationMetaModel getMetaModel()
- Overrides:
getMetaModel
in classTypeDeclaration<ClassOrInterfaceDeclaration>
- Returns:
- get JavaParser specific node introspection information.
-
replace
@Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") public boolean replace(Node node, Node replacementNode)
- Overrides:
replace
in classTypeDeclaration<ClassOrInterfaceDeclaration>
-
-