Class CelAbstractSyntaxTree


  • @Immutable
    public final class CelAbstractSyntaxTree
    extends java.lang.Object
    Represents a checked or unchecked expression, its source, and related metadata such as source position information.

    Note: Use CelProtoAbstractSyntaxTree if you need access to the protobuf equivalent ASTs, such as ParsedExpr and CheckedExpr from syntax.proto or checked.proto.

    • Method Detail

      • newParsedAst

        public static CelAbstractSyntaxTree newParsedAst​(CelExpr celExpr,
                                                         CelSource celSource)
        Constructs a new instance of CelAbstractSyntaxTree that represent a parsed expression.

        Note that ASTs should not be manually constructed except for special circumstances such as validating or optimizing an AST.

      • newCheckedAst

        @Internal
        public static CelAbstractSyntaxTree newCheckedAst​(CelExpr celExpr,
                                                          CelSource celSource,
                                                          java.util.Map<java.lang.Long,​CelReference> references,
                                                          java.util.Map<java.lang.Long,​CelType> types)
        Constructs a new instance of CelAbstractSyntaxTree that represent a checked expression.

        CEL Library Internals. Do not construct a type-checked AST by hand. Use a CelCompiler to type-check a parsed AST instead.

      • getExpr

        public CelExpr getExpr()
        Returns the underlying CelExpr representation of the abstract syntax tree.
      • isChecked

        public boolean isChecked()
        Tests whether the underlying abstract syntax tree has been type checked or not.
      • getResultType

        public CelType getResultType()
        For a type checked abstract syntax tree the resulting type is returned. Otherwise, the dynamic type is returned.
      • getProtoResultType

        public Type getProtoResultType()
        For a type checked abstract syntax tree the resulting type is returned in proto format described in checked.proto. Otherwise, the dynamic type is returned.
      • getSource

        public CelSource getSource()
        Returns the CelSource that was used during construction of the abstract syntax tree.
      • getType

        public java.util.Optional<CelType> getType​(long exprId)
      • getTypeMap

        public com.google.common.collect.ImmutableMap<java.lang.Long,​CelType> getTypeMap()
      • getReference

        public java.util.Optional<CelReference> getReference​(long exprId)
      • getReferenceMap

        public com.google.common.collect.ImmutableMap<java.lang.Long,​CelReference> getReferenceMap()
      • getReferenceOrThrow

        public CelReference getReferenceOrThrow​(long exprId)