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 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.SignatureNested 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
ConstructorsConstructorDescriptionMethodDeclaration(NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body)MethodDeclaration(NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter)MethodDeclaration(NodeList<Modifier> modifiers, Type type, String name)MethodDeclaration(NodeList<Modifier> modifiers, String name, Type type, NodeList<Parameter> parameters)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 TypeMethodDescription<R, A> Raccept(GenericVisitor<R,A> v, A arg)Accept method for visitor support.<A> voidaccept(VoidVisitor<A> v, A arg)Accept method for visitor support.clone()getBody()getDeclarationAsString(boolean includingModifiers, boolean includingThrows, boolean includingParameterName)The declaration returned has this schema:getType()Gets the typevoidifMethodDeclaration(Consumer<MethodDeclaration> action)booleanbooleanbooleanisNative()booleanbooleanbooleanresolve()Sets the bodysetDefault(boolean set)setModifiers(NodeList<Modifier> modifiers)setName(SimpleName name)setNative(boolean set)setParameters(NodeList<Parameter> parameters)setSynchronized(boolean set)setThrownExceptions(NodeList<ReferenceType> thrownExceptions)Sets the typesetTypeParameters(NodeList<TypeParameter> typeParameters)Methods inherited from class com.github.javaparser.ast.body.CallableDeclaration
appendThrowsIfRequested, asCallableDeclaration, getModifiers, getName, getParameters, getReceiverParameter, getSignature, getThrownExceptions, getTypeParameters, ifCallableDeclaration, isCallableDeclaration, isFixedArityMethod, isVariableArityMethod, removeReceiverParameter, setReceiverParameter, toCallableDeclarationMethods inherited from class com.github.javaparser.ast.body.BodyDeclaration
asAnnotationDeclaration, asAnnotationMemberDeclaration, asClassOrInterfaceDeclaration, asCompactConstructorDeclaration, asConstructorDeclaration, asEnumConstantDeclaration, asEnumDeclaration, asFieldDeclaration, asInitializerDeclaration, asRecordDeclaration, asTypeDeclaration, getAnnotations, ifAnnotationDeclaration, ifAnnotationMemberDeclaration, ifClassOrInterfaceDeclaration, ifCompactConstructorDeclaration, ifConstructorDeclaration, ifEnumConstantDeclaration, ifEnumDeclaration, ifFieldDeclaration, ifInitializerDeclaration, ifRecordDeclaration, ifTypeDeclaration, isAnnotationDeclaration, isAnnotationMemberDeclaration, isClassOrInterfaceDeclaration, isCompactConstructorDeclaration, isConstructorDeclaration, isEnumConstantDeclaration, isEnumDeclaration, isFieldDeclaration, isInitializerDeclaration, isRecordDeclaration, isTypeDeclaration, setAnnotations, toAnnotationDeclaration, toAnnotationMemberDeclaration, toClassOrInterfaceDeclaration, toCompactConstructorDeclaration, toConstructorDeclaration, toEnumConstantDeclaration, toEnumDeclaration, toFieldDeclaration, toInitializerDeclaration, toRecordDeclaration, toTypeDeclarationMethods 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, walkMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.github.javaparser.HasParentNode
findAncestor, findAncestor, hasParentNode, isDescendantOfMethods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAbstractModifier
isAbstract, setAbstractMethods 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, tryAddImportToParentCompilationUnitMethods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithDeclaration
getDeclarationAsString, getDeclarationAsStringMethods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier
isFinal, setFinalMethods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithJavadoc
getComment, getJavadoc, getJavadocComment, hasJavaDocComment, removeJavaDocComment, setComment, setJavadocComment, setJavadocComment, setJavadocComment, setJavadocCommentMethods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithModifiers
addModifier, getAccessSpecifier, getModifiers, hasModifier, removeModifier, setModifier, setModifiersMethods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithOptionalBlockStmt
createBodyMethods 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, tryAddImportToParentCompilationUnitMethods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithPrivateModifier
isPrivate, setPrivateMethods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithProtectedModifier
isProtected, setProtectedMethods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithPublicModifier
isPublic, setPublicMethods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithRange
containsWithin, containsWithinRange, getBegin, getEnd, hasRangeMethods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithSimpleName
getName, getNameAsExpression, getNameAsString, setNameMethods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithStaticModifier
isStatic, setStaticMethods inherited from interface com.github.javaparser.ast.nodeTypes.modifiers.NodeWithStrictfpModifier
isStrictfp, setStrictfpMethods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithThrownExceptions
addThrownException, addThrownException, getThrownException, getThrownExceptions, isThrown, isThrown, tryAddImportToParentCompilationUnitMethods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithType
getTypeAsString, setType, setType, tryAddImportToParentCompilationUnitMethods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters
addTypeParameter, addTypeParameter, getTypeParameter, getTypeParameters, isGeneric, setTypeParameter
-
Constructor Details
-
MethodDeclaration
public MethodDeclaration() -
MethodDeclaration
-
MethodDeclaration
-
MethodDeclaration
public MethodDeclaration(NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body) -
MethodDeclaration
public MethodDeclaration(NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter) -
MethodDeclaration
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 Details
-
accept
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
Description copied from interface:VisitableAccept method for visitor support. -
getBody
- Specified by:
getBodyin interfaceNodeWithOptionalBlockStmt<MethodDeclaration>
-
setBody
Sets the body- Specified by:
setBodyin interfaceNodeWithOptionalBlockStmt<MethodDeclaration>- Parameters:
body- the body, can be null- Returns:
- this, the MethodDeclaration
-
getType
Description copied from interface:NodeWithTypeGets the type- Specified by:
getTypein interfaceNodeWithType<MethodDeclaration,Type>- Returns:
- the type
-
setType
Description copied from interface:NodeWithTypeSets the type- Specified by:
setTypein interfaceNodeWithType<MethodDeclaration,Type>- Parameters:
type- the type- Returns:
- this
-
setModifiers
- Specified by:
setModifiersin interfaceNodeWithModifiers<MethodDeclaration>- Overrides:
setModifiersin classCallableDeclaration<MethodDeclaration>
-
setName
- Specified by:
setNamein interfaceNodeWithSimpleName<MethodDeclaration>- Overrides:
setNamein classCallableDeclaration<MethodDeclaration>
-
setParameters
- Specified by:
setParametersin interfaceNodeWithParameters<MethodDeclaration>- Overrides:
setParametersin classCallableDeclaration<MethodDeclaration>
-
setThrownExceptions
- Specified by:
setThrownExceptionsin interfaceNodeWithThrownExceptions<MethodDeclaration>- Overrides:
setThrownExceptionsin classCallableDeclaration<MethodDeclaration>
-
setTypeParameters
- 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- 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
-
toDescriptor
-
isNative
public boolean isNative() -
isSynchronized
public boolean isSynchronized() -
isDefault
public boolean isDefault() -
setNative
-
setSynchronized
-
setDefault
-
remove
- Overrides:
removein classCallableDeclaration<MethodDeclaration>
-
removeBody
- Specified by:
removeBodyin interfaceNodeWithOptionalBlockStmt<MethodDeclaration>
-
clone
- Overrides:
clonein classCallableDeclaration<MethodDeclaration>
-
getMetaModel
- Overrides:
getMetaModelin classCallableDeclaration<MethodDeclaration>- Returns:
- get JavaParser specific node introspection information.
-
replace
- Overrides:
replacein classCallableDeclaration<MethodDeclaration>
-
isMethodDeclaration
public boolean isMethodDeclaration()- Overrides:
isMethodDeclarationin classBodyDeclaration<MethodDeclaration>
-
asMethodDeclaration
- Overrides:
asMethodDeclarationin classBodyDeclaration<MethodDeclaration>
-
ifMethodDeclaration
- Overrides:
ifMethodDeclarationin classBodyDeclaration<MethodDeclaration>
-
resolve
- Specified by:
resolvein interfaceResolvable<ResolvedMethodDeclaration>
-
toMethodDeclaration
- Overrides:
toMethodDeclarationin classBodyDeclaration<MethodDeclaration>
-