Package com.github.javaparser.ast.body
Class MethodDeclaration
- java.lang.Object
-
- com.github.javaparser.ast.Node
-
- com.github.javaparser.ast.body.BodyDeclaration<T>
-
- com.github.javaparser.ast.body.CallableDeclaration<MethodDeclaration>
-
- com.github.javaparser.ast.body.MethodDeclaration
-
- All Implemented Interfaces:
NodeWithAbstractModifier<MethodDeclaration>,NodeWithAccessModifiers<MethodDeclaration>,NodeWithFinalModifier<MethodDeclaration>,NodeWithPrivateModifier<MethodDeclaration>,NodeWithProtectedModifier<MethodDeclaration>,NodeWithPublicModifier<MethodDeclaration>,NodeWithStaticModifier<MethodDeclaration>,NodeWithStrictfpModifier<MethodDeclaration>,NodeWithAnnotations<MethodDeclaration>,NodeWithDeclaration,NodeWithJavadoc<MethodDeclaration>,NodeWithModifiers<MethodDeclaration>,NodeWithOptionalBlockStmt<MethodDeclaration>,NodeWithParameters<MethodDeclaration>,NodeWithRange<Node>,NodeWithSimpleName<MethodDeclaration>,NodeWithThrownExceptions<MethodDeclaration>,NodeWithTokenRange<Node>,NodeWithType<MethodDeclaration,Type>,NodeWithTypeParameters<MethodDeclaration>,Observable,Visitable,HasParentNode<Node>,Resolvable<ResolvedMethodDeclaration>,Cloneable
public final class MethodDeclaration extends CallableDeclaration<MethodDeclaration> implements NodeWithType<MethodDeclaration,Type>, NodeWithOptionalBlockStmt<MethodDeclaration>, NodeWithJavadoc<MethodDeclaration>, NodeWithDeclaration, NodeWithSimpleName<MethodDeclaration>, NodeWithParameters<MethodDeclaration>, NodeWithThrownExceptions<MethodDeclaration>, NodeWithTypeParameters<MethodDeclaration>, NodeWithAccessModifiers<MethodDeclaration>, NodeWithAbstractModifier<MethodDeclaration>, NodeWithStaticModifier<MethodDeclaration>, NodeWithFinalModifier<MethodDeclaration>, NodeWithStrictfpModifier<MethodDeclaration>, Resolvable<ResolvedMethodDeclaration>
A method declaration. "public int abc() {return 1;}" in this example:class X { public int abc() {return 1;} }
All annotations preceding the return type will be set on this object, not on the return type. JavaParser doesn't know if it they are applicable to the method or the type.- Author:
- Julio Vilmar Gesser
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.github.javaparser.ast.body.CallableDeclaration
CallableDeclaration.Signature
-
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, NODE_BY_BEGIN_POSITION, prettyPrinterNoCommentsConfiguration, SYMBOL_RESOLVER_KEY
-
-
Constructor Summary
Constructors Constructor Description MethodDeclaration()MethodDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter)This constructor is used by the parser and is considered private.MethodDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, boolean isDefault, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body)Deprecated.this constructor allows you to set "isDefault", but this is no longer a field of this node, but simply one of the modifiers.MethodDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body)MethodDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter)MethodDeclaration(EnumSet<Modifier> modifiers, Type type, String name)MethodDeclaration(EnumSet<Modifier> modifiers, String name, Type type, NodeList<Parameter> parameters)
-
Method Summary
-
Methods inherited from class com.github.javaparser.ast.body.CallableDeclaration
appendThrowsIfRequested, asCallableDeclaration, getDeclarationAsString, getDeclarationAsString, getModifiers, getName, getParameters, getReceiverParameter, getSignature, getThrownExceptions, getTypeParameters, ifCallableDeclaration, isCallableDeclaration, removeReceiverParameter, setReceiverParameter, toCallableDeclaration
-
Methods inherited from class com.github.javaparser.ast.body.BodyDeclaration
asAnnotationDeclaration, asAnnotationMemberDeclaration, asClassOrInterfaceDeclaration, asConstructorDeclaration, asEnumConstantDeclaration, asEnumDeclaration, asFieldDeclaration, asInitializerDeclaration, asTypeDeclaration, getAnnotations, ifAnnotationDeclaration, ifAnnotationMemberDeclaration, ifClassOrInterfaceDeclaration, ifConstructorDeclaration, ifEnumConstantDeclaration, ifEnumDeclaration, ifFieldDeclaration, ifInitializerDeclaration, ifTypeDeclaration, isAnnotationDeclaration, isAnnotationMemberDeclaration, isClassOrInterfaceDeclaration, isConstructorDeclaration, isEnumConstantDeclaration, isEnumDeclaration, isFieldDeclaration, isInitializerDeclaration, isTypeDeclaration, setAnnotations, toAnnotationDeclaration, toAnnotationMemberDeclaration, toClassOrInterfaceDeclaration, toConstructorDeclaration, toEnumConstantDeclaration, toEnumDeclaration, toFieldDeclaration, toInitializerDeclaration, toTypeDeclaration
-
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, getNodesByType, getOrphanComments, getParentNode, getParentNodeForChildren, getParsed, getRange, getSymbolResolver, getTokenRange, hasComment, hashCode, 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, findParent, 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, addSingleMemberAnnotation, getAnnotation, getAnnotationByClass, getAnnotationByName, isAnnotationPresent, isAnnotationPresent, setAnnotation, tryAddImportToParentCompilationUnit
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithDeclaration
getDeclarationAsString, getDeclarationAsString
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier
isFinal, setFinal
-
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.NodeWithModifiers
addModifier, getModifiers, removeModifier, setModifier
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithOptionalBlockStmt
createBody
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithParameters
addAndGetParameter, addAndGetParameter, addAndGetParameter, addAndGetParameter, addParameter, addParameter, addParameter, addParameter, getParameter, getParameterByName, getParameterByType, getParameterByType, getParameters, hasParametersOfType, hasParametersOfType, setParameter, tryAddImportToParentCompilationUnit
-
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
getName, 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
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithThrownExceptions
addThrownException, addThrownException, getThrownException, getThrownExceptions, isThrown, isThrown, tryAddImportToParentCompilationUnit
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithType
getTypeAsString, setType, setType, tryAddImportToParentCompilationUnit
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters
addTypeParameter, addTypeParameter, getTypeParameter, getTypeParameters, isGeneric, setTypeParameter
-
-
-
-
Constructor Detail
-
MethodDeclaration
public MethodDeclaration()
-
MethodDeclaration
public MethodDeclaration(EnumSet<Modifier> modifiers, String name, Type type, NodeList<Parameter> parameters)
-
MethodDeclaration
public MethodDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body)
-
MethodDeclaration
public MethodDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter)
-
MethodDeclaration
@Deprecated public MethodDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, boolean isDefault, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body)
Deprecated.this constructor allows you to set "isDefault", but this is no longer a field of this node, but simply one of the modifiers. Use setDefault(boolean) or add DEFAULT to the modifiers set.
-
MethodDeclaration
public MethodDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter)
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:VisitableAccept method for visitor support.- Specified by:
acceptin 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:VisitableAccept method for visitor support.
-
getBody
public Optional<BlockStmt> getBody()
- Specified by:
getBodyin interfaceNodeWithOptionalBlockStmt<MethodDeclaration>
-
setBody
public MethodDeclaration setBody(BlockStmt body)
Sets the body- Specified by:
setBodyin interfaceNodeWithOptionalBlockStmt<MethodDeclaration>- Parameters:
body- the body, can be null- Returns:
- this, the MethodDeclaration
-
getType
public Type getType()
Description copied from interface:NodeWithTypeGets the type- Specified by:
getTypein interfaceNodeWithType<MethodDeclaration,Type>- Returns:
- the type
-
setType
public MethodDeclaration setType(Type type)
Description copied from interface:NodeWithTypeSets the type- Specified by:
setTypein interfaceNodeWithType<MethodDeclaration,Type>- Parameters:
type- the type- Returns:
- this
-
setModifiers
public MethodDeclaration setModifiers(EnumSet<Modifier> modifiers)
- Specified by:
setModifiersin interfaceNodeWithModifiers<MethodDeclaration>- Overrides:
setModifiersin classCallableDeclaration<MethodDeclaration>
-
setName
public MethodDeclaration setName(SimpleName name)
- Specified by:
setNamein interfaceNodeWithSimpleName<MethodDeclaration>- Overrides:
setNamein classCallableDeclaration<MethodDeclaration>
-
setParameters
public MethodDeclaration setParameters(NodeList<Parameter> parameters)
- Specified by:
setParametersin interfaceNodeWithParameters<MethodDeclaration>- Overrides:
setParametersin classCallableDeclaration<MethodDeclaration>
-
setThrownExceptions
public MethodDeclaration setThrownExceptions(NodeList<ReferenceType> thrownExceptions)
- Specified by:
setThrownExceptionsin interfaceNodeWithThrownExceptions<MethodDeclaration>- Overrides:
setThrownExceptionsin classCallableDeclaration<MethodDeclaration>
-
setTypeParameters
public MethodDeclaration setTypeParameters(NodeList<TypeParameter> typeParameters)
- Specified by:
setTypeParametersin interfaceNodeWithTypeParameters<MethodDeclaration>- Overrides:
setTypeParametersin classCallableDeclaration<MethodDeclaration>
-
getDeclarationAsString
public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows, boolean includingParameterName)
The declaration returned has this schema:[accessSpecifier] [static] [abstract] [final] [native] [synchronized] returnType methodName ([paramType [paramName]]) [throws exceptionsList]
- Specified by:
getDeclarationAsStringin interfaceNodeWithDeclaration- Specified by:
getDeclarationAsStringin classCallableDeclaration<MethodDeclaration>- Parameters:
includingModifiers- flag to include the modifiers (if present) in the string producedincludingThrows- flag to include the throws clause (if present) in the string producedincludingParameterName- flag to include the parameter name (while the parameter type is always included) in the string produced- Returns:
- method declaration as String
-
isNative
public boolean isNative()
-
isSynchronized
public boolean isSynchronized()
-
isDefault
public boolean isDefault()
-
setNative
public MethodDeclaration setNative(boolean set)
-
setSynchronized
public MethodDeclaration setSynchronized(boolean set)
-
setDefault
public MethodDeclaration setDefault(boolean set)
-
remove
public boolean remove(Node node)
- Overrides:
removein classCallableDeclaration<MethodDeclaration>
-
removeBody
public MethodDeclaration removeBody()
- Specified by:
removeBodyin interfaceNodeWithOptionalBlockStmt<MethodDeclaration>
-
clone
public MethodDeclaration clone()
- Overrides:
clonein classCallableDeclaration<MethodDeclaration>
-
getMetaModel
public MethodDeclarationMetaModel getMetaModel()
- Overrides:
getMetaModelin classCallableDeclaration<MethodDeclaration>- Returns:
- get JavaParser specific node introspection information.
-
replace
public boolean replace(Node node, Node replacementNode)
- Overrides:
replacein classCallableDeclaration<MethodDeclaration>
-
isMethodDeclaration
public boolean isMethodDeclaration()
- Overrides:
isMethodDeclarationin classBodyDeclaration<MethodDeclaration>
-
asMethodDeclaration
public MethodDeclaration asMethodDeclaration()
- Overrides:
asMethodDeclarationin classBodyDeclaration<MethodDeclaration>
-
ifMethodDeclaration
public void ifMethodDeclaration(Consumer<MethodDeclaration> action)
- Overrides:
ifMethodDeclarationin classBodyDeclaration<MethodDeclaration>
-
resolve
public ResolvedMethodDeclaration resolve()
- Specified by:
resolvein interfaceResolvable<ResolvedMethodDeclaration>
-
toMethodDeclaration
public Optional<MethodDeclaration> toMethodDeclaration()
- Overrides:
toMethodDeclarationin classBodyDeclaration<MethodDeclaration>
-
-