java.lang.Object
software.amazon.smithy.rulesengine.language.util.MandatorySourceLocation
software.amazon.smithy.rulesengine.language.syntax.expr.Expression
All Implemented Interfaces:
FromSourceLocation, ToNode, TypeCheck
Direct Known Subclasses:
Function, GetAttr, Literal, Reference

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

Expressions are the fundamental building block of the rule language.

  • Constructor Details

  • Method Details

    • of

      public static Expression of(boolean value)
    • of

      public static Expression 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.
    • 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
    • reference

      public static Reference reference(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.
    • literal

      public static Literal literal(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.
    • 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.
    • hashCode

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

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

      public GetAttr getAttr(String path)
      Constructs a GetAttr expression containing the given path string.
      Parameters:
      path - the path.
      Returns:
      the GetAttr expression.
    • getAttr

      public GetAttr getAttr(Identifier path)
      Constructs a GetAttr expression containing the given Identifier.
      Parameters:
      path - the path Identifier.
      Returns:
      the GetAttr expression.
    • typeCheck

      public Type typeCheck(Scope<Type> scope)
      Specified by:
      typeCheck in interface TypeCheck
    • type

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

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

      public IsSet isSet()
      Returns an IsSet expression for this instance.
      Returns:
      the IsSet expression.
    • equal

      public Function equal(boolean value)
      Returns a BooleanEquals expression comparing this expression to the provided boolean value.
      Parameters:
      value - the value to compare against.
      Returns:
      the BooleanEquals Function.
    • not

      public Not not()
      Returns a Not expression of this instance.
      Returns:
      the Not expression.
    • equal

      public Function equal(String value)
      Returns a StringEquals function of this expression and the given string value.
      Parameters:
      value - the string value to compare this expression to.
      Returns:
      the StringEquals Function.
    • parseArn

      public Function parseArn()
      Returns a ParseArn function of this expression.
      Returns:
      the ParseArn function expression.
    • substring

      public Function substring(int startIndex, int stopIndex, Boolean reverse)
      Returns a substring expression of this expression.
      Parameters:
      startIndex - the starting index of the string.
      stopIndex - the ending index of the string.
      reverse - whether the indexing is should start from end of the string to start.
      Returns:
      the Substring function expression.
    • isValidHostLabel

      public Function isValidHostLabel(boolean allowDots)
      Returns a isValidHostLabel expression of this expression.
      Parameters:
      allowDots - whether the UTF-8 . is considered valid within a host label.
      Returns:
      the isValidHostLabel function expression.
    • isVirtualHostableS3Bucket

      public Function isVirtualHostableS3Bucket(boolean allowDots)
      Returns a isVirtualHostableS3Bucket expression of this expression.
      Parameters:
      allowDots - whether the UTF-8 . is considered valid within a host label.
      Returns:
      the isVirtualHostableS3Bucket function expression.
    • parseUrl

      public Function parseUrl()
      Returns a parseUrl expression of this expression.
      Returns:
      the parseUrl function expression.
    • template

      public String template()
      Converts this expression to a string template. By default this implementation returns a RuntimeException.
      Returns:
      the string template.