KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > dom > IMethodBinding


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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  *******************************************************************************/

11
12 package org.eclipse.jdt.core.dom;
13
14 /**
15  * A method binding represents a method or constructor of a class or interface.
16  * Method bindings usually correspond directly to method or
17  * constructor declarations found in the source code.
18  * However, in certain cases of references to a generic method,
19  * the method binding may correspond to a copy of a generic method
20  * declaration with substitutions for the method's type parameters
21  * (for these, <code>getTypeArguments</code> returns a non-empty
22  * list, and either <code>isParameterizedMethod</code> or
23  * <code>isRawMethod</code> returns <code>true</code>).
24  * And in certain cases of references to a method declared in a
25  * generic type, the method binding may correspond to a copy of a
26  * method declaration with substitutions for the type's type
27  * parameters (for these, <code>getTypeArguments</code> returns
28  * an empty list, and both <code>isParameterizedMethod</code> and
29  * <code>isRawMethod</code> return <code>false</code>).
30  * <p>
31  * This interface is not intended to be implemented by clients.
32  * </p>
33  *
34  * @see ITypeBinding#getDeclaredMethods()
35  * @since 2.0
36  */

37 public interface IMethodBinding extends IBinding {
38     
39     /**
40      * Returns whether this binding is for a constructor or a method.
41      *
42      * @return <code>true</code> if this is the binding for a constructor,
43      * and <code>false</code> if this is the binding for a method
44      */

45     public boolean isConstructor();
46
47     /**
48      * Returns whether this binding is known to be a compiler-generated
49      * default constructor.
50      * <p>
51      * This method returns <code>false</code> for:
52      * <ul>
53      * <li>methods</li>
54      * <li>constructors with more than one parameter</li>
55      * <li>0-argument constructors where the binding information was obtained
56      * from a Java source file containing an explicit 0-argument constructor
57      * declaration</li>
58      * <li>0-argument constructors where the binding information was obtained
59      * from a Java class file (it is not possible to determine from a
60      * class file whether a 0-argument constructor was present in the source
61      * code versus generated automatically by a Java compiler)</li>
62      * </ul>
63      *
64      * @return <code>true</code> if this is known to be the binding for a
65      * compiler-generated default constructor, and <code>false</code>
66      * otherwise
67      * @since 3.0
68      */

69     public boolean isDefaultConstructor();
70     
71     /**
72      * Returns the name of the method declared in this binding. The method name
73      * is always a simple identifier. The name of a constructor is always the
74      * same as the declared name of its declaring class.
75      *
76      * @return the name of this method, or the declared name of this
77      * constructor's declaring class
78      */

79     public String JavaDoc getName();
80     
81     /**
82      * Returns the type binding representing the class or interface
83      * that declares this method or constructor.
84      *
85      * @return the binding of the class or interface that declares this method
86      * or constructor
87      */

88     public ITypeBinding getDeclaringClass();
89
90     /**
91      * Returns the resolved default value of an annotation type member,
92      * or <code>null</code> if the member has no default value, or if this
93      * is not the binding for an annotation type member.
94      * <p>
95      * Resolved values are represented as follows (same as for
96      * {@link IMemberValuePairBinding#getValue()}):
97      * <ul>
98      * <li>Primitive type - the equivalent boxed object</li>
99      * <li>java.lang.Class - the <code>ITypeBinding</code> for the class object</li>
100      * <li>java.lang.String - the string value itself</li>
101      * <li>enum type - the <code>IVariableBinding</code> for the enum constant</li>
102      * <li>annotation type - an <code>IAnnotationBinding</code></li>
103      * <li>array type - an <code>Object[]</code> whose elements are as per above
104      * (the language only allows single dimensional arrays in annotations)</li>
105      * </ul>
106      *
107      * @return the default value of this annotation type member, or <code>null</code>
108      * if none or not applicable
109      * @since 3.2
110      */

111     public Object JavaDoc getDefaultValue();
112
113     /**
114      * Returns the resolved annotations of a parameter of this method.
115      * The result returned is the same regardless of whether
116      * this is a parameterized method.
117      *
118      * @param paramIndex the index of the parameter of interest
119      * @return the resolved annotations of the <code>paramIndex</code>th parameter,
120      * or an empty list if there are none
121      * @throws ArrayIndexOutOfBoundsException if <code>paramIndex</code> is
122      * not a valid index
123      * @since 3.2
124      */

125     public IAnnotationBinding[] getParameterAnnotations(int paramIndex);
126
127     /**
128      * Returns a list of type bindings representing the formal parameter types,
129      * in declaration order, of this method or constructor. Returns an array of
130      * length 0 if this method or constructor does not takes any parameters.
131      * <p>
132      * Note that the binding for the last parameter type of a vararg method
133      * declaration like <code>void fun(Foo... args)</code> is always for
134      * an array type (i.e., <code>Foo[]</code>) reflecting the the way varargs
135      * get compiled. However, the type binding obtained directly from
136      * the <code>SingleVariableDeclaration</code> for the vararg parameter
137      * is always for the type as written; i.e., the type binding for
138      * <code>Foo</code>.
139      * </p>
140      * <p>
141      * Note: The result does not include synthetic parameters introduced by
142      * inner class emulation.
143      * </p>
144      *
145      * @return a (possibly empty) list of type bindings for the formal
146      * parameters of this method or constructor
147      */

148     public ITypeBinding[] getParameterTypes();
149
150     /**
151      * Returns the binding for the return type of this method. Returns the
152      * special primitive <code>void</code> return type for constructors.
153      *
154      * @return the binding for the return type of this method, or the
155      * <code>void</code> return type for constructors
156      */

157     public ITypeBinding getReturnType();
158
159     /**
160      * Returns a list of type bindings representing the types of the exceptions thrown
161      * by this method or constructor. Returns an array of length 0 if this method
162      * throws no exceptions. The resulting types are in no particular order.
163      *
164      * @return a list of type bindings for exceptions
165      * thrown by this method or constructor
166      */

167     public ITypeBinding[] getExceptionTypes();
168     
169     /**
170      * Returns the type parameters of this method or constructor binding.
171      * <p>
172      * Note that type parameters only occur on the binding of the
173      * declaring generic method. Type bindings corresponding to a raw or
174      * parameterized reference to a generic method do not carry type
175      * parameters (they instead have non-empty type arguments
176      * and non-trivial erasure).
177      * </p>
178      *
179      * @return the list of binding for the type variables for the type
180      * parameters of this method, or otherwise the empty list
181      * @see ITypeBinding#isTypeVariable()
182      * @since 3.1
183      */

184     public ITypeBinding[] getTypeParameters();
185
186     /**
187      * Returns whether this is the binding for an annotation type member.
188      *
189      * @return <code>true</code> iff this is the binding for an annotation type member
190      * and <code>false</code> otherwise
191      * @since 3.2
192      */

193     public boolean isAnnotationMember();
194
195     /**
196      * Returns whether this method binding represents a declaration of
197      * a generic method.
198      * <p>
199      * Note that type parameters only occur on the binding of the
200      * declaring generic method; e.g., <code>public &lt;T&gt; T identity(T t);</code>.
201      * Method bindings corresponding to a raw or parameterized reference to a generic
202      * method do not carry type parameters (they instead have non-empty type arguments
203      * and non-trivial erasure).
204      * This method is fully equivalent to <code>getTypeParameters().length &gt; 0)</code>.
205      * </p>
206      * <p>
207      * Note that {@link #isGenericMethod()},
208      * {@link #isParameterizedMethod()},
209      * and {@link #isRawMethod()} are mutually exclusive.
210      * </p>
211      *
212      * @return <code>true</code> if this method binding represents a
213      * declaration of a generic method, and <code>false</code> otherwise
214      * @see #getTypeParameters()
215      * @since 3.1
216      */

217     public boolean isGenericMethod();
218     
219     /**
220      * Returns whether this method binding represents an instance of
221      * a generic method corresponding to a parameterized method reference.
222      * <p>
223      * Note that {@link #isGenericMethod()},
224      * {@link #isParameterizedMethod()},
225      * and {@link #isRawMethod()} are mutually exclusive.
226      * </p>
227      *
228      * @return <code>true</code> if this method binding represents a
229      * an instance of a generic method corresponding to a parameterized
230      * method reference, and <code>false</code> otherwise
231      * @see #getMethodDeclaration()
232      * @see #getTypeArguments()
233      * @since 3.1
234      */

235     public boolean isParameterizedMethod();
236     
237     /**
238      * Returns the type arguments of this generic method instance, or the
239      * empty list for other method bindings.
240      * <p>
241      * Note that type arguments only occur on a method binding that represents
242      * an instance of a generic method corresponding to a raw or parameterized
243      * reference to a generic method. Do not confuse these with type parameters
244      * which only occur on the method binding corresponding directly to the
245      * declaration of a generic method.
246      * </p>
247      *
248      * @return the list of type bindings for the type arguments used to
249      * instantiate the corrresponding generic method, or otherwise the empty list
250      * @see #getMethodDeclaration()
251      * @see #isParameterizedMethod()
252      * @see #isRawMethod()
253      * @since 3.1
254      */

255     public ITypeBinding[] getTypeArguments();
256     
257     /**
258      * Returns the binding for the method declaration corresponding to this
259      * method binding. For parameterized methods ({@link #isParameterizedMethod()})
260      * and raw methods ({@link #isRawMethod()}), this method returns the binding
261      * for the corresponding generic method. For other method bindings, this
262      * returns the same binding.
263      *
264      * <p>Note: The one notable exception is the method <code>Object.getClass()</code>,
265      * which is declared to return <code>Class&lt;? extends Object&gt;</code>, but
266      * when invoked its return type becomes <code>Class&lt;? extends
267      * </code><em>R</em><code>&gt;</code>, where <em>R</em> is the compile type of
268      * the receiver of the method invocation.</p>
269      *
270      * @return the method binding
271      * @since 3.1
272      */

273     public IMethodBinding getMethodDeclaration();
274     
275     /**
276      * Returns whether this method binding represents an instance of
277      * a generic method corresponding to a raw method reference.
278      * <p>
279      * Note that {@link #isGenericMethod()},
280      * {@link #isParameterizedMethod()},
281      * and {@link #isRawMethod()} are mutually exclusive.
282      * </p>
283      *
284      * @return <code>true</code> if this method binding represents a
285      * an instance of a generic method corresponding to a raw
286      * method reference, and <code>false</code> otherwise
287      * @see #getMethodDeclaration()
288      * @see #getTypeArguments()
289      * @since 3.1
290      */

291     public boolean isRawMethod();
292     
293     /**
294      * Returns whether this method's signature is a subsignature of the given method as
295      * specified in section 8.4.2 of <em>The Java Language Specification, Third Edition</em> (JLS3).
296      *
297      * @return <code>true</code> if this method's signature is a subsignature of the given method
298      * @since 3.1
299      */

300     public boolean isSubsignature(IMethodBinding otherMethod);
301     
302     /**
303      * Returns whether this is a variable arity method.
304      * <p>
305      * Note: Variable arity ("varargs") methods were added in JLS3.
306      * </p>
307      *
308      * @return <code>true</code> if this is a variable arity method,
309      * and <code>false</code> otherwise
310      * @since 3.1
311      */

312     public boolean isVarargs();
313     
314     /**
315      * Returns whether this method overrides the given method,
316      * as specified in section 8.4.8.1 of <em>The Java Language
317      * Specification, Third Edition</em> (JLS3).
318      *
319      * @param method the method that is possibly overriden
320      * @return <code>true</code> if this method overrides the given method,
321      * and <code>false</code> otherwise
322      * @since 3.1
323      */

324     public boolean overrides(IMethodBinding method);
325 }
326
Popular Tags