public final class TypeDescriptor extends Object
Modifier and Type | Field and Description |
---|---|
static TypeDescriptor |
ANY
Represents all types.
|
static TypeDescriptor |
ARRAY
Represents an array with any content type.
|
static TypeDescriptor |
BOOLEAN
Represents a boolean type.
|
static TypeDescriptor |
DATE
Type descriptor for date.
|
static TypeDescriptor |
DURATION
Type descriptor for duration.
|
static TypeDescriptor |
EXCEPTION
Type descriptor for exception.
|
static TypeDescriptor |
EXECUTABLE
Represents an executable type returning any type and accepting any number of parameters of
any type.
|
static TypeDescriptor |
EXECUTABLE_ANY
Represents a raw executable type.
|
static TypeDescriptor |
HASH
Represents a hash map with any key type and any value type.
|
static TypeDescriptor |
HOST_OBJECT
Represents a host object.
|
static TypeDescriptor |
INSTANTIABLE
Represents an instantiable type accepting any number of parameters of any type.
|
static TypeDescriptor |
INSTANTIABLE_ANY
Represents a raw instantiable type.
|
static TypeDescriptor |
ITERABLE
Represents an iterable with any content type.
|
static TypeDescriptor |
ITERATOR
Represents an iterator with any content type.
|
static TypeDescriptor |
META_OBJECT
Type descriptor for metaobjects.
|
static TypeDescriptor |
NATIVE_POINTER
Represents a native pointer.
|
static TypeDescriptor |
NULL
The NULL type represents a type of null or undefined value.
|
static TypeDescriptor |
NUMBER
Represents a numeric type.
|
static TypeDescriptor |
OBJECT
Represents an object created by a guest language.
|
static TypeDescriptor |
STRING
Represents a string type.
|
static TypeDescriptor |
TIME
Type descriptor for time.
|
static TypeDescriptor |
TIME_ZONE
Type descriptor for time zone.
|
Modifier and Type | Method and Description |
---|---|
static TypeDescriptor |
array(TypeDescriptor componentType)
Creates a new array type with given component type.
|
boolean |
equals(Object obj) |
static TypeDescriptor |
executable(TypeDescriptor returnType,
boolean vararg,
TypeDescriptor... parameterTypes)
Creates a new executable type with a given return type and parameter types.
|
static TypeDescriptor |
executable(TypeDescriptor returnType,
TypeDescriptor... parameterTypes)
Creates a new executable type with a given return type and parameter types.
|
static TypeDescriptor |
forValue(Value value)
Creates a type for given
Value . |
static TypeDescriptor |
hash(TypeDescriptor keyType,
TypeDescriptor valueType)
Creates a new hash map type with given key type and value type.
|
int |
hashCode() |
static TypeDescriptor |
instantiable(TypeDescriptor instanceType,
boolean vararg,
TypeDescriptor... parameterTypes)
Creates a new instantiable type with a given parameter types.
|
static TypeDescriptor |
intersection(TypeDescriptor... types)
Creates a new intersection type.
|
boolean |
isAssignable(TypeDescriptor fromType)
Checks if the given type is assignable to this type.
|
boolean |
isIntersection()
Checks if this
TypeDescriptor represent an intersection type. |
boolean |
isUnion()
Checks if this
TypeDescriptor represent an union type. |
static TypeDescriptor |
iterable(TypeDescriptor componentType)
Creates a new iterable type with given component type.
|
static TypeDescriptor |
iterator(TypeDescriptor componentType)
Creates a new iterator type with given component type.
|
TypeDescriptor |
subtract(TypeDescriptor toRemove)
Creates a new type by removing the given type from this type.
|
String |
toString() |
static TypeDescriptor |
union(TypeDescriptor... types)
Creates a new union type.
|
public static final TypeDescriptor NULL
Value.isNull().
public static final TypeDescriptor BOOLEAN
Value.isBoolean().
public static final TypeDescriptor NUMBER
Value.isNumber().
public static final TypeDescriptor STRING
Value.isString().
public static final TypeDescriptor ITERABLE
public static final TypeDescriptor ITERATOR
public static final TypeDescriptor HASH
public static final TypeDescriptor OBJECT
Value.hasMembers().
public static final TypeDescriptor ARRAY
TypeDescriptor.isAssignable(org.graalvm.polyglot.tck.TypeDescriptor).
,
Value.hasArrayElements().
public static final TypeDescriptor HOST_OBJECT
Value.isHostObject().
public static final TypeDescriptor NATIVE_POINTER
Value.isNativePointer().
public static final TypeDescriptor DATE
Value.isDate().
public static final TypeDescriptor TIME
Value.isTime().
public static final TypeDescriptor TIME_ZONE
Value.isTimeZone().
public static final TypeDescriptor DURATION
Value.isDuration().
public static final TypeDescriptor META_OBJECT
Value.isMetaObject().
public static final TypeDescriptor EXCEPTION
Value.isException()
public static final TypeDescriptor EXECUTABLE
TypeDescriptor.executable(org.graalvm.polyglot.tck.TypeDescriptor, org.graalvm.polyglot.tck.TypeDescriptor...)
. This type can be used for creating value constructors but should not be used for specifying
expressions or statements parameter types as no other executable is assignable to it.
The JavaScript sample usage for no argument function constructor:
@Override
publicCollection
<? extendsSnippet
> createValueConstructors(Context
context) { returnCollections
.singleton(Snippet
.newBuilder( "function", context.eval("js", "(function(){ return function(){}})"),TypeDescriptor
.EXECUTABLE).build()); }
Value.canExecute().
public static final TypeDescriptor EXECUTABLE_ANY
TypeDescriptor.executable(org.graalvm.polyglot.tck.TypeDescriptor, org.graalvm.polyglot.tck.TypeDescriptor...)
. This type can be used for specifying expressions or statements parameter types when the
passed executable is actually not invoked.
The JavaScript sample usage for plus operator:
@Override
publicCollection
<? extendsSnippet
> createExpressions(Context
context) { finalCollection
<Snippet
> expressions = newArrayList
<>(); finalTypeDescriptor
numeric =TypeDescriptor
.union(TypeDescriptor
.NUMBER,TypeDescriptor
.BOOLEAN); finalTypeDescriptor
nonNumeric =TypeDescriptor
.union(TypeDescriptor
.STRING,TypeDescriptor
.OBJECT,TypeDescriptor
.ARRAY,TypeDescriptor
.EXECUTABLE_ANY);Snippet
.Builder builder =Snippet
.newBuilder( "+", context.eval( "js", "(function (a, b){ return a + b;})"),TypeDescriptor
.NUMBER). parameterTypes(numeric, numeric); expressions.add(builder.build()); builder =Snippet
.newBuilder( "+", context.eval( "js", "(function (a, b){ return a + b;})"),TypeDescriptor
.STRING). parameterTypes(nonNumeric,TypeDescriptor
.ANY); expressions.add(builder.build()); builder =Snippet
.newBuilder( "+", context.eval( "js", "(function (a, b){ return a + b;})"),TypeDescriptor
.STRING). parameterTypes(TypeDescriptor
.ANY, nonNumeric); expressions.add(builder.build()); return expressions; }
TypeDescriptor.EXECUTABLE
public static final TypeDescriptor INSTANTIABLE
TypeDescriptor.instantiable(org.graalvm.polyglot.tck.TypeDescriptor, boolean, org.graalvm.polyglot.tck.TypeDescriptor...)
. This type can be used for creating value constructors but should not be used for specifying
expressions or statements parameter types as no other instantiable is assignable to it.Value.canInstantiate().
public static final TypeDescriptor INSTANTIABLE_ANY
TypeDescriptor.instantiable(org.graalvm.polyglot.tck.TypeDescriptor, boolean, org.graalvm.polyglot.tck.TypeDescriptor...)
. This type can be used for specifying expressions or statements parameter types when the
passed instantiable is actually not invoked.TypeDescriptor.INSTANTIABLE
public static final TypeDescriptor ANY
public boolean isAssignable(TypeDescriptor fromType)
fromType
- the type to assignpublic boolean isUnion()
TypeDescriptor
represent an union type.public boolean isIntersection()
TypeDescriptor
represent an intersection type.public static TypeDescriptor union(TypeDescriptor... types)
types
- the types to include in the unionpublic static TypeDescriptor intersection(TypeDescriptor... types)
TypeDescriptor.ANY
and itself. The
no type is created as an empty intersection, TypeDescriptor.intersection()
.types
- the types to include in the intersectionpublic TypeDescriptor subtract(TypeDescriptor toRemove)
toRemove
type represent the same types then no type is
returned.union
type the toRemove
type is
removed from the union type. When the toRemove
type is also a union type then all
types in the toRemove
union type are removed.intersection
type the
toRemove
type is removed from the intersection type. When the toRemove
type
is also an intersection type then all types in the toRemove
intersection type are
removed.toRemove
types are parameterized types (array, iterable, iterator,
hash) of the same kind the type parameter types are subtracted applying the same rules.Examples:
toRemove
- the type to remove.public static TypeDescriptor array(TypeDescriptor componentType)
componentType
- the required component type.public static TypeDescriptor iterable(TypeDescriptor componentType)
componentType
- the required component type.public static TypeDescriptor iterator(TypeDescriptor componentType)
componentType
- the required component type.public static TypeDescriptor hash(TypeDescriptor keyType, TypeDescriptor valueType)
keyType
- the required key type.valueType
- the required value type.public static TypeDescriptor executable(TypeDescriptor returnType, TypeDescriptor... parameterTypes)
returnType
- the required return type, use ANY as any typeparameterTypes
- the required parameter typespublic static TypeDescriptor executable(TypeDescriptor returnType, boolean vararg, TypeDescriptor... parameterTypes)
returnType
- the required return type, use ANY as any typevararg
- the executable has variable length arguments or ignores additional parameters.
For executables created by the
LanguageProvider.createValueConstructors(org.graalvm.polyglot.Context)
set
to false
if the language neither ignores extra parameters nor the
executable has variable arguments length.parameterTypes
- the required parameter typespublic static TypeDescriptor instantiable(TypeDescriptor instanceType, boolean vararg, TypeDescriptor... parameterTypes)
instanceType
- the type of an instance, use ANY as any typevararg
- the instantiable has variable length arguments or ignores additional
parameters. For instantiables created by the
LanguageProvider.createValueConstructors(org.graalvm.polyglot.Context)
set
to false
if the language neither ignores extra parameters nor the
instantiable has variable arguments length.parameterTypes
- the required parameter typespublic static TypeDescriptor forValue(Value value)
Value
.value
- the value to create TypeDescriptor
for