1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.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.
22 * For a constructor, this returns the simple name of the declaring type.
23 * Note: This holds whether the constructor appears in a source or binary type
24 * (even though class files internally define constructor names to be <code>"<init>"</code>).
25 * For the class initialization methods in binary types, this returns
26 * the special name <code>"<clinit>"</code>.
27 * This is a handle-only method.
29 String getElementName();
31 * Returns the type signatures of the exceptions this method throws,
32 * in the order declared in the source. Returns an empty array
33 * if this method throws no exceptions.
35 * <p>For example, a source method declaring <code>"throws IOException"</code>,
36 * would return the array <code>{"QIOException;"}</code>.
38 * @exception JavaModelException if this element does not exist or if an
39 * exception occurs while accessing its corresponding resource.
40 * @return the type signatures of the exceptions this method throws,
41 * in the order declared in the source, an empty array if this method throws no exceptions
44 String[] getExceptionTypes() throws JavaModelException;
46 * Returns the number of parameters of this method.
47 * This is a handle-only method.
49 * @return the number of parameters of this method
51 int getNumberOfParameters();
53 * Returns the names of parameters in this method.
54 * For binary types, these names are invented as "arg"+i, where i starts at 1
55 * (even if source is associated with the binary).
56 * Returns an empty array if this method has no parameters.
58 * <p>For example, a method declared as <code>public void foo(String text, int length)</code>
59 * would return the array <code>{"text","length"}</code>.
61 * @exception JavaModelException if this element does not exist or if an
62 * exception occurs while accessing its corresponding resource.
63 * @return the names of parameters in this method, an empty array if this method has no parameters
65 String[] getParameterNames() throws JavaModelException;
67 * Returns the type signatures for the parameters of this method.
68 * Returns an empty array if this method has no parameters.
69 * This is a handle-only method.
71 * <p>For example, a source method declared as <code>public void foo(String text, int length)</code>
72 * would return the array <code>{"QString;","I"}</code>.
74 * @return the type signatures for the parameters of this method, an empty array if this method has no parameters
77 String[] getParameterTypes();
79 * Returns the type signature of the return value of this method.
80 * For constructors, this returns the signature for void.
82 * <p>For example, a source method declared as <code>public String getName()</code>
83 * would return <code>"QString;"</code>.
85 * @exception JavaModelException if this element does not exist or if an
86 * exception occurs while accessing its corresponding resource.
87 * @return the type signature of the return value of this method, void for constructors
90 String getReturnType() throws JavaModelException;
92 * Returns the signature of the method. This includes the signatures for the parameter
93 * types and return type, but does not include the method name or exception types.
95 * <p>For example, a source method declared as <code>public void foo(String text, int length)</code>
96 * would return <code>"(QString;I)V"</code>.
98 * @exception JavaModelException if this element does not exist or if an
99 * exception occurs while accessing its corresponding resource.
103 String getSignature() throws JavaModelException;
105 * Returns whether this method is a constructor.
107 * @exception JavaModelException if this element does not exist or if an
108 * exception occurs while accessing its corresponding resource.
110 * @return true if this method is a constructor, false otherwise
112 boolean isConstructor() throws JavaModelException;
114 * Returns whether this method is a main method.
115 * It is a main method if:
117 * <li>its name is equal to <code>"main"</code></li>
118 * <li>its return type is <code>void</code></li>
119 * <li>it is <code>static</code> and <code>public</code></li>
120 * <li>it defines one parameter whose type's simple name is </code>String[]</code></li>
123 * @exception JavaModelException if this element does not exist or if an
124 * exception occurs while accessing its corresponding resource.
126 * @return true if this method is a main method, false otherwise
128 boolean isMainMethod() throws JavaModelException;
130 * Returns whether this method is similar to the given method.
131 * Two methods are similar if:
133 * <li>their element names are equal</li>
134 * <li>they have the same number of parameters</li>
135 * <li>the simple names of their parameter types are equal</li>
137 * This is a handle-only method.
139 * @param method the given method
140 * @return true if this method is similar to the given method.
141 * @see Signature#getSimpleName
144 boolean isSimilar(IMethod method);