public interface ITypeBinding extends IBinding
void
)
- primitive types are referenced but not explicitly declarednull
getDeclaredTypes()
ANNOTATION, MEMBER_VALUE_PAIR, METHOD, MODULE, PACKAGE, TYPE, VARIABLE
Modifier and Type | Method and Description |
---|---|
ITypeBinding |
createArrayType(int dimension)
Answer an array type binding using the receiver and the given dimension.
|
String |
getBinaryName()
Returns the binary name of this type binding.
|
ITypeBinding |
getBound()
Returns the bound of this wildcard type if it has one.
|
ITypeBinding |
getComponentType()
Returns the binding representing the component type of this array type,
or
null if this is not an array type binding. |
IVariableBinding[] |
getDeclaredFields()
Returns a list of bindings representing all the fields declared
as members of this class, interface, or enum type.
|
IMethodBinding[] |
getDeclaredMethods()
Returns a list of method bindings representing all the methods and
constructors declared for this class, interface, enum, or annotation
type.
|
int |
getDeclaredModifiers()
Deprecated.
Use
getModifiers() instead.
This method was never implemented properly and historically has simply
delegated to the method getModifiers . Clients should call
getModifiers method directly. |
ITypeBinding[] |
getDeclaredTypes()
Returns a list of type bindings representing all the types declared as
members of this class, interface, or enum type.
|
ITypeBinding |
getDeclaringClass()
Returns the type binding representing the class, interface, or enum
that declares this binding.
|
IBinding |
getDeclaringMember()
If this type binding represents a local type, possibly an anonymous class, then:
If the local type is declared in the body of a method,
answers the binding of that declaring method.
|
IMethodBinding |
getDeclaringMethod()
Returns the method binding representing the method that declares this binding
of a local type or type variable.
|
int |
getDimensions()
Returns the dimensionality of this array type, or
0 if this
is not an array type binding. |
ITypeBinding |
getElementType()
Returns the binding representing the element type of this array type,
or
null if this is not an array type binding. |
ITypeBinding |
getErasure()
Returns the erasure of this type binding.
|
IMethodBinding |
getFunctionalInterfaceMethod()
Returns the single abstract method that constitutes the single function
contract (aside from any redeclarations of methods of
java.lang.Object )
of the receiver interface type or null if there is no such contract or if the receiver
is not an interface. |
ITypeBinding |
getGenericTypeOfWildcardType()
Returns the generic type associated with this wildcard type, if it has one.
|
ITypeBinding[] |
getInterfaces()
Returns a list of type bindings representing the direct superinterfaces
of the class, interface, or enum type represented by this type binding.
|
int |
getModifiers()
Returns the compiled modifiers for this class, interface, enum,
or annotation type binding.
|
default IModuleBinding |
getModule()
Returns the binding of the module associated with the package in which
this type is declared.
|
String |
getName()
Returns the unqualified name of the type represented by this binding
if it has one.
|
IPackageBinding |
getPackage()
Returns the binding for the package in which this type is declared.
|
String |
getQualifiedName()
Returns the fully qualified name of the type represented by this
binding if it has one.
|
int |
getRank()
Returns the rank associated with this wildcard type.
|
ITypeBinding |
getSuperclass()
Returns the type binding for the superclass of the type represented
by this class binding.
|
IAnnotationBinding[] |
getTypeAnnotations()
Returns the type annotations that this type reference is annotated with.
|
ITypeBinding[] |
getTypeArguments()
Returns the type arguments of this generic type instance, or the
empty list for other type bindings.
|
ITypeBinding[] |
getTypeBounds()
Returns the upper type bounds of this type variable, wildcard, capture, or intersectionType.
|
ITypeBinding |
getTypeDeclaration()
Returns the binding for the type declaration corresponding to this type
binding.
|
ITypeBinding[] |
getTypeParameters()
Returns the type parameters of this class or interface type binding.
|
ITypeBinding |
getWildcard()
Returns the corresponding wildcard binding of this capture binding.
|
boolean |
isAnnotation()
Returns whether this type binding represents an annotation type.
|
boolean |
isAnonymous()
Returns whether this type binding represents an anonymous class.
|
boolean |
isArray()
Returns whether this type binding represents an array type.
|
boolean |
isAssignmentCompatible(ITypeBinding variableType)
Returns whether an expression of this type can be assigned to a variable
of the given type, as specified in section 5.2 of The Java Language
Specification, Third Edition (JLS3).
|
boolean |
isCapture()
Returns whether this type binding represents a capture binding.
|
boolean |
isCastCompatible(ITypeBinding type)
Returns whether this type is cast compatible with the given type,
as specified in section 5.5 of The Java Language
Specification, Third Edition (JLS3).
|
boolean |
isClass()
Returns whether this type binding represents a class type or a recovered binding.
|
boolean |
isEnum()
Returns whether this type binding represents an enum type.
|
boolean |
isFromSource()
Returns whether this type binding originated in source code.
|
boolean |
isGenericType()
Returns whether this type binding represents a declaration of
a generic class or interface.
|
boolean |
isInterface()
Returns whether this type binding represents an interface type.
|
boolean |
isIntersectionType()
Returns whether this type binding represents an intersection binding.
|
boolean |
isLocal()
Returns whether this type binding represents a local class.
|
boolean |
isMember()
Returns whether this type binding represents a member class or
interface.
|
boolean |
isNested()
Returns whether this type binding represents a nested class, interface,
enum, or annotation type.
|
boolean |
isNullType()
Returns whether this type binding represents the null type.
|
boolean |
isParameterizedType()
Returns whether this type binding represents an instance of
a generic type corresponding to a parameterized type reference.
|
boolean |
isPrimitive()
Returns whether this type binding represents a primitive type.
|
boolean |
isRawType()
Returns whether this type binding represents an instance of
a generic type corresponding to a raw type reference.
|
boolean |
isSubTypeCompatible(ITypeBinding type)
Returns whether this type is subtype compatible with the given type,
as specified in section 4.10 of The Java Language
Specification, Third Edition (JLS3).
|
boolean |
isTopLevel()
Returns whether this type binding represents a top-level class,
interface, enum, or annotation type.
|
boolean |
isTypeVariable()
Returns whether this type binding represents a type variable.
|
boolean |
isUpperbound()
Returns whether this wildcard type is an upper bound
("extends") as opposed to a lower bound ("super").
|
boolean |
isWildcardType()
Returns whether this type binding represents a wildcard type.
|
equals, getAnnotations, getJavaElement, getKey, getKind, isDeprecated, isEqualTo, isRecovered, isSynthetic, toString
ITypeBinding createArrayType(int dimension)
If the receiver is an array binding, then the resulting dimension is the given dimension plus the dimension of the receiver. Otherwise the resulting dimension is the given dimension.
dimension
- the given dimensionIllegalArgumentException:
- String getBinaryName()
Note that in some cases, the binary name may be unavailable. This may happen, for example, for a local type declared in unreachable code.
null
if the binary name is unknownITypeBinding getBound()
null
if this is not a wildcard type.null
if noneisWildcardType()
,
isUpperbound()
,
getTypeBounds()
ITypeBinding getGenericTypeOfWildcardType()
null
if this is not a wildcard type.null
if noneisWildcardType()
int getRank()
-1
if this is not a wildcard type.-1
if noneisWildcardType()
ITypeBinding getComponentType()
null
if this is not an array type binding. The component
type of an array might be an array type (with one dimension less than
this array type).null
if this is
not an array typegetElementType()
IVariableBinding[] getDeclaredFields()
These include public, protected, default (package-private) access, and private fields declared by the class, but excludes inherited fields. Synthetic fields may or may not be included. Fields from binary types that reference unresolved types may not be included.
Returns an empty list if the class, interface, or enum declares no fields, and for other kinds of type bindings that do not directly have members.
The resulting bindings are in no particular order.
IMethodBinding[] getDeclaredMethods()
These include public, protected, default (package-private) access, and private methods Synthetic methods and constructors may or may not be included. Returns an empty list if the class, interface, or enum, type declares no methods or constructors, if the annotation type declares no members, or if this type binding represents some other kind of type binding. Methods from binary types that reference unresolved types may not be included.
The resulting bindings are in no particular order.
int getDeclaredModifiers()
getModifiers()
instead.
This method was never implemented properly and historically has simply
delegated to the method getModifiers
. Clients should call
getModifiers
method directly.getModifiers
method should be used if
the compiled modifiers are needed. Returns -1 if this type does not
represent a class or interface.Modifier
constantsgetModifiers()
,
Modifier
ITypeBinding[] getDeclaredTypes()
ITypeBinding getDeclaringClass()
The declaring class of a member class, interface, enum, annotation type is the class, interface, or enum type of which it is a member. The declaring class of a local class or interface (including anonymous classes) is the innermost class or interface containing the expression or statement in which this type is declared.
The declaring class of a type variable is the class in which the type
variable is declared if it is declared on a type. It returns
null
otherwise.
The declaring class of a capture binding is the innermost class or interface containing the expression or statement in which this capture is declared.
Array types, primitive types, the null type, top-level types, wildcard types, recovered binding have no declaring class.
null
if noneIMethodBinding getDeclaringMethod()
The declaring method of a local class or interface (including anonymous
classes) is the innermost method containing the expression or statement in
which this type is declared. Returns null
if the type
is declared in an initializer.
The declaring method of a type variable is the method in which the type
variable is declared if it is declared on a method. It
returns null
otherwise.
Array types, primitive types, the null type, top-level types, wildcard types, capture bindings, and recovered binding have no declaring method.
null
if noneIBinding getDeclaringMember()
If this type binding does not represent a local type, null
is returned.
default IModuleBinding getModule()
The module of a recovered type reference binding is the module
associated with the package returned by getPackage()
ie either
the module associated with the package of the enclosing type, or,
if the type name is the name of a well-known type, the module associated with the package of the matching
well-known type.
null
if this type binding represents a primitive type, an array type,
the null type, a type variable, a wildcard type or a capture binding.int getDimensions()
0
if this
is not an array type binding.0
if this is not an array typeITypeBinding getElementType()
null
if this is not an array type binding. The element
type of an array type is never itself an array type.
To get the type annotations on dimensions, clients should repeatedly
call getComponentType() and get the type annotations from there.null
if this is
not an array typeITypeBinding getErasure()
isParameterizedType()
)
- returns the binding for the corresponding generic type.isRawType()
)
- returns the binding for the corresponding generic type.isWildcardType()
)
- returns the binding for the upper bound if it has one and
java.lang.Object in other cases.isTypeVariable()
)
- returns the binding for the erasure of the leftmost bound
if it has bounds and java.lang.Object if it does not.isCapture()
)
- returns the binding for the erasure of the leftmost bound
if it has bounds and java.lang.Object if it does not.isArray()
) - returns an array type of
the same dimension (getDimensions()
) as this type
binding for which the element type is the erasure of the element type
(getElementType()
) of this type binding.IMethodBinding getFunctionalInterfaceMethod()
java.lang.Object
)
of the receiver interface type or null
if there is no such contract or if the receiver
is not an interface.
The returned method binding may be synthetic and its declaring type
may be a super interface type of this type binding.
null
if the receiver is not a functional interface typeITypeBinding[] getInterfaces()
If this type binding represents a class or enum type, the return value
is an array containing type bindings representing all interfaces
directly implemented by this class. The number and order of the interface
objects in the array corresponds to the number and order of the interface
names in the implements
clause of the original declaration
of this type.
If this type binding represents an interface, the array contains
type bindings representing all interfaces directly extended by this
interface. The number and order of the interface objects in the array
corresponds to the number and order of the interface names in the
extends
clause of the original declaration of this interface.
If the class or enum implements no interfaces, or the interface extends no interfaces, or if this type binding represents an array type, a primitive type, the null type, a type variable, an annotation type, a wildcard type, or a capture binding, this method returns an array of length 0.
int getModifiers()
getModifiers
in interface IBinding
Modifier
String getName()
"String"
or "Collection"
.
Note that the type parameters of a generic type are not included."int"
."String[]"
. Note that the component type is never an
an anonymous class."X"
."Collection<String>"
.
"Collection"
."? extends InputStream"
.
getName
in interface IBinding
getQualifiedName()
IPackageBinding getPackage()
The package of a recovered type reference binding is either the package of the enclosing type, or, if the type name is the name of a well-known type, the package of the matching well-known type.
null
if this type
binding represents a primitive type, an array type, the null type,
a type variable, a wildcard type, a capture binding.String getQualifiedName()
"java.lang.String"
or "java.util.Collection"
.
Note that the type parameters of a generic type are not included."java.io.ObjectInputStream.GetField"
.
If the binding is for a member type that corresponds to a particular instance
of a generic type arising from a parameterized type reference, the simple
name of the type is followed by the fully qualified names of the type arguments
(as computed by this method) surrounded by "<>" and separated by ",".
Example: "pkg.Outer.Inner<java.lang.String>"
.
"int"
."java.lang.String[]"
."X"
."java.util.Collection<java.lang.String>"
.
"java.util.Collection"
. Note that the
the type parameters are omitted."? extends java.io.InputStream"
.
getName()
ITypeBinding getSuperclass()
If this type binding represents any class other than the class
java.lang.Object
, then the type binding for the direct
superclass of this class is returned. If this type binding represents
the class java.lang.Object
, then null
is
returned.
Loops that ascend the class hierarchy need a suitable termination test.
Rather than test the superclass for null
, it is more
transparent to check whether the class is Object
, by
comparing whether the class binding is identical to
ast.resolveWellKnownType("java.lang.Object")
.
If this type binding represents an interface, an array type, a
primitive type, the null type, a type variable, an enum type,
an annotation type, a wildcard type, or a capture binding then
null
is returned.
null
if noneAST.resolveWellKnownType(String)
IAnnotationBinding[] getTypeAnnotations()
For example, the following three type references would produce three distinct type bindings for java.lang.String that share the same key:
getComponentType()
and get the type annotations from there.getTypeDeclaration()
,
IBinding.getKey()
ITypeBinding[] getTypeArguments()
Note that type arguments only occur on a type binding that represents
an instance of a generic type corresponding to a parameterized type
reference (e.g., Collection<String>
).
Do not confuse these with type parameters which only occur on the
type binding corresponding directly to the declaration of the
generic class or interface (e.g., Collection<T>
).
getTypeDeclaration()
,
isGenericType()
,
isParameterizedType()
,
isRawType()
ITypeBinding[] getTypeBounds()
Note that per construction, it can only contain one class or array type, at most, and then it is located in first position.
Also note that array type bound may only occur in the case of a capture
binding, e.g. capture-of ? extends Object[]
isTypeVariable()
,
isWildcardType()
,
isCapture()
,
isIntersectionType()
ITypeBinding getTypeDeclaration()
For parameterized types (isParameterizedType()
)
and most raw types (isRawType()
), this method returns the binding
for the corresponding generic type (isGenericType()
.
For raw member types (isRawType()
, isMember()
)
of a raw declaring class, the type declaration is a generic or a non-generic
type.
A different non-generic binding will be returned when one of the declaring types/methods was parameterized.
For other type bindings, this method returns the binding for the type declaration
corresponding to this type binding. In particular, for type bindings that
contain a type annotation
, this method returns the binding for the type
declaration, which does not contain the type annotations from the use site.
IBinding.isEqualTo(IBinding)
ITypeBinding[] getTypeParameters()
Note that type parameters only occur on the binding of the
declaring generic class or interface; e.g., Collection<T>
.
Type bindings corresponding to a raw or parameterized reference to a generic
type do not carry type parameters (they instead have non-empty type arguments
and non-trivial erasure).
isTypeVariable()
ITypeBinding getWildcard()
null
if this type bindings does not represent
a capture binding.null
otherwiseboolean isAnnotation()
Note that an annotation type is always an interface.
true
if this object represents an annotation type,
and false
otherwiseboolean isAnonymous()
An anonymous class is a subspecies of local class, and therefore mutually
exclusive with member types. Note that anonymous classes have no name
(getName
returns the empty string).
true
if this type binding is for an anonymous class,
and false
otherwiseboolean isArray()
true
if this type binding is for an array type,
and false
otherwisegetElementType()
,
getDimensions()
boolean isAssignmentCompatible(ITypeBinding variableType)
If the receiver or the argument is a recovered type, the answer is always false,
unless the two types are identical or the argument is java.lang.Object
.
variableType
- the type of a variable to check compatibility againsttrue
if an expression of this type can be assigned to a
variable of the given type, and false
otherwiseboolean isCapture()
Capture bindings result from capture conversion as specified in section 5.1.10 of The Java Language Specification, Third Edition (JLS3).
A capture binding may have upper bounds and a lower bound.
Upper bounds may be accessed using getTypeBounds()
,
the lower bound must be accessed indirectly through the associated
wildcard getWildcard()
when it is a lower bound wildcard.
Note that capture bindings are distinct from type variables
(even though they are often depicted as synthetic type
variables); as such, isTypeVariable()
answers
false
for capture bindings, and
isCapture()
answers false
for type variables.
true
if this type binding is a capture,
and false
otherwisegetTypeBounds()
,
getWildcard()
boolean isCastCompatible(ITypeBinding type)
NOTE: The cast compatibility check performs backwards.
When testing whether type B can be cast to type A, one would use:
A.isCastCompatible(B)
If the receiver or the argument is a recovered type, the answer is always false,
unless the two types are identical or the argument is java.lang.Object
.
type
- the type to check compatibility againsttrue
if this type is cast compatible with the
given type, and false
otherwiseboolean isClass()
true
if this object represents a class or a recovered binding,
and false
otherwiseboolean isEnum()
true
if this object represents an enum type,
and false
otherwiseboolean isFromSource()
false
for all primitive types, the null type,
array types, and for all classes, interfaces, enums, annotation
types, type variables, parameterized type references,
raw type references, wildcard types, and capture bindings
whose information came from a pre-compiled binary class file.true
if the type is in source code,
and false
otherwiseboolean isGenericType()
Note that type parameters only occur on the binding of the
declaring generic class or interface; e.g., Collection<T>
.
Type bindings corresponding to a raw or parameterized reference to a generic
type 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 isGenericType()
,
isParameterizedType()
,
and isRawType()
are mutually exclusive.
true
if this type binding represents a
declaration of a generic class or interface, and false
otherwisegetTypeParameters()
boolean isInterface()
Note that an interface can also be an annotation type.
true
if this object represents an interface,
and false
otherwiseboolean isIntersectionType()
Intersection types can be derived from type parameter bounds and cast expressions; they also arise in the processes of capture conversion and least upper bound computation as specified in section 4.9 of The Java Language Specification, Java SE 8 Edition (JLS8).
All the types in the intersection type can be accessed using
getTypeBounds()
. Wildcard types with more than one
bound will also be reported as intersection type. To check whether this
is a wildcard type, use isWildcardType()
.
true
if this type binding is an intersecting type,
and false
otherwisegetTypeBounds()
,
isWildcardType()
boolean isLocal()
A local class is any nested class or enum type not declared as a member of another class or interface. A local class is a subspecies of nested type, and mutually exclusive with member types. For anonymous classes, which are considered a subspecies of local classes, this method returns true.
Note: This deviates from JLS3 14.3, which states that anonymous types are not local types since they do not have a name. Also note that interfaces and annotation types cannot be local.
true
if this type binding is for a local class or
enum type, and false
otherwiseboolean isMember()
A member type is any type declared as a member of another type. A member type is a subspecies of nested type, and mutually exclusive with local types.
true
if this type binding is for a member class,
interface, enum, or annotation type, and false
otherwiseboolean isNested()
A nested type is any type whose declaration occurs within the body of another. The set of nested types is disjoint from the set of top-level types. Nested types further subdivide into member types, local types, and anonymous types.
true
if this type binding is for a nested class,
interface, enum, or annotation type, and false
otherwiseboolean isNullType()
The null type is the type of a NullLiteral
node.
true
if this type binding is for the null type,
and false
otherwiseboolean isParameterizedType()
For example, an AST type like
Collection<String>
typically resolves to a
type binding whose type argument is the type binding for the
class java.lang.String
and whose erasure is the type
binding for the generic type java.util.Collection
.
Note that isGenericType()
,
isParameterizedType()
,
and isRawType()
are mutually exclusive.
true
if this type binding represents a
an instance of a generic type corresponding to a parameterized
type reference, and false
otherwisegetTypeArguments()
,
getTypeDeclaration()
boolean isPrimitive()
There are nine predefined type bindings to represent the eight primitive
types and void
. These have the same names as the primitive
types that they represent, namely boolean, byte, char, short, int,
long, float, and double, and void.
true
if this type binding is for a primitive type,
and false
otherwiseboolean isRawType()
For example, an AST type like
Collection
typically resolves to a
type binding whose type argument is the type binding for
the class java.lang.Object
(the
default bound for the single type parameter of
java.util.Collection
) and whose erasure is the
type binding for the generic type
java.util.Collection
.
Note that isGenericType()
,
isParameterizedType()
,
and isRawType()
are mutually exclusive.
true
if this type binding represents a
an instance of a generic type corresponding to a raw
type reference, and false
otherwisegetTypeDeclaration()
,
getTypeArguments()
boolean isSubTypeCompatible(ITypeBinding type)
If the receiver or the argument is a recovered type, the answer is always false,
unless the two types are identical or the argument is java.lang.Object
.
type
- the type to check compatibility againsttrue
if this type is subtype compatible with the
given type, and false
otherwiseboolean isTopLevel()
A top-level type is any type whose declaration does not occur within the body of another type declaration. The set of top level types is disjoint from the set of nested types.
true
if this type binding is for a top-level class,
interface, enum, or annotation type, and false
otherwiseboolean isTypeVariable()
Note that type variables are distinct from capture bindings
(even though capture bindings are often depicted as synthetic
type variables); as such, isTypeVariable()
answers
false
for capture bindings, and
isCapture()
answers false
for type variables.
true
if this type binding is for a type variable,
and false
otherwisegetName()
,
getTypeBounds()
boolean isUpperbound()
true
if this wildcard type has a bound that is
an upper bound, and false
in all other casesisWildcardType()
,
getBound()
boolean isWildcardType()
For example, an AST type like
Collection<? extends Number>
typically resolves to a
parameterized type binding whose type argument is a wildcard type
with upper type bound java.lang.Number
.
true
if this object represents a wildcard type,
and false
otherwisegetBound()
,
isUpperbound()
Copyright (c) 2000, 2018 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.