public interface ITypeBinding extends IBinding
void
)
- primitive types are referenced but not explicitly declarednull
This interface is not intended to be implemented by clients.
Modifier and Type | Method and Description |
---|---|
ITypeBinding |
createArrayType(int dimension)
Answer an array type binding using the receiver and the given dimension.
|
java.lang.String |
getBinaryName()
Returns the binary name of this type binding.
|
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.
|
IFunctionBinding[] |
getDeclaredMethods()
Returns a list of method bindings representing all the methods and
constructors declared for this class, interface, enum, or annotation
type.
|
int |
getDeclaredModifiers()
Returns the declared modifiers for this class or interface binding
as specified in the original source declaration of the class or
interface.
|
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.
|
IFunctionBinding |
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.
|
int |
getModifiers()
Returns the compiled modifiers for this class, interface, enum,
or annotation type binding.
|
java.lang.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.
|
java.lang.String |
getQualifiedName()
Returns the fully qualified name of the type represented by this
binding if it has one.
|
ITypeBinding |
getSuperclass()
Returns the type binding for the superclass of the type represented
by this class binding.
|
ITypeBinding |
getTypeDeclaration()
Returns the binding for the type declaration corresponding to this type
binding.
|
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.
|
boolean |
isCastCompatible(ITypeBinding type)
Returns whether this type is cast compatible with the given type.
|
boolean |
isClass()
Returns whether this type binding represents a class type or a recovered binding.
|
boolean |
isCompilationUnit() |
boolean |
isFromSource()
Returns whether this type binding originated in source code.
|
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 |
isPrimitive()
Returns whether this type binding represents a primitive type.
|
boolean |
isSubTypeCompatible(ITypeBinding type)
Returns whether this type is subtype compatible with the given type.
|
boolean |
isTopLevel()
Returns whether this type binding represents a top-level class,
interface, enum, or annotation type.
|
equals, getJavaElement, getKey, getKind, isDeprecated, isEqualTo, isRecovered, 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:
- java.lang.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 getComponentType()
null
if this is not an array type binding. The component
type of an array might be an array type.
This is subject to change before 3.2 release.
null
if this is
not an array typeIVariableBinding[] 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 unresolvable 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.
IFunctionBinding[] 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 unresolvable types may not be included.
The resulting bindings are in no particular order.
int getDeclaredModifiers()
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, recovered binding have no declaring class.
null
if noneIFunctionBinding 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, capture bindings, and recovered binding have no declaring method.
null
if noneint 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 is never itself an array type.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.#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.int getModifiers()
getDeclaredModifiers
method
should be used if the original modifiers are needed.
Returns 0 if this type does not represent a class, an interface, an enum, an annotation
type or a recovered type.getModifiers
in interface IBinding
getDeclaredModifiers()
java.lang.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"
.getName
in interface IBinding
getQualifiedName()
IPackageBinding getPackage()
The package of a recovered type reference binding is the package of the enclosing type.
null
if this type
binding represents a primitive type, an array type, the null type,
a type variable, a capture binding.java.lang.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.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, or a capture binding then
null
is returned.
null
if noneAST.resolveWellKnownType(String)
ITypeBinding getTypeDeclaration()
For parameterized types (#isParameterizedType()
)
and most raw types (#isRawType()
), this method returns the binding
for the corresponding generic type.
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 returns the same binding.
boolean 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 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 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, and capture bindings
whose information came from a pre-compiled binary class file.true
if the type is in source code,
and false
otherwiseboolean 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. Note that anonymous classes are a subspecies of local classes.
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 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 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 isCompilationUnit()
Copyright (c) IBM Corp. and others 2000, 2016. All Rights Reserved.