| java.lang.Object org.eclipse.jdt.core.dom.ASTNode org.eclipse.jdt.core.dom.BodyDeclaration org.eclipse.jdt.core.dom.MethodDeclaration
MethodDeclaration | public class MethodDeclaration extends BodyDeclaration (Code) | | 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 } ] Block
For 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).
since: 2.0 |
Constructor Summary | |
| MethodDeclaration(AST ast) Creates a new AST node for a method declaration owned
by the given AST. |
Method Summary | |
void | accept0(ASTVisitor visitor) | ASTNode | clone0(AST target) | public Block | getBody() Returns the body of this method declaration, or null if
this method has no body. | public int | getExtraDimensions() Returns the number of extra array dimensions over and above the
explicitly-specified return type.
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. | public SimpleName | getName() Returns the name of the method declared in this method declaration. | final int | getNodeType0() | public Type | getReturnType() Returns the return type of the method declared in this method
declaration, exclusive of any extra array dimensions (JLS2 API only). | public Type | getReturnType2() Returns the return type of the method declared in this method
declaration, exclusive of any extra array dimensions (added in JLS3 API). | final List | internalGetChildListProperty(ChildListPropertyDescriptor property) | final Type | internalGetReturnType() Internal synonym for deprecated method. | final boolean | internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) | final ASTNode | internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) | final int | internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value) | final ChildPropertyDescriptor | internalJavadocProperty() | final ChildListPropertyDescriptor | internalModifiers2Property() | final SimplePropertyDescriptor | internalModifiersProperty() | void | internalSetReturnType(Type type) Internal synonym for deprecated method. | final List | internalStructuralPropertiesForType(int apiLevel) | public boolean | isConstructor() Returns whether this declaration declares a constructor or a method. | public boolean | isVarargs() Returns whether this method declaration declares a
variable arity method (added in JLS3 API). | int | memSize() | public List | parameters() Returns the live ordered list of method parameter declarations for this
method declaration. | public static List | propertyDescriptors(int apiLevel) Returns a list of structural property descriptors for this node type. | public IMethodBinding | resolveBinding() Resolves and returns the binding for the method or constructor declared
in this method or constructor declaration. | public void | setBody(Block body) Sets or clears the body of this method declaration.
Note that there is a subtle difference between having no body
(as in "void foo();" ) and having an empty body (as in
"void foo() {}"). | public void | setConstructor(boolean isConstructor) Sets whether this declaration declares a constructor or a method. | public void | setExtraDimensions(int dimensions) Sets the number of extra array dimensions over and above the
explicitly-specified return type.
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. | public void | setName(SimpleName methodName) Sets the name of the method declared in this method declaration to the
given name. | public 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 (JLS2 API only). | public 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).
This is one of the few places where the void type is meaningful.
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. | final boolean | subtreeMatch0(ASTMatcher matcher, Object other) | public List | thrownExceptions() Returns the live ordered list of thrown exception names in this method
declaration. | int | treeSize() | public List | typeParameters() Returns the live ordered list of type parameters of this method
declaration (added in JLS3 API). |
CONSTRUCTOR_PROPERTY | final public static SimplePropertyDescriptor CONSTRUCTOR_PROPERTY(Code) | | The "constructor" structural property of this node type.
since: 3.0 |
EXTRA_DIMENSIONS_PROPERTY | final public static SimplePropertyDescriptor EXTRA_DIMENSIONS_PROPERTY(Code) | | The "extraDimensions" structural property of this node type.
since: 3.0 |
JAVADOC_PROPERTY | final public static ChildPropertyDescriptor JAVADOC_PROPERTY(Code) | | The "javadoc" structural property of this node type.
since: 3.0 |
MODIFIERS2_PROPERTY | final public static ChildListPropertyDescriptor MODIFIERS2_PROPERTY(Code) | | The "modifiers" structural property of this node type (added in JLS3 API).
since: 3.1 |
MODIFIERS_PROPERTY | final public static SimplePropertyDescriptor MODIFIERS_PROPERTY(Code) | | The "modifiers" structural property of this node type (JLS2 API only).
since: 3.0 |
RETURN_TYPE2_PROPERTY | final public static ChildPropertyDescriptor RETURN_TYPE2_PROPERTY(Code) | | The "returnType2" structural property of this node type (added in JLS3 API).
since: 3.1 |
RETURN_TYPE_PROPERTY | final public static ChildPropertyDescriptor RETURN_TYPE_PROPERTY(Code) | | The "returnType" structural property of this node type (JLS2 API only).
since: 3.0 |
THROWN_EXCEPTIONS_PROPERTY | final public static ChildListPropertyDescriptor THROWN_EXCEPTIONS_PROPERTY(Code) | | The "thrownExceptions" structural property of this node type).
since: 3.0 |
TYPE_PARAMETERS_PROPERTY | final public static ChildListPropertyDescriptor TYPE_PARAMETERS_PROPERTY(Code) | | The "typeParameters" structural property of this node type (added in JLS3 API).
since: 3.1 |
MethodDeclaration | MethodDeclaration(AST ast)(Code) | | Creates a new AST node for a method declaration owned
by the given AST. By default, the declaration is for a method of an
unspecified, but legal, name; no modifiers; no javadoc; no type
parameters; void return type; no parameters; no array dimensions after
the parameters; no thrown exceptions; and no body (as opposed to an
empty body).
N.B. This constructor is package-private; all subclasses must be
declared in the same package; clients are unable to declare
additional subclasses.
Parameters: ast - the AST that is to own this node |
getBody | public Block getBody()(Code) | | Returns the body of this method declaration, or null if
this method has no body.
Note that there is a subtle difference between having no body and having
an empty body ("{}").
the method body, or null if this method has nobody |
getExtraDimensions | public int getExtraDimensions()(Code) | | Returns the number of extra array dimensions over and above the
explicitly-specified return type.
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.
the number of extra array dimensions since: 2.1 |
getName | public SimpleName getName()(Code) | | Returns the name of the method declared in this method declaration.
For a constructor declaration, this should be the same as the name
of the class.
the method name node |
getNodeType0 | final int getNodeType0()(Code) | | |
getReturnType | public Type getReturnType()(Code) | | Returns the return type of the method declared in this method
declaration, exclusive of any extra array dimensions (JLS2 API only).
This is one of the few places where the void type is meaningful.
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.
the return type, possibly the void primitive type exception: UnsupportedOperationException - if this operation is used inan AST later than JLS2MethodDeclaration.getReturnType2() |
getReturnType2 | public Type getReturnType2()(Code) | | Returns the return type of the method declared in this method
declaration, exclusive of any extra array dimensions (added in JLS3 API).
This is one of the few places where the void type is meaningful.
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.
the return type, possibly the void primitive type,or null if none exception: UnsupportedOperationException - if this operation is used ina JLS2 AST since: 3.1 |
internalGetReturnType | final Type internalGetReturnType()(Code) | | Internal synonym for deprecated method. Used to avoid
deprecation warnings.
since: 3.1 |
internalSetReturnType | void internalSetReturnType(Type type)(Code) | | Internal synonym for deprecated method. Used to avoid
deprecation warnings.
since: 3.1 |
internalStructuralPropertiesForType | final List internalStructuralPropertiesForType(int apiLevel)(Code) | | |
isConstructor | public boolean isConstructor()(Code) | | Returns whether this declaration declares a constructor or a method.
true if this is a constructor declaration,and false if this is a method declaration |
isVarargs | public boolean isVarargs()(Code) | | Returns whether this method declaration declares a
variable arity method (added in JLS3 API). The convenience method checks
whether the last parameter is so marked.
true if this is a variable arity method declaration,and false otherwise exception: UnsupportedOperationException - if this operation is used ina JLS2 AST See Also: SingleVariableDeclaration.isVarargs since: 3.1 |
parameters | public List parameters()(Code) | | Returns the live ordered list of method parameter declarations for this
method declaration.
the live list of method parameter declarations(element type: SingleVariableDeclaration ) |
propertyDescriptors | public static List propertyDescriptors(int apiLevel)(Code) | | Returns a list of structural property descriptors for this node type.
Clients must not modify the result.
Parameters: apiLevel - the API level; one of the AST.JLS* constants a list of property descriptors (element type: StructuralPropertyDescriptor) since: 3.0 |
resolveBinding | public IMethodBinding resolveBinding()(Code) | | Resolves and returns the binding for the method or constructor declared
in this method or constructor declaration.
Note that bindings are generally unavailable unless requested when the
AST is being built.
the binding, or null if the binding cannot be resolved |
setBody | public void setBody(Block body)(Code) | | Sets or clears the body of this method declaration.
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.
Parameters: body - the block node, or null if there is none exception: IllegalArgumentException - if:- the node belongs to a different AST
- the node already has a parent
- a cycle in would be created
|
setConstructor | public void setConstructor(boolean isConstructor)(Code) | | Sets whether this declaration declares a constructor or a method.
Parameters: isConstructor - true for a constructor declaration,and false for a method declaration |
setExtraDimensions | public void setExtraDimensions(int dimensions)(Code) | | Sets the number of extra array dimensions over and above the
explicitly-specified return type.
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.
Parameters: dimensions - the number of array dimensions exception: IllegalArgumentException - if the number of dimensions isnegative since: 2.1 |
setName | public void setName(SimpleName methodName)(Code) | | Sets the name of the method declared in this method declaration to the
given name. For a constructor declaration, this should be the same as
the name of the class.
Parameters: methodName - the new method name exception: IllegalArgumentException - if:- the node belongs to a different AST
- the node already has a parent
|
setReturnType | public void setReturnType(Type type)(Code) | | Sets the return type of the method declared in this method declaration
to the given type, exclusive of any extra array dimensions (JLS2 API only). This is one
of the few places where the void type is meaningful.
Note that this child is not relevant for constructor declarations
(although it does still figure in subtree equality comparisons and visits).
Parameters: type - the new return type, possibly the void primitive type exception: IllegalArgumentException - if:- the node belongs to a different AST
- the node already has a parent
exception: UnsupportedOperationException - if this operation is used inan AST later than JLS2MethodDeclaration.setReturnType2(Type) |
setReturnType2 | public void setReturnType2(Type type)(Code) | | 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).
This is one of the few places where the void type is meaningful.
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.
Parameters: type - the new return type, possibly the void primitive type,or null if none exception: UnsupportedOperationException - if this operation is used ina JLS2 AST exception: IllegalArgumentException - if:- the node belongs to a different AST
- the node already has a parent
since: 3.1 |
thrownExceptions | public List thrownExceptions()(Code) | | Returns the live ordered list of thrown exception names in this method
declaration.
the live list of exception names(element type: Name ) |
typeParameters | public List typeParameters()(Code) | | Returns the live ordered list of type parameters of this method
declaration (added in JLS3 API). This list is non-empty for parameterized methods.
the live list of type parameters(element type: TypeParameter ) exception: UnsupportedOperationException - if this operation is used ina JLS2 AST since: 3.1 |
Methods inherited from org.eclipse.jdt.core.dom.ASTNode | final public void accept(ASTVisitor visitor)(Code)(Java Doc) abstract void accept0(ASTVisitor visitor)(Code)(Java Doc) final void acceptChild(ASTVisitor visitor, ASTNode child)(Code)(Java Doc) final void acceptChildren(ASTVisitor visitor, ASTNode.NodeList children)(Code)(Java Doc) static void addProperty(StructuralPropertyDescriptor property, List propertyList)(Code)(Java Doc) void appendDebugString(StringBuffer buffer)(Code)(Java Doc) final void appendPrintString(StringBuffer buffer)(Code)(Java Doc) final void checkModifiable()(Code)(Java Doc) static void checkNewChild(ASTNode node, ASTNode newChild, boolean cycleCheck, Class nodeType)(Code)(Java Doc) final ASTNode clone(AST target)(Code)(Java Doc) abstract ASTNode clone0(AST target)(Code)(Java Doc) public static ASTNode copySubtree(AST target, ASTNode node)(Code)(Java Doc) public static List copySubtrees(AST target, List nodes)(Code)(Java Doc) static void createPropertyList(Class nodeClass, List propertyList)(Code)(Java Doc) final public void delete()(Code)(Java Doc) final public boolean equals(Object obj)(Code)(Java Doc) final public AST getAST()(Code)(Java Doc) final public int getFlags()(Code)(Java Doc) final public int getLength()(Code)(Java Doc) final public StructuralPropertyDescriptor getLocationInParent()(Code)(Java Doc) final public int getNodeType()(Code)(Java Doc) abstract int getNodeType0()(Code)(Java Doc) final public ASTNode getParent()(Code)(Java Doc) final public Object getProperty(String propertyName)(Code)(Java Doc) final public ASTNode getRoot()(Code)(Java Doc) final public int getStartPosition()(Code)(Java Doc) final public Object getStructuralProperty(StructuralPropertyDescriptor property)(Code)(Java Doc) final public int hashCode()(Code)(Java Doc) List internalGetChildListProperty(ChildListPropertyDescriptor property)(Code)(Java Doc) boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value)(Code)(Java Doc) ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child)(Code)(Java Doc) int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value)(Code)(Java Doc) Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, Object value)(Code)(Java Doc) abstract List internalStructuralPropertiesForType(int apiLevel)(Code)(Java Doc) abstract int memSize()(Code)(Java Doc) public static Class nodeClassForType(int nodeType)(Code)(Java Doc) final void postLazyInit(ASTNode newChild, ChildPropertyDescriptor property)(Code)(Java Doc) final void postReplaceChild(ASTNode oldChild, ASTNode newChild, ChildPropertyDescriptor property)(Code)(Java Doc) final void postValueChange(SimplePropertyDescriptor property)(Code)(Java Doc) final void preLazyInit()(Code)(Java Doc) final void preReplaceChild(ASTNode oldChild, ASTNode newChild, ChildPropertyDescriptor property)(Code)(Java Doc) final void preValueChange(SimplePropertyDescriptor property)(Code)(Java Doc) final public Map properties()(Code)(Java Doc) static List reapPropertyList(List propertyList)(Code)(Java Doc) final public void setFlags(int flags)(Code)(Java Doc) final void setParent(ASTNode parent, StructuralPropertyDescriptor property)(Code)(Java Doc) final public void setProperty(String propertyName, Object data)(Code)(Java Doc) final public void setSourceRange(int startPosition, int length)(Code)(Java Doc) final public void setStructuralProperty(StructuralPropertyDescriptor property, Object value)(Code)(Java Doc) final String standardToString()(Code)(Java Doc) static int stringSize(String string)(Code)(Java Doc) final public List structuralPropertiesForType()(Code)(Java Doc) final public int subtreeBytes()(Code)(Java Doc) final public boolean subtreeMatch(ASTMatcher matcher, Object other)(Code)(Java Doc) abstract boolean subtreeMatch0(ASTMatcher matcher, Object other)(Code)(Java Doc) final void supportedOnlyIn2()(Code)(Java Doc) final public String toString()(Code)(Java Doc) abstract int treeSize()(Code)(Java Doc) final void unsupportedIn2()(Code)(Java Doc)
|
|
|