public abstract class ReflectionLibrary extends Library
resolving a
target message. Then the message can be sent to a receiver that may implement that message. The
message name and class may be resolved dynamically.
String messageName = "isArray";
Message message = Message.resolve(ArrayLibrary.class, messageName);
Object receiver = 42;
try {
ReflectionLibrary.getFactory().getUncached().send(receiver, message);
} catch (Exception e) {
// handle error
}
@ExportLibrary(ReflectionLibrary.class)
static class AgnosticWrapper {
final Object delegate;
AgnosticWrapper(Object delegate) {
this.delegate = delegate;
}
@ExportMessage
final Object send(Message message, Object[] args,
@CachedLibrary("this.delegate") ReflectionLibrary reflection) throws Exception {
// do before
Object result = reflection.send(delegate, message, args);
// do after
return result;
}
}
Node.Child, Node.Children| Modifier | Constructor and Description |
|---|---|
protected |
ReflectionLibrary()
Constructor for generated subclasses.
|
| Modifier and Type | Method and Description |
|---|---|
static LibraryFactory<ReflectionLibrary> |
getFactory()
Returns the library factory for
ReflectionLibrary. |
static ReflectionLibrary |
getUncached()
Returns the uncached automatically dispatched version of the reflection library.
|
static ReflectionLibrary |
getUncached(Object v)
Returns the uncached manually dispatched version of the reflection library.
|
Object |
send(Object receiver,
Message message,
Object... args)
Sends a given message to the target receiver with the provided arguments.
|
accept, adoptChildren, atomic, atomic, copy, deepCopy, getChildren, getCost, getDebugProperties, getDescription, getEncapsulatingSourceSection, getLock, getParent, getRootNode, getSourceSection, insert, insert, isAdoptable, isSafelyReplaceableBy, notifyInserted, onReplace, replace, replace, reportPolymorphicSpecialize, toStringprotected ReflectionLibrary()
public Object send(Object receiver, Message message, Object... args) throws Exception
IllegalArgumentException will be thrown.Exceptionpublic static LibraryFactory<ReflectionLibrary> getFactory()
ReflectionLibrary.public static ReflectionLibrary getUncached()
ReflectionLibrary.getFactory().getUncached().LibraryFactory.getUncached()public static ReflectionLibrary getUncached(Object v)
ReflectionLibrary.getFactory().getUncached(v).LibraryFactory.getUncached(Object)