|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.jdt.core.dom.ASTNode
org.eclipse.jdt.core.dom.BodyDeclaration
org.eclipse.jdt.core.dom.MethodDeclaration
public class MethodDeclaration
Method declaration AST node type. A method declaration is the union of a method declaration and a constructor declaration. For JLS2:
MethodDeclaration: [ Javadoc ] { Modifier } ( Type | void ) Identifier ( [ FormalParameter { , FormalParameter } ] ) {[ ] } [ throws TypeName { , TypeName } ] ( Block | ; ) ConstructorDeclaration: [ Javadoc ] { Modifier } Identifier ( [ FormalParameter { , FormalParameter } ] ) [throws TypeName { , TypeName } ] BlockFor JLS3, type parameters and reified modifiers (and annotations) were added:
MethodDeclaration: [ Javadoc ] { ExtendedModifier } [ < TypeParameter { , TypeParameter } > ] ( Type | void ) Identifier ( [ FormalParameter { , FormalParameter } ] ) {[ ] } [ throws TypeName { , TypeName } ] ( Block | ; ) ConstructorDeclaration: [ Javadoc ] { ExtendedModifier } [ < TypeParameter { , TypeParameter } > ] 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 "<" token (method, no modifiers, type parameters), or the first character of the return type (method, no modifiers, no type parameters), 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 | |
---|---|
static ChildPropertyDescriptor |
BODY_PROPERTY
The "body" structural property of this node type. |
static SimplePropertyDescriptor |
CONSTRUCTOR_PROPERTY
The "constructor" structural property of this node type. |
static SimplePropertyDescriptor |
EXTRA_DIMENSIONS_PROPERTY
The "extraDimensions" structural property of this node type. |
static ChildPropertyDescriptor |
JAVADOC_PROPERTY
The "javadoc" structural property of this node type. |
static SimplePropertyDescriptor |
MODIFIERS_PROPERTY
The "modifiers" structural property of this node type (JLS2 API only). |
static ChildListPropertyDescriptor |
MODIFIERS2_PROPERTY
The "modifiers" structural property of this node type (added in JLS3 API). |
static ChildPropertyDescriptor |
NAME_PROPERTY
The "name" structural property of this node type. |
static ChildListPropertyDescriptor |
PARAMETERS_PROPERTY
The "parameters" structural property of this node type). |
static ChildPropertyDescriptor |
RETURN_TYPE_PROPERTY
The "returnType" structural property of this node type (JLS2 API only). |
static ChildPropertyDescriptor |
RETURN_TYPE2_PROPERTY
The "returnType2" structural property of this node type (added in JLS3 API). |
static ChildListPropertyDescriptor |
THROWN_EXCEPTIONS_PROPERTY
The "thrownExceptions" structural property of this node type). |
static ChildListPropertyDescriptor |
TYPE_PARAMETERS_PROPERTY
The "typeParameters" structural property of this node type (added in JLS3 API). |
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. |
SimpleName |
getName()
Returns the name of the method declared in this method declaration. |
Type |
getReturnType()
Deprecated. In the JLS3 API, this method is replaced by getReturnType2() ,
which may return null . |
Type |
getReturnType2()
Returns the return type of the method declared in this method declaration, exclusive of any extra array dimensions (added in JLS3 API). |
boolean |
isConstructor()
Returns whether this declaration declares a constructor or a method. |
boolean |
isVarargs()
Returns whether this method declaration declares a variable arity method (added in JLS3 API). |
java.util.List |
parameters()
Returns the live ordered list of method parameter declarations for this method declaration. |
static java.util.List |
propertyDescriptors(int apiLevel)
Returns a list of structural property descriptors for this node type. |
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 |
setName(SimpleName methodName)
Sets the name of the method declared in this method declaration to the given name. |
void |
setReturnType(Type type)
Deprecated. In the JLS3 API, this method is replaced by setReturnType2(Type) , which accepts null . |
void |
setReturnType2(Type type)
Sets the return type of the method declared in this method declaration to the given type, exclusive of any extra array dimensions (added in JLS3 API). |
java.util.List |
thrownExceptions()
Returns the live ordered list of thrown exception names in this method declaration. |
java.util.List |
typeParameters()
Returns the live ordered list of type parameters of this method declaration (added in JLS3 API). |
Methods inherited from class org.eclipse.jdt.core.dom.BodyDeclaration |
---|
getJavadoc, getJavadocProperty, getModifiers, getModifiersProperty, modifiers, setJavadoc, setModifiers |
Methods inherited from class org.eclipse.jdt.core.dom.ASTNode |
---|
accept, copySubtree, copySubtrees, delete, equals, getAST, getFlags, getLength, getLocationInParent, getNodeType, getParent, getProperty, getRoot, getStartPosition, getStructuralProperty, hashCode, nodeClassForType, properties, setFlags, setProperty, setSourceRange, setStructuralProperty, structuralPropertiesForType, subtreeBytes, subtreeMatch, toString |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final ChildPropertyDescriptor JAVADOC_PROPERTY
public static final SimplePropertyDescriptor MODIFIERS_PROPERTY
public static final ChildListPropertyDescriptor MODIFIERS2_PROPERTY
public static final SimplePropertyDescriptor CONSTRUCTOR_PROPERTY
public static final ChildPropertyDescriptor NAME_PROPERTY
public static final ChildPropertyDescriptor RETURN_TYPE_PROPERTY
public static final ChildPropertyDescriptor RETURN_TYPE2_PROPERTY
public static final SimplePropertyDescriptor EXTRA_DIMENSIONS_PROPERTY
public static final ChildListPropertyDescriptor TYPE_PARAMETERS_PROPERTY
public static final ChildListPropertyDescriptor PARAMETERS_PROPERTY
public static final ChildListPropertyDescriptor THROWN_EXCEPTIONS_PROPERTY
public static final ChildPropertyDescriptor BODY_PROPERTY
Method Detail |
---|
public static java.util.List propertyDescriptors(int apiLevel)
apiLevel
- the API level; one of the AST.JLS* constants
StructuralPropertyDescriptor
)public 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 java.util.List typeParameters()
TypeParameter
)
java.lang.UnsupportedOperationException
- if this operation is used in
a JLS2 ASTpublic SimpleName getName()
public void setName(SimpleName methodName)
methodName
- the new method name
java.lang.IllegalArgumentException
- if:
public java.util.List parameters()
SingleVariableDeclaration
)public boolean isVarargs()
true
if this is a variable arity method declaration,
and false
otherwise
java.lang.UnsupportedOperationException
- if this operation is used in
a JLS2 ASTSingleVariableDeclaration.isVarargs()
public java.util.List thrownExceptions()
Name
)public Type getReturnType()
getReturnType2()
,
which may return null
.
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.
java.lang.UnsupportedOperationException
- if this operation is used in
an AST later than JLS2public void setReturnType(Type type)
setReturnType2(Type)
, which accepts null
.
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 type
java.lang.IllegalArgumentException
- if:
java.lang.UnsupportedOperationException
- if this operation is used in
an AST later than JLS2public Type getReturnType2()
Note that this child is not relevant for constructor declarations (although, if present, it does still figure in subtree equality comparisons and visits), and is devoid of the binding information ordinarily available. In the JLS2 API, the return type is mandatory. In the JLS3 API, the return type is optional.
null
if none
java.lang.UnsupportedOperationException
- if this operation is used in
a JLS2 ASTpublic void setReturnType2(Type type)
Note that this child is not relevant for constructor declarations (although it does still figure in subtree equality comparisons and visits). In the JLS2 API, the return type is mandatory. In the JLS3 API, the return type is optional.
type
- the new return type, possibly the void primitive type,
or null
if none
java.lang.UnsupportedOperationException
- if this operation is used in
a JLS2 AST
java.lang.IllegalArgumentException
- 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 dimensions
java.lang.IllegalArgumentException
- 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 none
java.lang.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
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |