Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / IMethod.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.core;
12
13 /**
14  * Represents a method (or constructor) declared in a type.
15  * <p>
16  * This interface is not intended to be implemented by clients.
17  * </p>
18  */
19 public interface IMethod extends IMember {
20 /**
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>"&lt;init&gt;"</code>).
25  * For the class initialization methods in binary types, this returns
26  * the special name <code>"&lt;clinit&gt;"</code>.
27  * This is a handle-only method.
28  */
29 String getElementName();
30 /**
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.
34  *
35  * <p>For example, a source method declaring <code>"throws IOException"</code>,
36  * would return the array <code>{"QIOException;"}</code>.
37  *
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
42  * @see Signature
43  */
44 String[] getExceptionTypes() throws JavaModelException;
45 /**
46  * Returns the number of parameters of this method.
47  * This is a handle-only method.
48  * 
49  * @return the number of parameters of this method
50  */
51 int getNumberOfParameters();
52 /**
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.
57  *
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>.
60  *
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
64  */
65 String[] getParameterNames() throws JavaModelException;
66 /**
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.
70  *
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>.
73  * 
74  * @return the type signatures for the parameters of this method, an empty array if this method has no parameters
75  * @see Signature
76  */
77 String[] getParameterTypes();
78 /**
79  * Returns the type signature of the return value of this method.
80  * For constructors, this returns the signature for void.
81  *
82  * <p>For example, a source method declared as <code>public String getName()</code>
83  * would return <code>"QString;"</code>.
84  *
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
88  * @see Signature
89  */
90 String getReturnType() throws JavaModelException;
91 /**
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.
94  *
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>.
97  *
98  * @exception JavaModelException if this element does not exist or if an
99  *      exception occurs while accessing its corresponding resource.
100  *
101  * @see Signature
102  */
103 String getSignature() throws JavaModelException;
104 /**
105  * Returns whether this method is a constructor.
106  *
107  * @exception JavaModelException if this element does not exist or if an
108  *      exception occurs while accessing its corresponding resource.
109  * 
110  * @return true if this method is a constructor, false otherwise
111  */
112 boolean isConstructor() throws JavaModelException;
113 /**
114  * Returns whether this method is a main method.
115  * It is a main method if:
116  * <ul>
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>
121  * </ul>
122  * 
123  * @exception JavaModelException if this element does not exist or if an
124  *      exception occurs while accessing its corresponding resource.
125  * @since 2.0
126  * @return true if this method is a main method, false otherwise
127  */
128 boolean isMainMethod() throws JavaModelException;
129 /**
130  * Returns whether this method is similar to the given method.
131  * Two methods are similar if:
132  * <ul>
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>
136  * </ul>
137  * This is a handle-only method.
138  * 
139  * @param method the given method
140  * @return true if this method is similar to the given method.
141  * @see Signature#getSimpleName
142  * @since 2.0
143  */
144 boolean isSimilar(IMethod method);
145 }