1 /*******************************************************************************
2 * Copyright (c) 2000, 2008 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.core.dom;
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>).
31 * @see ITypeBinding#getDeclaredMethods()
33 * @noimplement This interface is not intended to be implemented by clients.
35 public interface IMethodBinding extends IBinding {
38 * Returns whether this binding is for a constructor or a method.
40 * @return <code>true</code> if this is the binding for a constructor,
41 * and <code>false</code> if this is the binding for a method
43 public boolean isConstructor();
46 * Returns whether this binding is known to be a compiler-generated
47 * default constructor.
49 * This method returns <code>false</code> for:
52 * <li>constructors with more than one parameter</li>
53 * <li>0-argument constructors where the binding information was obtained
54 * from a Java source file containing an explicit 0-argument constructor
56 * <li>0-argument constructors where the binding information was obtained
57 * from a Java class file (it is not possible to determine from a
58 * class file whether a 0-argument constructor was present in the source
59 * code versus generated automatically by a Java compiler)</li>
62 * @return <code>true</code> if this is known to be the binding for a
63 * compiler-generated default constructor, and <code>false</code>
67 public boolean isDefaultConstructor();
70 * Returns the name of the method declared in this binding. The method name
71 * is always a simple identifier. The name of a constructor is always the
72 * same as the declared name of its declaring class.
74 * @return the name of this method, or the declared name of this
75 * constructor's declaring class
77 public String getName();
80 * Returns the type binding representing the class or interface
81 * that declares this method or constructor.
83 * @return the binding of the class or interface that declares this method
86 public ITypeBinding getDeclaringClass();
89 * Returns the resolved default value of an annotation type member,
90 * or <code>null</code> if the member has no default value, or if this
91 * is not the binding for an annotation type member.
93 * Resolved values are represented as follows (same as for
94 * {@link IMemberValuePairBinding#getValue()}):
96 * <li>Primitive type - the equivalent boxed object</li>
97 * <li>java.lang.Class - the <code>ITypeBinding</code> for the class object</li>
98 * <li>java.lang.String - the string value itself</li>
99 * <li>enum type - the <code>IVariableBinding</code> for the enum constant</li>
100 * <li>annotation type - an <code>IAnnotationBinding</code></li>
101 * <li>array type - an <code>Object[]</code> whose elements are as per above
102 * (the language only allows single dimensional arrays in annotations)</li>
105 * @return the default value of this annotation type member, or <code>null</code>
106 * if none or not applicable
109 public Object getDefaultValue();
112 * Returns the resolved annotations of a parameter of this method.
113 * The result returned is the same regardless of whether
114 * this is a parameterized method.
116 * @param paramIndex the index of the parameter of interest
117 * @return the resolved annotations of the <code>paramIndex</code>th parameter,
118 * or an empty list if there are none
119 * @throws ArrayIndexOutOfBoundsException if <code>paramIndex</code> is
123 public IAnnotationBinding[] getParameterAnnotations(int paramIndex);
126 * Returns a list of type bindings representing the formal parameter types,
127 * in declaration order, of this method or constructor. Returns an array of
128 * length 0 if this method or constructor does not takes any parameters.
130 * Note that the binding for the last parameter type of a vararg method
131 * declaration like <code>void fun(Foo... args)</code> is always for
132 * an array type (i.e., <code>Foo[]</code>) reflecting the the way varargs
133 * get compiled. However, the type binding obtained directly from
134 * the <code>SingleVariableDeclaration</code> for the vararg parameter
135 * is always for the type as written; i.e., the type binding for
139 * Note: The result does not include synthetic parameters introduced by
140 * inner class emulation.
143 * @return a (possibly empty) list of type bindings for the formal
144 * parameters of this method or constructor
146 public ITypeBinding[] getParameterTypes();
149 * Returns the binding for the return type of this method. Returns the
150 * special primitive <code>void</code> return type for constructors.
152 * @return the binding for the return type of this method, or the
153 * <code>void</code> return type for constructors
155 public ITypeBinding getReturnType();
158 * Returns a list of type bindings representing the types of the exceptions thrown
159 * by this method or constructor. Returns an array of length 0 if this method
160 * throws no exceptions. The resulting types are in no particular order.
162 * @return a list of type bindings for exceptions
163 * thrown by this method or constructor
165 public ITypeBinding[] getExceptionTypes();
168 * Returns the type parameters of this method or constructor binding.
170 * Note that type parameters only occur on the binding of the
171 * declaring generic method. Type bindings corresponding to a raw or
172 * parameterized reference to a generic method do not carry type
173 * parameters (they instead have non-empty type arguments
174 * and non-trivial erasure).
177 * @return the list of binding for the type variables for the type
178 * parameters of this method, or otherwise the empty list
179 * @see ITypeBinding#isTypeVariable()
182 public ITypeBinding[] getTypeParameters();
185 * Returns whether this is the binding for an annotation type member.
187 * @return <code>true</code> iff this is the binding for an annotation type member
188 * and <code>false</code> otherwise
191 public boolean isAnnotationMember();
194 * Returns whether this method binding represents a declaration of
197 * Note that type parameters only occur on the binding of the
198 * declaring generic method; e.g., <code>public <T> T identity(T t);</code>.
199 * Method bindings corresponding to a raw or parameterized reference to a generic
200 * method do not carry type parameters (they instead have non-empty type arguments
201 * and non-trivial erasure).
202 * This method is fully equivalent to <code>getTypeParameters().length > 0)</code>.
205 * Note that {@link #isGenericMethod()},
206 * {@link #isParameterizedMethod()},
207 * and {@link #isRawMethod()} are mutually exclusive.
210 * @return <code>true</code> if this method binding represents a
211 * declaration of a generic method, and <code>false</code> otherwise
212 * @see #getTypeParameters()
215 public boolean isGenericMethod();
218 * Returns whether this method binding represents an instance of
219 * a generic method corresponding to a parameterized method reference.
221 * Note that {@link #isGenericMethod()},
222 * {@link #isParameterizedMethod()},
223 * and {@link #isRawMethod()} are mutually exclusive.
226 * @return <code>true</code> if this method binding represents a
227 * an instance of a generic method corresponding to a parameterized
228 * method reference, and <code>false</code> otherwise
229 * @see #getMethodDeclaration()
230 * @see #getTypeArguments()
233 public boolean isParameterizedMethod();
236 * Returns the type arguments of this generic method instance, or the
237 * empty list for other method bindings.
239 * Note that type arguments only occur on a method binding that represents
240 * an instance of a generic method corresponding to a raw or parameterized
241 * reference to a generic method. Do not confuse these with type parameters
242 * which only occur on the method binding corresponding directly to the
243 * declaration of a generic method.
246 * @return the list of type bindings for the type arguments used to
247 * instantiate the corrresponding generic method, or otherwise the empty list
248 * @see #getMethodDeclaration()
249 * @see #isParameterizedMethod()
250 * @see #isRawMethod()
253 public ITypeBinding[] getTypeArguments();
256 * Returns the binding for the method declaration corresponding to this
257 * method binding. For parameterized methods ({@link #isParameterizedMethod()})
258 * and raw methods ({@link #isRawMethod()}), this method returns the binding
259 * for the corresponding generic method. For other method bindings, this
260 * returns the same binding.
262 * <p>Note: The one notable exception is the method <code>Object.getClass()</code>,
263 * which is declared to return <code>Class<? extends Object></code>, but
264 * when invoked its return type becomes <code>Class<? extends
265 * </code><em>R</em><code>></code>, where <em>R</em> is the compile type of
266 * the receiver of the method invocation.</p>
268 * @return the method binding
271 public IMethodBinding getMethodDeclaration();
274 * Returns whether this method binding represents an instance of
275 * a generic method corresponding to a raw method reference.
277 * Note that {@link #isGenericMethod()},
278 * {@link #isParameterizedMethod()},
279 * and {@link #isRawMethod()} are mutually exclusive.
282 * @return <code>true</code> if this method binding represents a
283 * an instance of a generic method corresponding to a raw
284 * method reference, and <code>false</code> otherwise
285 * @see #getMethodDeclaration()
286 * @see #getTypeArguments()
289 public boolean isRawMethod();
292 * Returns whether this method's signature is a subsignature of the given method as
293 * specified in section 8.4.2 of <em>The Java Language Specification, Third Edition</em> (JLS3).
295 * @return <code>true</code> if this method's signature is a subsignature of the given method
298 public boolean isSubsignature(IMethodBinding otherMethod);
301 * Returns whether this is a variable arity method.
303 * Note: Variable arity ("varargs") methods were added in JLS3.
306 * @return <code>true</code> if this is a variable arity method,
307 * and <code>false</code> otherwise
310 public boolean isVarargs();
313 * Returns whether this method overrides the given method,
314 * as specified in section 8.4.8.1 of <em>The Java Language
315 * Specification, Third Edition</em> (JLS3).
317 * @param method the method that is possibly overriden
318 * @return <code>true</code> if this method overrides the given method,
319 * and <code>false</code> otherwise
322 public boolean overrides(IMethodBinding method);