Class DynamicObject.GetNode
java.lang.Object
com.oracle.truffle.api.nodes.Node
com.oracle.truffle.api.object.DynamicObject.GetNode
- All Implemented Interfaces:
NodeInterface, Cloneable
- Enclosing class:
DynamicObject
Gets the value of a property or returns a default value if no such property exists.
Specialized return type variants are available for when a primitive result is expected.
- Since:
- 25.1
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Node
Node.Child, Node.Children -
Method Summary
Modifier and TypeMethodDescriptionstatic DynamicObject.GetNodecreate()abstract Objectexecute(DynamicObject receiver, Object key, Object defaultValue) Gets the value of an existing property or returns the provided default value if no such property exists.abstract doubleexecuteDouble(DynamicObject receiver, Object key, Object defaultValue) Gets the value of an existing property or returns the provided default value if no such property exists.abstract intexecuteInt(DynamicObject receiver, Object key, Object defaultValue) Gets the value of an existing property or returns the provided default value if no such property exists.abstract longexecuteLong(DynamicObject receiver, Object key, Object defaultValue) Gets the value of an existing property or returns the provided default value if no such property exists.static DynamicObject.GetNodeMethods inherited from class Node
accept, adoptChildren, atomic, atomic, copy, deepCopy, getChildren, getCost, getDebugProperties, getDescription, getEncapsulatingSourceSection, getLock, getParent, getRootNode, getSourceSection, insert, insert, isAdoptable, isSafelyReplaceableBy, notifyInserted, onReplace, replace, replace, reportPolymorphicSpecialize, reportReplace, toString
-
Method Details
-
execute
Gets the value of an existing property or returns the provided default value if no such property exists.Usage examples:
Simple use of
DynamicObject.GetNodewith a pre-interned symbol key.abstract static class GetSimpleNode extends Node { abstract Object execute(DynamicObject receiver, Object key); @Specialization static Object doCached(MyDynamicObjectSubclass receiver, Symbol key, @Cached DynamicObject.GetNode getNode) { return getNode.execute(receiver, key, NULL_VALUE); } }Simple use of
DynamicObject.GetNodewith a string key cached by equality.abstract static class GetStringKeyNode extends Node { abstract Object execute(DynamicObject receiver, Object key); @Specialization(guards = "equalNode.execute(key, cachedKey, UTF_16)", limit = "3") static Object doCached(MyDynamicObjectSubclass receiver, TruffleString key, @Cached("key") TruffleString cachedKey, @Cached TruffleString.EqualNode equalNode, @Cached DynamicObject.GetNode getNode) { return getNode.execute(receiver, cachedKey, NULL_VALUE); } }- Parameters:
key- the property key, compared by identity (==), not equality (equals). SeeDynamicObjectfor more information.defaultValue- value to be returned if the property does not exist- Returns:
- the property's value if it exists, else
defaultValue. - Since:
- 25.1
-
executeInt
public abstract int executeInt(DynamicObject receiver, Object key, Object defaultValue) throws UnexpectedResultException Gets the value of an existing property or returns the provided default value if no such property exists.- Parameters:
key- the property key, compared by identity (==), not equality (equals). SeeDynamicObjectfor more information.defaultValue- the value to be returned if the property does not exist- Returns:
- the property's value if it exists, else
defaultValue. - Throws:
UnexpectedResultException- if the value (or default value if the property is missing) is not anint- Since:
- 25.1
- See Also:
-
executeLong
public abstract long executeLong(DynamicObject receiver, Object key, Object defaultValue) throws UnexpectedResultException Gets the value of an existing property or returns the provided default value if no such property exists.- Parameters:
key- the property key, compared by identity (==), not equality (equals). SeeDynamicObjectfor more information.defaultValue- the value to be returned if the property does not exist- Returns:
- the property's value if it exists, else
defaultValue. - Throws:
UnexpectedResultException- if the value (or default value if the property is missing) is not anlong- Since:
- 25.1
- See Also:
-
executeDouble
public abstract double executeDouble(DynamicObject receiver, Object key, Object defaultValue) throws UnexpectedResultException Gets the value of an existing property or returns the provided default value if no such property exists.- Parameters:
key- the property key, compared by identity (==), not equality (equals). SeeDynamicObjectfor more information.defaultValue- the value to be returned if the property does not exist- Returns:
- the property's value if it exists, else
defaultValue. - Throws:
UnexpectedResultException- if the value (or default value if the property is missing) is not andouble- Since:
- 25.1
- See Also:
-
create
- Since:
- 25.1
-
getUncached
- Since:
- 25.1
-