public final class DynamicObject
extends java.lang.Object
The methods plug
and propertyMissing
are left undocumented. They are being used
by the Golo runtime to dispatch method invocations on dynamic objects.
Modifier and Type | Field and Description |
---|---|
static java.lang.invoke.MethodHandle |
DISPATCH_CALL |
static java.lang.invoke.MethodHandle |
DISPATCH_GET |
static java.lang.invoke.MethodHandle |
DISPATCH_SET |
Constructor and Description |
---|
DynamicObject() |
Modifier and Type | Method and Description |
---|---|
DynamicObject |
copy() |
DynamicObject |
define(java.lang.String name,
java.lang.Object value)
Defines a property.
|
static java.lang.Object |
dispatchCall(java.lang.String property,
java.lang.Object... args)
Dispatch dynamic object "methods".
|
static java.lang.Object |
dispatchGetterStyle(java.lang.String property,
DynamicObject object)
Dispatches getter-style dynamic object methods, i.e., methods with a receiver and no argument.
|
static java.lang.Object |
dispatchSetterStyle(java.lang.String property,
DynamicObject object,
java.lang.Object arg)
Dispatches setter-style dynamic object methods, i.e., methods with a receiver and exactly 1 argument.
|
DynamicObject |
fallback(java.lang.Object value)
Let the user define a fallback behavior.
|
DynamicObject |
freeze()
Freezes a dynamic object, meaning that its properties cannot be added, updated and removed anymore.
|
java.lang.Object |
get(java.lang.String name) |
boolean |
hasMethod(java.lang.String method)
Verify if a method is defined for the dynamic object.
|
java.lang.invoke.MethodHandle |
invoker(java.lang.String property,
java.lang.invoke.MethodType type)
Gives an invoker method handle for a given property.
|
boolean |
isFrozen()
Tells whether the dynamic object is frozen or not.
|
DynamicObject |
mixin(DynamicObject other)
Mixes all properties from another dynamic object into this one, overwriting existing properties.
|
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> |
properties() |
DynamicObject |
undefine(java.lang.String name)
Removes a property.
|
public static final java.lang.invoke.MethodHandle DISPATCH_CALL
public static final java.lang.invoke.MethodHandle DISPATCH_GET
public static final java.lang.invoke.MethodHandle DISPATCH_SET
public DynamicObject define(java.lang.String name, java.lang.Object value)
name
- the property name.value
- the property value.java.lang.IllegalStateException
- if the dynamic object is frozen.public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> properties()
public java.lang.Object get(java.lang.String name)
name
- the property name.public DynamicObject undefine(java.lang.String name)
name
- the property name.public DynamicObject copy()
public DynamicObject mixin(DynamicObject other)
other
- the dynamic object to mix the properties from.public DynamicObject freeze()
public boolean isFrozen()
true
if frozen, false
otherwise.public static java.lang.Object dispatchCall(java.lang.String property, java.lang.Object... args) throws java.lang.Throwable
args
.property
- the method property in the dynamic object.args
- the arguments.java.lang.Throwable
- in case everything is wrong.public static java.lang.Object dispatchGetterStyle(java.lang.String property, DynamicObject object) throws java.lang.Throwable
property
- the method property in the dynamic object.object
- the receiver object.java.lang.Throwable
- in case everything is wrong.public static java.lang.Object dispatchSetterStyle(java.lang.String property, DynamicObject object, java.lang.Object arg) throws java.lang.Throwable
property
- the method property in the dynamic object.object
- the receiver object.arg
- the arguments.java.lang.Throwable
- in case everything is wrong.public java.lang.invoke.MethodHandle invoker(java.lang.String property, java.lang.invoke.MethodType type)
While this method may be useful in itself, it is mostly relevant for the Golo runtime internals so as to allow calling "methods" on dynamic objects, as in:
# obj is some dynamic object... obj: foo("bar") println(foo: bar()) obj: define("plop", |this| -> "Plop!") println(obj: plop())
property
- the name of a property.type
- the expected invoker type with at least one parameter (the dynamic object as a receiver).public boolean hasMethod(java.lang.String method)
method
- the method name.true
if method is defined, false
otherwise.public DynamicObject fallback(java.lang.Object value)
value
- the fallback value