|
Eclipse JDT 2.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.eclipse.jdt.core.dom.ASTNode | +--org.eclipse.jdt.core.dom.BodyDeclaration | +--org.eclipse.jdt.core.dom.MethodDeclaration
Method declaration AST node type. A method declaration is the union of a method declaration and a constructor declaration.
MethodDeclaration: [ Javadoc ] { Modifier } ( Type | void ) Identifier ( [ FormalParameter { , FormalParameter } ] ) {[ ] } [ throws TypeName { , TypeName } ] ( Block | ; ) ConstructorDeclaration: [ Javadoc ] { Modifier } Identifier ( [ FormalParameter { , FormalParameter } ] ) [throws TypeName { , TypeName } ] Block
When a Javadoc comment is present, the source range begins with the first character of the "/**" comment delimiter. When there is no Javadoc comment, the source range begins with the first character of the first modifier keyword (if modifiers), or the first character of the return type (method, no modifiers), or the first character of the identifier (constructor, no modifiers). The source range extends through the last character of the ";" token (if no body), or the last character of the block (if body).
Method Summary | |
Block |
getBody()
Returns the body of this method declaration, or null if
this method has no body. |
int |
getExtraDimensions()
Returns the number of extra array dimensions over and above the explicitly-specified return type. |
int |
getModifiers()
Returns the modifiers explicitly specified on this declaration. |
SimpleName |
getName()
Returns the name of the method declared in this method declaration. |
int |
getNodeType()
Returns an integer value identifying the type of this concrete AST node. |
Type |
getReturnType()
Returns the return type of the method declared in this method declaration, exclusive of any extra array dimensions. |
boolean |
isConstructor()
Returns whether this declaration declares a constructor or a method. |
List |
parameters()
Returns the live ordered list of method parameter declarations for this method declaration. |
IMethodBinding |
resolveBinding()
Resolves and returns the binding for the method or constructor declared in this method or constructor declaration. |
void |
setBody(Block body)
Sets or clears the body of this method declaration. |
void |
setConstructor(boolean isConstructor)
Sets whether this declaration declares a constructor or a method. |
void |
setExtraDimensions(int dimensions)
Sets the number of extra array dimensions over and above the explicitly-specified return type. |
void |
setModifiers(int modifiers)
Sets the modifiers explicitly specified on this declaration. |
void |
setName(SimpleName methodName)
Sets the name of the method declared in this method declaration to the given name. |
void |
setReturnType(Type type)
Sets the return type of the method declared in this method declaration to the given type, exclusive of any extra array dimensions. |
boolean |
subtreeMatch(ASTMatcher matcher,
Object other)
Returns whether the subtree rooted at the given node matches the given other object as decided by the given matcher. |
List |
thrownExceptions()
Returns the live ordered list of thrown exception names in this method declaration. |
Methods inherited from class org.eclipse.jdt.core.dom.BodyDeclaration |
getJavadoc, setJavadoc |
Methods inherited from class org.eclipse.jdt.core.dom.ASTNode |
accept, copySubtree, copySubtrees, equals, getAST, getFlags, getLength, getParent, getProperty, getRoot, getStartPosition, properties, setFlags, setProperty, setSourceRange, subtreeBytes, toString |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
public int getNodeType()
ASTNode
For each concrete node type there is a unique node type constant (name
and value). The unique node type constant for a concrete node type such as
CastExpression
is ASTNode.CAST_EXPRESSION
.
getNodeType
in class ASTNode
org.eclipse.jdt.core.dom.ASTNode
public boolean subtreeMatch(ASTMatcher matcher, Object other)
ASTNode
subtreeMatch
in class ASTNode
org.eclipse.jdt.core.dom.ASTNode
matcher
- the matcherother
- the other object, or null
true
if the subtree matches, or
false
if they do not matchpublic boolean isConstructor()
true
if this is a constructor declaration,
and false
if this is a method declarationpublic void setConstructor(boolean isConstructor)
isConstructor
- true
for a constructor declaration,
and false
for a method declarationpublic int getModifiers()
Note that deprecated is not included.
Modifier
public void setModifiers(int modifiers)
The following modifiers are valid for methods: public, private, protected, static, final, synchronized, native, abstract, and strictfp. For constructors, only public, private, and protected are meaningful.
modifiers
- the bit-wise or of Modifier constantsIllegalArgumentException
- if the modifiers are illegalModifier
public SimpleName getName()
public void setName(SimpleName methodName)
methodName
- the new method nameIllegalArgumentException
- if:
public List parameters()
SingleVariableDeclaration
)public List thrownExceptions()
Name
)public Type getReturnType()
Note that this child is not relevant for constructor declarations (although it does still figure in subtree equality comparisons and visits), and is devoid of the binding information ordinarily available.
public void setReturnType(Type type)
Note that this child is not relevant for constructor declarations (although it does still figure in subtree equality comparisons and visits).
type
- the new return type, possibly the void primitive typeIllegalArgumentException
- if:
public int getExtraDimensions()
For example, int foo()[][]
has a return type of
int
and two extra array dimensions;
int[][] foo()
has a return type of int[][]
and zero extra array dimensions. The two constructs have different
ASTs, even though there are really syntactic variants of the same
method declaration.
public void setExtraDimensions(int dimensions)
For example, int foo()[][]
is rendered as a return
type of int
with two extra array dimensions;
int[][] foo()
is rendered as a return type of
int[][]
with zero extra array dimensions. The two
constructs have different ASTs, even though there are really syntactic
variants of the same method declaration.
dimensions
- the number of array dimensionsIllegalArgumentException
- if the number of dimensions is
negativepublic Block getBody()
null
if
this method has no body.
Note that there is a subtle difference between having no body and having an empty body ("{}").
null
if this method has no
bodypublic void setBody(Block body)
Note that there is a subtle difference between having no body
(as in "void foo();"
) and having an empty body (as in
"void foo() {}"). Abstract methods, and methods declared in interfaces,
have no body. Non-abstract methods, and all constructors, have a body.
body
- the block node, or null
if
there is noneIllegalArgumentException
- if:
public IMethodBinding resolveBinding()
Note that bindings are generally unavailable unless requested when the AST is being built.
null
if the binding cannot be
resolved
|
Eclipse JDT 2.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |