java.lang.Object
software.amazon.smithy.rulesengine.language.evaluation.Scope<T>
Type Parameters:
T - The type of values in scope.

public final class Scope<T> extends Object
Scope is a stack for tracking facts for named values of the given type.
  • Constructor Details

    • Scope

      public Scope()
      Crates a new, empty scope with a single layer.
  • Method Details

    • fromNode

      public static Scope<Value> fromNode(Node node)
      Creates a Scope instance from the given Node information.
      Parameters:
      node - the node to deserialize.
      Returns:
      the created Scope.
    • inScope

      public <U> U inScope(Supplier<U> supplier)
      Assesses a value supplier in the current scope.
      Type Parameters:
      U - the type of the value returned by the supplier.
      Parameters:
      supplier - the value supplier to assess.
      Returns:
      the value returned by the supplier.
    • push

      public void push()
      Pushes an empty ScopeLayer into the current scope.
    • pop

      public void pop()
      Pops the most recent ScopeLayer out of the current scope.
    • insert

      public void insert(String name, T value)
      Inserts a named value into the current scope.
      Parameters:
      name - the name of the value to insert.
      value - the value to insert.
    • insert

      public void insert(Identifier name, T value)
      Inserts a named value into the current scope.
      Parameters:
      name - the name of the value to insert.
      value - the value to insert.
    • setNonNull

      public void setNonNull(Reference name)
      Inserts a non-null reference into the current scope.
      Parameters:
      name - the name of the reference to insert.
    • isNonNull

      public boolean isNonNull(Reference reference)
      Gets if a reference is non-null in the current scope.
      Parameters:
      reference - the reference to check nullability for.
      Returns:
      true if the reference is non-null, false otherwise.
    • getDeclaration

      public Optional<Map.Entry<Identifier,T>> getDeclaration(Identifier name)
      Gets the first declaration in scope for the specified identifier.
      Parameters:
      name - the identifier to retrieve a declaration for.
      Returns:
      an optional of the declaration for the identifier, or empty otherwise.
    • expectValue

      public T expectValue(Identifier name) throws InnerParseError
      Gets the first value in scope for the specified identifier, throwing InnerParseError if the identifier is undefined in all the scope.
      Parameters:
      name - the identifier to retrieve a declaration for.
      Returns:
      the value for the identifier.
      Throws:
      InnerParseError - when the identifier has no value in the scope.
    • getValue

      public Optional<T> getValue(Identifier name)
      Gets the first value in scope for the specified identifier.
      Parameters:
      name - the identifier to retrieve a value for.
      Returns:
      an optional of the value for the identifier, or empty otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object