001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: * IBM Corporation - added J2SE 1.5 support
011: *******************************************************************************/package org.eclipse.jdt.core;
012:
013: /**
014: * Represents a method (or constructor) declared in a type.
015: * <p>
016: * This interface is not intended to be implemented by clients.
017: * </p>
018: */
019: public interface IMethod extends IMember {
020: /**
021: * Returns the simple name of this method.
022: * For a constructor, this returns the simple name of the declaring type.
023: * Note: This holds whether the constructor appears in a source or binary type
024: * (even though class files internally define constructor names to be <code>"<init>"</code>).
025: * For the class initialization methods in binary types, this returns
026: * the special name <code>"<clinit>"</code>.
027: * This is a handle-only method.
028: * @return the simple name of this method
029: */
030: String getElementName();
031:
032: /**
033: * Returns the type signatures of the exceptions this method throws,
034: * in the order declared in the source. Returns an empty array
035: * if this method throws no exceptions.
036: * <p>
037: * For example, a source method declaring <code>"throws IOException"</code>,
038: * would return the array <code>{"QIOException;"}</code>.
039: * </p>
040: * <p>
041: * The type signatures may be either unresolved (for source types)
042: * or resolved (for binary types), and either basic (for basic types)
043: * or rich (for parameterized types). See {@link Signature} for details.
044: * </p>
045: *
046: * @exception JavaModelException if this element does not exist or if an
047: * exception occurs while accessing its corresponding resource.
048: * @return the type signatures of the exceptions this method throws,
049: * in the order declared in the source, an empty array if this method throws no exceptions
050: * @see Signature
051: */
052: String[] getExceptionTypes() throws JavaModelException;
053:
054: /**
055: * Returns the formal type parameter signatures for this method.
056: * Returns an empty array if this method has no formal type parameters.
057: * <p>
058: * The formal type parameter signatures may be either unresolved (for source
059: * types) or resolved (for binary types). See {@link Signature} for details.
060: * </p>
061: *
062: * @exception JavaModelException if this element does not exist or if an
063: * exception occurs while accessing its corresponding resource.
064: * @return the formal type parameter signatures of this method,
065: * in the order declared in the source, an empty array if none
066: * @see Signature
067: * @since 3.0
068: * @deprecated Use {@link #getTypeParameters()} instead
069: */
070: String[] getTypeParameterSignatures() throws JavaModelException;
071:
072: /**
073: * Returns the formal type parameters for this method.
074: * Returns an empty array if this method has no formal type parameters.
075: *
076: * @exception JavaModelException if this element does not exist or if an
077: * exception occurs while accessing its corresponding resource.
078: * @return the formal type parameters of this method,
079: * in the order declared in the source, an empty array if none
080: * @since 3.1
081: */
082: ITypeParameter[] getTypeParameters() throws JavaModelException;
083:
084: /**
085: * Returns the number of parameters of this method.
086: * This is a handle-only method.
087: *
088: * @return the number of parameters of this method
089: */
090: int getNumberOfParameters();
091:
092: /**
093: * Returns the binding key for this method. A binding key is a key that uniquely
094: * identifies this method. It allows access to generic info for parameterized
095: * methods.
096: *
097: * @return the binding key for this method
098: * @see org.eclipse.jdt.core.dom.IBinding#getKey()
099: * @see BindingKey
100: * @since 3.1
101: */
102: String getKey();
103:
104: /**
105: * Returns the names of parameters in this method.
106: * For binary types, associated source or attached Javadoc are used to retrieve the names.
107: * If none can be retrieved, then these names are invented as "arg"+i, where i starts at 0.
108: * Returns an empty array if this method has no parameters.
109: *
110: * <p>For example, a method declared as <code>public void foo(String text, int length)</code>
111: * would return the array <code>{"text","length"}</code>.
112: * </p>
113: *
114: * @exception JavaModelException if this element does not exist or if an
115: * exception occurs while accessing its corresponding resource.
116: * @return the names of parameters in this method, an empty array if this method has no parameters
117: */
118: String[] getParameterNames() throws JavaModelException;
119:
120: /**
121: * Returns the type signatures for the parameters of this method.
122: * Returns an empty array if this method has no parameters.
123: * This is a handle-only method.
124: * <p>
125: * For example, a source method declared as <code>public void foo(String text, int length)</code>
126: * would return the array <code>{"QString;","I"}</code>.
127: * </p>
128: * <p>
129: * The type signatures may be either unresolved (for source types)
130: * or resolved (for binary types), and either basic (for basic types)
131: * or rich (for parameterized types). See {@link Signature} for details.
132: * </p>
133: *
134: * @return the type signatures for the parameters of this method, an empty array if this method has no parameters
135: * @see Signature
136: */
137: String[] getParameterTypes();
138:
139: /**
140: * Returns the names of parameters in this method.
141: * For binary types, these names are invented as "arg"+i, where i starts at 0
142: * (even if source is associated with the binary or if Javdoc is attached to the binary).
143: * Returns an empty array if this method has no parameters.
144: *
145: * <p>For example, a method declared as <code>public void foo(String text, int length)</code>
146: * would return the array <code>{"text","length"}</code>. For the same method in a
147: * binary, this would return <code>{"arg0", "arg1"}</code>.
148: * </p>
149: *
150: * @exception JavaModelException if this element does not exist or if an
151: * exception occurs while accessing its corresponding resource.
152: * @return the names of parameters in this method, an empty array if this method has no parameters
153: * @since 3.2
154: */
155: String[] getRawParameterNames() throws JavaModelException;
156:
157: /**
158: * Returns the type signature of the return value of this method.
159: * For constructors, this returns the signature for void.
160: * <p>
161: * For example, a source method declared as <code>public String getName()</code>
162: * would return <code>"QString;"</code>.
163: * </p>
164: * <p>
165: * The type signature may be either unresolved (for source types)
166: * or resolved (for binary types), and either basic (for basic types)
167: * or rich (for parameterized types). See {@link Signature} for details.
168: * </p>
169: *
170: * @exception JavaModelException if this element does not exist or if an
171: * exception occurs while accessing its corresponding resource.
172: * @return the type signature of the return value of this method, void for constructors
173: * @see Signature
174: */
175: String getReturnType() throws JavaModelException;
176:
177: /**
178: * Returns the signature of this method. This includes the signatures for the
179: * parameter types and return type, but does not include the method name,
180: * exception types, or type parameters.
181: * <p>
182: * For example, a source method declared as <code>public void foo(String text, int length)</code>
183: * would return <code>"(QString;I)V"</code>.
184: * </p>
185: * <p>
186: * The type signatures embedded in the method signature may be either unresolved
187: * (for source types) or resolved (for binary types), and either basic (for
188: * basic types) or rich (for parameterized types). See {@link Signature} for
189: * details.
190: * </p>
191: *
192: * @return the signature of this method
193: * @exception JavaModelException if this element does not exist or if an
194: * exception occurs while accessing its corresponding resource.
195: * @see Signature
196: */
197: String getSignature() throws JavaModelException;
198:
199: /**
200: * Returns the type parameter declared in this method with the given name.
201: * This is a handle-only method. The type parameter may or may not exist.
202: *
203: * @param name the given simple name
204: * @return the type parameter declared in this method with the given name
205: * @since 3.1
206: */
207: ITypeParameter getTypeParameter(String name);
208:
209: /**
210: * Returns whether this method is a constructor.
211: *
212: * @exception JavaModelException if this element does not exist or if an
213: * exception occurs while accessing its corresponding resource.
214: *
215: * @return true if this method is a constructor, false otherwise
216: */
217: boolean isConstructor() throws JavaModelException;
218:
219: /**
220: * Returns whether this method is a main method.
221: * It is a main method if:
222: * <ul>
223: * <li>its name is equal to <code>"main"</code></li>
224: * <li>its return type is <code>void</code></li>
225: * <li>it is <code>static</code> and <code>public</code></li>
226: * <li>it defines one parameter whose type's simple name is <code>String[]</code></li>
227: * </ul>
228: *
229: * @exception JavaModelException if this element does not exist or if an
230: * exception occurs while accessing its corresponding resource.
231: * @since 2.0
232: * @return true if this method is a main method, false otherwise
233: */
234: boolean isMainMethod() throws JavaModelException;
235:
236: /**
237: * Returns whether this method represents a resolved method.
238: * If a method is resoved, its key contains resolved information.
239: *
240: * @return whether this method represents a resolved method.
241: * @since 3.1
242: */
243: boolean isResolved();
244:
245: /**
246: * Returns whether this method is similar to the given method.
247: * Two methods are similar if:
248: * <ul>
249: * <li>their element names are equal</li>
250: * <li>they have the same number of parameters</li>
251: * <li>the simple names of their parameter types are equal</li>
252: * </ul>
253: * This is a handle-only method.
254: *
255: * @param method the given method
256: * @return true if this method is similar to the given method.
257: * @see Signature#getSimpleName(char[])
258: * @since 2.0
259: */
260: boolean isSimilar(IMethod method);
261: }
|