1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.core.jdom;
14 * Represents a method declaration.
15 * The corresponding syntactic units are MethodDeclaration (JLS2 8.4),
16 * ConstructorDeclaration (JLS2 8.8), and AbstractMethodDeclaration (JLS2 9.4).
17 * A method has no children and its parent is a type.
18 * Local classes are considered to be part of the body of a method, not a child.
20 * This interface is not intended to be implemented by clients.
23 public interface IDOMMethod extends IDOMMember {
25 * Adds the given exception to the end of the list of exceptions this method
26 * is declared to throw.
27 * The syntax for an exception type name is defined by Method Throws (JLS2 8.4.4).
28 * Type names must be specified as they would appear in source code. For
29 * example: <code>"IOException"</code> or <code>"java.io.IOException"</code>.
30 * This is a convenience method for <code>setExceptions</code>.
32 * @param exceptionType the exception type
33 * @exception IllegalArgumentException if <code>null</code> is specified
36 public void addException(String exceptionType) throws IllegalArgumentException;
38 * Adds the given parameter to the end of the parameter list.
39 * This is a convenience method for <code>setParameters</code>.
40 * The syntax for parameter names is defined by Formal Parameters (JLS2 8.4.1).
41 * The syntax for type names is defined by Formal Parameters (JLS2 8.4.1).
42 * Type names must be specified as they would appear in source code. For
43 * example: <code>"File"</code>, <code>"java.io.File"</code>, or
44 * <code>"int[]"</code>.
46 * @param type the type name
47 * @param name the parameter name
48 * @exception IllegalArgumentException if <code>null</code> is specified for
49 * either the type or the name
52 public void addParameter(String type, String name) throws IllegalArgumentException;
54 * Returns the body of this method. The method body includes all code following
55 * the method declaration, including the enclosing braces.
57 * @return the body, or <code>null</code> if the method has no body (for
58 * example, for an abstract or native method)
60 public String getBody();
62 * Returns the names of the exception types this method throws
63 * in the order in which they are declared in the source, or an empty array
64 * if this method declares no exception types.
65 * The syntax for an exception type name is defined by Method Throws (JLS2 8.4.4).
66 * Type names appear as they would in source code. For example:
67 * <code>"IOException"</code> or <code>"java.io.IOException"</code>.
69 * @return the list of exception types
71 public String[] getExceptions();
73 * The <code>IDOMMethod</code> refinement of this <code>IDOMNode</code>
74 * method returns the name of this method. Returns <code>null</code> for
75 * constructors. The syntax for a method name is defined by Identifier
76 * of MethodDeclarator (JLS2 8.4).
78 public String getName();
80 * Returns the names of parameters in this method in the order they are declared,
81 * or <code>null</code> if no parameters are declared.
82 * The syntax for parameter names is defined by Formal Parameters (JLS2 8.4.1).
84 * @return the list of parameter names, or <code>null</code> if no parameters
87 public String[] getParameterNames();
89 * Returns the type names for the parameters of this method in the order they are declared,
90 * or <code>null</code> if no parameters are declared.
91 * The syntax for type names is defined by Formal Parameters (JLS2 8.4.1).
92 * Type names must be specified as they would appear in source code. For
93 * example: <code>"File"</code>, <code>"java.io.File"</code>, or
94 * <code>"int[]"</code>.
96 * @return the list of parameter types, or <code>null</code> if no parameters
99 public String[] getParameterTypes();
101 * Returns the return type name, or <code>null</code>.
102 * Returns <code>null</code> for constructors.
103 * The syntax for return type name corresponds to ReturnType in
104 * MethodDeclaration (JLS2 8.4). Names are returned as they appear in the source
105 * code; for example: <code>"File"</code>, <code>"java.io.File"</code>,
106 * <code>"int[]"</code>, or <code>"void"</code>.
108 * @return the return type
110 public String getReturnType();
112 * Returns whether this method is a constructor.
114 * @return <code>true</code> for constructors, and <code>false</code> for methods
116 public boolean isConstructor();
118 * Sets the body of this method. The method body includes all code following
119 * the method declaration, including the enclosing braces. No formatting or
120 * syntax checking is performed on the body.
122 * @return the body, or <code>null</code> indicating the method has no body (for
123 * example, for an abstract or native method)
125 public void setBody(String body);
127 * Sets whether this method represents a constructor.
129 * @param b <code>true</code> for constructors, and <code>false</code> for methods
131 public void setConstructor(boolean b);
133 * Sets the names of the exception types this method throws,
134 * in the order in which they are declared in the source. An empty array
135 * indicates this method declares no exception types.
136 * The syntax for an exception type name is defined by Method Throws (JLS2 8.4.4).
137 * Type names must be specified as they would appear in source code. For
138 * example: <code>"IOException"</code> or <code>"java.io.IOException"</code>.
140 * @param exceptionTypes the list of exception types
142 public void setExceptions(String[] exceptionTypes);
144 * The <code>IDOMMethod</code> refinement of this <code>IDOMNode</code>
145 * method sets the name of this method. The syntax for a method
146 * name is defined by Identifer of MethodDeclarator (JLS2 8.4).
148 * The name of a constructor is always <code>null</code> and thus it
152 * @exception IllegalArgumentException if <code>null</code> is specified
154 public void setName(String name) throws IllegalArgumentException;
156 * Sets the types and names of parameters in this method in the order they are
157 * to be declared. If both <code>types</code> and <code>names</code> are <code>null</code>
158 * this indicates that this method has no parameters.
159 * The syntax for parameter names is defined by Formal Parameters (JLS2 8.4.1).
160 * The syntax for type names is defined by Formal Parameters (JLS2 8.4.1).
161 * Type names must be specified as they would appear in source code. For
162 * example: <code>"File"</code>, <code>"java.io.File"</code>, or
163 * <code>"int[]"</code>.
165 * @param types the list of type names
166 * @param names the list of parameter name
167 * @exception IllegalArgumentException if the number of types and names do not
168 * match, or if either argument is <code>null</code>
170 public void setParameters(String[] types, String[] names) throws IllegalArgumentException;
172 * Sets the return type name. This has no effect on constructors.
173 * The syntax for return type name corresponds to ReturnType in
174 * MethodDeclaration (JLS2 8.4). Type names are specified as they appear in the
175 * source code; for example: <code>"File"</code>, <code>"java.io.File"</code>,
176 * <code>"int[]"</code>, or <code>"void"</code>.
178 * @param type the return type
179 * @exception IllegalArgumentException if <code>null</code> is specified
181 public void setReturnType(String type) throws IllegalArgumentException;