KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > IMethod


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * IBM Corporation - added J2SE 1.5 support
11  *******************************************************************************/

12 package org.eclipse.jdt.core;
13
14 /**
15  * Represents a method (or constructor) declared in a type.
16  * <p>
17  * This interface is not intended to be implemented by clients.
18  * </p>
19  */

20 public interface IMethod extends IMember {
21 /**
22  * Returns the simple name of this method.
23  * For a constructor, this returns the simple name of the declaring type.
24  * Note: This holds whether the constructor appears in a source or binary type
25  * (even though class files internally define constructor names to be <code>"&lt;init&gt;"</code>).
26  * For the class initialization methods in binary types, this returns
27  * the special name <code>"&lt;clinit&gt;"</code>.
28  * This is a handle-only method.
29  * @return the simple name of this method
30  */

31 String JavaDoc getElementName();
32 /**
33  * Returns the type signatures of the exceptions this method throws,
34  * in the order declared in the source. Returns an empty array
35  * if this method throws no exceptions.
36  * <p>
37  * For example, a source method declaring <code>"throws IOException"</code>,
38  * would return the array <code>{"QIOException;"}</code>.
39  * </p>
40  * <p>
41  * The type signatures may be either unresolved (for source types)
42  * or resolved (for binary types), and either basic (for basic types)
43  * or rich (for parameterized types). See {@link Signature} for details.
44  * </p>
45  *
46  * @exception JavaModelException if this element does not exist or if an
47  * exception occurs while accessing its corresponding resource.
48  * @return the type signatures of the exceptions this method throws,
49  * in the order declared in the source, an empty array if this method throws no exceptions
50  * @see Signature
51  */

52 String JavaDoc[] getExceptionTypes() throws JavaModelException;
53
54 /**
55  * Returns the formal type parameter signatures for this method.
56  * Returns an empty array if this method has no formal type parameters.
57  * <p>
58  * The formal type parameter signatures may be either unresolved (for source
59  * types) or resolved (for binary types). See {@link Signature} for details.
60  * </p>
61  *
62  * @exception JavaModelException if this element does not exist or if an
63  * exception occurs while accessing its corresponding resource.
64  * @return the formal type parameter signatures of this method,
65  * in the order declared in the source, an empty array if none
66  * @see Signature
67  * @since 3.0
68  * @deprecated Use {@link #getTypeParameters()} instead
69  */

70 String JavaDoc[] getTypeParameterSignatures() throws JavaModelException;
71 /**
72  * Returns the formal type parameters for this method.
73  * Returns an empty array if this method has no formal type parameters.
74  *
75  * @exception JavaModelException if this element does not exist or if an
76  * exception occurs while accessing its corresponding resource.
77  * @return the formal type parameters of this method,
78  * in the order declared in the source, an empty array if none
79  * @since 3.1
80  */

81 ITypeParameter[] getTypeParameters() throws JavaModelException;
82 /**
83  * Returns the number of parameters of this method.
84  * This is a handle-only method.
85  *
86  * @return the number of parameters of this method
87  */

88 int getNumberOfParameters();
89 /**
90  * Returns the binding key for this method. A binding key is a key that uniquely
91  * identifies this method. It allows access to generic info for parameterized
92  * methods.
93  *
94  * @return the binding key for this method
95  * @see org.eclipse.jdt.core.dom.IBinding#getKey()
96  * @see BindingKey
97  * @since 3.1
98  */

99 String JavaDoc getKey();
100 /**
101  * Returns the names of parameters in this method.
102  * For binary types, associated source or attached Javadoc are used to retrieve the names.
103  * If none can be retrieved, then these names are invented as "arg"+i, where i starts at 0.
104  * Returns an empty array if this method has no parameters.
105  *
106  * <p>For example, a method declared as <code>public void foo(String text, int length)</code>
107  * would return the array <code>{"text","length"}</code>.
108  * </p>
109  *
110  * @exception JavaModelException if this element does not exist or if an
111  * exception occurs while accessing its corresponding resource.
112  * @return the names of parameters in this method, an empty array if this method has no parameters
113  */

114 String JavaDoc[] getParameterNames() throws JavaModelException;
115 /**
116  * Returns the type signatures for the parameters of this method.
117  * Returns an empty array if this method has no parameters.
118  * This is a handle-only method.
119  * <p>
120  * For example, a source method declared as <code>public void foo(String text, int length)</code>
121  * would return the array <code>{"QString;","I"}</code>.
122  * </p>
123  * <p>
124  * The type signatures may be either unresolved (for source types)
125  * or resolved (for binary types), and either basic (for basic types)
126  * or rich (for parameterized types). See {@link Signature} for details.
127  * </p>
128  *
129  * @return the type signatures for the parameters of this method, an empty array if this method has no parameters
130  * @see Signature
131  */

132 String JavaDoc[] getParameterTypes();
133 /**
134  * Returns the names of parameters in this method.
135  * For binary types, these names are invented as "arg"+i, where i starts at 0
136  * (even if source is associated with the binary or if Javdoc is attached to the binary).
137  * Returns an empty array if this method has no parameters.
138  *
139  * <p>For example, a method declared as <code>public void foo(String text, int length)</code>
140  * would return the array <code>{"text","length"}</code>. For the same method in a
141  * binary, this would return <code>{"arg0", "arg1"}</code>.
142  * </p>
143  *
144  * @exception JavaModelException if this element does not exist or if an
145  * exception occurs while accessing its corresponding resource.
146  * @return the names of parameters in this method, an empty array if this method has no parameters
147  * @since 3.2
148  */

149 String JavaDoc[] getRawParameterNames() throws JavaModelException;
150 /**
151  * Returns the type signature of the return value of this method.
152  * For constructors, this returns the signature for void.
153  * <p>
154  * For example, a source method declared as <code>public String getName()</code>
155  * would return <code>"QString;"</code>.
156  * </p>
157  * <p>
158  * The type signature may be either unresolved (for source types)
159  * or resolved (for binary types), and either basic (for basic types)
160  * or rich (for parameterized types). See {@link Signature} for details.
161  * </p>
162  *
163  * @exception JavaModelException if this element does not exist or if an
164  * exception occurs while accessing its corresponding resource.
165  * @return the type signature of the return value of this method, void for constructors
166  * @see Signature
167  */

168 String JavaDoc getReturnType() throws JavaModelException;
169 /**
170  * Returns the signature of this method. This includes the signatures for the
171  * parameter types and return type, but does not include the method name,
172  * exception types, or type parameters.
173  * <p>
174  * For example, a source method declared as <code>public void foo(String text, int length)</code>
175  * would return <code>"(QString;I)V"</code>.
176  * </p>
177  * <p>
178  * The type signatures embedded in the method signature may be either unresolved
179  * (for source types) or resolved (for binary types), and either basic (for
180  * basic types) or rich (for parameterized types). See {@link Signature} for
181  * details.
182  * </p>
183  *
184  * @return the signature of this method
185  * @exception JavaModelException if this element does not exist or if an
186  * exception occurs while accessing its corresponding resource.
187  * @see Signature
188  */

189 String JavaDoc getSignature() throws JavaModelException;
190 /**
191  * Returns the type parameter declared in this method with the given name.
192  * This is a handle-only method. The type parameter may or may not exist.
193  *
194  * @param name the given simple name
195  * @return the type parameter declared in this method with the given name
196  * @since 3.1
197  */

198 ITypeParameter getTypeParameter(String JavaDoc name);
199 /**
200  * Returns whether this method is a constructor.
201  *
202  * @exception JavaModelException if this element does not exist or if an
203  * exception occurs while accessing its corresponding resource.
204  *
205  * @return true if this method is a constructor, false otherwise
206  */

207 boolean isConstructor() throws JavaModelException;
208
209 /**
210  * Returns whether this method is a main method.
211  * It is a main method if:
212  * <ul>
213  * <li>its name is equal to <code>"main"</code></li>
214  * <li>its return type is <code>void</code></li>
215  * <li>it is <code>static</code> and <code>public</code></li>
216  * <li>it defines one parameter whose type's simple name is <code>String[]</code></li>
217  * </ul>
218  *
219  * @exception JavaModelException if this element does not exist or if an
220  * exception occurs while accessing its corresponding resource.
221  * @since 2.0
222  * @return true if this method is a main method, false otherwise
223  */

224 boolean isMainMethod() throws JavaModelException;
225 /**
226  * Returns whether this method represents a resolved method.
227  * If a method is resoved, its key contains resolved information.
228  *
229  * @return whether this method represents a resolved method.
230  * @since 3.1
231  */

232 boolean isResolved();
233 /**
234  * Returns whether this method is similar to the given method.
235  * Two methods are similar if:
236  * <ul>
237  * <li>their element names are equal</li>
238  * <li>they have the same number of parameters</li>
239  * <li>the simple names of their parameter types are equal</li>
240  * </ul>
241  * This is a handle-only method.
242  *
243  * @param method the given method
244  * @return true if this method is similar to the given method.
245  * @see Signature#getSimpleName(char[])
246  * @since 2.0
247  */

248 boolean isSimilar(IMethod method);
249 }
250
Popular Tags