Interface TypeBuilder


public interface TypeBuilder

Interface for constructing riskscape Type objects from a riskscape type-expression, e.g. # returns a simple text type text # returns an integer that can be null nullable(integer) # returns a one-based enum containing foo -1, bar -2, baz -3 enum('foo', 'bar', 'baz') # returns a WithinRange type of Integers between 0 and 100 range(integer, 0, 100) # return a struct struct(animal: enum('cat', 'dog', 'pig'), weight: range(floating, 0, 1000000))

  • Method Details

    • build

      Type build(String typeExpression)

      Construct a Riskscape Type from a type-expression.

      Throws:
      TypeBuildingException - if there was a problem building the type
    • buildSimpleType

      Type buildSimpleType(AST.Symbol symbol)

      Construct a type from a symbol. These are normally going to be SimpleTypes but this is not enforced

    • buildComplexType

      Type buildComplexType(AST.ComplexType ast)

      Construct a type from a complex type expression - e.g. the type is a composition of other types

    • getTypeSet

      TypeSet getTypeSet()

      A type set to use for referring to user-defined LinkedTypes

    • expectType

      default Type expectType(AST ast, Function<AST,RuntimeException> orElse)

      Helper method for TypeConstructors for expecting an AST to be either a AST.Symbol or a AST.ComplexType. If ast is a type-ish node, then a Type is built and returned

      Parameters:
      orElse - exception supplier if ast is not of the correct type
    • expectConstant

      default Object expectConstant(AST ast, Function<AST,RuntimeException> orElse)

      Helper method for TypeConstructors that expects an AST to be an AST.Constant and return its java value.

      Parameters:
      orElse - exception supplier if ast is not an AST.Constant
    • expectConstantsOfType

      default List<Object> expectConstantsOfType(AST.ComplexType complexType, Type subType, List<AST> args, int argOffset)

      Helper method for TypeConstructors that expects the tail of an argument list to all be constants that coerce to a particular riskscape type.

      Parameters:
      complexType - the AST we are building a Type from
      subType - the Type that all constants must coerce to
      args - the argument list
      argOffset - index to start from in the argument list
      Returns:
      the coerced list of arguments
    • expectAST

      default <T extends AST> T expectAST(Class<T> expectedASTClass, AST ast, Function<AST,RuntimeException> orElse)

      Helper method for TypeConstructors for return a cast AST where it is a particular type of AST node.

      Parameters:
      expectedASTClass - the desired class
      ast - the node to check
      orElse - an exception supplier if the ast is not of the desired type.
      Returns:
      the ast, cast according to expectedASTClass