|
Eclipse JDT 2.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | 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 } ] MethodBodyNormal form:
MethodDeclaration: [ Javadoc ] { Modifier } ( Type | void ) Identifier ( [ FormalParamter { , 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).
Field Summary |
Method Summary | |
Block |
getBody()
Returns the body of this method declaration, or null if
this method has no body. |
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. |
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 |
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. |
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
public boolean subtreeMatch(ASTMatcher matcher, Object other)
ASTNode
subtreeMatch
in class 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 constants
IllegalArgumentException
- if the modifiers are illegalModifier
public SimpleName getName()
public void setName(SimpleName methodName)
methodName
- the new method name
IllegalArgumentException
- 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).
public void setReturnType(Type type)
Note that this child is not relevant for constructor declarations (although it does still figure in subtree equality comparisons).
type
- the new return type, possibly the void primitive type
IllegalArgumentException
- if:
public 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 none
IllegalArgumentException
- 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.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |