public static final class StaticShape.Builder extends Object
StaticShape
instances. The builder instance is not
thread-safe and must not be used from multiple threads at the same time.StaticShape.newBuilder(TruffleLanguage)
Modifier and Type | Method and Description |
---|---|
StaticShape<DefaultStaticObjectFactory> |
build()
Builds a new static shape using the configuration of this
builder.
|
<T> StaticShape<T> |
build(Class<?> superClass,
Class<T> factoryInterface)
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 parent
StaticShape . |
StaticShape.Builder |
property(StaticProperty property,
Class<?> type,
boolean storeAsFinal)
Adds a
StaticProperty to the static shape to be constructed. |
public StaticShape.Builder property(StaticProperty property, Class<?> type, boolean storeAsFinal)
StaticProperty
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.property
- the StaticProperty
to be addedtype
- the type of the StaticProperty
to be added.storeAsFinal
- if this property value can be stored in a final fieldIllegalArgumentException
- 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
nullDefaultStaticProperty
public StaticShape<DefaultStaticObjectFactory> build()
StaticShape.getFactory()
implements
DefaultStaticObjectFactory
and static objects extend Object
.StaticShape
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.DefaultStaticObjectFactory
,
StaticShape.Builder.build(StaticShape)
,
StaticShape.Builder.build(Class, Class)
public <T> StaticShape<T> build(StaticShape<T> parentShape)
StaticShape
. Static properties of the parent shape
can be used to access field values of static objects with the child shape. The factory
class returned by StaticShape.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.T
- the generic type of the parent shapeparentShape
- the parent shapeStaticShape
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.StaticShape.Builder.build()
,
StaticShape.Builder.build(Class, Class)
public <T> StaticShape<T> build(Class<?> superClass, Class<T> factoryInterface)
StaticShape.getFactory()
implements
factoryInterface and static objects extend superClass.
The following constraints are enforced:
Cloneable
, it cannot override Object.clone()
with a
final method
T
- the class of the factory interfacesuperClass
- the class that static objects must extendfactoryInterface
- the factory interface that the factory class returned by
StaticShape.getFactory()
must implementStaticShape
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, if StaticShape
is not visible to
the class loader of factoryInterface, if superClass has abstract methods or
if superClass is Cloneable
and overrides Object.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.StaticShape.Builder.build()
,
StaticShape.Builder.build(StaticShape)