Class Expression
- java.lang.Object
-
- software.amazon.smithy.rulesengine.language.util.MandatorySourceLocation
-
- software.amazon.smithy.rulesengine.language.syntax.expr.Expression
-
- All Implemented Interfaces:
FromSourceLocation,ToNode,TypeCheck
public abstract class Expression extends MandatorySourceLocation implements TypeCheck, ToNode
A dynamically computed expression.Expressions are the fundamental building block of the rule language.
-
-
Constructor Summary
Constructors Constructor Description Expression(FromSourceLocation sourceLocation)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract <R> Raccept(ExpressionVisitor<R> visitor)Invoke theExpressionVisitorfunctions for this expression.Functionequal(boolean value)Returns aBooleanEqualsexpression comparing this expression to the provided boolean value.Functionequal(java.lang.String value)Returns a StringEquals function of this expression and the given string value.abstract booleanequals(java.lang.Object obj)static ExpressionfromNode(Node node)Constructs an expression from the providedNode.GetAttrgetAttr(java.lang.String path)Constructs aGetAttrexpression containing the given path string.GetAttrgetAttr(Identifier path)Constructs aGetAttrexpression containing the givenIdentifier.abstract inthashCode()IsSetisSet()Returns an IsSet expression for this instance.FunctionisValidHostLabel(boolean allowDots)Returns a isValidHostLabel expression of this expression.FunctionisVirtualHostableS3Bucket(boolean allowDots)Returns a isVirtualHostableS3Bucket expression of this expression.static Literalliteral(StringNode node)Constructs aLiteralfrom the givenStringNode.Notnot()Returns a Not expression of this instance.static Expressionof(boolean value)static Expressionof(int value)Construct an integer literal for the given value, and returns it as an expression.static Literalof(java.lang.String value)Constructs a string literal for the given values.FunctionparseArn()Returns a ParseArn function of this expression.static ExpressionparseShortform(java.lang.String shortForm, FromSourceLocation context)Parse a value from a "short form" used within a template.FunctionparseUrl()Returns a parseUrl expression of this expression.static Referencereference(Identifier name, FromSourceLocation context)Constructs aReferencefor the givenIdentifierat the given location.Functionsubstring(int startIndex, int stopIndex, java.lang.Boolean reverse)Returns a substring expression of this expression.java.lang.Stringtemplate()Converts this expression to a string template.Typetype()Returns the type for this expression, throws a runtime exception iftypeCheckhas not been invoked.TypetypeCheck(Scope<Type> scope)protected abstract TypetypeCheckLocal(Scope<Type> scope)-
Methods inherited from class software.amazon.smithy.rulesengine.language.util.MandatorySourceLocation
getSourceLocation
-
-
-
-
Constructor Detail
-
Expression
public Expression(FromSourceLocation sourceLocation)
-
-
Method Detail
-
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(java.lang.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 providedNode.- Parameters:
node- the node to construct the expression from.- Returns:
- the expression.
-
parseShortform
public static Expression parseShortform(java.lang.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 aReferencefor the givenIdentifierat the given location.- Parameters:
name- the referenced identifier.context- the source location.- Returns:
- the reference.
-
literal
public static Literal literal(StringNode node)
Constructs aLiteralfrom the givenStringNode.- 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 theExpressionVisitorfunctions 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:
hashCodein classjava.lang.Object
-
equals
public abstract boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
getAttr
public GetAttr getAttr(java.lang.String path)
Constructs aGetAttrexpression containing the given path string.- Parameters:
path- the path.- Returns:
- the
GetAttrexpression.
-
getAttr
public GetAttr getAttr(Identifier path)
Constructs aGetAttrexpression containing the givenIdentifier.- Parameters:
path- the pathIdentifier.- Returns:
- the
GetAttrexpression.
-
type
public Type type()
Returns the type for this expression, throws a runtime exception iftypeCheckhas 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 aBooleanEqualsexpression comparing this expression to the provided boolean value.- Parameters:
value- the value to compare against.- Returns:
- the BooleanEquals
Function.
-
equal
public Function equal(java.lang.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, java.lang.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 java.lang.String template()
Converts this expression to a string template. By default this implementation returns aRuntimeException.- Returns:
- the string template.
-
-