/******************************************************************************* * Copyright (c) 2000, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * * Contributors: * IBM Corporation - initial API and implementation * Technical University Berlin - extended API and implementation * Stephan Herrmann - Contribution for * Bug 429813 - [1.8][dom ast] IMethodBinding#getJavaElement() should return IMethod for lambda *******************************************************************************/ package org.eclipse.jdt.core.dom; /** * A method binding represents a method or constructor of a class or interface. * Method bindings usually correspond directly to method or * constructor declarations found in the source code. * However, in certain cases of references to a generic method, * the method binding may correspond to a copy of a generic method * declaration with substitutions for the method's type parameters * (for these, getTypeArguments returns a non-empty * list, and either isParameterizedMethod or * isRawMethod returns true). * And in certain cases of references to a method declared in a * generic type, the method binding may correspond to a copy of a * method declaration with substitutions for the type's type * parameters (for these, getTypeArguments returns * an empty list, and both isParameterizedMethod and * isRawMethod return false). * * @see ITypeBinding#getDeclaredMethods() * @since 2.0 * @noimplement This interface is not intended to be implemented by clients. */ public interface IMethodBinding extends IBinding { /** * Returns whether this binding is for a constructor or a method. * * @return true if this is the binding for a constructor, * and false if this is the binding for a method */ public boolean isConstructor(); /** * Returns whether this binding is known to be a compiler-generated * default constructor. *

* This method returns false for: *

* * @return true if this is known to be the binding for a * compiler-generated default constructor, and false * otherwise * @since 3.0 */ public boolean isDefaultConstructor(); /** * Returns the name of the method declared in this binding. The method name * is always a simple identifier. The name of a constructor is always the * same as the declared name of its declaring class. * * @return the name of this method, or the declared name of this * constructor's declaring class */ @Override public String getName(); /** * Returns the type binding representing the class or interface * that declares this method or constructor. * * @return the binding of the class or interface that declares this method * or constructor */ public ITypeBinding getDeclaringClass(); /** * If this method binding represents a lambda expression then: * *

* If this method binding does not represent a lambda expression, * null is returned. *

* @return a method binding or field binding representing the member that * contains the lambda expression represented by this method binding, * or null for regular method bindings. * @since 3.11 */ public IBinding getDeclaringMember(); /** * Returns the resolved default value of an annotation type member, * or null if the member has no default value, or if this * is not the binding for an annotation type member. *

* Resolved values are represented as follows (same as for * {@link IMemberValuePairBinding#getValue()}): *

* * @return the default value of this annotation type member, or null * if none or not applicable * @since 3.2 */ public Object getDefaultValue(); /** * Returns the resolved declaration annotations of a parameter of this method. * The result returned is the same regardless of whether * this is a parameterized method. *

* Note: This method only returns declaration annotations. * Type annotations in the sense of JLS8 9.7.4 are not returned. * Type annotations can be retrieved from a parameter type * via {@link ITypeBinding#getTypeAnnotations()}. *

* * @param paramIndex the index of the parameter of interest * @return the resolved declaration annotations of the paramIndexth parameter, * or an empty list if there are none * @throws ArrayIndexOutOfBoundsException if paramIndex is * not a valid index * @since 3.2 */ public IAnnotationBinding[] getParameterAnnotations(int paramIndex); /** * Returns a list of type bindings representing the formal parameter types, * in declaration order, of this method or constructor. Returns an array of * length 0 if this method or constructor does not takes any parameters. *

* Note that the binding for the last parameter type of a vararg method * declaration like void fun(Foo... args) is always for * an array type (i.e., Foo[]) reflecting the the way varargs * get compiled. However, the type binding obtained directly from * the SingleVariableDeclaration for the vararg parameter * is always for the type as written; i.e., the type binding for * Foo. *

*

* Note: The result does not include synthetic parameters introduced by * inner class emulation. Explicit receiver parameters are also not included. *

* * @return a (possibly empty) list of type bindings for the formal * parameters of this method or constructor */ public ITypeBinding[] getParameterTypes(); /** * Returns the type of this method's receiver or null * if there is no receiver declared explicitly. * * @return the type of this method's receiver or null * if there is no receiver declared explicitly. * * @since 3.10 */ public ITypeBinding getDeclaredReceiverType(); /** * Returns the binding for the return type of this method. Returns the * special primitive void return type for constructors. *

* For methods, the type binding that is returned contains type annotations * if any. For e.g. the following code would get the type annotations on a * method:

* IAnnotationBinding[] annots = getReturnType().getTypeAnnotations() *

* For a constructor, the returned binding does not include type annotations. * * @return the binding for the return type of this method, or the * void return type for constructors */ public ITypeBinding getReturnType(); /** * Returns a list of type bindings representing the types of the exceptions thrown * by this method or constructor. Returns an array of length 0 if this method * throws no exceptions. The resulting types are in no particular order. * * @return a list of type bindings for exceptions * thrown by this method or constructor */ public ITypeBinding[] getExceptionTypes(); /** * Returns the type parameters of this method or constructor binding. *

* Note that type parameters only occur on the binding of the * declaring generic method. Type bindings corresponding to a raw or * parameterized reference to a generic method do not carry type * parameters (they instead have non-empty type arguments * and non-trivial erasure). *

* * @return the list of binding for the type variables for the type * parameters of this method, or otherwise the empty list * @see ITypeBinding#isTypeVariable() * @since 3.1 */ public ITypeBinding[] getTypeParameters(); /** * Returns whether this is the binding for an annotation type member. * * @return true iff this is the binding for an annotation type member * and false otherwise * @since 3.2 */ public boolean isAnnotationMember(); /** * Returns whether this method binding represents a declaration of * a generic method. *

* Note that type parameters only occur on the binding of the * declaring generic method; e.g., public <T> T identity(T t);. * Method bindings corresponding to a raw or parameterized reference to a generic * method do not carry type parameters (they instead have non-empty type arguments * and non-trivial erasure). * This method is fully equivalent to getTypeParameters().length > 0). *

*

* Note that {@link #isGenericMethod()}, * {@link #isParameterizedMethod()}, * and {@link #isRawMethod()} are mutually exclusive. *

* * @return true if this method binding represents a * declaration of a generic method, and false otherwise * @see #getTypeParameters() * @since 3.1 */ public boolean isGenericMethod(); /** * Returns whether this method binding represents an instance of * a generic method corresponding to a parameterized method reference. *

* Note that {@link #isGenericMethod()}, * {@link #isParameterizedMethod()}, * and {@link #isRawMethod()} are mutually exclusive. *

* * @return true if this method binding represents a * an instance of a generic method corresponding to a parameterized * method reference, and false otherwise * @see #getMethodDeclaration() * @see #getTypeArguments() * @since 3.1 */ public boolean isParameterizedMethod(); /** * Returns the type arguments of this generic method instance, or the * empty list for other method bindings. *

* Note that type arguments only occur on a method binding that represents * an instance of a generic method corresponding to a raw or parameterized * reference to a generic method. Do not confuse these with type parameters * which only occur on the method binding corresponding directly to the * declaration of a generic method. *

* * @return the list of type bindings for the type arguments used to * instantiate the corrresponding generic method, or otherwise the empty list * @see #getMethodDeclaration() * @see #isParameterizedMethod() * @see #isRawMethod() * @since 3.1 */ public ITypeBinding[] getTypeArguments(); /** * Returns the binding for the method declaration corresponding to this * method binding. * * * @return the method binding * @since 3.1 */ public IMethodBinding getMethodDeclaration(); /** * Returns whether this method binding represents an instance of * a generic method corresponding to a raw method reference. *

* Note that {@link #isGenericMethod()}, * {@link #isParameterizedMethod()}, * and {@link #isRawMethod()} are mutually exclusive. *

* * @return true if this method binding represents a * an instance of a generic method corresponding to a raw * method reference, and false otherwise * @see #getMethodDeclaration() * @see #getTypeArguments() * @since 3.1 */ public boolean isRawMethod(); /** * Returns whether this method's signature is a subsignature of the given method as * specified in section 8.4.2 of The Java Language Specification, Third Edition (JLS3). * * @return true if this method's signature is a subsignature of the given method * @since 3.1 */ public boolean isSubsignature(IMethodBinding otherMethod); /** * Returns whether this is a variable arity method. *

* Note: Variable arity ("varargs") methods were added in JLS3. *

* * @return true if this is a variable arity method, * and false otherwise * @since 3.1 */ public boolean isVarargs(); /** * Returns whether this method overrides the given method, * as specified in section 8.4.8.1 of The Java Language * Specification, Third Edition (JLS3). * * @param method the method that is possibly overriden * @return true if this method overrides the given method, * and false otherwise * @since 3.1 */ public boolean overrides(IMethodBinding method); /** * Returns a list of variable bindings representing the synthetic outer * local variables. Returns an empty array for non-lambda expressions or if * this method does not have any synthetic parameters. * * @return a (possibly empty) list of variable bindings for the synthetic * outer locals of this method if this is a lambda expression, else an empty array. * @since 3.18 */ public IVariableBinding[] getSyntheticOuterLocals(); //{ObjectTeams: /** * Is method copied due to implicit inheritance? * (beware: copied methods don't have a java element.) * * @since OTDT 1.1.3 */ public boolean isCopied(); // SH} }