Package com.oracle.truffle.api.library
Annotation Interface GenerateLibrary.Abstract
- Enclosing class:
GenerateLibrary
Makes a library message abstract, but allows to keep a default implementation. By default,
abstract messages throw an
AbstractMethodError
if they are not exported for a given
receiver type. To customize this behavior the library message can specify a method body and
annotate it with GenerateLibrary.Abstract
to keep requiring an implementation from exports.
For example:
@GenerateLibrary public abstract class ArrayLibrary extends Library { @Abstract(ifExported = "read") public boolean isArray(Object receiver) { return false; } @Abstract(ifExported = "isArray") public int read(Object receiver, int index) { throw new UnsupportedOperationException(); } }In this example a receiver that does not export the
ArrayLibrary
will return
false
for isArray
and throw an
UnsupportedOperationException for read
calls. A message may be made
conditionally abstract by specifying the ifExported()
attribute.- Since:
- 19.0
- See Also:
-
Element Details
-
ifExported
String[] ifExportedSpecifies a message to be abstract only if another message is implemented. Multiple other messages can be specified. If the list is empty, the message is always abstract unlessifExportedAsWarning()
is not empty. If the list is not empty it takes precedence overifExportedAsWarning()
.For example:
@GenerateLibrary public abstract class ArrayLibrary extends Library { @Abstract(ifExported = "read") public boolean isArray(Object receiver) { return false; } @Abstract(ifExported = "isArray") public int read(Object receiver, int index) { throw new UnsupportedOperationException(); } }
In this example the isArray message only needs to be exported if the read message is exported and vice-versa.- Since:
- 19.0
- Default:
{}
-
ifExportedAsWarning
String[] ifExportedAsWarningSpecifies a message to be abstract only if another message is implemented. Multiple other messages can be specified. The message is not actually made abstract unless it is in theifExported()
list. Only a warning is produced that prompts the user to implement the messageFor example:
@GenerateLibrary public abstract class MaybeNumberLibrary extends Library { public boolean isNumber(Object receiver) { return false; } @Abstract(ifExportedAsWarning = "isNumber") public Number getNumber(Object receiver) { throw new UnsupportedOperationException(); } }
In this example, if the isNumber message is exported and the getNumber message is not, the user gets a warning.- Since:
- 23.0
- Default:
{}
-