public final class Interop extends Object
Foreign objects will always have a Java type in Espresso, how a Java type is attached to a foreign object remains an implementation detail.
Polyglot| Modifier and Type | Method and Description |
|---|---|
static BigInteger |
asBigInteger(Object receiver)
Returns the receiver value as Java BigInteger primitive if the number fits without loss of
precision.
|
static boolean |
asBoolean(Object receiver)
Returns the Java boolean value if the receiver represents a
boolean like value. |
static byte |
asByte(Object receiver)
Returns the receiver value as Java byte primitive if the number fits without loss of
precision.
|
static double |
asDouble(Object receiver)
Returns the receiver value as Java double primitive if the number fits without loss of
precision.
|
static float |
asFloat(Object receiver)
Returns the receiver value as Java float primitive if the number fits without loss of
precision.
|
static int |
asInt(Object receiver)
Returns the receiver value as Java int primitive if the number fits without loss of
precision.
|
static long |
asLong(Object receiver)
Returns the receiver value as Java long primitive if the number fits without loss of
precision.
|
static long |
asPointer(Object receiver)
Returns the pointer value as long value if the receiver represents a pointer like value.
|
static short |
asShort(Object receiver)
Returns the receiver value as Java short primitive if the number fits without loss of
precision.
|
static String |
asString(Object receiver)
Returns the Java string value if the receiver represents a
string
like value. |
static Object |
execute(Object receiver,
Object... arguments)
Executes an executable value with the given arguments.
|
static boolean |
fitsInBigInteger(Object receiver)
Returns
true if the receiver represents a number and its value fits
in a Java BigInteger without loss of precision, else false. |
static 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. |
static 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. |
static 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. |
static 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. |
static 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. |
static 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. |
static long |
getArraySize(Object receiver)
Returns the array size of the receiver.
|
static long |
getBufferSize(Object receiver)
Returns the buffer size of the receiver, in bytes.
|
static Object |
getDeclaringMetaObject(Object receiver)
Returns declaring meta object.
|
static Object |
getExceptionCause(Object receiver)
Returns the internal cause of the receiver.
|
static int |
getExceptionExitStatus(Object receiver)
Returns exception exit status of the receiver.
|
static Object |
getExceptionMessage(Object receiver)
Returns exception message of the receiver.
|
static Object |
getExceptionStackTrace(Object receiver)
Returns the exception stack trace of the receiver that is of type exception.
|
static ExceptionType |
getExceptionType(Object receiver)
Returns
exception type of the receiver. |
static Object |
getExecutableName(Object receiver)
Returns executable name of the receiver.
|
static Object |
getHashEntriesIterator(Object receiver)
Returns the hash entries iterator for the receiver.
|
static Object |
getHashKeysIterator(Object receiver)
Returns the hash keys iterator for the receiver.
|
static long |
getHashSize(Object receiver)
Returns the number of receiver entries.
|
static Object |
getHashValuesIterator(Object receiver)
Returns the hash values iterator for the receiver.
|
static Object |
getIterator(Object receiver)
Returns the iterator for the receiver.
|
static Object |
getIteratorNextElement(Object receiver)
Returns the next element in the iteration.
|
static Object |
getMembers(Object receiver)
Returns an array of member name strings.
|
static Object |
getMetaObject(Object receiver)
Returns the metaobject that is associated with this value.
|
static Object |
getMetaQualifiedName(Object metaObject)
Returns the qualified name of a metaobject as
string. |
static Object |
getMetaSimpleName(Object metaObject)
Returns the simple name of a metaobject as
string. |
static boolean |
hasArrayElements(Object receiver)
Returns
true if the receiver may have array elements. |
static boolean |
hasBufferElements(Object receiver)
Returns
true if the receiver may have buffer elements. |
static boolean |
hasDeclaringMetaObject(Object receiver)
Returns
true if the receiver has a declaring meta object. |
static boolean |
hasExceptionCause(Object receiver)
Returns
true if the receiver is an exception with an attached internal cause. |
static boolean |
hasExceptionMessage(Object receiver)
Returns
true if the receiver is an exception that has an exception message. |
static boolean |
hasExceptionStackTrace(Object receiver)
Returns
true if the receiver is an exception and has a stack trace. |
static boolean |
hasExecutableName(Object receiver)
Returns
true if the receiver has an executable name. |
static boolean |
hasHashEntries(Object receiver)
Returns
true if the receiver may have hash entries. |
static boolean |
hasIdentity(Object receiver)
Returns
true if and only if the receiver specifies identity, else
false. |
static boolean |
hasIterator(Object receiver)
Returns
true if the receiver provides an iterator. |
static boolean |
hasIteratorNextElement(Object receiver)
Returns
true if the receiver is an iterator which has more elements, else
false. |
static boolean |
hasMemberReadSideEffects(Object receiver,
String member)
Returns
true if reading a member may cause a side-effect. |
static boolean |
hasMembers(Object receiver)
Returns
true if the receiver may have members. |
static boolean |
hasMemberWriteSideEffects(Object receiver,
String member)
Returns
true if writing a member may cause a side-effect, besides the write
operation of the member. |
static boolean |
hasMetaObject(Object receiver)
Returns
true if the receiver value has a metaobject associated. |
static int |
identityHashCode(Object receiver)
Returns an identity hash code for the receiver if it has
identity. |
static Object |
instantiate(Object receiver,
Object... arguments)
Instantiates the receiver value with the given arguments.
|
static Object |
invokeMember(Object receiver,
String member,
Object... arguments)
Invokes a member for a given receiver and arguments.
|
static <T> T |
invokeMemberWithCast(Class<T> targetType,
Object receiver,
String member,
Object... arguments)
Invokes a member for a given receiver and arguments where the expected return target type is
passed in to assist the runtime in converting the result of the invocation.
|
static boolean |
isArrayElementExisting(Object receiver,
long index)
Returns true if the array element is existing.
|
static boolean |
isArrayElementInsertable(Object receiver,
long index)
Returns
true if a given array element index is not existing and
insertable. |
static boolean |
isArrayElementModifiable(Object receiver,
long index)
Returns
true if a given array element index is existing and
writable. |
static boolean |
isArrayElementReadable(Object receiver,
long index)
Returns
true if a given array element is readable. |
static boolean |
isArrayElementRemovable(Object receiver,
long index)
Returns
true if a given array element index is existing and
removable. |
static boolean |
isArrayElementWritable(Object receiver,
long index)
Returns true if the array element is
modifiable or insertable. |
static boolean |
isBoolean(Object receiver)
Returns
true if the receiver represents a boolean like value, else
false. |
static boolean |
isBufferWritable(Object receiver)
Returns
true if the receiver is a modifiable buffer. |
static boolean |
isException(Object receiver)
Returns
true if the receiver value represents a throwable exception/error. |
static boolean |
isExceptionIncompleteSource(Object receiver)
Returns
true if receiver value represents an incomplete source exception. |
static boolean |
isExecutable(Object receiver)
Returns
true if the receiver represents an executable value, else
false. |
static boolean |
isHashEntryExisting(Object receiver,
Object key)
Returns
true if mapping for a given key is existing. |
static boolean |
isHashEntryInsertable(Object receiver,
Object key)
Returns
true if mapping for the specified key does not exist and is
writable. |
static boolean |
isHashEntryModifiable(Object receiver,
Object key)
Returns
true if mapping for the specified key exists and is
writable. |
static boolean |
isHashEntryReadable(Object receiver,
Object key)
Returns
true if mapping for the specified key exists and is
readable. |
static boolean |
isHashEntryRemovable(Object receiver,
Object key)
Returns
true if mapping for the specified key exists and is removable. |
static boolean |
isHashEntryWritable(Object receiver,
Object key)
|
static boolean |
isIdentical(Object receiver,
Object other)
Returns
true if two values represent the identical value, else
false. |
static boolean |
isInstantiable(Object receiver)
Returns
true if the receiver represents an instantiable value, else
false. |
static boolean |
isIterator(Object receiver)
Returns
true if the receiver represents an iterator. |
static boolean |
isMemberExisting(Object receiver,
String member)
Returns true if the member is existing.
|
static boolean |
isMemberInsertable(Object receiver,
String member)
Returns
true if a given member is not existing and
writable. |
static boolean |
isMemberInvocable(Object receiver,
String member)
Returns
true if a given member is invocable. |
static boolean |
isMemberModifiable(Object receiver,
String member)
Returns
true if a given member is existing and
writable. |
static boolean |
isMemberReadable(Object receiver,
String member)
Returns
true if a given member is readable. |
static boolean |
isMemberRemovable(Object receiver,
String member)
Returns
true if a given member is existing and removable. |
static boolean |
isMemberWritable(Object receiver,
String member)
Returns true if the member is
modifiable or
insertable. |
static boolean |
isMetaInstance(Object receiver,
Object instance)
Returns
true if the given instance is of the provided receiver metaobject, else
false. |
static boolean |
isMetaObject(Object receiver)
Returns
true if the receiver value represents a metaobject. |
static boolean |
isNull(Object receiver)
Returns
true if the receiver represents a null like value, else
false. |
static boolean |
isNumber(Object receiver)
Returns
true if the receiver represents a number value, else
false. |
static boolean |
isPointer(Object receiver)
Returns
true if the receiver value represents a native pointer. |
static boolean |
isString(Object receiver)
Returns
true if the receiver represents a string value, else
false. |
static Object |
readArrayElement(Object receiver,
long index)
Reads the value of an array element by index.
|
static byte |
readBufferByte(Object receiver,
long byteOffset)
Reads the byte from the receiver object at the given byte offset from the start of the
buffer.
|
static double |
readBufferDouble(Object receiver,
ByteOrder order,
long byteOffset)
Reads the double from the receiver object in the given byte order at the given byte offset
from the start of the buffer.
|
static float |
readBufferFloat(Object receiver,
ByteOrder order,
long byteOffset)
Reads the float from the receiver object in the given byte order at the given byte offset
from the start of the buffer.
|
static int |
readBufferInt(Object receiver,
ByteOrder order,
long byteOffset)
Reads the int from the receiver object in the given byte order at the given byte offset from
the start of the buffer.
|
static long |
readBufferLong(Object receiver,
ByteOrder order,
long byteOffset)
Reads the long from the receiver object in the given byte order at the given byte offset from
the start of the buffer.
|
static short |
readBufferShort(Object receiver,
ByteOrder order,
long byteOffset)
Reads the short from the receiver object in the given byte order at the given byte offset
from the start of the buffer.
|
static Object |
readHashValue(Object receiver,
Object key)
Reads the value for the specified key.
|
static Object |
readHashValueOrDefault(Object receiver,
Object key,
Object defaultValue)
Reads the value for the specified key or returns the
defaultValue when the mapping
for the specified key does not exist or is not readable. |
static Object |
readMember(Object receiver,
String member)
Reads the value of a given member.
|
static void |
removeArrayElement(Object receiver,
long index)
Remove an array element from the receiver object.
|
static void |
removeHashEntry(Object receiver,
Object key)
Removes the mapping for a given key from the receiver.
|
static void |
removeMember(Object receiver,
String member)
Removes a member from the receiver object.
|
static RuntimeException |
throwException(Object receiver)
Throws the receiver object as an exception of the source language, as if it was thrown by the
source language itself.
|
static Object |
toDisplayString(Object receiver)
Converts the receiver to a human readable
string of the language. |
static Object |
toDisplayString(Object receiver,
boolean allowSideEffects)
Converts the receiver to a human readable
string. |
static void |
toNative(Object receiver)
Attempts to transform a receiver to a value that represents a raw native pointer.
|
static void |
writeArrayElement(Object receiver,
long index,
Object value)
Writes the value of an array element by index.
|
static void |
writeBufferByte(Object receiver,
long byteOffset,
byte value)
Writes the given byte from the receiver object at the given byte offset from the start of the
buffer.
|
static void |
writeBufferDouble(Object receiver,
ByteOrder order,
long byteOffset,
double value)
Writes the given double from the receiver object in the given byte order at the given byte
offset from the start of the buffer.
|
static void |
writeBufferFloat(Object receiver,
ByteOrder order,
long byteOffset,
float value)
Writes the given float from the receiver object in the given byte order at the given byte
offset from the start of the buffer.
|
static void |
writeBufferInt(Object receiver,
ByteOrder order,
long byteOffset,
int value)
Writes the given int from the receiver object in the given byte order at the given byte
offset from the start of the buffer.
|
static void |
writeBufferLong(Object receiver,
ByteOrder order,
long byteOffset,
long value)
Writes the given long from the receiver object in the given byte order at the given byte
offset from the start of the buffer.
|
static void |
writeBufferShort(Object receiver,
ByteOrder order,
long byteOffset,
short value)
Writes the given short from the receiver object in the given byte order at the given byte
offset from the start of the buffer.
|
static void |
writeHashEntry(Object receiver,
Object key,
Object value)
Associates the specified value with the specified key in the receiver.
|
static void |
writeMember(Object receiver,
String member,
Object value)
Writes the value of a given member.
|
public static 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.
Foreign objects for which this method returns true behave the same as Java
null, but its identity is preserved.public static 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.
Foreign objects for which this method returns true, can be
polyglot-casted as boolean or
Boolean (casting to a boxed type always preserves identity).Interop.asBoolean(Object)public static boolean asBoolean(Object receiver) throws UnsupportedMessageException
boolean like value.UnsupportedMessageException - if and only if Interop.isBoolean(Object) returns
false for the same receiver.Interop.isBoolean(Object)public static boolean isString(Object receiver)
true if the receiver represents a string value, else
false. Invoking this message does not cause any observable side-effects.
Foreign objects for which this method returns true, can be
polyglot-casted as String; in this particular
case the the conversion is eager and does not preserves identity.Interop.asString(Object)public static String asString(Object receiver) throws UnsupportedMessageException
string
like value.
There's no guarantee about preserving or not the identity of foreign objects.
UnsupportedMessageException - if and only if Interop.isString(Object) returns
false for the same receiver.Interop.isString(Object)public static boolean isNumber(Object receiver)
true if the receiver represents a number value, else
false. Invoking this message does not cause any observable side-effects.Interop.fitsInByte(Object),
Interop.fitsInShort(Object),
Interop.fitsInInt(Object),
Interop.fitsInLong(Object),
Interop.fitsInFloat(Object),
Interop.fitsInDouble(Object),
Interop.asByte(Object),
Interop.asShort(Object),
Interop.asInt(Object),
Interop.asLong(Object),
Interop.asFloat(Object),
Interop.asDouble(Object)public static 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.
Foreign objects for which this method returns true, can be
polyglot-casted as byte or Byte
(casting to a boxed type always preserves identity).Interop.isNumber(Object),
Interop.asByte(Object)public static 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.
Foreign objects for which this method returns true, can be
polyglot-casted as short or Short
(casting to a boxed type always preserves identity).Interop.isNumber(Object),
Interop.asShort(Object)public static 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.
Foreign objects for which this method returns true, can be
polyglot-casted as int or Integer
(casting to a boxed type always preserves identity).Interop.isNumber(Object),
Interop.asInt(Object)public static 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.
Foreign objects for which this method returns true, can be
polyglot-casted as long or Long
(casting to a boxed type always preserves identity).Interop.isNumber(Object),
Interop.asLong(Object)public static 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.
Foreign objects for which this method returns true, can be
polyglot-casted as float or Float
(casting to a boxed type always preserves identity).Interop.isNumber(Object),
Interop.asFloat(Object)public static 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.
Foreign objects for which this method returns true, can be
polyglot-casted as double or Double
(casting to a boxed type always preserves identity).Interop.isNumber(Object),
Interop.asDouble(Object)public static boolean fitsInBigInteger(Object receiver)
true if the receiver represents a number and its value fits
in a Java BigInteger without loss of precision, else false. Invoking this
message does not cause any observable side-effects.
Foreign objects for which this method returns true, can be
polyglot-casted as BigInteger.Interop.isNumber(Object),
Interop.asBigInteger(Object)public static byte asByte(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if the receiver is not a
Interop.isNumber(Object) or it does not fit without less of precision.Interop.isNumber(Object),
Interop.fitsInByte(Object)public static short asShort(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if the receiver is not a
Interop.isNumber(Object) or it does not fit without less of precision.Interop.isNumber(Object),
Interop.fitsInShort(Object)public static int asInt(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if the receiver is not a
Interop.isNumber(Object) or it does not fit without less of precision.Interop.isNumber(Object),
Interop.fitsInInt(Object)public static long asLong(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if the receiver is not a
Interop.isNumber(Object) or it does not fit without less of precision.Interop.isNumber(Object),
Interop.fitsInLong(Object)public static float asFloat(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if the receiver is not a
Interop.isNumber(Object) or it does not fit without less of precision.Interop.isNumber(Object),
Interop.fitsInFloat(Object)public static double asDouble(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if the receiver is not a
Interop.isNumber(Object) or it does not fit without less of precision.Interop.isNumber(Object),
Interop.fitsInDouble(Object)public static BigInteger asBigInteger(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if the receiver is not a
Interop.isNumber(Object) or it does not fit without loss of precision.Interop.isNumber(Object),
Interop.fitsInBigInteger(Object)public static boolean isException(Object receiver)
true if the receiver value represents a throwable exception/error.
Invoking this message does not cause any observable side-effects. Returns false
by default.
Objects must only return true if they support Interop.throwException(java.lang.Object) as well.
If this method is implemented then also Interop.throwException(Object) must be implemented.
Foreign objects for which this method returns true, can be
polyglot-casted as ForeignException; identity is
preserved.
Interop.throwException(Object)public static RuntimeException throwException(Object receiver) throws UnsupportedMessageException
Interop.isException(Object) must be implemented.
Any interop value can be an exception value and export Interop.throwException(Object).
Foreign exceptions thrown with this method can be caught as ForeignException. Note
that ForeignException can only catch foreign exceptions. Native guest Java exceptions
can also be thrown with this method.
assert Interop.isException(foreignException);
try {
throw Interop.throwException(foreignException);
} catch (ForeignException e) {
log(e.getClass() + ": " + e.getMessage());
...
throw e;
}
UnsupportedMessageException - if and only if Interop.isException(Object) returns
false for the same receiver.Interop.isException(Object),
ForeignExceptionpublic static ExceptionType getExceptionType(Object receiver) throws UnsupportedMessageException
exception type of the receiver. Throws
UnsupportedMessageException when the receiver is not an exception.UnsupportedMessageExceptionInterop.isException(Object),
ExceptionTypepublic static boolean isExceptionIncompleteSource(Object receiver) throws UnsupportedMessageException
true if receiver value represents an incomplete source exception. Throws
UnsupportedMessageException when the receiver is not an exception or the exception is not a ExceptionType.PARSE_ERROR.UnsupportedMessageExceptionInterop.isException(Object),
Interop.getExceptionType(Object)public static int getExceptionExitStatus(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException
when the receiver is not an exception of the
exit type. A return value zero indicates that the execution of the
application was successful, a non-zero value that it failed. The individual interpretation of
non-zero values depends on the application.UnsupportedMessageExceptionInterop.isException(Object),
Interop.getExceptionType(Object),
ExceptionTypepublic static boolean hasExceptionCause(Object receiver)
true if the receiver is an exception with an attached internal cause.
Invoking this message does not cause any observable side-effects. Returns false by
default.Interop.isException(Object),
Interop.getExceptionCause(Object)public static Object getExceptionCause(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException when
the receiver is not an exception or has no internal cause. The
return value of this message is guaranteed to return true for
Interop.isException(Object).
The identity of the returned value is guaranteed to be preserved but it cannot be assumed that the returned value will have a specific Java type.
UnsupportedMessageExceptionInterop.isException(Object),
Interop.hasExceptionCause(Object)public static boolean hasExceptionMessage(Object receiver)
true if the receiver is an exception that has an exception message. Invoking
this message does not cause any observable side-effects. Returns false by default.Interop.isException(Object),
Interop.getExceptionMessage(Object)public static Object getExceptionMessage(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException when
the receiver is not an exception or has no exception message.
The return value of this message is guaranteed to return true for
Interop.isString(Object).
The identity of the returned object is preserved, but its Java type is not necessarily
String. The returned value could be a string originated in a foreign language,
incompatible with Java's String e.g. rope, mutable, different encoding...
To correctly convert to a Java String use Interop.asString:
Object maybeForeign = Interop.toDisplayString(foreignObject, false); assert Interop.isString(maybeForeign); String displayString = Interop.asString(maybeForeign);
UnsupportedMessageExceptionInterop.isException(Object),
Interop.hasExceptionMessage(Object)public static boolean hasExceptionStackTrace(Object receiver)
true if the receiver is an exception and has a stack trace. Invoking this
message does not cause any observable side-effects. Returns false by default.Interop.isException(Object),
Interop.getExceptionStackTrace(Object)public static Object getExceptionStackTrace(Object receiver) throws UnsupportedMessageException
array of objects with potentially
executable name and declaring meta object of the caller. Throws UnsupportedMessageException when the
receiver is not an exception or has no stack trace. Invoking
this message or accessing the stack trace elements array must not cause any observable
side-effects.
The identity of the returned value is guaranteed to be preserved but it cannot be assumed that the returned value will have a specific Java type.
UnsupportedMessageExceptionInterop.isException(Object),
Interop.hasExceptionStackTrace(Object)public static boolean hasArrayElements(Object receiver)
true if the receiver may have array elements. Therefore, At least one of
Interop.readArrayElement(Object, long), Interop.writeArrayElement(Object, long, Object),
Interop.removeArrayElement(Object, long) must not throw {#link
UnsupportedMessageException. 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.Interop.getArraySize(Object)public static Object readArrayElement(Object receiver, long index) throws UnsupportedMessageException, InvalidArrayIndexException
The identity of the returned value is guaranteed to be preserved but it cannot be assumed that the returned value will have a specific Java type.
The user must convert the result to the expected type:
Object value = Interop.readArrayElement(new int[]{42}, 0);
assert Interop.fitsInInt(value);
int intValue = Interop.asInt(value);
UnsupportedMessageException - when the receiver does not support reading at all. An
empty receiver with no readable array elements supports the read operation (even
though there is nothing to read), therefore it throws
UnknownIdentifierException for all arguments instead.InvalidArrayIndexException - if the given index is not
readable, e.g. when the index is
invalid or the index is out of bounds.public static long getArraySize(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if Interop.hasArrayElements(Object) returns
false.public static boolean isArrayElementReadable(Object receiver, long index)
true if a given array element is readable. This method may only return true if Interop.hasArrayElements(Object)
returns true as well. Invoking this message does not cause any observable
side-effects. Returns false by default.Interop.readArrayElement(Object, long)public static 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 - when the receiver does not support writing at all, e.g.
when it is immutable.InvalidArrayIndexException - if the given index is not
insertable nor
modifiable, e.g. when the index
is invalid or the index is out of bounds and the array does not support growing.UnsupportedTypeException - if the provided value type is not allowed to be written.public static void removeArrayElement(Object receiver, long index) throws UnsupportedMessageException, InvalidArrayIndexException
removable. This method may only
return true if Interop.hasArrayElements(Object) returns true as
well and Interop.isArrayElementInsertable(Object, long) returns false.
This method does not have observable side-effects other than the removed array element and
shift of remaining elements. If shifting is not supported then the array might allow only
removal of last element.UnsupportedMessageException - when the receiver does not support removing at all, e.g.
when it is immutable.InvalidArrayIndexException - if the given index is not
removable, e.g. when the index is
invalid, the index is out of bounds, or the array does not support shifting of
remaining elements.Interop.isArrayElementRemovable(Object, long)public static boolean isArrayElementModifiable(Object receiver, long index)
true if a given array element index is existing and
writable. This method may only return
true if Interop.hasArrayElements(Object) returns true as well and
Interop.isArrayElementInsertable(Object, long) returns false. Invoking this
message does not cause any observable side-effects. Returns false by default.Interop.writeArrayElement(Object, long, Object),
Interop.isArrayElementInsertable(Object, long)public static 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 Interop.hasArrayElements(Object) returns true as well and
Interop.isArrayElementExisting(Object, long)} returns false. Invoking this
message does not cause any observable side-effects. Returns false by default.Interop.writeArrayElement(Object, long, Object),
Interop.isArrayElementModifiable(Object, long)public static boolean isArrayElementRemovable(Object receiver, long index)
true if a given array element index is existing and
removable. This method may only return
true if Interop.hasArrayElements(Object) returns true as well and
Interop.isArrayElementInsertable(Object, long)} returns false. Invoking this
message does not cause any observable side-effects. Returns false by default.Interop.removeArrayElement(Object, long)public static boolean isArrayElementWritable(Object receiver, long index)
modifiable or insertable.public static boolean isArrayElementExisting(Object receiver, long index)
modifiable,
readable or
removable.public static boolean hasMetaObject(Object receiver)
true if the receiver value has a metaobject associated. The metaobject
represents a description of the object, reveals its kind and its features. Some information
that a metaobject might define includes the base object's type, interface, class, methods,
attributes, etc. Should return false when no metaobject is known for this type.
Returns false by default.
An example, for Java objects the returned metaobject is the class
instance. In JavaScript this could be the function or class that is associated with the
object.
Metaobjects for primitive values or values of other languages may be provided using language views. While an object is associated with a metaobject in one language, the metaobject might be a different when viewed from another language.
This method must not cause any observable side-effects. If this method is implemented then
also Interop.getMetaObject(Object) must be implemented.
Interop.getMetaObject(Object),
Interop.isMetaObject(Object)public static Object getMetaObject(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException by default.
The returned object must return true for Interop.isMetaObject(Object) and
provide implementations for Interop.getMetaSimpleName(Object),
Interop.getMetaQualifiedName(Object), and Interop.isMetaInstance(Object, Object). For all
values with metaobjects it must at hold that
isMetaInstance(getMetaObject(value), value) ==
true.
This method must not cause any observable side-effects. If this method is implemented then
also Interop.hasMetaObject(Object) must be implemented.
The identity of the returned value is guaranteed to be preserved but it cannot be assumed that the returned value will have a specific Java type.
UnsupportedMessageException - if and only if Interop.hasMetaObject(Object) returns
false for the same receiver.Interop.hasMetaObject(Object)public static Object toDisplayString(Object receiver, boolean allowSideEffects)
string. Each language may
have special formating conventions - even primitive values may not follow the traditional
Java rules. The format of the returned string is intended to be interpreted by humans not
machines and should therefore not be relied upon by machines. By default the receiver class
name and its identity hash code is used as string
representation.
String representations for primitive values or values of other languages may be provided
using language views. It is common that languages provide different string representations
for primitive and foreign values. To convert the result value to a Java string use
Interop.asString(Object).
The identity of the returned object is preserved, but its Java type is not necessarily
String. The returned value could be a string originated in a foreign language,
incompatible with Java's String e.g. rope, mutable, different encoding...
To correctly convert to a Java String use Interop.asString:
Object maybeForeign = Interop.toDisplayString(foreignObject, false); assert Interop.isString(maybeForeign); String displayString = Interop.asString(maybeForeign);
allowSideEffects - whether side-effects are allowed in the production of the string.public static Object toDisplayString(Object receiver)
string of the language.
Short-cut for toDisplayString(true).Interop.toDisplayString(Object, boolean)public static boolean isMetaObject(Object receiver)
true if the receiver value represents a metaobject. Metaobjects may be
values that naturally occur in a language or they may be returned by
Interop.getMetaObject(Object). A metaobject represents a description of the object, reveals
its kind and its features. If a receiver is a metaobject it is often also
instantiable, but this is not a requirement.
Sample interpretations: In Java an instance of the type Class is a metaobject.
In JavaScript any function instance is a metaobject. For example, the metaobject of a
JavaScript class is the associated constructor function.
This method must not cause any observable side-effects. If this method is implemented then
also Interop.getMetaQualifiedName(Object), Interop.getMetaSimpleName(Object) and
Interop.isMetaInstance(Object, Object) must be implemented as well.
public static Object getMetaQualifiedName(Object metaObject) throws UnsupportedMessageException
string.
Sample interpretations: The qualified name of a Java class includes the package name
and its class name. JavaScript does not have the notion of qualified name and therefore
returns the simple name instead.
This method must not cause any observable side-effects. If this method is implemented then
also Interop.isMetaObject(Object) must be implemented as well.
The identity of the returned object is preserved, but its Java type is not necessarily
String. The returned value could be a string originated in a foreign language,
incompatible with Java's String e.g. rope, mutable, different encoding...
To correctly convert to a Java String use Interop.asString:
Object maybeForeign = Interop.getMetaQualifiedName(foreignObject); assert Interop.isString(maybeForeign); String metaQualifiedName = Interop.asString(maybeForeign);
UnsupportedMessageException - if and only if Interop.isMetaObject(Object) returns
false for the same receiver.public static Object getMetaSimpleName(Object metaObject) throws UnsupportedMessageException
string.
Sample interpretations: The simple name of a Java class is the class name.
This method must not cause any observable side-effects. If this method is implemented then
also Interop.isMetaObject(Object) must be implemented as well.
The identity of the returned object is preserved, but its Java type is not necessarily
String. The returned value could be a string originated in a foreign language,
incompatible with Java's String e.g. rope, mutable, different encoding...
To correctly convert to a Java String use Interop.asString:
Object maybeForeign = Interop.getMetaSimpleName(foreignObject); assert Interop.isString(maybeForeign); String metaSimpleName = Interop.asString(maybeForeign);
UnsupportedMessageException - if and only if Interop.isMetaObject(Object) returns
false for the same receiver.public static boolean isMetaInstance(Object receiver, Object instance) throws UnsupportedMessageException
true if the given instance is of the provided receiver metaobject, else
false.
Sample interpretations: A Java object is an instance of its returned
class.
This method must not cause any observable side-effects. If this method is implemented then
also Interop.isMetaObject(Object) must be implemented as well.
instance - the instance object to check.UnsupportedMessageException - if and only if Interop.isMetaObject(Object) returns
false for the same receiver.public static boolean isIdentical(Object receiver, Object other)
true if two values represent the identical value, else
false. Two values are identical if and only if they have specified identity
semantics in the target language and refer to the identical instance.
By default, an interop value does not support identical comparisons, and will return
false for any invocation of this method. Use Interop.hasIdentity(Object) to
find out whether a receiver supports identity comparisons.
This method has the following properties:
x,
Interop.isIdentical(x, x) may return false if the object does not support
identity, else true. This method is reflexive if x supports identity. A
value supports identity if Interop.isIdentical(x, x) returns true. The
method Interop.hasIdentity(Object) may be used to document this intent explicitly.
x and y,
Interop.isIdentical(x, y) returns true if and only if
Interop.isIdentical(y, x) returns true.
x, y, and z, if
Interop.isIdentical(x, y) returns true and Interop.isIdentical(y, z)
returns true, then Interop.isIdentical(x, z) returns true.
x and y, multiple invocations of
Interop.isIdentical(x, y) consistently returns true or consistently return
false.
Note that the target language identical semantics typically does not map directly to interop
identical implementation. Instead target language identity is specified by the language
operation, may take multiple other rules into account and may only fallback to interop
identical for values without dedicated interop type. For example, in many languages
primitives like numbers or strings may be identical, in the target language sense, still
identity can only be exposed for objects and non-primitive values. Primitive values like
Integer can never be interop identical to other boxed language integers as this would
violate the symmetric property.
This method performs double dispatch by forwarding calls to isIdenticalOrUndefined with receiver and other value first and then with reversed parameters if the result was undefined. This allows the receiver and the other value to negotiate identity semantics.
This method must not cause any observable side-effects.
public static boolean hasIdentity(Object receiver)
true if and only if the receiver specifies identity, else
false. This method is a short-cut for
isIdentical(receiver, receiver). This message cannot be exported. To add
identity support to the receiver export isIdenticalOrUndefined(Object, Object) instead.public static int identityHashCode(Object receiver) throws UnsupportedMessageException
identity. If the receiver has no identity then an UnsupportedMessageException is
thrown. The identity hash code may be used by languages to store foreign values with identity
in an identity hash map.
Interop.isIdentical(Object, Object)
message, then calling the identityHashCode method on each of the two objects must produce the
same integer result.
UnsupportedMessageException - if and only if Interop.hasIdentity(Object) returns
false for the same receiver.Interop.isIdentical(Object, Object)public static boolean hasMembers(Object receiver)
true if the receiver may have members. Therefore, at least one of
Interop.readMember(Object, String), Interop.writeMember(Object, String, Object),
Interop.removeMember(Object, String), Interop.invokeMember(Object, String, Object...) must
not throw UnsupportedMessageException. 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.Interop.getMembers(Object),
Interop.isMemberReadable(Object, String),
Interop.isMemberModifiable(Object, String),
Interop.isMemberInvocable(Object, String),
Interop.isMemberInsertable(Object, String),
Interop.isMemberRemovable(Object, String),
Interop.readMember(Object, String),
Interop.writeMember(Object, String, Object),
Interop.removeMember(Object, String),
Interop.invokeMember(Object, String, Object...)public static Object getMembers(Object receiver) throws UnsupportedMessageException
true for
Interop.hasArrayElements(Object) and every array element must be of type
string.
The identity of the returned value is guaranteed to be preserved but it cannot be assumed that the returned value will have a specific Java type.
UnsupportedMessageException - if and only if the receiver does not have any
members.Interop.hasMembers(Object)public static boolean isMemberReadable(Object receiver, String member)
true if a given member is readable.
This method may only return true if Interop.hasMembers(Object) returns
true as well and Interop.isMemberInsertable(Object, String) returns
false. Invoking this message does not cause any observable side-effects. Returns
false by default.Interop.readMember(Object, String)public static 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
Interop.hasMemberReadSideEffects(Object, String) returns true.
The identity of the returned value is guaranteed to be preserved but it cannot be assumed that the returned value will have a specific Java type.
UnsupportedMessageException - if when the receiver does not support reading at all. An
empty receiver with no readable members supports the read operation (even though
there is nothing to read), therefore it throws UnknownIdentifierException
for all arguments instead.UnknownIdentifierException - if the given member is not
readable, e.g. when the member with the
given name does not exist.Interop.hasMemberReadSideEffects(Object, String)public static boolean isMemberModifiable(Object receiver, String member)
true if a given member is existing and
writable. This method may only return
true if Interop.hasMembers(Object) returns true as well and
Interop.isMemberInsertable(Object, String) returns false. Invoking this message
does not cause any observable side-effects. Returns false by default.Interop.writeMember(Object, String, Object)public static boolean isMemberInsertable(Object receiver, String member)
true if a given member is not existing and
writable. This method may only return
true if Interop.hasMembers(Object) returns true as well and
Interop.isMemberExisting(Object, String) returns false. Invoking this message
does not cause any observable side-effects. Returns false by default.Interop.writeMember(Object, String, Object)public static 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 - when the receiver does not support writing at all, e.g.
when it is immutable.UnknownIdentifierException - if the given member is not
modifiable nor
insertable.UnsupportedTypeException - if the provided value type is not allowed to be written.Interop.hasMemberWriteSideEffects(Object, String)public static boolean isMemberRemovable(Object receiver, String member)
true if a given member is existing and removable. This method may only
return true if Interop.hasMembers(Object) returns true as well and
Interop.isMemberInsertable(Object, String) returns false. Invoking this message
does not cause any observable side-effects. Returns false by default.Interop.removeMember(Object, String)public static 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 - when the receiver does not support removing at all, e.g.
when it is immutable.UnknownIdentifierException - if the given member is not
Interop.isMemberRemovable(Object, String) removable}, e.g. the receiver does not
have a member with the given name.Interop.isMemberRemovable(Object, String)public static boolean isMemberInvocable(Object receiver, String member)
true if a given member is invocable. This method may only return
true if Interop.hasMembers(Object) returns true as well and
Interop.isMemberInsertable(Object, String) returns false. Invoking this message
does not cause any observable side-effects. Returns false by default.Interop.invokeMember(Object, String, Object...)public static Object invokeMember(Object receiver, String member, Object... arguments) throws UnsupportedMessageException, ArityException, UnknownIdentifierException, UnsupportedTypeException
The identity of the returned value is guaranteed to be preserved but it cannot be assumed that the returned value will have a specific Java type.
UnknownIdentifierException - if the given member does not exist or is not
invocable.UnsupportedTypeException - if one of the arguments is not compatible to the executable
signature. The exception is thrown on best effort basis, dynamic languages may
throw their own exceptions if the arguments are wrong.ArityException - if the number of expected arguments does not match the number of
actual arguments.UnsupportedMessageException - when the receiver does not support invoking at all, e.g.
when storing executable members is not allowed.Interop.isMemberInvocable(Object, String)public static <T> T invokeMemberWithCast(Class<T> targetType, Object receiver, String member, Object... arguments) throws UnsupportedMessageException, ArityException, UnknownIdentifierException, UnsupportedTypeException
Interop.invokeMember(Object, String, Object...).UnknownIdentifierException - if the given member does not exist or is not
invocable.UnsupportedTypeException - if one of the arguments is not compatible to the executable
signature. Also thrown if the return value is not compatible with the passed
targetType.The exception is thrown on best effort basis, dynamic languages may
throw their own exceptions if the arguments are wrong.ArityException - if the number of expected arguments does not match the number of
actual arguments.UnsupportedMessageException - when the receiver does not support invoking at all, e.g.
when storing executable members is not allowed.Interop.isMemberInvocable(Object, String)public static boolean isMemberWritable(Object receiver, String member)
modifiable or
insertable.public static boolean isMemberExisting(Object receiver, String member)
modifiable,
readable, removable or invocable.public static 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.
Interop.readMember(Object, String)public static 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.
Interop.writeMember(Object, String, Object)public static 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 Interop.isPointer(Object), and wait for
the Interop.toNative(Object) message to trigger the transformation.
Interop.asPointer(Object),
Interop.toNative(Object)public static long asPointer(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if Interop.isPointer(Object) returns
false for the same receiver.Interop.isPointer(Object)public static void toNative(Object receiver)
Interop.isPointer(Object)
and can be unwrapped using the Interop.asPointer(Object) message. If transformation cannot
be done Interop.isPointer(Object) will keep returning false.Interop.isPointer(Object),
Interop.asPointer(Object)public static 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.Interop.execute(Object, Object...)public static Object execute(Object receiver, Object... arguments) throws UnsupportedTypeException, ArityException, UnsupportedMessageException
The identity of the returned value is guaranteed to be preserved but it cannot be assumed that the returned value will have a specific Java type.
UnsupportedTypeException - if one of the arguments is not compatible to the executable
signature. The exception is thrown on best effort basis, dynamic languages may
throw their own exceptions if the arguments are wrong.ArityException - if the number of expected arguments does not match the number of
actual arguments.UnsupportedMessageException - if and only if Interop.isExecutable(Object) returns
false for the same receiver.Interop.isExecutable(Object)public static boolean isInstantiable(Object receiver)
true if the receiver represents an instantiable value, else
false. Contructors or metaobjects 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.Interop.instantiate(Object, Object...),
Interop.isMetaObject(Object)public static Object instantiate(Object receiver, Object... arguments) throws UnsupportedTypeException, ArityException, UnsupportedMessageException
The identity of the returned value is guaranteed to be preserved but it cannot be assumed that the returned value will have a specific Java type.
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 Interop.isInstantiable(Object) returns
false for the same receiver.Interop.isExecutable(Object)public static boolean hasExecutableName(Object receiver)
true if the receiver has an executable name. Invoking this message does not
cause any observable side-effects. Returns false by default.Interop.getExecutableName(Object)public static Object getExecutableName(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException when the
receiver is has no executable name. The return value is an
interop value that is guaranteed to return true for Interop.isString(Object).
The identity of the returned object is preserved, but its Java type is not necessarily
String. The returned value could be a string originated in a foreign language,
incompatible with Java's String e.g. rope, mutable, different encoding...
To correctly convert to a Java String use Interop.asString:
Object maybeForeign = Interop.getExecutableName(foreignObject); assert Interop.isString(maybeForeign); String executableName = Interop.asString(maybeForeign);
UnsupportedMessageExceptionInterop.hasExecutableName(Object)public static boolean hasDeclaringMetaObject(Object receiver)
true if the receiver has a declaring meta object. The declaring meta object
is the meta object of the executable or meta object that declares the receiver value.
Invoking this message does not cause any observable side-effects. Returns false by
default.Interop.getDeclaringMetaObject(Object)public static Object getDeclaringMetaObject(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException when the receiver is
has no declaring meta object. The return value is an
interop value that is guaranteed to return true for
Interop.isMetaObject(Object).
The identity of the returned value is guaranteed to be preserved but it cannot be assumed that the returned value will have a specific Java type.
UnsupportedMessageExceptionInterop.hasDeclaringMetaObject(Object)public static boolean hasBufferElements(Object receiver)
true if the receiver may have buffer elements.
If this message returns true, then Interop.getBufferSize(Object),
Interop.readBufferByte(Object, long), Interop.readBufferShort(Object, ByteOrder, long),
Interop.readBufferInt(Object, ByteOrder, long),
Interop.readBufferLong(Object, ByteOrder, long),
Interop.readBufferFloat(Object, ByteOrder, long) and
Interop.readBufferDouble(Object, ByteOrder, long) must not throw
UnsupportedMessageException.
Invoking this message does not cause any observable side-effects.
By default, it returns false.
public static boolean isBufferWritable(Object receiver) throws UnsupportedMessageException
true if the receiver is a modifiable buffer.
If this message returns true, then Interop.getBufferSize(Object),
Interop.writeBufferByte(Object, long, byte),
Interop.writeBufferShort(Object, ByteOrder, long, short),
Interop.writeBufferInt(Object, ByteOrder, long, int),
Interop.writeBufferLong(Object, ByteOrder, long, long),
Interop.writeBufferFloat(Object, ByteOrder, long, float) and
Interop.writeBufferDouble(Object, ByteOrder, long, double) must not throw
UnsupportedMessageException.
Invoking this message does not cause any observable side-effects.
UnsupportedMessageException - if and only if Interop.hasBufferElements(Object) returns
falsepublic static long getBufferSize(Object receiver) throws UnsupportedMessageException
Invoking this message does not cause any observable side-effects.
UnsupportedMessageException - if and only if Interop.hasBufferElements(Object) returns
falsepublic static byte readBufferByte(Object receiver, long byteOffset) throws UnsupportedMessageException, InvalidBufferOffsetException
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
Invoking this message does not cause any observable side-effects.
InvalidBufferOffsetException - if and only if
byteOffset < 0 || byteOffset >= Interop.getBufferSize(Object)UnsupportedMessageException - if and only if either Interop.hasBufferElements(Object)
returns false returns falsepublic static void writeBufferByte(Object receiver, long byteOffset, byte value) throws UnsupportedMessageException, InvalidBufferOffsetException
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
InvalidBufferOffsetException - if and only if
byteOffset < 0 || byteOffset >= Interop.getBufferSize(Object)UnsupportedMessageException - if and only if either Interop.hasBufferElements(Object)
or Interop.isBufferWritable(java.lang.Object) returns falsepublic static short readBufferShort(Object receiver, ByteOrder order, long byteOffset) throws UnsupportedMessageException, InvalidBufferOffsetException
Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
Invoking this message does not cause any observable side-effects.
InvalidBufferOffsetException - if and only if
byteOffset < 0 || byteOffset >= Interop.getBufferSize(Object) - 1UnsupportedMessageException - if and only if Interop.hasBufferElements(Object) returns
falsepublic static void writeBufferShort(Object receiver, ByteOrder order, long byteOffset, short value) throws UnsupportedMessageException, InvalidBufferOffsetException
Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
InvalidBufferOffsetException - if and only if
byteOffset < 0 || byteOffset >= Interop.getBufferSize(Object) - 1UnsupportedMessageException - if and only if either Interop.hasBufferElements(Object)
or Interop.isBufferWritable(java.lang.Object) returns falsepublic static int readBufferInt(Object receiver, ByteOrder order, long byteOffset) throws UnsupportedMessageException, InvalidBufferOffsetException
Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
Invoking this message does not cause any observable side-effects.
InvalidBufferOffsetException - if and only if
byteOffset < 0 || byteOffset >= Interop.getBufferSize(Object) - 3UnsupportedMessageException - if and only if Interop.hasBufferElements(Object) returns
falsepublic static void writeBufferInt(Object receiver, ByteOrder order, long byteOffset, int value) throws UnsupportedMessageException, InvalidBufferOffsetException
Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
InvalidBufferOffsetException - if and only if
byteOffset < 0 || byteOffset >= Interop.getBufferSize(Object) - 3UnsupportedMessageException - if and only if either Interop.hasBufferElements(Object)
or Interop.isBufferWritable(java.lang.Object) returns falsepublic static long readBufferLong(Object receiver, ByteOrder order, long byteOffset) throws UnsupportedMessageException, InvalidBufferOffsetException
Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
Invoking this message does not cause any observable side-effects.
InvalidBufferOffsetException - if and only if
byteOffset < 0 || byteOffset >= Interop.getBufferSize(Object) - 7UnsupportedMessageException - if and only if Interop.hasBufferElements(Object) returns
falsepublic static void writeBufferLong(Object receiver, ByteOrder order, long byteOffset, long value) throws UnsupportedMessageException, InvalidBufferOffsetException
Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
InvalidBufferOffsetException - if and only if
byteOffset < 0 || byteOffset >= Interop.getBufferSize(Object) - 7UnsupportedMessageException - if and only if either Interop.hasBufferElements(Object)
or Interop.isBufferWritable(java.lang.Object) returns falsepublic static float readBufferFloat(Object receiver, ByteOrder order, long byteOffset) throws UnsupportedMessageException, InvalidBufferOffsetException
Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
Invoking this message does not cause any observable side-effects.
InvalidBufferOffsetException - if and only if
byteOffset < 0 || byteOffset >= Interop.getBufferSize(Object) - 3UnsupportedMessageException - if and only if Interop.hasBufferElements(Object) returns
falsepublic static void writeBufferFloat(Object receiver, ByteOrder order, long byteOffset, float value) throws UnsupportedMessageException, InvalidBufferOffsetException
Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
InvalidBufferOffsetException - if and only if
byteOffset < 0 || byteOffset >= Interop.getBufferSize(Object) - 3UnsupportedMessageException - if and only if either Interop.hasBufferElements(Object)
or Interop.isBufferWritable(java.lang.Object) returns falsepublic static double readBufferDouble(Object receiver, ByteOrder order, long byteOffset) throws UnsupportedMessageException, InvalidBufferOffsetException
Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
Invoking this message does not cause any observable side-effects.
InvalidBufferOffsetException - if and only if
byteOffset < 0 || byteOffset >= Interop.getBufferSize(Object) - 7UnsupportedMessageException - if and only if Interop.hasBufferElements(Object) returns
falsepublic static void writeBufferDouble(Object receiver, ByteOrder order, long byteOffset, double value) throws UnsupportedMessageException, InvalidBufferOffsetException
Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
InvalidBufferOffsetException - if and only if
byteOffset < 0 || byteOffset >= Interop.getBufferSize(Object) - 7UnsupportedMessageException - if and only if either Interop.hasBufferElements(Object)
or Interop.isBufferWritable(java.lang.Object) returns falsepublic static boolean hasIterator(Object receiver)
true if the receiver provides an iterator. For example, an array or a list
provide an iterator over their content. Invoking this message does not cause any observable
side-effects. By default returns true for receivers that have
array elements.Interop.getIterator(Object)public static Object getIterator(Object receiver) throws UnsupportedMessageException
iterator. Invoking this message does not cause any observable
side-effects.UnsupportedMessageException - if and only if Interop.hasIterator(Object) returns
false for the same receiver.public static boolean isIterator(Object receiver)
true if the receiver represents an iterator. Invoking this message does not
cause any observable side-effects. Returns false by default.Interop.hasIterator(Object),
Interop.getIterator(Object)public static boolean hasIteratorNextElement(Object receiver) throws UnsupportedMessageException
true if the receiver is an iterator which has more elements, else
false. Multiple calls to the Interop.hasIteratorNextElement(Object) might lead to
different results if the underlying data structure is modified.UnsupportedMessageException - if and only if Interop.isIterator(Object) returns
false for the same receiver.Interop.isIterator(Object),
Interop.getIteratorNextElement(Object)public static Object getIteratorNextElement(Object receiver) throws UnsupportedMessageException, StopIterationException
Interop.getIteratorNextElement(Object) may throw the StopIterationException despite
the Interop.hasIteratorNextElement(Object) returned true.UnsupportedMessageException - if Interop.isIterator(Object) returns false for
the same receiver or when the underlying iterator element exists but is not
readable.StopIterationException - if the iteration has no more elements. Even if the
StopIterationException was thrown it might not be thrown again by a next
Interop.getIteratorNextElement(Object) invocation on the same receiver due to a
modification of an underlying iterable.Interop.isIterator(Object),
Interop.hasIteratorNextElement(Object)public static boolean hasHashEntries(Object receiver)
true if the receiver may have hash entries. Therefore, at least one of
Interop.readHashValue(Object, Object), Interop.writeHashEntry(Object, Object, Object),
Interop.removeHashEntry(Object, Object) must not throw UnsupportedMessageException.
For example, the contents of a map data structure could be interpreted as hash elements.
Invoking this message does not cause any observable side-effects. Returns false by
default.Interop.getHashEntriesIterator(Object),
Interop.getHashSize(Object),
Interop.isHashEntryReadable(Object, Object),
Interop.isHashEntryWritable(Object, Object),
Interop.isHashEntryInsertable(Object, Object),
Interop.isHashEntryRemovable(Object, Object),
Interop.readHashValue(Object, Object),
Interop.readHashValueOrDefault(Object, Object, Object),
Interop.writeHashEntry(Object, Object, Object),
Interop.removeHashEntry(Object, Object)public static long getHashSize(Object receiver) throws UnsupportedMessageException
UnsupportedMessageException - if and only if Interop.hasHashEntries(Object) returns
false.public static boolean isHashEntryReadable(Object receiver, Object key)
true if mapping for the specified key exists and is
readable. This method may only return true if
Interop.hasHashEntries(Object) returns true as well and
Interop.isHashEntryInsertable(Object, Object) returns false. Invoking this message
does not cause any observable side-effects. Returns false by default.Interop.readHashValue(Object, Object)public static Object readHashValue(Object receiver, Object key) throws UnsupportedMessageException, UnknownKeyException
UnsupportedMessageException - if the receiver does not support reading at all. An empty
receiver with no readable hash entries supports the read operation (even though
there is nothing to read), therefore it throws UnknownKeyException for
all arguments instead.UnknownKeyException - if mapping for the specified key is not
readable, e.g. when the hash does
not contain specified key.Interop.isHashEntryReadable(Object, Object),
Interop.readHashValueOrDefault(Object, Object, Object)public static Object readHashValueOrDefault(Object receiver, Object key, Object defaultValue) throws UnsupportedMessageException
defaultValue when the mapping
for the specified key does not exist or is not readable.UnsupportedMessageException - if the receiver does not support reading at all. An empty
receiver with no readable hash entries supports the read operation (even though
there is nothing to read), therefore it returns the defaultValue for all
arguments instead.Interop.isHashEntryReadable(Object, Object),
Interop.readHashValue(Object, Object)public static boolean isHashEntryModifiable(Object receiver, Object key)
true if mapping for the specified key exists and is
writable. This method may only return
true if Interop.hasHashEntries(Object) returns true as well and
Interop.isHashEntryInsertable(Object, Object) returns false. Invoking this message
does not cause any observable side-effects. Returns false by default.Interop.writeHashEntry(Object, Object, Object)public static boolean isHashEntryInsertable(Object receiver, Object key)
true if mapping for the specified key does not exist and is
writable. This method may only return
true if Interop.hasHashEntries(Object) returns true as well and
Interop.isHashEntryExisting(Object, Object) returns false. Invoking this message
does not cause any observable side-effects. Returns false by default.Interop.writeHashEntry(Object, Object, Object)public static boolean isHashEntryWritable(Object receiver, Object key)
public static void writeHashEntry(Object receiver, Object key, Object value) throws UnsupportedMessageException, UnknownKeyException, UnsupportedTypeException
modifiable, or not
existing and insertable.UnsupportedMessageException - when the receiver does not support writing at all, e.g.
when it is immutable.UnknownKeyException - if mapping for the specified key is not
modifiable nor
insertable.UnsupportedTypeException - if the provided key type or value type is not allowed to be
written.public static boolean isHashEntryRemovable(Object receiver, Object key)
true if mapping for the specified key exists and is removable. This method
may only return true if Interop.hasHashEntries(Object) returns true as well
and Interop.isHashEntryInsertable(Object, Object) returns false. Invoking this
message does not cause any observable side-effects. Returns false by default.Interop.removeHashEntry(Object, Object)public static void removeHashEntry(Object receiver, Object key) throws UnsupportedMessageException, UnknownKeyException
removable.UnsupportedMessageException - when the receiver does not support removing at all, e.g.
when it is immutable.UnknownKeyException - if the given mapping is not
removable, e.g. the receiver does
not have a mapping for given key.Interop.isHashEntryRemovable(Object, Object)public static boolean isHashEntryExisting(Object receiver, Object key)
true if mapping for a given key is existing. The mapping is existing if it is
modifiable,
readable or
removable.public static Object getHashEntriesIterator(Object receiver) throws UnsupportedMessageException
iterator of array elements. The
first array element is a key, the second array element is an associated value. Array returned
by the iterator may be modifiable but detached from the hash, updating the array elements may
not update the hash. So even if array elements are
modifiable always use
Interop.writeHashEntry(Object, Object, Object) to update the hash mapping.UnsupportedMessageException - if and only if Interop.hasHashEntries(Object) returns
false for the same receiver.public static Object getHashKeysIterator(Object receiver) throws UnsupportedMessageException
iterator.UnsupportedMessageException - if and only if Interop.hasHashEntries(Object) returns
false for the same receiver.public static Object getHashValuesIterator(Object receiver) throws UnsupportedMessageException
iterator.UnsupportedMessageException - if and only if Interop.hasHashEntries(Object) returns
false for the same receiver.