java.lang.Object
software.amazon.smithy.rulesengine.language.syntax.SyntaxElement
software.amazon.smithy.rulesengine.language.syntax.expressions.Expression
All Implemented Interfaces:
FromSourceLocation, ToNode, TypeCheck, ToCondition, ToExpression
Direct Known Subclasses:
LibraryFunction, Literal, Reference

public abstract class Expression extends SyntaxElement implements FromSourceLocation, ToNode, TypeCheck
A dynamically computed expression.

Expressions are the fundamental building block of the rule language.

  • Constructor Details

  • Method Details

    • of

      public static Literal of(boolean value)
    • of

      public static Literal of(int value)
      Construct an integer literal for the given value, and returns it as an expression.
      Parameters:
      value - the integer value.
      Returns:
      the integer value as a literal expression.
    • of

      public static Literal of(String value)
      Constructs a string literal for the given values.
      Parameters:
      value - the string value.
      Returns:
      the string value as a literal.
    • fromNode

      public static Expression fromNode(Node node)
      Constructs an expression from the provided Node.
      Parameters:
      node - the node to construct the expression from.
      Returns:
      the expression.
    • fromNode

      public static Expression fromNode(Node node, EndpointComponentFactory factory)
      Constructs an expression from the provided Node, resolving any functions (including functions nested as arguments) using the given EndpointComponentFactory.

      When factory is null, the default statically-discovered function factory is used. Threading the factory here ensures functions used as arguments to other functions are resolved against the same classloader as the enclosing rule-set.

      Parameters:
      node - the node to construct the expression from.
      factory - the factory used to resolve functions, or null.
      Returns:
      the expression.
    • parseShortform

      public static Expression parseShortform(String shortForm, FromSourceLocation context)
      Parse a value from a "short form" used within a template.
      Parameters:
      shortForm - the shortform value
      Returns:
      the parsed expression
    • getReference

      public static Reference getReference(Identifier name, FromSourceLocation context)
      Constructs a Reference for the given Identifier at the given location.
      Parameters:
      name - the referenced identifier.
      context - the source location.
      Returns:
      the reference.
    • getReference

      public static Reference getReference(Identifier name)
      Constructs a Reference for the given Identifier.
      Parameters:
      name - the referenced identifier.
      Returns:
      the reference.
    • getReference

      public static Reference getReference(String name)
      Constructs a Reference for the given Identifier.
      Parameters:
      name - the referenced identifier.
      Returns:
      the reference.
    • getLiteral

      public static Literal getLiteral(StringNode node)
      Constructs a Literal from the given StringNode.
      Parameters:
      node - the node to construct the literal from.
      Returns:
      the string node as a literal.
    • getReferences

      public final Set<String> getReferences()
      Get the set of variables that this condition references.
      Returns:
      variable references by name.
    • calculateReferences

      protected Set<String> calculateReferences()
      Computes the references of an expression.
      Returns:
      the computed references.
    • accept

      public abstract <R> R accept(ExpressionVisitor<R> visitor)
      Invoke the ExpressionVisitor functions for this expression.
      Type Parameters:
      R - the visitor return type.
      Parameters:
      visitor - the visitor to be invoked.
      Returns:
      the return value of the visitor.
    • typeCheckLocal

      protected abstract Type typeCheckLocal(Scope<Type> scope) throws InnerParseError
      Throws:
      InnerParseError
    • type

      public Type type()
      Returns the type for this expression, throws a runtime exception if typeCheck has not been invoked.
      Returns:
      the type.
    • toExpression

      public Expression toExpression()
      Description copied from interface: ToExpression
      Convert this into an expression.
      Specified by:
      toExpression in interface ToExpression
      Returns:
      the expression.
    • hashCode

      public abstract int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public abstract boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getSourceLocation

      public SourceLocation getSourceLocation()
      Description copied from interface: FromSourceLocation
      Gets the source location of a value.
      Specified by:
      getSourceLocation in interface FromSourceLocation
      Returns:
      Returns the source location of the value.
    • typeCheck

      public Type typeCheck(Scope<Type> scope)
      Description copied from interface: TypeCheck
      Checks whether the given types within a scope satisfy the constraints.
      Specified by:
      typeCheck in interface TypeCheck
      Parameters:
      scope - the scope to evaluate.
      Returns:
      the type validated by the scope check.