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;
14 * Represents a method (or constructor) declared in a type.
16 * This interface is not intended to be implemented by clients.
19 public interface IMethod extends IMember {
21 * Returns the simple name of this method. For a constructor, this returns
22 * the simple name of the declaring type. Note: This holds whether the
23 * constructor appears in a source or binary type (even though class files
24 * internally define constructor names to be <code>"<init>"</code>).
25 * For the class initialization methods in binary types, this returns the
26 * special name <code>"<clinit>"</code>. This is a handle-only
29 String getElementName();
32 * Returns the type signatures of the exceptions this method throws, in the
33 * order declared in the source. Returns an empty array if this method
34 * throws no exceptions.
37 * For example, a source method declaring <code>"throws IOException"</code>,
38 * would return the array <code>{"QIOException;"}</code>.
40 * @exception JavaModelException
41 * if this element does not exist or if an exception occurs
42 * while accessing its corresponding resource.
43 * @return the type signatures of the exceptions this method throws, in the
44 * order declared in the source, an empty array if this method
45 * throws no exceptions
48 String[] getExceptionTypes() throws JavaModelException;
51 * Returns the number of parameters of this method. This is a handle-only
54 * @return the number of parameters of this method
56 int getNumberOfParameters();
59 * Returns the names of parameters in this method. For binary types, these
60 * names are invented as "arg"+i, where i starts at 1 (even if source is
61 * associated with the binary). Returns an empty array if this method has no
65 * For example, a method declared as
66 * <code>public void foo(String text, int length)</code> would return the
67 * array <code>{"text","length"}</code>.
69 * @exception JavaModelException
70 * if this element does not exist or if an exception occurs
71 * while accessing its corresponding resource.
72 * @return the names of parameters in this method, an empty array if this
73 * method has no parameters
75 String[] getParameterNames() throws JavaModelException;
78 * Returns the type signatures for the parameters of this method. Returns an
79 * empty array if this method has no parameters. This is a handle-only
83 * For example, a source method declared as
84 * <code>public void foo(String text, int length)</code> would return the
85 * array <code>{"QString;","I"}</code>.
87 * @return the type signatures for the parameters of this method, an empty
88 * array if this method has no parameters
91 String[] getParameterTypes();
94 * Returns the type signature of the return value of this method. For
95 * constructors, this returns the signature for void.
98 * For example, a source method declared as
99 * <code>public String getName()</code> would return
100 * <code>"QString;"</code>.
102 * @exception JavaModelException
103 * if this element does not exist or if an exception occurs
104 * while accessing its corresponding resource.
105 * @return the type signature of the return value of this method, void for
109 String getReturnType() throws JavaModelException;
112 * Returns the signature of the method. This includes the signatures for the
113 * parameter types and return type, but does not include the method name or
117 * For example, a source method declared as
118 * <code>public void foo(String text, int length)</code> would return
119 * <code>"(QString;I)V"</code>.
121 * @exception JavaModelException
122 * if this element does not exist or if an exception occurs
123 * while accessing its corresponding resource.
127 String getSignature() throws JavaModelException;
130 * Returns whether this method is a constructor.
132 * @exception JavaModelException
133 * if this element does not exist or if an exception occurs
134 * while accessing its corresponding resource.
136 * @return true if this method is a constructor, false otherwise
138 boolean isConstructor() throws JavaModelException;
141 * Returns whether this method is a main method. It is a main method if:
143 * <li>its name is equal to <code>"main"</code></li>
144 * <li>its return type is <code>void</code></li>
145 * <li>it is <code>static</code> and <code>public</code></li>
146 * <li>it defines one parameter whose type's simple name is </code>String[]</code></li>
149 * @exception JavaModelException
150 * if this element does not exist or if an exception occurs
151 * while accessing its corresponding resource.
153 * @return true if this method is a main method, false otherwise
155 boolean isMainMethod() throws JavaModelException;
158 * Returns whether this method is similar to the given method. Two methods
161 * <li>their element names are equal</li>
162 * <li>they have the same number of parameters</li>
163 * <li>the simple names of their parameter types are equal</li>
165 * This is a handle-only method.
169 * @return true if this method is similar to the given method.
170 * @see Signature#getSimpleName
173 boolean isSimilar(IMethod method);