public abstract class InteropLibrary extends Library
The interop API differentiates between the source and the target language. The source language is
the language that implements/exports the message implementations. The implementations map types
of the source language to the interop protocol as it is specified by the protocol. For example,
language values that represent arrays or array like structures should implement the messages for
array based access. This allows the target language to call the
protocol without knowledge of the concrete source language. The target language embeds the
interop protocol semantics as part of their existing language semantics. For example, language
operations that access array elements in the target language should call
array access messages for interop values.
The interop protocol only allows interop values to be used as receivers, return values or parameters of messages. Allowed Java types of interop values are:
TruffleObject: Any subclass of TruffleObject is interpreted depending on the
interop messages it exports. Truffle objects are expected but not required
to export interop library messages.
String and Character are interpreted as string
value.
Boolean is interpreted as boolean value.
Byte, Short, Integer, Long, Float and Double
are interpreted as number values.
The following type combinations are mutually exclusive and cannot return true for
the type check message of the same receiver value:
executable,
instantiable, pointers, have
members or array elements at the
same time.
If a date or time value has a timezone then it is called aware
, otherwise naive
An aware time and date has sufficient knowledge of applicable algorithmic and political time adjustments, such as time zone and daylight saving time information, to locate itself relative to other aware objects. An aware object is used to represent a specific moment in time that is not open to interpretation.
A naive time and date does not contain enough information to unambiguously locate itself relative to other date/time objects. Whether a naive object represents Coordinated Universal Time (UTC), local time, or time in some other timezone is purely up to the program, just like it is up to the program whether a particular number represents metres, miles, or mass. Naive objects are easy to understand and to work with, at the cost of ignoring some aspects of reality.
Interop messages throw checked exceptions to indicate error states. The
target language is supposed to always catch those exceptions and translate them into guest
language errors of the target language. Interop message contracts are verified only if assertions
(-ea) are enabled.
Reference documentation of Truffle Libraries.Node.Child, Node.Children| Modifier | Constructor and Description |
|---|---|
protected |
InteropLibrary() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
asBoolean(Object receiver)
Returns the Java boolean value if the receiver represents a
boolean like value. |
byte |
asByte(Object receiver)
Returns the receiver value as Java byte primitive if the number fits without loss of
precision.
|
LocalDate |
asDate(Object receiver)
Returns the receiver as date if this object represents a
date. |
double |
asDouble(Object receiver)
Returns the receiver value as Java double primitive if the number fits without loss of
precision.
|
Duration |
asDuration(Object receiver)
Returns the receiver as duration if this object represents a
duration. |
float |
asFloat(Object receiver)
Returns the receiver value as Java float primitive if the number fits without loss of
precision.
|
Instant |
asInstant(Object receiver)
Returns the receiver as instant if this object represents an
instant. |
int |
asInt(Object receiver)
Returns the receiver value as Java int primitive if the number fits without loss of
precision.
|
long |
asLong(Object receiver)
Returns the receiver value as Java long primitive if the number fits without loss of
precision.
|
long |
asPointer(Object receiver)
Returns the pointer value as long value if the receiver represents a pointer like value.
|
protected boolean |
assertAdopted()
Utility for libraries to require adoption before cached versions of nodes can be executed.
|
short |
asShort(Object receiver)
Returns the receiver value as Java short primitive if the number fits without loss of
precision.
|
String |
asString(Object receiver)
Returns the Java boolean value if the receiver represents a
boolean like value. |
LocalTime |
asTime(Object receiver)
Returns the receiver as time if this object represents a
time. |
ZoneId |
asTimeZone(Object receiver)
Returns the receiver as timestamp if this object represents a
timezone. |
Object |
execute(Object receiver,
Object... arguments)
Executes an executable value with the given arguments.
|
boolean |
fitsInByte(Object receiver)
Returns
true if the receiver represents a number and its value fits
in a Java byte primitive without loss of precision, else false. |
boolean |
fitsInDouble(Object receiver)
Returns
true if the receiver represents a number and its value fits
in a Java double primitive without loss of precision, else false. |
boolean |
fitsInFloat(Object receiver)
Returns
true if the receiver represents a number and its value fits
in a Java float primitive without loss of precision, else false. |
boolean |
fitsInInt(Object receiver)
Returns
true if the receiver represents a number and its value fits
in a Java int primitive without loss of precision, else false. |
boolean |
fitsInLong(Object receiver)
Returns
true if the receiver represents a number and its value fits
in a Java long primitive without loss of precision, else false. |
boolean |
fitsInShort(Object receiver)
Returns
true if the receiver represents a number and its value fits
in a Java short primitive without loss of precision, else false. |
long |
getArraySize(Object receiver)
Returns the array size of the receiver.
|
static LibraryFactory<InteropLibrary> |
getFactory()
Returns the library factory for the interop library.
|
Object |
getMembers(Object receiver)
Short-cut for
getMembers(receiver, false). |
Object |
getMembers(Object receiver,
boolean includeInternal)
Returns an array of member name strings.
|
boolean |
hasArrayElements(Object receiver)
Returns
true if the receiver may have array elements. |
boolean |
hasMemberReadSideEffects(Object receiver,
String member)
Returns
true if reading a member may cause a side-effect. |
boolean |
hasMembers(Object receiver)
Returns
true if the receiver may have members. |
boolean |
hasMemberWriteSideEffects(Object receiver,
String member)
Returns
true if writing a member may cause a side-effect, besides the write
operation of the member. |
Object |
instantiate(Object receiver,
Object... arguments)
Instantiates the receiver value with the given arguments.
|
Object |
invokeMember(Object receiver,
String member,
Object... arguments)
Invokes a member for a given receiver and arguments.
|
boolean |
isArrayElementExisting(Object receiver,
long index)
Returns true if the array element is existing.
|
boolean |
isArrayElementInsertable(Object receiver,
long index)
Returns
true if a given array element index is not existing and
insertable. |
boolean |
isArrayElementModifiable(Object receiver,
long index)
Returns
true if a given array element index is existing and
writable. |
boolean |
isArrayElementReadable(Object receiver,
long index)
Returns
true if a given array element is readable. |
boolean |
isArrayElementRemovable(Object receiver,
long index)
Returns
true if a given array element index is existing and
removable. |
boolean |
isArrayElementWritable(Object receiver,
long index)
Returns true if the array element is
modifiable or insertable. |
boolean |
isBoolean(Object receiver)
Returns
true if the receiver represents a boolean like value, else
false. |
boolean |
isDate(Object receiver)
Returns
true if this object represents a date, else false. |
boolean |
isDuration(Object receiver)
Returns
true if this object represents a duration, else false. |
boolean |
isExecutable(Object receiver)
Returns
true if the receiver represents an executable value, else
false. |
boolean |
isInstant(Object receiver)
Returns
true if the receiver represents an instant. |
boolean |
isInstantiable(Object receiver)
Returns
true if the receiver represents an instantiable value, else
false. |
boolean |
isMemberExisting(Object receiver,
String member)
Returns true if the member is existing.
|
boolean |
isMemberInsertable(Object receiver,
String member)
Returns
true if a given member is not existing and
writable. |
boolean |
isMemberInternal(Object receiver,
String member)
Returns true if a member is internal.
|
boolean |
isMemberInvocable(Object receiver,
String member)
Returns
true if a given member is invocable. |
boolean |
isMemberModifiable(Object receiver,
String member)
Returns
true if a given member is existing and
writable. |
boolean |
isMemberReadable(Object receiver,
String member)
Returns
true if a given member is readable. |
boolean |
isMemberRemovable(Object receiver,
String member)
Returns
true if a given member is existing and removable. |
boolean |
isMemberWritable(Object receiver,
String member)
Returns true if the member is
modifiable or
insertable. |
boolean |
isNull(Object receiver)
Returns
true if the receiver represents a null like value, else
false. |
boolean |
isNumber(Object receiver)
Returns
true if the receiver represents a number value, else
false. |
boolean |
isPointer(Object receiver)
Returns
true if the receiver value represents a native pointer. |
boolean |
isString(Object receiver)
Returns
true if the receiver represents a string value, else
false. |
boolean |
isTime(Object receiver)
Returns
true if this object represents a time, else false. |
boolean |
isTimeZone(Object receiver)
Returns
true if this object represents a timezone, else false. |
Object |
readArrayElement(Object receiver,
long index)
Reads the value of an array element by index.
|
Object |
readMember(Object receiver,
String member)
Reads the value of a given member.
|
void |
removeArrayElement(Object receiver,
long index)
Remove an array element from the receiver object.
|
void |
removeMember(Object receiver,
String member)
Removes a member from the receiver object.
|
void |
toNative(Object receiver)
Transforms a
receiver to a value that represents a raw native pointer. |
void |
writeArrayElement(Object receiver,
long index,
Object value)
Writes the value of an array element by index.
|
void |
writeMember(Object receiver,
String member,
Object value)
Writes the value of a given member.
|
accept, adoptChildren, atomic, atomic, copy, deepCopy, getChildren, getCost, getDebugProperties, getDescription, getEncapsulatingSourceSection, getLock, getParent, getRootNode, getSourceSection, insert, insert, isAdoptable, isSafelyReplaceableBy, lookupContextReference, lookupLanguageReference, notifyInserted, onReplace, replace, replace, reportPolymorphicSpecialize, toStringpublic boolean isNull(Object receiver)
true if the receiver represents a null like value, else
false. Most object oriented languages have one or many values representing null
values. Invoking this message does not cause any observable side-effects.public boolean isBoolean(Object receiver)
true if the receiver represents a boolean like value, else
false. Invoking this message does not cause any observable side-effects.InteropLibrary.asBoolean(Object)public boolean asBoolean(Object receiver) throws UnsupportedMessageException
boolean like value.UnsupportedMessageException - if and only if InteropLibrary.isBoolean(Object) returns
false for the same receiver.InteropLibrary.isBoolean(Object)public boolean isExecutable(Object receiver)
true if the receiver represents an executable value, else
false. Functions, methods or closures are common examples of executable values.
Invoking this message does not cause any observable side-effects. Note that receiver values
which are executable might also be
instantiable.InteropLibrary.execute(Object, Object...)public Object execute(Object receiver, Object... arguments) throws UnsupportedTypeException, ArityException, UnsupportedMessageException
UnsupportedTypeException - if one of the arguments is not compatible to the executable
signatureArityException - if the number of expected arguments does not match the number of
actual arguments.UnsupportedMessageException - if and only if InteropLibrary.isExecutable(Object) returns
false for the same receiver.InteropLibrary.isExecutable(Object)public boolean isInstantiable(Object receiver)
true if the receiver represents an instantiable value, else
false. Contructors or meta-objects are typical examples of instantiable values.
Invoking this message does not cause any observable side-effects. Note that receiver values
which are executable might also be
instantiable.InteropLibrary.instantiate(Object, Object...)public Object instantiate(Object receiver, Object... arguments) throws UnsupportedTypeException, ArityException, UnsupportedMessageException
UnsupportedTypeException - if one of the arguments is not compatible to the executable
signatureArityException - if the number of expected arguments does not match the number of
actual arguments.UnsupportedMessageException - if and only if InteropLibrary.isInstantiable(Object) returns
false for the same receiver.InteropLibrary.isExecutable(Object)public boolean isString(Object receiver)
true if the receiver represents a string value, else
false. Invoking this message does not cause any observable side-effects.InteropLibrary.asString(Object)public String asString(Object receiver) throws UnsupportedMessageException
boolean like value.UnsupportedMessageException - if and only if InteropLibrary.isString(Object) returns
false for the same receiver.InteropLibrary.isBoolean(Object)public boolean isNumber(Object receiver)
true if the receiver represents a number value, else
false. Invoking this message does not cause any observable side-effects.InteropLibrary.fitsInByte(Object),
InteropLibrary.fitsInShort(Object),
InteropLibrary.fitsInInt(Object),
InteropLibrary.fitsInLong(Object),
InteropLibrary.fitsInFloat(Object),
InteropLibrary.fitsInDouble(Object),
InteropLibrary.asByte(Object),
InteropLibrary.asShort(Object),
InteropLibrary.asInt(Object),
InteropLibrary.asLong(Object),
InteropLibrary.asFloat(Object),
InteropLibrary.asDouble(Object)public boolean fitsInByte(Object receiver)
true if the receiver represents a number and its value fits
in a Java byte primitive without loss of precision, else false. Invoking this
message does not cause any observable side-effects.InteropLibrary.isNumber(Object),
InteropLibrary.asByte(Object)public boolean fitsInShort(Object receiver)
true if the receiver represents a number and its value fits
in a Java short primitive without loss of precision, else false. Invoking this
message does not cause any observable side-effects.InteropLibrary.isNumber(Object),
InteropLibrary.asShort(Object)public boolean fitsInInt(Object receiver)
true if the receiver represents a number and its value fits
in a Java int primitive without loss of precision, else false. Invoking this
message does not cause any observable side-effects.InteropLibrary.isNumber(Object),
InteropLibrary.asInt(Object)public boolean fitsInLong(Object receiver)
true if the receiver represents a number and its value fits
in a Java long primitive without loss of precision, else false. Invoking this
message does not cause any observable side-effects.InteropLibrary.isNumber(Object),
InteropLibrary.asLong(Object)public boolean fitsInFloat(Object receiver)
true if the receiver represents a number and its value fits
in a Java float primitive without loss of precision, else false. Invoking this
message does not cause any observable side-effects.InteropLibrary.isNumber(Object),
InteropLibrary.asFloat(Object)public boolean fitsInDouble(Object receiver)
true if the receiver represents a number and its value fits
in a Java double primitive without loss of precision, else false. Invoking this
message does not cause any observable side-effects.InteropLibrary.isNumber(Object),
InteropLibrary.asDouble(Object)public byte asByte(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if the receiver is not a
InteropLibrary.isNumber(Object) or it does not fit without less of precision.InteropLibrary.isNumber(Object),
InteropLibrary.fitsInByte(Object)public short asShort(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if the receiver is not a
InteropLibrary.isNumber(Object) or it does not fit without less of precision.InteropLibrary.isNumber(Object),
InteropLibrary.fitsInShort(Object)public int asInt(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if the receiver is not a
InteropLibrary.isNumber(Object) or it does not fit without less of precision.InteropLibrary.isNumber(Object),
InteropLibrary.fitsInInt(Object)public long asLong(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if the receiver is not a
InteropLibrary.isNumber(Object) or it does not fit without less of precision.InteropLibrary.isNumber(Object),
InteropLibrary.fitsInLong(Object)public float asFloat(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if the receiver is not a
InteropLibrary.isNumber(Object) or it does not fit without less of precision.InteropLibrary.isNumber(Object),
InteropLibrary.fitsInFloat(Object)public double asDouble(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if the receiver is not a
InteropLibrary.isNumber(Object) or it does not fit without less of precision.InteropLibrary.isNumber(Object),
InteropLibrary.fitsInDouble(Object)public boolean hasMembers(Object receiver)
true if the receiver may have members. Members are structural elements
of a class. For example, a method or field is a member of a class. Invoking this message does
not cause any observable side-effects. Returns false by default.InteropLibrary.getMembers(Object, boolean),
InteropLibrary.isMemberReadable(Object, String),
InteropLibrary.isMemberModifiable(Object, String),
InteropLibrary.isMemberInvocable(Object, String),
InteropLibrary.isMemberInsertable(Object, String),
InteropLibrary.isMemberRemovable(Object, String),
InteropLibrary.readMember(Object, String),
InteropLibrary.writeMember(Object, String, Object),
InteropLibrary.removeMember(Object, String),
InteropLibrary.invokeMember(Object, String, Object...)public Object getMembers(Object receiver, boolean includeInternal) throws UnsupportedMessageException
true for
InteropLibrary.hasArrayElements(Object) and every array element must be of type
string.
If the includeInternal argument is true then internal member names are returned
as well. Internal members are implementation specific and should not be exposed to guest
language application. An example of internal members are internal slots in ECMAScript.
UnsupportedMessageException - if and only if the receiver does not have any
members.InteropLibrary.hasMembers(Object)public final Object getMembers(Object receiver) throws UnsupportedMessageException
getMembers(receiver, false). Invoking this message
does not cause any observable side-effects.UnsupportedMessageException - if and only if the receiver has no
members.InteropLibrary.getMembers(Object, boolean)public boolean isMemberReadable(Object receiver, String member)
true if a given member is readable.
This method may only return true if InteropLibrary.hasMembers(Object) returns
true as well and InteropLibrary.isMemberInsertable(Object, String) returns
false. Invoking this message does not cause any observable side-effects. Returns
false by default.InteropLibrary.readMember(Object, String)public Object readMember(Object receiver, String member) throws UnsupportedMessageException, UnknownIdentifierException
readable and invocable then the result of reading
the member is executable and is bound to this receiver. This
method must have not observable side-effects unless
InteropLibrary.hasMemberReadSideEffects(Object, String) returns true.UnsupportedMessageException - if the member is not readableUnknownIdentifierException - if the given member does not exist.InteropLibrary.hasMemberReadSideEffects(Object, String)public boolean isMemberModifiable(Object receiver, String member)
true if a given member is existing and
writable. This method may only return
true if InteropLibrary.hasMembers(Object) returns true as well and
InteropLibrary.isMemberInsertable(Object, String) returns false. Invoking this message
does not cause any observable side-effects. Returns false by default.InteropLibrary.writeMember(Object, String, Object)public boolean isMemberInsertable(Object receiver, String member)
true if a given member is not existing and
writable. This method may only return
true if InteropLibrary.hasMembers(Object) returns true as well and
InteropLibrary.isMemberExisting(Object, String) returns false. Invoking this message
does not cause any observable side-effects. Returns false by default.InteropLibrary.writeMember(Object, String, Object)public void writeMember(Object receiver, String member, Object value) throws UnsupportedMessageException, UnknownIdentifierException, UnsupportedTypeException
modifiable, or not existing and
insertable.
This method must have not observable side-effects other than the changed member unless
side-effects are allowed.UnsupportedMessageException - if the member is not writableUnknownIdentifierException - if the given member is not insertable and does not exist.UnsupportedTypeException - if the provided value type is not allowed to be writtenInteropLibrary.hasMemberWriteSideEffects(Object, String)public boolean isMemberRemovable(Object receiver, String member)
true if a given member is existing and removable. This method may only
return true if InteropLibrary.hasMembers(Object) returns true as well and
InteropLibrary.isMemberInsertable(Object, String) returns false. Invoking this message
does not cause any observable side-effects. Returns false by default.InteropLibrary.removeMember(Object, String)public void removeMember(Object receiver, String member) throws UnsupportedMessageException, UnknownIdentifierException
removable.
This method does not have not observable side-effects other than the removed member.UnsupportedMessageException - if the member is not removableUnknownIdentifierException - if the given member is not existing but removing would be
allowedInteropLibrary.isMemberRemovable(Object, String)public boolean isMemberInvocable(Object receiver, String member)
true if a given member is invocable. This method may only return
true if InteropLibrary.hasMembers(Object) returns true as well and
InteropLibrary.isMemberInsertable(Object, String) returns false. Invoking this message
does not cause any observable side-effects. Returns false by default.InteropLibrary.invokeMember(Object, String, Object...)public Object invokeMember(Object receiver, String member, Object... arguments) throws UnsupportedMessageException, ArityException, UnknownIdentifierException, UnsupportedTypeException
UnknownIdentifierException - if the given member does not exist.UnsupportedTypeException - if one of the arguments is not compatible to the executable
signatureArityException - if the number of expected arguments does not match the number of
actual arguments.UnsupportedMessageException - if the member is not invocableInteropLibrary.isMemberInvocable(Object, String)public boolean isMemberInternal(Object receiver, String member)
InteropLibrary.getMembers(Object, boolean) by default. Internal members are only relevant to guest
language implementations and tools, but not to guest applications or embedders. An example of
internal members are internal slots in ECMAScript. Invoking this message does not cause any
observable side-effects. Returns false by default.InteropLibrary.getMembers(Object, boolean)public final boolean isMemberWritable(Object receiver, String member)
modifiable or
insertable.public final boolean isMemberExisting(Object receiver, String member)
modifiable,
readable, removable or invocable.public boolean hasMemberReadSideEffects(Object receiver, String member)
true if reading a member may cause a side-effect. Invoking this message
does not cause any observable side-effects. A member read does not cause any side-effects by
default.
For instance in JavaScript a property read may have side-effects if the property has a getter function.
InteropLibrary.readMember(Object, String)public boolean hasMemberWriteSideEffects(Object receiver, String member)
true if writing a member may cause a side-effect, besides the write
operation of the member. Invoking this message does not cause any observable side-effects. A
member write does not cause any side-effects by default.
For instance in JavaScript a property write may have side-effects if the property has a setter function.
InteropLibrary.writeMember(Object, String, Object)public boolean hasArrayElements(Object receiver)
true if the receiver may have array elements. For example, the contents
of an array or list datastructure could be interpreted as array elements. Invoking this
message does not cause any observable side-effects. Returns false by default.InteropLibrary.getArraySize(Object)public Object readArrayElement(Object receiver, long index) throws UnsupportedMessageException, InvalidArrayIndexException
UnsupportedMessageException - if the array element is not readable.InvalidArrayIndexException - if the array index is out of bounds or invalid.public long getArraySize(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if InteropLibrary.hasArrayElements(Object) returns
false.public boolean isArrayElementReadable(Object receiver, long index)
true if a given array element is readable. This method may only return true if InteropLibrary.hasArrayElements(Object)
returns true as well. Invoking this message does not cause any observable
side-effects. Returns false by default.InteropLibrary.readArrayElement(Object, long)public void writeArrayElement(Object receiver, long index, Object value) throws UnsupportedMessageException, UnsupportedTypeException, InvalidArrayIndexException
modifiable, or not existing and
insertable.
This method must have not observable side-effects other than the changed array element.UnsupportedMessageException - if the array element is not writableInvalidArrayIndexException - if the array element is not insertable and does not exist.UnsupportedTypeException - if the provided value type is not allowed to be writtenpublic void removeArrayElement(Object receiver, long index) throws UnsupportedMessageException, InvalidArrayIndexException
removable. This method may only
return true if InteropLibrary.hasArrayElements(Object) returns true as
well and InteropLibrary.isArrayElementInsertable(Object, long) returns false.
This method does not have not observable side-effects other than the removed array element.UnsupportedMessageException - if the array element is not removableInvalidArrayIndexException - if the given array element index is not existing but
removing would be allowedInteropLibrary.isArrayElementRemovable(Object, long)public boolean isArrayElementModifiable(Object receiver, long index)
true if a given array element index is existing and
writable. This method may only return
true if InteropLibrary.hasArrayElements(Object) returns true as well and
InteropLibrary.isArrayElementInsertable(Object, long) returns false. Invoking this
message does not cause any observable side-effects. Returns false by default.public boolean isArrayElementInsertable(Object receiver, long index)
true if a given array element index is not existing and
insertable. This method may only return
true if InteropLibrary.hasArrayElements(Object) returns true as well and
InteropLibrary.isArrayElementExisting(Object, long)} returns false. Invoking this
message does not cause any observable side-effects. Returns false by default.public boolean isArrayElementRemovable(Object receiver, long index)
true if a given array element index is existing and
removable. This method may only return
true if InteropLibrary.hasArrayElements(Object) returns true as well and
InteropLibrary.isArrayElementInsertable(Object, long)} returns false. Invoking this
message does not cause any observable side-effects. Returns false by default.InteropLibrary.removeArrayElement(Object, long)public final boolean isArrayElementWritable(Object receiver, long index)
modifiable or insertable.public final boolean isArrayElementExisting(Object receiver, long index)
modifiable,
readable or
removable.public boolean isPointer(Object receiver)
true if the receiver value represents a native pointer. Native pointers
are represented as 64 bit pointers. Invoking this message does not cause any observable
side-effects. Returns false by default.
It is expected that objects should only return true if the native pointer value
corresponding to this object already exists, and obtaining it is a cheap operation. If an
object can be transformed to a pointer representation, but this hasn't happened yet, the
object is expected to return false with InteropLibrary.isPointer(Object), and wait for
the InteropLibrary.toNative(Object) message to trigger the transformation.
InteropLibrary.asPointer(Object),
InteropLibrary.toNative(Object)public long asPointer(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if InteropLibrary.isPointer(Object) returns
false for the same receiver.InteropLibrary.isPointer(Object)public void toNative(Object receiver)
receiver to a value that represents a raw native pointer.
After the transformation, the provided receiver returns true for InteropLibrary.isPointer(Object)
and can be unwrapped using the InteropLibrary.asPointer(Object) message.InteropLibrary.isPointer(Object),
InteropLibrary.asPointer(Object)public Instant asInstant(Object receiver) throws UnsupportedMessageException
instant. If a value is an instant then it is also a date,
time and timezone. Using this method may
be more efficient than reconstructing the timestamp from the date, time and timezone data.
Implementers should implement this method if they can provide a more efficient conversion to Instant than reconstructing it from date, time and timezone date. Implementers must ensure that the following Java code snippet always holds:
ZoneId zone = getTimeZone(receiver); LocalDate date = getDate(receiver); LocalTime time = getTime(receiver); assert ZonedDateTime.of(date, time, zone).toInstant().equals(getInstant(receiver));
UnsupportedMessageException - if InteropLibrary.isInstant(Object) returns false.InteropLibrary.isDate(Object),
InteropLibrary.isTime(Object),
InteropLibrary.isTimeZone(Object)public final boolean isInstant(Object receiver)
true if the receiver represents an instant. If a value is an instant
then it is also a date, time and
timezone.
This method is short-hand for:
isDate(v) &&isTime(v) &&isTimeZone(v)
InteropLibrary.isDate(Object),
InteropLibrary.isTime(Object),
InteropLibrary.isInstant(Object),
InteropLibrary.asInstant(Object)public boolean isTimeZone(Object receiver)
true if this object represents a timezone, else false. The
interpretation of timezone objects may vary:
InteropLibrary.isDate(Object) and InteropLibrary.isTime(Object) return true, then the
returned date or time information is aware of this timezone.
InteropLibrary.isDate(Object) and InteropLibrary.isTime(Object) returns false, then
it represents just timezone information.
AssertionError is thrown if assertions are enabled.
If this method is implemented then also InteropLibrary.asTimeZone(Object) must be implemented.
InteropLibrary.asTimeZone(Object),
InteropLibrary.asInstant(Object)public ZoneId asTimeZone(Object receiver) throws UnsupportedMessageException
timezone.UnsupportedMessageException - if InteropLibrary.isTimeZone(Object) returns false
.InteropLibrary.isTimeZone(Object)public boolean isDate(Object receiver)
true if this object represents a date, else false. If the
receiver is also a timezone then the date is aware, otherwise it
is naive.InteropLibrary.asDate(Object)public LocalDate asDate(Object receiver) throws UnsupportedMessageException
date. The
returned date is either aware if the receiver has a timezone
otherwise it is naive.UnsupportedMessageException - if InteropLibrary.isDate(Object) returns false.InteropLibrary.isDate(Object)public boolean isTime(Object receiver)
true if this object represents a time, else false. If the
receiver is also a timezone then the time is aware, otherwise it
is naive.InteropLibrary.asTime(Object)public LocalTime asTime(Object receiver) throws UnsupportedMessageException
time. The
returned time is either aware if the receiver has a timezone
otherwise it is naive.UnsupportedMessageException - if InteropLibrary.isTime(Object) returns false.InteropLibrary.isTime(Object)public boolean isDuration(Object receiver)
true if this object represents a duration, else false.Duration,
InteropLibrary.asDate(Object)public Duration asDuration(Object receiver) throws UnsupportedMessageException
duration.UnsupportedMessageException - if InteropLibrary.isDuration(Object) returns false
.InteropLibrary.isDuration(Object)public static LibraryFactory<InteropLibrary> getFactory()
ResolvedLibrary.resolve(InteropLibrary.class).LibraryFactory.resolve(Class)protected final boolean assertAdopted()