Class CelExpr
- java.lang.Object
-
- dev.cel.common.ast.CelExpr
-
@Internal @Immutable public abstract class CelExpr extends java.lang.Object
An abstract representation of a common expression.This is the native type equivalent of Expr message in syntax.proto.
Expressions are abstractly represented as a collection of identifiers, select statements, function calls, literals, and comprehensions. All operators with the exception of the '.' operator are modelled as function calls. This makes it easy to represent new operators into the existing AST.
All references within expressions must resolve to a [Decl][] provided at type-check for an expression to be valid. A reference may either be a bare identifier `name` or a qualified identifier `google.api.name`. References may either refer to a value or a function declaration.
For example, the expression `google.api.name.startsWith('expr')` references the declaration `google.api.name` within a [Expr.Select][] expression, and the function declaration `startsWith`.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCelExpr.BuilderBuilder for CelExpr.static classCelExpr.CelCallA call expression, including calls to predefined functions and operators.static classCelExpr.CelComprehensionA comprehension expression applied to a list or map.static classCelExpr.CelCreateListA list creation expression.static classCelExpr.CelCreateMapA map creation expression.static classCelExpr.CelCreateStructA message creation expression.static classCelExpr.CelIdentAn identifier expression.static classCelExpr.CelNotSetAn unset expression.static classCelExpr.CelSelectA field selection expression.static classCelExpr.ExprKindDenotes the kind of the expression.
-
Constructor Summary
Constructors Constructor Description CelExpr()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description CelExpr.CelCallcall()Gets the underlying call expression.CelExpr.CelCallcallOrDefault()Gets the underlying call expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.CALL.CelExpr.CelComprehensioncomprehension()Gets the underlying comprehension expression.CelExpr.CelComprehensioncomprehensionOrDefault()Gets the underlying comprehension expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.COMPREHENSION.CelConstantconstant()Gets the underlying constant expression.CelConstantconstantOrDefault()Gets the underlying constant expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.CONSTANT.CelExpr.CelCreateListcreateList()Gets the underlying createList expression.CelExpr.CelCreateListcreateListOrDefault()Gets the underlying createList expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.CREATE_LIST.CelExpr.CelCreateMapcreateMap()Gets the underlying createMap expression.CelExpr.CelCreateMapcreateMapOrDefault()Gets the underlying createMap expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.CREATE_MAP.CelExpr.CelCreateStructcreateStruct()Gets the underlying createStruct expression.CelExpr.CelCreateStructcreateStructOrDefault()Gets the underlying createStruct expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.CREATE_STRUCT.abstract CelExpr.ExprKindexprKind()Represents the variant of the expression.abstract longid()Required.CelExpr.CelIdentident()Gets the underlying identifier expression.CelExpr.CelIdentidentOrDefault()Gets the underlying identifier expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.IDENT.static CelExpr.BuildernewBuilder()static CelExprofCallExpr(long id, java.util.Optional<CelExpr> targetExpr, java.lang.String function, com.google.common.collect.ImmutableList<CelExpr> arguments)static CelExprofComprehension(long id, java.lang.String iterVar, CelExpr iterRange, java.lang.String accuVar, CelExpr accuInit, CelExpr loopCondition, CelExpr loopStep, CelExpr result)static CelExprofConstantExpr(long id, CelConstant celConstant)static CelExprofCreateListExpr(long id, com.google.common.collect.ImmutableList<CelExpr> elements, com.google.common.collect.ImmutableList<java.lang.Integer> optionalIndices)static CelExpr.CelCreateMap.EntryofCreateMapEntryExpr(long id, CelExpr mapKey, CelExpr value, boolean isOptionalEntry)static CelExprofCreateMapExpr(long id, com.google.common.collect.ImmutableList<CelExpr.CelCreateMap.Entry> entries)static CelExpr.CelCreateStruct.EntryofCreateStructEntryExpr(long id, java.lang.String fieldKey, CelExpr value, boolean isOptionalEntry)static CelExprofCreateStructExpr(long id, java.lang.String messageName, com.google.common.collect.ImmutableList<CelExpr.CelCreateStruct.Entry> entries)static CelExprofIdentExpr(long id, java.lang.String identName)static CelExprofNotSet(long id)static CelExprofSelectExpr(long id, CelExpr operandExpr, java.lang.String field, boolean isTestOnly)CelExpr.CelSelectselect()Gets the underlying select expression.CelExpr.CelSelectselectOrDefault()Gets the underlying select expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.SELECT.abstract CelExpr.BuildertoBuilder()java.lang.StringtoString()
-
-
-
Method Detail
-
id
public abstract long id()
Required. An id assigned to this node by the parser which is unique in a given expression tree. This is used to associate type information and other attributes to a node in the parse tree.
-
exprKind
public abstract CelExpr.ExprKind exprKind()
Represents the variant of the expression.
-
constant
public CelConstant constant()
Gets the underlying constant expression.- Throws:
java.lang.UnsupportedOperationException- if expression is notCelExpr.ExprKind.Kind.CONSTANT.
-
ident
public CelExpr.CelIdent ident()
Gets the underlying identifier expression.- Throws:
java.lang.UnsupportedOperationException- if expression is notCelExpr.ExprKind.Kind.IDENT.
-
select
public CelExpr.CelSelect select()
Gets the underlying select expression.- Throws:
java.lang.UnsupportedOperationException- if expression is notCelExpr.ExprKind.Kind.SELECT.
-
call
public CelExpr.CelCall call()
Gets the underlying call expression.- Throws:
java.lang.UnsupportedOperationException- if expression is notCelExpr.ExprKind.Kind.CALL.
-
createList
public CelExpr.CelCreateList createList()
Gets the underlying createList expression.- Throws:
java.lang.UnsupportedOperationException- if expression is notCelExpr.ExprKind.Kind.CREATE_LIST.
-
createStruct
public CelExpr.CelCreateStruct createStruct()
Gets the underlying createStruct expression.- Throws:
java.lang.UnsupportedOperationException- if expression is notCelExpr.ExprKind.Kind.CREATE_STRUCT.
-
createMap
public CelExpr.CelCreateMap createMap()
Gets the underlying createMap expression.- Throws:
java.lang.UnsupportedOperationException- if expression is notCelExpr.ExprKind.createMap().
-
comprehension
public CelExpr.CelComprehension comprehension()
Gets the underlying comprehension expression.- Throws:
java.lang.UnsupportedOperationException- if expression is notCelExpr.ExprKind.Kind.COMPREHENSION.
-
constantOrDefault
public CelConstant constantOrDefault()
Gets the underlying constant expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.CONSTANT.
-
identOrDefault
public CelExpr.CelIdent identOrDefault()
Gets the underlying identifier expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.IDENT.
-
selectOrDefault
public CelExpr.CelSelect selectOrDefault()
Gets the underlying select expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.SELECT.
-
callOrDefault
public CelExpr.CelCall callOrDefault()
Gets the underlying call expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.CALL.
-
createListOrDefault
public CelExpr.CelCreateList createListOrDefault()
Gets the underlying createList expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.CREATE_LIST.
-
createStructOrDefault
public CelExpr.CelCreateStruct createStructOrDefault()
Gets the underlying createStruct expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.CREATE_STRUCT.
-
createMapOrDefault
public CelExpr.CelCreateMap createMapOrDefault()
Gets the underlying createMap expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.CREATE_MAP.
-
comprehensionOrDefault
public CelExpr.CelComprehension comprehensionOrDefault()
Gets the underlying comprehension expression or a default instance of one if expression is notCelExpr.ExprKind.Kind.COMPREHENSION.
-
toBuilder
public abstract CelExpr.Builder toBuilder()
-
newBuilder
public static CelExpr.Builder newBuilder()
-
ofNotSet
public static CelExpr ofNotSet(long id)
-
ofConstantExpr
public static CelExpr ofConstantExpr(long id, CelConstant celConstant)
-
ofIdentExpr
public static CelExpr ofIdentExpr(long id, java.lang.String identName)
-
ofSelectExpr
public static CelExpr ofSelectExpr(long id, CelExpr operandExpr, java.lang.String field, boolean isTestOnly)
-
ofCallExpr
public static CelExpr ofCallExpr(long id, java.util.Optional<CelExpr> targetExpr, java.lang.String function, com.google.common.collect.ImmutableList<CelExpr> arguments)
-
ofCreateListExpr
public static CelExpr ofCreateListExpr(long id, com.google.common.collect.ImmutableList<CelExpr> elements, com.google.common.collect.ImmutableList<java.lang.Integer> optionalIndices)
-
ofCreateStructExpr
public static CelExpr ofCreateStructExpr(long id, java.lang.String messageName, com.google.common.collect.ImmutableList<CelExpr.CelCreateStruct.Entry> entries)
-
ofCreateMapExpr
public static CelExpr ofCreateMapExpr(long id, com.google.common.collect.ImmutableList<CelExpr.CelCreateMap.Entry> entries)
-
ofCreateStructEntryExpr
public static CelExpr.CelCreateStruct.Entry ofCreateStructEntryExpr(long id, java.lang.String fieldKey, CelExpr value, boolean isOptionalEntry)
-
ofCreateMapEntryExpr
public static CelExpr.CelCreateMap.Entry ofCreateMapEntryExpr(long id, CelExpr mapKey, CelExpr value, boolean isOptionalEntry)
-
ofComprehension
public static CelExpr ofComprehension(long id, java.lang.String iterVar, CelExpr iterRange, java.lang.String accuVar, CelExpr accuInit, CelExpr loopCondition, CelExpr loopStep, CelExpr result)
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-