Top Description Fields Constructors Methods
com.github.javaparser.ast.body

public 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>
Class Inheritance
All Implemented Interfaces
com.github.javaparser.resolution.Resolvable, com.github.javaparser.ast.nodeTypes.modifiers.NodeWithStrictfpModifier, com.github.javaparser.ast.nodeTypes.NodeWithModifiers, com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier, com.github.javaparser.ast.nodeTypes.modifiers.NodeWithStaticModifier, com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAbstractModifier, com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAccessModifiers, com.github.javaparser.ast.nodeTypes.modifiers.NodeWithProtectedModifier, com.github.javaparser.ast.nodeTypes.modifiers.NodeWithPrivateModifier, com.github.javaparser.ast.nodeTypes.modifiers.NodeWithPublicModifier, com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters, com.github.javaparser.ast.nodeTypes.NodeWithThrownExceptions, com.github.javaparser.ast.nodeTypes.NodeWithParameters, com.github.javaparser.ast.nodeTypes.NodeWithSimpleName, com.github.javaparser.ast.nodeTypes.NodeWithDeclaration, com.github.javaparser.ast.nodeTypes.NodeWithJavadoc, com.github.javaparser.ast.nodeTypes.NodeWithOptionalBlockStmt, com.github.javaparser.ast.nodeTypes.NodeWithType
Imports
com.github.javaparser.ast.*, .Node, .Generated, com.github.javaparser.ast.expr.AnnotationExpr, .SimpleName, com.github.javaparser.ast.nodeTypes.*, com.github.javaparser.ast.nodeTypes.modifiers.*, com.github.javaparser.ast.observer.ObservableProperty, com.github.javaparser.ast.stmt.BlockStmt, com.github.javaparser.ast.type.ClassOrInterfaceType, .ReferenceType, .Type, .TypeParameter, com.github.javaparser.ast.visitor.GenericVisitor, .VoidVisitor, .CloneVisitor, java.util.Optional, com.github.javaparser.metamodel.MethodDeclarationMetaModel, .JavaParserMetaModel, .OptionalProperty, com.github.javaparser.TokenRange, com.github.javaparser.resolution.Resolvable, com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration, java.util.function.Consumer

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

Field Summary

Modifier and TypeField and Description
private BlockStmt
private Type

Constructor Summary

AccessConstructor and Description
public
public
MethodDeclaration(final NodeList<Modifier> modifiers, final Type type, final String name)

public
MethodDeclaration(final NodeList<Modifier> modifiers, final String name, final Type type, final NodeList<Parameter> parameters)

public
MethodDeclaration(final NodeList<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final NodeList<TypeParameter> typeParameters, final Type type, final SimpleName name, final NodeList<Parameter> parameters, final NodeList<ReferenceType> thrownExceptions, final BlockStmt body)

public
MethodDeclaration(final NodeList<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final NodeList<TypeParameter> typeParameters, final Type type, final SimpleName name, final NodeList<Parameter> parameters, final NodeList<ReferenceType> thrownExceptions, final BlockStmt body, ReceiverParameter receiverParameter)

