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 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.
CallableDeclaration.Signature
Node.BreadthFirstIterator, Node.DirectChildrenIterator, Node.ObserverRegistrationMode, Node.ParentsVisitor, Node.Parsedness, Node.PostOrderIterator, Node.PreOrderIterator, Node.TreeTraversal
ABSOLUTE_BEGIN_LINE, ABSOLUTE_END_LINE, LINE_SEPARATOR_KEY, NODE_BY_BEGIN_POSITION, PHANTOM_KEY, prettyPrinterNoCommentsConfiguration, PRINTER_KEY, SYMBOL_RESOLVER_KEY
appendThrowsIfRequested, asCallableDeclaration, getModifiers, getName, getParameters, getReceiverParameter, getSignature, getThrownExceptions, getTypeParameters, ifCallableDeclaration, isCallableDeclaration, isFixedArityMethod, isVariableArityMethod, removeReceiverParameter, setReceiverParameter, toCallableDeclaration
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, toTypeDeclaration
addOrphanComment, containsData, createDefaultPrinter, createDefaultPrinter, customInitialization, equals, findAll, findAll, findAll, findByRange, findCompilationUnit, findData, 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, walk
finalize, getClass, notify, notifyAll, wait, wait, wait
getTypeAsString, setType, setType, tryAddImportToParentCompilationUnit
createBody
getComment, getJavadoc, getJavadocComment, hasJavaDocComment, removeJavaDocComment, setComment, setJavadocComment, setJavadocComment, setJavadocComment, setJavadocComment
getDeclarationAsString, getDeclarationAsString
getName, getNameAsExpression, getNameAsString, setName
addAndGetParameter, addAndGetParameter, addAndGetParameter, addAndGetParameter, addParameter, addParameter, addParameter, addParameter, getParameter, getParameterByName, getParameterByType, getParameterByType, getParameters, hasParametersOfType, hasParametersOfType, setParameter, tryAddImportToParentCompilationUnit
addThrownException, addThrownException, getThrownException, getThrownExceptions, isThrown, isThrown, tryAddImportToParentCompilationUnit
addTypeParameter, addTypeParameter, getTypeParameter, getTypeParameters, isGeneric, setTypeParameter
setPublic
isPrivate, setPrivate
isProtected, setProtected
addModifier, getAccessSpecifier, getModifiers, hasModifier, removeModifier, setModifier, setModifiers
setAbstract
isStatic, setStatic
isFinal, setFinal
isStrictfp, setStrictfp
addAndGetAnnotation, addAndGetAnnotation, addAnnotation, addAnnotation, addAnnotation, addMarkerAnnotation, addMarkerAnnotation, addSingleMemberAnnotation, addSingleMemberAnnotation, addSingleMemberAnnotation, addSingleMemberAnnotation, getAnnotation, getAnnotationByClass, getAnnotationByName, isAnnotationPresent, isAnnotationPresent, setAnnotation, tryAddImportToParentCompilationUnit
findAncestor, findAncestor, findAncestor, hasParentNode, isDescendantOf
containsWithin, containsWithinRange, getBegin, getEnd, hasRange
public MethodDeclaration()
public MethodDeclaration(NodeList<Modifier> modifiers, String name, Type type, NodeList<Parameter> parameters)
public MethodDeclaration(NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body)
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)
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)
public <R,A> R accept(GenericVisitor<R,A> v, A arg)
Visitable
accept
in interface Visitable
R
- the type of the return value of the visitorA
- the type the user argument passed to the visitorv
- the visitor implementationarg
- the argument passed to the visitor (of type A)public <A> void accept(VoidVisitor<A> v, A arg)
Visitable
public Optional<BlockStmt> getBody()
getBody
in interface NodeWithOptionalBlockStmt<MethodDeclaration>
public MethodDeclaration setBody(BlockStmt body)
setBody
in interface NodeWithOptionalBlockStmt<MethodDeclaration>
body
- the body, can be nullpublic Type getType()
NodeWithType
getType
in interface NodeWithType<MethodDeclaration,Type>
public MethodDeclaration setType(Type type)
NodeWithType
setType
in interface NodeWithType<MethodDeclaration,Type>
type
- the typepublic MethodDeclaration setModifiers(NodeList<Modifier> modifiers)
setModifiers
in interface NodeWithModifiers<MethodDeclaration>
setModifiers
in class CallableDeclaration<MethodDeclaration>
public MethodDeclaration setName(SimpleName name)
setName
in interface NodeWithSimpleName<MethodDeclaration>
setName
in class CallableDeclaration<MethodDeclaration>
public MethodDeclaration setParameters(NodeList<Parameter> parameters)
setParameters
in interface NodeWithParameters<MethodDeclaration>
setParameters
in class CallableDeclaration<MethodDeclaration>
public MethodDeclaration setThrownExceptions(NodeList<ReferenceType> thrownExceptions)
setThrownExceptions
in interface NodeWithThrownExceptions<MethodDeclaration>
setThrownExceptions
in class CallableDeclaration<MethodDeclaration>
public MethodDeclaration setTypeParameters(NodeList<TypeParameter> typeParameters)
setTypeParameters
in interface NodeWithTypeParameters<MethodDeclaration>
setTypeParameters
in class CallableDeclaration<MethodDeclaration>
public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows, boolean includingParameterName)
[accessSpecifier] [static] [abstract] [final] [native] [synchronized] returnType methodName ([paramType [paramName]]) [throws exceptionsList]
getDeclarationAsString
in interface NodeWithDeclaration
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 producedpublic String toDescriptor()
public boolean isPublic()
isPublic
in interface NodeWithPublicModifier<MethodDeclaration>
public boolean isAbstract()
isAbstract
in interface NodeWithAbstractModifier<MethodDeclaration>
public boolean isNative()
public boolean isSynchronized()
public boolean isDefault()
public MethodDeclaration setNative(boolean set)
public MethodDeclaration setSynchronized(boolean set)
public MethodDeclaration setDefault(boolean set)
public boolean remove(Node node)
remove
in class CallableDeclaration<MethodDeclaration>
public MethodDeclaration removeBody()
removeBody
in interface NodeWithOptionalBlockStmt<MethodDeclaration>
public MethodDeclaration clone()
clone
in class CallableDeclaration<MethodDeclaration>
public MethodDeclarationMetaModel getMetaModel()
getMetaModel
in class CallableDeclaration<MethodDeclaration>
public boolean replace(Node node, Node replacementNode)
replace
in class CallableDeclaration<MethodDeclaration>
public boolean isMethodDeclaration()
isMethodDeclaration
in class BodyDeclaration<MethodDeclaration>
public MethodDeclaration asMethodDeclaration()
asMethodDeclaration
in class BodyDeclaration<MethodDeclaration>
public void ifMethodDeclaration(Consumer<MethodDeclaration> action)
ifMethodDeclaration
in class BodyDeclaration<MethodDeclaration>
public ResolvedMethodDeclaration resolve()
resolve
in interface Resolvable<ResolvedMethodDeclaration>
public Optional<MethodDeclaration> toMethodDeclaration()
toMethodDeclaration
in class BodyDeclaration<MethodDeclaration>
Copyright © 2007–2024. All rights reserved.