Interface IMethodBinding
- All Superinterfaces:
IBinding
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
).- Since:
- 2.0
- See Also:
- Restriction:
- This interface is not intended to be implemented by clients.
-
Field Summary
Fields inherited from interface org.eclipse.jdt.core.dom.IBinding
ANNOTATION, MEMBER_VALUE_PAIR, METHOD, MODULE, PACKAGE, TYPE, VARIABLE
-
Method Summary
Modifier and TypeMethodDescriptionReturns the type of this method's receiver ornull
if there is no receiver declared explicitly.Returns the type binding representing the class or interface that declares this method or constructor.If this method binding represents a lambda expression then: If the lambda expression is declared in the body of a method, answers the binding of that declaring method.Returns the resolved default value of an annotation type member, ornull
if the member has no default value, or if this is not the binding for an annotation type member.Returns a list of type bindings representing the types of the exceptions thrown by this method or constructor.Returns the binding for the method declaration corresponding to this method binding.getName()
Returns the name of the method declared in this binding.getParameterAnnotations
(int paramIndex) Returns the resolved declaration annotations of a parameter of this method.String[]
Returns the ordered list of parameter names for this method.Returns a list of type bindings representing the formal parameter types, in declaration order, of this method or constructor.Returns the binding for the return type of this method.Returns a list of variable bindings representing the synthetic outer local variables.Returns the type arguments of this generic method instance, or the empty list for other method bindings.Returns the type parameters of this method or constructor binding.boolean
Returns whether this is the binding for an annotation type member.boolean
Returns whether this binding is for a canonical constructor or not.boolean
Returns whether this binding is for a compact constructor or not.boolean
Returns whether this binding is for a constructor or a method.boolean
Returns whether this binding is known to be a compiler-generated default constructor.boolean
Returns whether this method binding represents a declaration of a generic method.boolean
Returns whether this method binding represents an instance of a generic method corresponding to a parameterized method reference.boolean
Returns whether this method binding represents an instance of a generic method corresponding to a raw method reference.boolean
isSubsignature
(IMethodBinding otherMethod) 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).boolean
Returns if this is a compiler generated equals(), hashCode(), toString() or any accessor method of a Record or not.boolean
Returns whether this is a variable arity method.boolean
overrides
(IMethodBinding method) Returns whether this method overrides the given method, as specified in section 8.4.8.1 of The Java Language Specification, Third Edition (JLS3).Methods inherited from interface org.eclipse.jdt.core.dom.IBinding
equals, getAnnotations, getJavaElement, getKey, getKind, getModifiers, isDeprecated, isEqualTo, isRecovered, isSynthetic, toString
-
Method Details
-
isConstructor
boolean isConstructor()Returns whether this binding is for a constructor or a method.- Returns:
true
if this is the binding for a constructor, andfalse
if this is the binding for a method
-
isCompactConstructor
boolean isCompactConstructor()Returns whether this binding is for a compact constructor or not.This method returns
true
for:- compact constructors where the binding information was obtained from a Java source file containing a compact constructor declaration
This method returns
false
for:- methods
- constructors
- constructors where the binding information was obtained from a Java class file (it is not possible to determine from a class file whether a constructor is a compact constructor or not
- Returns:
true
if this is the binding for a compact constructor in a source file and andfalse
otherwise- Since:
- 3.26
-
isCanonicalConstructor
boolean isCanonicalConstructor()Returns whether this binding is for a canonical constructor or not.This method returns
true
for canonical constructors- Returns:
true
if this is the binding for a canonical constructor andfalse
otherwise- Since:
- 3.26
-
isDefaultConstructor
boolean isDefaultConstructor()Returns whether this binding is known to be a compiler-generated default constructor.This method returns
false
for:- methods
- constructors with more than one parameter
- 0-argument constructors where the binding information was obtained from a Java source file containing an explicit 0-argument constructor declaration
- 0-argument constructors where the binding information was obtained from a Java class file (it is not possible to determine from a class file whether a 0-argument constructor was present in the source code versus generated automatically by a Java compiler)
- Returns:
true
if this is known to be the binding for a compiler-generated default constructor, andfalse
otherwise- Since:
- 3.0
-
getName
String getName()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. -
getDeclaringClass
ITypeBinding getDeclaringClass()Returns the type binding representing the class or interface that declares this method or constructor.- Returns:
- the binding of the class or interface that declares this method or constructor
-
getDeclaringMember
IBinding getDeclaringMember()If this method binding represents a lambda expression then:- If the lambda expression is declared in the body of a method, answers the binding of that declaring method.
- Otherwise, if the lambda expression is declared in the initializer of a field, answers the binding of that declaring field.
- Otherwise, if the lambda expression is declared in a static initializer or an instance initializer, a method binding is returned to represent that initializer (selector is an empty string in this case).
If this method binding does not represent a lambda expression,
null
is returned.- Returns:
- 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
-
getDefaultValue
Object getDefaultValue()Returns the resolved default value of an annotation type member, ornull
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
IMemberValuePairBinding.getValue()
):- Primitive type - the equivalent boxed object
- java.lang.Class - the
ITypeBinding
for the class object - java.lang.String - the string value itself
- enum type - the
IVariableBinding
for the enum constant - annotation type - an
IAnnotationBinding
- array type - an
Object[]
whose elements are as per above (the language only allows single dimensional arrays in annotations)
- Returns:
- the default value of this annotation type member, or
null
if none or not applicable - Since:
- 3.2
-
getParameterAnnotations
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
ITypeBinding.getTypeAnnotations()
.- Parameters:
paramIndex
- the index of the parameter of interest- Returns:
- the resolved declaration annotations of the
paramIndex
th parameter, or an empty list if there are none - Throws:
ArrayIndexOutOfBoundsException
- ifparamIndex
is not a valid index- Since:
- 3.2
-
getParameterTypes
ITypeBinding[] getParameterTypes()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 theSingleVariableDeclaration
for the vararg parameter is always for the type as written; i.e., the type binding forFoo
.Note: The result does not include synthetic parameters introduced by inner class emulation. Explicit receiver parameters are also not included.
- Returns:
- a (possibly empty) list of type bindings for the formal parameters of this method or constructor
-
getDeclaredReceiverType
ITypeBinding getDeclaredReceiverType()Returns the type of this method's receiver ornull
if there is no receiver declared explicitly.- Returns:
- the type of this method's receiver or
null
if there is no receiver declared explicitly. - Since:
- 3.10
-
getReturnType
ITypeBinding getReturnType()Returns the binding for the return type of this method. Returns the special primitivevoid
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:
For a constructor, the returned binding does not include type annotations.
IAnnotationBinding[] annots = getReturnType().getTypeAnnotations()
- Returns:
- the binding for the return type of this method, or the
void
return type for constructors
-
getExceptionTypes
ITypeBinding[] getExceptionTypes()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.- Returns:
- a list of type bindings for exceptions thrown by this method or constructor
-
getTypeParameters
ITypeBinding[] getTypeParameters()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).
- Returns:
- the list of binding for the type variables for the type parameters of this method, or otherwise the empty list
- Since:
- 3.1
- See Also:
-
isAnnotationMember
boolean isAnnotationMember()Returns whether this is the binding for an annotation type member.- Returns:
true
iff this is the binding for an annotation type member andfalse
otherwise- Since:
- 3.2
-
isGenericMethod
boolean isGenericMethod()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 togetTypeParameters().length > 0)
.Note that
isGenericMethod()
,isParameterizedMethod()
, andisRawMethod()
are mutually exclusive.- Returns:
true
if this method binding represents a declaration of a generic method, andfalse
otherwise- Since:
- 3.1
- See Also:
-
isParameterizedMethod
boolean isParameterizedMethod()Returns whether this method binding represents an instance of a generic method corresponding to a parameterized method reference.Note that
isGenericMethod()
,isParameterizedMethod()
, andisRawMethod()
are mutually exclusive.- Returns:
true
if this method binding represents a an instance of a generic method corresponding to a parameterized method reference, andfalse
otherwise- Since:
- 3.1
- See Also:
-
getTypeArguments
ITypeBinding[] getTypeArguments()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.
- Returns:
- the list of type bindings for the type arguments used to instantiate the corrresponding generic method, or otherwise the empty list
- Since:
- 3.1
- See Also:
-
getMethodDeclaration
IMethodBinding getMethodDeclaration()Returns the binding for the method declaration corresponding to this method binding.- For parameterized methods (
isParameterizedMethod()
) and raw methods (isRawMethod()
), this method returns the binding for the corresponding generic method. - For references to the method
Object.getClass()
, returns the binding for the method declaration which is declared to returnClass<?>
orClass<? extends Object>
. In the reference binding, the return type becomesClass<? extends
R>
, where R is the erasure of the static type of the receiver of the method invocation. - For references to a signature polymorphic method from class MethodHandle, returns the declaration of the method. In the reference binding, the parameter types and the return type are determined by the concrete invocation context.
- For lambda methods, returns the (possibly parameterized) single abstract method of the functional type.
- For other method bindings, this returns the same binding.
- Returns:
- the method binding
- Since:
- 3.1
- For parameterized methods (
-
isRawMethod
boolean isRawMethod()Returns whether this method binding represents an instance of a generic method corresponding to a raw method reference.Note that
isGenericMethod()
,isParameterizedMethod()
, andisRawMethod()
are mutually exclusive.- Returns:
true
if this method binding represents a an instance of a generic method corresponding to a raw method reference, andfalse
otherwise- Since:
- 3.1
- See Also:
-
isSubsignature
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).- Returns:
true
if this method's signature is a subsignature of the given method- Since:
- 3.1
-
isVarargs
boolean isVarargs()Returns whether this is a variable arity method.Note: Variable arity ("varargs") methods were added in JLS3.
- Returns:
true
if this is a variable arity method, andfalse
otherwise- Since:
- 3.1
-
overrides
Returns whether this method overrides the given method, as specified in section 8.4.8.1 of The Java Language Specification, Third Edition (JLS3).- Parameters:
method
- the method that is possibly overriden- Returns:
true
if this method overrides the given method, andfalse
otherwise- Since:
- 3.1
-
getSyntheticOuterLocals
IVariableBinding[] getSyntheticOuterLocals()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.- Returns:
- 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
-
isSyntheticRecordMethod
boolean isSyntheticRecordMethod()Returns if this is a compiler generated equals(), hashCode(), toString() or any accessor method of a Record or not. Methods equals(), hashCode() and toString() and accessor methods of a Record do not have AccSynthetic flag set for them even if they are compiler generated methods. To differentiate between these above compiler generated methods and user created methods equals(), hashCode() and toString() or accessor methods in a Record, this function can be used.- Returns:
true
for compiler generated equals(), hashCode() and toString() or any accessor method of a Record, else it returnsfalse
.- Since:
- 3.26
-
getParameterNames
String[] getParameterNames()Returns the ordered list of parameter names for this method. This is useful when there is no corresponding method element associated with the binding.- Returns:
- an array of the parameter names (in order)
- Since:
- 3.31
-