Class Literal
java.lang.Object
software.amazon.smithy.rulesengine.language.util.MandatorySourceLocation
software.amazon.smithy.rulesengine.language.syntax.expr.Expression
software.amazon.smithy.rulesengine.language.syntax.expr.Literal
- All Implemented Interfaces:
FromSourceLocation
,ToNode
,TypeCheck
Literals allow rules and properties to define arbitrarily nested JSON structures (e.g.for properties)
They support template strings, but _do not_ support template objects since that creates ambiguity. Template
s
are a basic example of literals–literal strings. Literals can also be booleans, objects, integers or tuples.
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescription<T> T
accept
(Literal.Vistor<T> visitor) Invokes the providedLiteral.Vistor
.<R> R
accept
(ExpressionVisitor<R> visitor) Invoke theExpressionVisitor
functions for this expression.asBool()
Attempts to convert the literal to aBoolean
if possible.Attempts to convert the literal to anLiteral.Integer
.asRecord()
Attempts to convert the literal to a map ofIdentifier
toLiteral
.asString()
Attempts to convert the literal to aTemplate
if possible.asTuple()
Attempts to convert the literal to a list ofLiteral
values.static Literal
bool
(boolean value) Constructs a bool literal from a boolean value.boolean
evaluate
(RuleEvaluator evaluator) Attempts to convert the literal to aString
.static Literal
Constructs a literal from aNode
based on the Node's type.Gets the source location of a value.int
hashCode()
static Literal
integer
(int value) Constructs an integer literal from an integer value.static Literal
record
(Map<Identifier, Literal> record) Constructs a record literal of values.static Literal
Constructs a string literal from aTemplate
value.toNode()
Converts a value to aNode
.toString()
Returns the string representation of the literal.static Literal
Constructs a tuple literal of values.typeCheckLocal
(Scope<Type> scope)
-
Method Details
-
tuple
Constructs a tuple literal of values.- Parameters:
values
- the values.- Returns:
- the tuple literal.
-
record
Constructs a record literal of values.- Parameters:
record
- a map of values to be converted to a record.- Returns:
- the record literal.
-
string
Constructs a string literal from aTemplate
value.- Parameters:
value
- the template value.- Returns:
- the string literal.
-
integer
Constructs an integer literal from an integer value.- Parameters:
value
- the integer value.- Returns:
- the integer literal.
-
bool
Constructs a bool literal from a boolean value.- Parameters:
value
- the boolean value.- Returns:
- the bool literal.
-
fromNode
Constructs a literal from aNode
based on the Node's type.- Parameters:
node
- a node to construct as a literal.- Returns:
- the literal representation of the node.
-
expectLiteralString
Attempts to convert the literal to aString
. Otherwise throws an exception.- Returns:
- the literal as a string.
-
asBool
Attempts to convert the literal to aBoolean
if possible. Otherwise, returns an empty optional.- Returns:
- an optional boolean.
-
asString
Attempts to convert the literal to aTemplate
if possible. Otherwise, returns an empty optional.- Returns:
- an optional boolean.
-
asRecord
Attempts to convert the literal to a map ofIdentifier
toLiteral
. Otherwise, returns an empty optional.- Returns:
- an optional map.
-
asTuple
Attempts to convert the literal to a list ofLiteral
values. Otherwise, returns an empty optional.- Returns:
- the optional list.
-
asInteger
Attempts to convert the literal to anLiteral.Integer
. Otherwise, returns an empty optional.- Returns:
- the optional integer.
-
accept
Invokes the providedLiteral.Vistor
.- Type Parameters:
T
- the visitor return type.- Parameters:
visitor
- the visitor.- Returns:
- the return value of the vistor.
-
toString
Returns the string representation of the literal. -
getSourceLocation
Description copied from interface:FromSourceLocation
Gets the source location of a value.- Specified by:
getSourceLocation
in interfaceFromSourceLocation
- Overrides:
getSourceLocation
in classMandatorySourceLocation
- Returns:
- Returns the source location of the value.
-
accept
Description copied from class:Expression
Invoke theExpressionVisitor
functions for this expression.- Specified by:
accept
in classExpression
- Type Parameters:
R
- the visitor return type.- Parameters:
visitor
- the visitor to be invoked.- Returns:
- the return value of the visitor.
-
hashCode
public int hashCode()- Specified by:
hashCode
in classExpression
-
equals
- Specified by:
equals
in classExpression
-
typeCheckLocal
- Specified by:
typeCheckLocal
in classExpression
-
evaluate
- Parameters:
evaluator
- the rule-set evaluator.- Returns:
- the resulting value.
-
toNode
Description copied from interface:ToNode
Converts a value to aNode
.- Returns:
- Returns the creates Node.
-