Class StaticShape.Builder
java.lang.Object
com.oracle.truffle.api.staticobject.StaticShape.Builder
- Enclosing class:
StaticShape<T>
Builder class to construct
StaticShape
instances. The builder instance is not
thread-safe and must not be used from multiple threads at the same time.- Since:
- 21.3.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds a new static shape using the configuration of this builder.<T> StaticShape
<T> build
(StaticShape<T> parentShape) Builds a new static shape that extends the provided parentStaticShape
.<T> StaticShape
<T> Builds a new static shape using the configuration of this builder.property
(StaticProperty property, Class<?> type, boolean storeAsFinal) Adds aStaticProperty
to the static shape to be constructed.
-
Method Details
-
property
Adds aStaticProperty
to the static shape to be constructed. The property id cannot be null or an empty String. It is not allowed to add two properties with the same id to the same builder, or to add the same property to more than one builder. Static shapes that extend a parent shape can have properties with the same id of those in the parent shape. Only property accesses that match the specified type are allowed. Property values can be optionally stored in a final field. Accesses to such values might be specially optimized by the compiler. For example, reads might be constant-folded. It is up to the user to enforce that property values stored as final are not assigned more than once.- Parameters:
property
- theStaticProperty
to be addedtype
- the type of theStaticProperty
to be added.storeAsFinal
- if this property value can be stored in a final field- Returns:
- the Builder instance
- Throws:
IllegalArgumentException
- if more than 65535 properties are added, or if the property id is an empty string or it is equal to the id of another static property already registered to this builder.IllegalStateException
- if this method is invoked after building a static shapeNullPointerException
- if the property id is null- Since:
- 21.3.0
- See Also:
-
build
Builds a new static shape using the configuration of this builder. The factory class returned byStaticShape.getFactory()
implementsDefaultStaticObjectFactory
and static objects extendObject
.- Returns:
- the new
StaticShape
- Throws:
IllegalStateException
- if a static property was added to more than one builder or multiple times to the same builder, if this method is invoked more than once, or if one of the static property types is not visible to the class loader that loaded the default factory interface.- Since:
- 21.3.0
- See Also:
-
build
Builds a new static shape that extends the provided parentStaticShape
. Static properties of the parent shape can be used to access field values of static objects with the child shape. The factory class returned byStaticShape.getFactory()
extends the one of the parent shape and static objects extend the static object class allocated by the factory class of the parent shape.- Type Parameters:
T
- the generic type of the parent shape- Parameters:
parentShape
- the parent shape- Returns:
- the new
StaticShape
- Throws:
IllegalStateException
- if a static property was added to more than one builder or multiple times to the same builder, if this method is invoked more than once, or if one of the static property types is not visible to the class loader that loaded the default factory interface.- Since:
- 21.3.0
- See Also:
-
build
Builds a new static shape using the configuration of this builder. The factory class returned byStaticShape.getFactory()
implements factoryInterface and static objects extend superClass.The following constraints are enforced:
- factoryInterface must be an interface
- the arguments of every method in factoryInterface must match those of a visible constructor of superClass
- the return type of every method in factoryInterface must be assignable from the superClass
- superClass does not have abstract methods
- if superClass is
Cloneable
, it cannot overrideObject.clone()
with a final method
- Type Parameters:
T
- the class of the factory interface- Parameters:
superClass
- the class that static objects must extendfactoryInterface
- the factory interface that the factory class returned byStaticShape.getFactory()
must implement- Returns:
- the new
StaticShape
- Throws:
IllegalArgumentException
- if factoryInterface is not an interface, if the arguments of a method in factoryInterface do not match those of a visible constructor in superClass, if the return type of a method in factoryInterface is not assignable from superClass, ifStaticShape
is not visible to the class loader of factoryInterface, if superClass has abstract methods or if superClass isCloneable
and overridesObject.clone()
with a final methodIllegalStateException
- if a static property was added to more than one builder or multiple times to the same builder, if this method is invoked more than once, or if one of the static property types is not visible to the class loader that loaded the factory interface.- Since:
- 21.3.0
- See Also:
-