Eclipse JDT
2.0

org.eclipse.jdt.core.jdom
Interface IDOMMethod

All Superinterfaces:
Cloneable, IDOMMember, IDOMNode

public interface IDOMMethod
extends IDOMMember

Represents a method declaration. The corresponding syntactic units are MethodDeclaration (JLS2 8.4), ConstructorDeclaration (JLS2 8.8), and AbstractMethodDeclaration (JLS2 9.4). A method has no children and its parent is a type. Local classes are considered to be part of the body of a method, not a child.

This interface is not intended to be implemented by clients.


Field Summary
 
Fields inherited from interface org.eclipse.jdt.core.jdom.IDOMNode
COMPILATION_UNIT, FIELD, IMPORT, INITIALIZER, METHOD, PACKAGE, TYPE
 
Method Summary
 void addException(String exceptionType)
          Adds the given exception to the end of the list of exceptions this method is declared to throw.
 void addParameter(String type, String name)
          Adds the given parameter to the end of the parameter list.
 String getBody()
          Returns the body of this method.
 String[] getExceptions()
          Returns the names of the exception types this method throws in the order in which they are declared in the source, or an empty array if this method declares no exception types.
 String getName()
          The IDOMMethod refinement of this IDOMNode method returns the name of this method.
 String[] getParameterNames()
          Returns the names of parameters in this method in the order they are declared, or null if no parameters are declared.
 String[] getParameterTypes()
          Returns the type names for the parameters of this method in the order they are declared, or null if no parameters are declared.
 String getReturnType()
          Returns the return type name, or null.
 boolean isConstructor()
          Returns whether this method is a constructor.
 void setBody(String body)
          Sets the body of this method.
 void setConstructor(boolean b)
          Sets whether this method represents a constructor.
 void setExceptions(String[] exceptionTypes)
          Sets the names of the exception types this method throws, in the order in which they are declared in the source.
 void setName(String name)
          The IDOMMethod refinement of this IDOMNode method sets the name of this method.
 void setParameters(String[] types, String[] names)
          Sets the types and names of parameters in this method in the order they are to be declared.
 void setReturnType(String type)
          Sets the return type name.
 
Methods inherited from interface org.eclipse.jdt.core.jdom.IDOMMember
getComment, getFlags, setComment, setFlags
 
Methods inherited from interface org.eclipse.jdt.core.jdom.IDOMNode
addChild, canHaveChildren, clone, getCharacters, getChild, getChildren, getContents, getFirstChild, getJavaElement, getNextNode, getNodeType, getParent, getPreviousNode, insertSibling, isAllowableChild, isSignatureEqual, remove
 

Method Detail

addException

public void addException(String exceptionType)
                  throws IllegalArgumentException
Adds the given exception to the end of the list of exceptions this method is declared to throw. The syntax for an exception type name is defined by Method Throws (JLS2 8.4.4). Type names must be specified as they would appear in source code. For example: "IOException" or "java.io.IOException". This is a convenience method for setExceptions.

Parameters:
exceptionType - the exception type
Throws:
IllegalArgumentException - if null is specified
See Also:
setExceptions(java.lang.String[])

addParameter

public void addParameter(String type,
                         String name)
                  throws IllegalArgumentException
Adds the given parameter to the end of the parameter list. This is a convenience method for setParameters. The syntax for parameter names is defined by Formal Parameters (JLS2 8.4.1). The syntax for type names is defined by Formal Parameters (JLS2 8.4.1). Type names must be specified as they would appear in source code. For example: "File", "java.io.File", or "int[]".

Parameters:
type - the type name
name - the parameter name
Throws:
IllegalArgumentException - if null is specified for either the type or the name
See Also:
setParameters(java.lang.String[], java.lang.String[])

getBody

public String getBody()
Returns the body of this method. The method body includes all code following the method declaration, including the enclosing braces.

Returns:
the body, or null if the method has no body (for example, for an abstract or native method)

getExceptions

