Class Ite
java.lang.Object
software.amazon.smithy.rulesengine.language.syntax.SyntaxElement
software.amazon.smithy.rulesengine.language.syntax.expressions.Expression
software.amazon.smithy.rulesengine.language.syntax.expressions.functions.LibraryFunction
software.amazon.smithy.rulesengine.language.syntax.expressions.functions.Ite
- All Implemented Interfaces:
FromSourceLocation,ToNode,TypeCheck,ToCondition,ToExpression
An if-then-else (ITE) function that returns one of two values based on a boolean condition.
This function is critical for avoiding SSA (Static Single Assignment) fragmentation in BDD compilation. By computing conditional values atomically without branching, it prevents the graph explosion that occurs when boolean flags like UseFips or UseDualStack create divergent paths with distinct variable identities.
Semantics: ite(condition, trueValue, falseValue)
- If condition is true, returns trueValue
- If condition is false, returns falseValue
- The condition must be a non-optional boolean (use coalesce to provide a default if needed)
Type checking rules (least upper bound of nullability):
ite(Boolean, T, T) => T- both non-optional, result is non-optionalite(Boolean, T, Optional<T>) => Optional<T>- any optional makes result optionalite(Boolean, Optional<T>, T) => Optional<T>- any optional makes result optionalite(Boolean, Optional<T>, Optional<T>) => Optional<T>- both optional, result is optional
Available since: rules engine 1.1.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from class software.amazon.smithy.rulesengine.language.syntax.expressions.functions.LibraryFunction
definition, functionNode -
Method Summary
Modifier and TypeMethodDescription<R> Raccept(ExpressionVisitor<R> visitor) Invoke theExpressionVisitorfunctions for this expression.Get the rules engine version that this syntax element is available since.static Ite.DefinitionGets theFunctionDefinitionimplementation.static IteofExpressions(ToExpression condition, ToExpression trueValue, ToExpression falseValue) Creates aItefunction from the given expressions.static IteofStrings(ToExpression conditionRef, String trueValue, String falseValue) Creates aItefunction with a reference condition and string values.protected TypetypeCheckLocal(Scope<Type> scope) Methods inherited from class software.amazon.smithy.rulesengine.language.syntax.expressions.functions.LibraryFunction
calculateReferences, canonicalize, equals, expectOneArgument, getArguments, getFunctionDefinition, getName, getSourceLocation, hashCode, shouldSwapArgs, toConditionBuilder, toNode, toStringMethods inherited from class software.amazon.smithy.rulesengine.language.syntax.expressions.Expression
fromNode, getLiteral, getReference, getReference, getReference, getReferences, of, of, of, parseShortform, toExpression, type, typeCheckMethods inherited from class software.amazon.smithy.rulesengine.language.syntax.SyntaxElement
booleanEqual, getAttr, getAttr, isSet, isValidHostLabel, not, parseUrl, stringEqual, substring, templateMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface software.amazon.smithy.rulesengine.language.syntax.ToCondition
toCondition, toCondition
-
Field Details
-
ID
- See Also:
-
-
Method Details
-
getDefinition
Gets theFunctionDefinitionimplementation.- Returns:
- the function definition.
-
ofExpressions
public static Ite ofExpressions(ToExpression condition, ToExpression trueValue, ToExpression falseValue) Creates aItefunction from the given expressions.- Parameters:
condition- the boolean condition to evaluatetrueValue- the value to return if condition is truefalseValue- the value to return if condition is false- Returns:
- The resulting
Itefunction.
-
ofStrings
Creates aItefunction with a reference condition and string values.- Parameters:
conditionRef- the reference to a boolean parametertrueValue- the string value if condition is truefalseValue- the string value if condition is false- Returns:
- The resulting
Itefunction.
-
availableSince
Description copied from class:SyntaxElementGet the rules engine version that this syntax element is available since.- Overrides:
availableSincein classSyntaxElement- Returns:
- the version this is available since.
-
accept
Description copied from class:ExpressionInvoke theExpressionVisitorfunctions for this expression.- Specified by:
acceptin classExpression- Type Parameters:
R- the visitor return type.- Parameters:
visitor- the visitor to be invoked.- Returns:
- the return value of the visitor.
-
typeCheckLocal
- Overrides:
typeCheckLocalin classLibraryFunction- Throws:
InnerParseError
-