public
MethodDeclaration(TokenRange tokenRange, NodeList<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 Summary

Modifier and TypeMethod and Description
public <R, A> R
accept(final GenericVisitor<R, A>
the visitor implementation
v
,
final A
the argument passed to the visitor (of type A)
arg
)

Implements com.github.javaparser.ast.visitor.Visitable.accept.

Accept method for visitor support.
public <A> void
accept(final VoidVisitor<A>
the visitor implementation
v
,
final A
any value relevant for the visitor (of type A)
arg
)

Implements com.github.javaparser.ast.visitor.Visitable.accept.

Accept method for visitor support.
public MethodDeclaration
public MethodDeclaration
clone()

Overrides com.github.javaparser.ast.body.CallableDeclaration.clone.

Creates and returns a copy of this object.
public Optional<BlockStmt>
public String

Returns:

method declaration as String
getDeclarationAsString
(boolean
flag to include the modifiers (if present) in the string produced
includingModifiers
,
boolean
flag to include the throws clause (if present) in the string produced
includingThrows
,
boolean
flag to include the parameter name (while the parameter type is always included) in the string produced
includingParameterName
)

Implements com.github.javaparser.ast.nodeTypes.NodeWithDeclaration.getDeclarationAsString.

The declaration returned has this schema:

[accessSpecifier] [static] [abstract] [final] [native] [synchronized] returnType methodName ([paramType [paramName]]) [throws exceptionsList]

public MethodDeclarationMetaModel
public Type
public void
public boolean
public boolean
public boolean
public boolean
public boolean
public MethodDeclaration
public boolean
public ResolvedMethodDeclaration
public MethodDeclaration

Returns:

this, the MethodDeclaration
setBody
(final BlockStmt
the body, can be null
body
)

Implements com.github.javaparser.ast.nodeTypes.NodeWithOptionalBlockStmt.setBody.

Sets the body
public MethodDeclaration
setDefault(boolean set)

public MethodDeclaration
public MethodDeclaration
public MethodDeclaration
setNative(boolean set)

public MethodDeclaration
public MethodDeclaration
setSynchronized(boolean set)

public MethodDeclaration
public MethodDeclaration
setType(final Type
the type
type
)

Implements com.github.javaparser.ast.nodeTypes.NodeWithType.setType.

Sets the type
public MethodDeclaration
public Optional<MethodDeclaration>
Inherited from com.github.javaparser.ast.body.CallableDeclaration:
appendThrowsIfRequestedasCallableDeclarationgetModifiersgetNamegetParametersgetReceiverParametergetSignaturegetThrownExceptionsgetTypeParametersifCallableDeclarationisCallableDeclarationremoveReceiverParametersetReceiverParametertoCallableDeclaration

Field Detail

bodyback to summary
private BlockStmt body
Annotations
@OptionalProperty
typeback to summary
private Type type

Constructor Detail

MethodDeclarationback to summary
public MethodDeclaration()
MethodDeclarationback to summary
public MethodDeclaration(final NodeList<Modifier> modifiers, final Type type, final String name)
MethodDeclarationback to summary
public MethodDeclaration(final NodeList<Modifier> modifiers, final String name, final Type type, final NodeList<Parameter> parameters)
MethodDeclarationback to summary
public MethodDeclaration(final NodeList<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final NodeList<TypeParameter> typeParameters, final Type type, final SimpleName name, final NodeList<Parameter> parameters, final NodeList<ReferenceType> thrownExceptions, final BlockStmt body)
MethodDeclarationback to summary
public MethodDeclaration(final NodeList<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final NodeList<TypeParameter> typeParameters, final Type type, final SimpleName name, final NodeList<Parameter> parameters, final NodeList<ReferenceType> thrownExceptions, final BlockStmt body, ReceiverParameter receiverParameter)
Annotations
@AllFieldsConstructor
MethodDeclarationback to summary
public MethodDeclaration(TokenRange tokenRange, NodeList<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.

Annotations
@Generated:com.github.javaparser.generator.core.node.MainConstructorGenerator

Method Detail

acceptback to summary
public <R, A> R accept(final GenericVisitor<R, A> v, final A arg)

Implements com.github.javaparser.ast.visitor.Visitable.accept.

Doc from com.github.javaparser.ast.visitor.Visitable.accept.

Accept method for visitor support.

Parameters
<R>
the type of the return value of the visitor
<A>
the type the user argument passed to the visitor
v:GenericVisitor<R, A>

the visitor implementation

arg:A

the argument passed to the visitor (of type A)

Returns:R

the result of the visit (of type R)

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.AcceptGenerator
acceptback to summary
public <A> void accept(final VoidVisitor<A> v, final A arg)

Implements com.github.javaparser.ast.visitor.Visitable.accept.

Doc from com.github.javaparser.ast.visitor.Visitable.accept.

Accept method for visitor support.

Parameters
<A>
the type the argument passed for the visitor
v:VoidVisitor<A>

the visitor implementation

arg:A

any value relevant for the visitor (of type A)

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.AcceptGenerator
asMethodDeclarationback to summary
public MethodDeclaration asMethodDeclaration()

Overrides com.github.javaparser.ast.body.BodyDeclaration.asMethodDeclaration.

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator
cloneback to summary
public MethodDeclaration clone()

Overrides com.github.javaparser.ast.body.CallableDeclaration.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:MethodDeclaration

a clone of this instance.

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.CloneGenerator
getBodyback to summary
public Optional<BlockStmt> getBody()

Implements com.github.javaparser.ast.nodeTypes.NodeWithOptionalBlockStmt.getBody.

Annotations
@Generated:com.github.javaparser.generator.core.node.PropertyGenerator
getDeclarationAsStringback to summary
public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows, boolean includingParameterName)

Implements com.github.javaparser.ast.nodeTypes.NodeWithDeclaration.getDeclarationAsString.

The declaration returned has this schema:

[accessSpecifier] [static] [abstract] [final] [native] [synchronized] returnType methodName ([paramType [paramName]]) [throws exceptionsList]

Parameters
includingModifiers:boolean

Doc from com.github.javaparser.ast.nodeTypes.NodeWithDeclaration.getDeclarationAsString.

flag to include the modifiers (if present) in the string produced

includingThrows:boolean

Doc from com.github.javaparser.ast.nodeTypes.NodeWithDeclaration.getDeclarationAsString.

flag to include the throws clause (if present) in the string produced

includingParameterName:boolean

Doc from com.github.javaparser.ast.nodeTypes.NodeWithDeclaration.getDeclarationAsString.

flag to include the parameter name (while the parameter type is always included) in the string produced

Returns:String

method declaration as String

Annotations
@Override
getMetaModelback to summary
public MethodDeclarationMetaModel getMetaModel()

Overrides com.github.javaparser.ast.body.CallableDeclaration.getMetaModel.

Returns:MethodDeclarationMetaModel

Doc from com.github.javaparser.ast.Node.getMetaModel.

get JavaParser specific node introspection information.

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.GetMetaModelGenerator
getTypeback to summary
public Type getType()

Implements com.github.javaparser.ast.nodeTypes.NodeWithType.getType.

Doc from com.github.javaparser.ast.nodeTypes.NodeWithType.getType.

Gets the type

Returns:Type

the type

Annotations
@Generated:com.github.javaparser.generator.core.node.PropertyGenerator
ifMethodDeclarationback to summary
public void ifMethodDeclaration(Consumer<MethodDeclaration> action)

Overrides com.github.javaparser.ast.body.BodyDeclaration.ifMethodDeclaration.

Annotations
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator
isDefaultback to summary
public boolean isDefault()
isMethodDeclarationback to summary
public boolean isMethodDeclaration()

Overrides com.github.javaparser.ast.body.BodyDeclaration.isMethodDeclaration.

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator
isNativeback to summary
public boolean isNative()
isSynchronizedback to summary
public boolean isSynchronized()
removeback to summary
public boolean remove(Node node)

Overrides com.github.javaparser.ast.body.CallableDeclaration.remove.

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.RemoveMethodGenerator
removeBodyback to summary
public MethodDeclaration removeBody()

Implements com.github.javaparser.ast.nodeTypes.NodeWithOptionalBlockStmt.removeBody.

Annotations
@Generated:com.github.javaparser.generator.core.node.RemoveMethodGenerator
replaceback to summary
public boolean replace(Node node, Node replacementNode)

Overrides com.github.javaparser.ast.body.CallableDeclaration.replace.

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.ReplaceMethodGenerator
resolveback to summary
public ResolvedMethodDeclaration resolve()

Implements com.github.javaparser.resolution.Resolvable.resolve.

Annotations
@Override
setBodyback to summary
public MethodDeclaration setBody(final BlockStmt body)

Implements com.github.javaparser.ast.nodeTypes.NodeWithOptionalBlockStmt.setBody.

Sets the body

Parameters
body:BlockStmt

the body, can be null

Returns:MethodDeclaration

this, the MethodDeclaration

Annotations
@Generated:com.github.javaparser.generator.core.node.PropertyGenerator
setDefaultback to summary
public MethodDeclaration setDefault(boolean set)
setModifiersback to summary
public MethodDeclaration setModifiers(final NodeList<Modifier> modifiers)

Overrides com.github.javaparser.ast.body.CallableDeclaration.setModifiers.

Implements com.github.javaparser.ast.nodeTypes.NodeWithModifiers.setModifiers.

Annotations
@Override
setNameback to summary
public MethodDeclaration setName(final SimpleName name)

Overrides com.github.javaparser.ast.body.CallableDeclaration.setName.

Implements com.github.javaparser.ast.nodeTypes.NodeWithSimpleName.setName.

Annotations
@Override
setNativeback to summary
public MethodDeclaration setNative(boolean set)
setParametersback to summary
public MethodDeclaration setParameters(final NodeList<Parameter> parameters)

Overrides com.github.javaparser.ast.body.CallableDeclaration.setParameters.

Implements com.github.javaparser.ast.nodeTypes.NodeWithParameters.setParameters.

Annotations
@Override
setSynchronizedback to summary
public MethodDeclaration setSynchronized(boolean set)
setThrownExceptionsback to summary
public MethodDeclaration setThrownExceptions(final NodeList<ReferenceType> thrownExceptions)

Overrides com.github.javaparser.ast.body.CallableDeclaration.setThrownExceptions.

Implements com.github.javaparser.ast.nodeTypes.NodeWithThrownExceptions.setThrownExceptions.

Annotations
@Override
setTypeback to summary
public MethodDeclaration setType(final Type type)

Implements com.github.javaparser.ast.nodeTypes.NodeWithType.setType.

Doc from com.github.javaparser.ast.nodeTypes.NodeWithType.setType.

Sets the type

Parameters
type:Type

the type

Returns:MethodDeclaration

this

Annotations
@Generated:com.github.javaparser.generator.core.node.PropertyGenerator
setTypeParametersback to summary
public MethodDeclaration setTypeParameters(final NodeList<TypeParameter> typeParameters)

Overrides com.github.javaparser.ast.body.CallableDeclaration.setTypeParameters.

Implements com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters.setTypeParameters.

Annotations
@Override
toMethodDeclarationback to summary
public Optional<MethodDeclaration> toMethodDeclaration()

Overrides com.github.javaparser.ast.body.BodyDeclaration.toMethodDeclaration.

Annotations
@Override
@Generated:com.github.javaparser.generator.core.node.TypeCastingGenerator