public String[] getExceptions()
Returns the names of the exception types this method throws in the order in which they are declared in the source, or an empty array if this method declares no exception types. The syntax for an exception type name is defined by Method Throws (JLS2 8.4.4). Type names appear as they would in source code. For example: "IOException" or "java.io.IOException".

Returns:
the list of exception types

getName

public String getName()
The IDOMMethod refinement of this IDOMNode method returns the name of this method. Returns null for constructors. The syntax for a method name is defined by Identifier of MethodDeclarator (JLS2 8.4).

Specified by:
getName in interface IDOMNode
Returns:
the name, or null if it has no name

getParameterNames

public String[] getParameterNames()
Returns the names of parameters in this method in the order they are declared, or null if no parameters are declared. The syntax for parameter names is defined by Formal Parameters (JLS2 8.4.1).

Returns:
the list of parameter names, or null if no parameters are declared

getParameterTypes

public String[] getParameterTypes()
Returns the type names for the parameters of this method in the order they are declared, or null if no parameters are declared. The syntax for type names is defined by Formal Parameters (JLS2 8.4.1). Type names must be specified as they would appear in source code. For example: "File", "java.io.File", or "int[]".

Returns:
the list of parameter types, or null if no parameters are declared

getReturnType

public String getReturnType()
Returns the return type name, or null. Returns null for constructors. The syntax for return type name corresponds to ReturnType in MethodDeclaration (JLS2 8.4). Names are returned as they appear in the source code; for example: "File", "java.io.File", "int[]", or "void".

Returns:
the return type

isConstructor

public boolean isConstructor()
Returns whether this method is a constructor.

Returns:
true for constructors, and false for methods

setBody

public void setBody(String body)
Sets the body of this method. The method body includes all code following the method declaration, including the enclosing braces. No formatting or syntax checking is performed on the body.

Returns:
the body, or null indicating the method has no body (for example, for an abstract or native method)

setConstructor

public void setConstructor(boolean b)
Sets whether this method represents a constructor.

Parameters:
b - true for constructors, and false for methods

setExceptions

public void setExceptions(String[] exceptionTypes)
Sets the names of the exception types this method throws, in the order in which they are declared in the source. An empty array indicates this method declares no exception types. The syntax for an exception type name is defined by Method Throws (JLS2 8.4.4). Type names must be specified as they would appear in source code. For example: "IOException" or "java.io.IOException".

Parameters:
exceptionTypes - the list of exception types

setName

public void setName(String name)
             throws IllegalArgumentException
The IDOMMethod refinement of this IDOMNode method sets the name of this method. The syntax for a method name is defined by Identifer of MethodDeclarator (JLS2 8.4).

The name of a constructor is always null and thus it must not be set.

Specified by:
setName in interface IDOMNode
Parameters:
name - the name, or null to clear the name
Throws:
IllegalArgumentException - if null is specified

setParameters

public void setParameters(String[] types,
                          String[] names)
                   throws IllegalArgumentException
Sets the types and names of parameters in this method in the order they are to be declared. If both types and names are null this indicates that this method has no parameters. The syntax for parameter names is defined by Formal Parameters (JLS2 8.4.1). The syntax for type names is defined by Formal Parameters (JLS2 8.4.1). Type names must be specified as they would appear in source code. For example: "File", "java.io.File", or "int[]".

Parameters:
types - the list of type names
names - the list of parameter name
Throws:
IllegalArgumentException - if the number of types and names do not match, or if either argument is null

setReturnType

public void setReturnType(String type)
                   throws IllegalArgumentException
Sets the return type name. This has no effect on constructors. The syntax for return type name corresponds to ReturnType in MethodDeclaration (JLS2 8.4). Type names are specified as they appear in the source code; for example: "File", "java.io.File", "int[]", or "void".

Parameters:
type - the return type
Throws:
IllegalArgumentException - if null is specified

Eclipse JDT
2.0

Copyright (c) IBM Corp. and others 2000, 2002. All Rights Reserved.