Class MethodDecl
- java.lang.Object
-
- com.tonic.analysis.source.ast.decl.MethodDecl
-
-
Constructor Summary
Constructors Constructor Description MethodDecl(String name, SourceType returnType)Creates a declaration with an unknown source location.MethodDecl(String name, SourceType returnType, SourceLocation location)Creates a declaration with no modifiers, parameters or body.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.MethodDecladdAnnotation(AnnotationExpr annotation)Appends an annotation.MethodDecladdModifier(Modifier modifier)Adds one modifier, keeping the existing ones.MethodDecladdParameter(ParameterDecl parameter)Appends a parameter at the end of the parameter list.MethodDecladdThrowsType(SourceType throwsType)Appends a declared thrown type.MethodDecladdTypeParameter(SourceType typeParam)Appends a generic type parameter.NodeList<AnnotationExpr>getAnnotations()BlockStmtgetBody()List<ASTNode>getChildren()Lists the direct children a node holds, in source order.SourceLocationgetLocation()Gets the source location of this node.Set<Modifier>getModifiers()StringgetName()NodeList<ParameterDecl>getParameters()ASTNodegetParent()Gets the parent node in the AST tree.SourceTypegetReturnType()StringgetSignature()Renders the name and parameter types as name(type,type), ignoring the return type.NodeList<SourceType>getThrowsTypes()NodeList<SourceType>getTypeParameters()booleanhasBody()booleanisAbstract()booleanisDefault()booleanisFinal()booleanisNative()booleanisPrivate()booleanisProtected()booleanisPublic()booleanisStatic()booleanisSynchronized()voidsetBody(BlockStmt body)Sets the body, reparenting the new block and releasing the old one.voidsetName(String name)Sets the method name.voidsetParent(ASTNode parent)Sets the enclosing AST node.voidsetReturnType(SourceType returnType)Sets the declared return type.StringtoString()MethodDeclwithBody(BlockStmt body)Sets the body, reparenting the new block and releasing the old one.MethodDeclwithModifiers(Set<Modifier> modifiers)Replaces the whole modifier set.MethodDeclwithName(String name)Sets the method name.MethodDeclwithReturnType(SourceType returnType)Sets the declared return type.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.tonic.analysis.source.ast.ASTNode
deepClone, findAll, findAll, findAncestor, findFirst, findFirst, getRoot, isDescendantOf, remove, replaceWith, stream, stream, walk
-
-
-
-
Constructor Detail
-
MethodDecl
public MethodDecl(String name, SourceType returnType, SourceLocation location)
Creates a declaration with no modifiers, parameters or body.- Parameters:
name- the method namereturnType- the declared return typelocation- the source location, null for unknown
-
MethodDecl
public MethodDecl(String name, SourceType returnType)
Creates a declaration with an unknown source location.- Parameters:
name- the method namereturnType- the declared return type
-
-
Method Detail
-
getName
public String getName()
- Returns:
- the name
-
setName
public void setName(String name)
Sets the method name.- Parameters:
name- the new name
-
getAnnotations
public NodeList<AnnotationExpr> getAnnotations()
- Returns:
- the annotations
-
getReturnType
public SourceType getReturnType()
- Returns:
- the return type
-
setReturnType
public void setReturnType(SourceType returnType)
Sets the declared return type.- Parameters:
returnType- the new return type
-
getParameters
public NodeList<ParameterDecl> getParameters()
- Returns:
- the parameters
-
getTypeParameters
public NodeList<SourceType> getTypeParameters()
- Returns:
- the type parameters
-
getThrowsTypes
public NodeList<SourceType> getThrowsTypes()
- Returns:
- the throws types
-
getBody
public BlockStmt getBody()
- Returns:
- the body
-
setBody
public void setBody(BlockStmt body)
Sets the body, reparenting the new block and releasing the old one.- Parameters:
body- the new body, or null to make the method bodyless
-
getLocation
public SourceLocation getLocation()
Description copied from interface:ASTNodeGets the source location of this node.- Specified by:
getLocationin interfaceASTNode- Returns:
- the source location, or null if unknown
-
getParent
public ASTNode getParent()
Description copied from interface:ASTNodeGets the parent node in the AST tree.
-
setParent
public void setParent(ASTNode parent)
Sets the enclosing AST node.
-
withName
public MethodDecl withName(String name)
Sets the method name.- Parameters:
name- the new name- Returns:
- this declaration
-
withReturnType
public MethodDecl withReturnType(SourceType returnType)
Sets the declared return type.- Parameters:
returnType- the new return type- Returns:
- this declaration
-
withModifiers
public MethodDecl withModifiers(Set<Modifier> modifiers)
Replaces the whole modifier set.- Parameters:
modifiers- the modifiers to hold- Returns:
- this declaration
-
addModifier
public MethodDecl addModifier(Modifier modifier)
Adds one modifier, keeping the existing ones.- Parameters:
modifier- the modifier to add- Returns:
- this declaration
-
addAnnotation
public MethodDecl addAnnotation(AnnotationExpr annotation)
Appends an annotation.- Parameters:
annotation- the annotation to add- Returns:
- this declaration
-
addParameter
public MethodDecl addParameter(ParameterDecl parameter)
Appends a parameter at the end of the parameter list.- Parameters:
parameter- the parameter to add- Returns:
- this declaration
-
addTypeParameter
public MethodDecl addTypeParameter(SourceType typeParam)
Appends a generic type parameter.- Parameters:
typeParam- the type parameter to add- Returns:
- this declaration
-
addThrowsType
public MethodDecl addThrowsType(SourceType throwsType)
Appends a declared thrown type.- Parameters:
throwsType- the thrown type to add- Returns:
- this declaration
-
withBody
public MethodDecl withBody(BlockStmt body)
Sets the body, reparenting the new block and releasing the old one.- Parameters:
body- the new body, or null to make the method bodyless- Returns:
- this declaration
-
hasBody
public boolean hasBody()
- Returns:
- true if the method has a body rather than being abstract or native
-
isPublic
public boolean isPublic()
- Returns:
- true if the public modifier is set
-
isProtected
public boolean isProtected()
- Returns:
- true if the protected modifier is set
-
isPrivate
public boolean isPrivate()
- Returns:
- true if the private modifier is set
-
isStatic
public boolean isStatic()
- Returns:
- true if the static modifier is set
-
isFinal
public boolean isFinal()
- Returns:
- true if the final modifier is set
-
isAbstract
public boolean isAbstract()
- Returns:
- true if the abstract modifier is set
-
isSynchronized
public boolean isSynchronized()
- Returns:
- true if the synchronized modifier is set
-
isNative
public boolean isNative()
- Returns:
- true if the native modifier is set
-
isDefault
public boolean isDefault()
- Returns:
- true if the default modifier is set
-
getSignature
public String getSignature()
Renders the name and parameter types as name(type,type), ignoring the return type.- Returns:
- the signature string
-
getChildren
public List<ASTNode> getChildren()
Description copied from interface:ASTNodeLists the direct children a node holds, in source order.- Specified by:
getChildrenin interfaceASTNode- Returns:
- the direct children, empty for a leaf
-
accept
public <T> T accept(SourceVisitor<T> visitor)
Description copied from interface:ASTNodeAccepts a visitor for this node.
-
-