public final class DynamicObject extends 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 MethodHandle |
DISPATCH_CALL |
static MethodHandle |
DISPATCH_GET |
static MethodHandle |
DISPATCH_SET |
| Constructor and Description |
|---|
DynamicObject() |
| Modifier and Type | Method and Description |
|---|---|
DynamicObject |
copy() |
DynamicObject |
define(String name,
Object value)
Defines a property.
|
static Object |
dispatchCall(String property,
Object... args)
Dispatch dynamic object "methods".
|
static Object |
dispatchGetterStyle(String property,
DynamicObject object)
Dispatches getter-style dynamic object methods, i.e., methods with a receiver and no argument.
|
static Object |
dispatchSetterStyle(String property,
DynamicObject object,
Object arg)
Dispatches setter-style dynamic object methods, i.e., methods with a receiver and exactly 1 argument.
|
DynamicObject |
fallback(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.
|
Object |
get(String name) |
boolean |
hasMethod(String method)
Verify if a method is defined for the dynamic object.
|
MethodHandle |
invoker(String property,
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.
|
Set<Map.Entry<String,Object>> |
properties() |
DynamicObject |
undefine(String name)
Removes a property.
|
public static final MethodHandle DISPATCH_CALL
public static final MethodHandle DISPATCH_GET
public static final MethodHandle DISPATCH_SET
public DynamicObject define(String name, Object value)
name - the property name.value - the property value.IllegalStateException - if the dynamic object is frozen.public Object get(String name)
name - the property name.public DynamicObject undefine(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 Object dispatchCall(String property, Object... args) throws Throwable
args.property - the method property in the dynamic object.args - the arguments.Throwable - in case everything is wrong.public static Object dispatchGetterStyle(String property, DynamicObject object) throws Throwable
property - the method property in the dynamic object.object - the receiver object.Throwable - in case everything is wrong.public static Object dispatchSetterStyle(String property, DynamicObject object, Object arg) throws Throwable
property - the method property in the dynamic object.object - the receiver object.arg - the arguments.Throwable - in case everything is wrong.public MethodHandle invoker(String property, 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(String method)
method - the method name.true if method is defined, false otherwise.public DynamicObject fallback(Object value)
value - the fallback valueCopyright © 2015 Institut National des Sciences Appliquées de Lyon (INSA-Lyon). All rights reserved.