Class Scope<T>
java.lang.Object
software.amazon.smithy.rulesengine.language.evaluation.Scope<T>
- Type Parameters:
T
- The type of values in scope.
Scope is a stack for tracking facts for named values of the given type.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionexpectValue
(Identifier name) Gets the first value in scope for the specified identifier, throwingInnerParseError
if the identifier is undefined in all the scope.Creates aScope
instance from the given Node information.getDeclaration
(Identifier name) Gets the first declaration in scope for the specified identifier.getValue
(Identifier name) Gets the first value in scope for the specified identifier.<U> U
Assesses a value supplier in the current scope.void
Inserts a named value into the current scope.void
insert
(Identifier name, T value) Inserts a named value into the current scope.boolean
Gets if a reference is non-null in the current scope.void
pop()
Pops the most recentScopeLayer
out of the current scope.void
push()
Pushes an emptyScopeLayer
into the current scope.void
setNonNull
(Reference name) Inserts a non-null reference into the current scope.toString()
-
Constructor Details
-
Scope
public Scope()Crates a new, empty scope with a single layer.
-
-
Method Details
-
fromNode
Creates aScope
instance from the given Node information.- Parameters:
node
- the node to deserialize.- Returns:
- the created Scope.
-
inScope
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 emptyScopeLayer
into the current scope. -
pop
public void pop()Pops the most recentScopeLayer
out of the current scope. -
insert
Inserts a named value into the current scope.- Parameters:
name
- the name of the value to insert.value
- the value to insert.
-
insert
Inserts a named value into the current scope.- Parameters:
name
- the name of the value to insert.value
- the value to insert.
-
setNonNull
Inserts a non-null reference into the current scope.- Parameters:
name
- the name of the reference to insert.
-
isNonNull
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
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
Gets the first value in scope for the specified identifier, throwingInnerParseError
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
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
-