Class StaticShape.Builder

java.lang.Object
com.oracle.truffle.api.staticobject.StaticShape.Builder
Enclosing class:
StaticShape<T>

public static final class StaticShape.Builder extends Object
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 Details

    • property

      public StaticShape.Builder property(StaticProperty property, Class<?> type, boolean storeAsFinal)
      Adds a 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.
      Parameters:
      property - the StaticProperty to be added
      type - the type of the StaticProperty 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 shape
      NullPointerException - 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 by StaticShape.getFactory() implements DefaultStaticObjectFactory and static objects extend Object.
      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

      public <T> StaticShape<T> build(StaticShape<T> parentShape)
      Builds a new static shape that extends the provided parent 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.
      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

      public <T> StaticShape<T> build(Class<?> superClass, Class<T> factoryInterface)
      Builds a new static shape using the configuration of this builder. The factory class returned by StaticShape.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 override Object.clone() with a final method
      Type Parameters:
      T - the class of the factory interface
      Parameters:
      superClass - the class that static objects must extend
      factoryInterface - the factory interface that the factory class returned by StaticShape.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, 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 method
      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 factory interface.
      Since:
      21.3.0
      See Also: