Class Env


  • @Internal
    public class Env
    extends java.lang.Object
    Environment used during checking of expressions. Provides name resolution and error reporting.

    Note: the environment is not thread-safe. Create multiple envs from scratch for working with different threads.

    CEL Library Internals. Do Not Use. CEL-Java users should leverage the Fluent APIs instead. See CelCompilerFactory.

    • Field Detail

      • ERROR_IDENT_DECL

        public static final CelIdentDecl ERROR_IDENT_DECL
        An ident declaration to represent an error.
      • ERROR_FUNCTION_DECL

        public static final CelFunctionDecl ERROR_FUNCTION_DECL
        A function declaration to represent an error.
    • Method Detail

      • unconfigured

        @Deprecated
        public static Env unconfigured​(Errors errors)
        Deprecated.
        Do not use. This exists for compatibility reasons. Migrate to CEL-Java fluent APIs. See CelCompilerFactory.
      • unconfigured

        @Deprecated
        public static Env unconfigured​(Errors errors,
                                       TypeProvider typeProvider,
                                       dev.cel.common.CelOptions celOptions)
        Deprecated.
        Do not use. This exists for compatibility reasons. Migrate to CEL-Java fluent APIs. See CelCompilerFactory.
        Creates an unconfigured Env value without the standard CEL types, functions, and operators using a custom typeProvider.
      • standard

        @Deprecated
        public static Env standard​(Errors errors)
        Deprecated.
        Do not use. This exists for compatibility reasons. Migrate to CEL-Java fluent APIs. See CelCompilerFactory.
      • standard

        @Deprecated
        public static Env standard​(Errors errors,
                                   TypeProvider typeProvider)
        Deprecated.
        Do not use. This exists for compatibility reasons. Migrate to CEL-Java fluent APIs. See CelCompilerFactory.
      • standard

        @Deprecated
        public static Env standard​(Errors errors,
                                   TypeProvider typeProvider,
                                   dev.cel.common.CelOptions celOptions)
        Deprecated.
        Do not use. This exists for compatibility reasons. Migrate to CEL-Java fluent APIs. See CelCompilerFactory.
        Creates an Env value configured with the standard types, functions, and operators, configured with a custom typeProvider and a reference to the celOptions to use within the environment.

        Note: standard declarations are configured in an isolated scope, and may be shadowed by subsequent declarations with the same signature.

      • getErrorContext

        public Errors getErrorContext()
        Returns the current Errors object.
      • getTypeProvider

        public TypeProvider getTypeProvider()
        Returns the TypeProvider.
      • enterScope

        public void enterScope()
        Enters a new scope. All new declarations added to the environment exist only in this scope, and will shadow declarations of the same name in outer scopes. This includes overloads in outer scope (overloads from different scopes are not merged).
      • exitScope

        public void exitScope()
        Exits a previously opened scope, forgetting all declarations created in this scope.
      • scopeDepth

        public int scopeDepth()
        Return the current scope depth for the environment.
      • getDeclGroup

        public Env.DeclGroup getDeclGroup()
        Returns the top-most declaration scope.
      • getDeclGroup

        public Env.DeclGroup getDeclGroup​(int scopeDepth)
        Returns the DeclGroup at the given scopeDepth, where depth of 0 represents root scope.
      • resetTypeAndRefMaps

        public void resetTypeAndRefMaps()
        Reset type and ref maps. This must be called before type checking an expression.
      • getRefMap

        public java.util.Map<java.lang.Long,​dev.cel.common.ast.CelReference> getRefMap()
        Returns the reference map.
      • getTypeMap

        public java.util.Map<java.lang.Long,​dev.cel.common.types.CelType> getTypeMap()
        Returns the type map.
      • getType

        @Deprecated
        public dev.cel.expr.Type getType​(dev.cel.expr.Expr expr)
        Deprecated.
        Do not use. Migrate to CEL-Java fluent APIs.
        Returns the type associated with an expression by expression id. It's an error to call this method if the type is not present.
      • add

        @CanIgnoreReturnValue
        @Deprecated
        public Env add​(dev.cel.expr.Decl decl)
        Deprecated.
        Migrate to the CEL-Java fluent APIs and leverage the publicly available native types (e.g: CelCompilerFactory accepts CelFunctionDecl and CelVarDecl).
        Adds a declaration to the environment, based on the Decl proto. Will report errors if the declaration overlaps with an existing one, or clashes with a macro.
      • add

        @CanIgnoreReturnValue
        public Env add​(CelIdentDecl celIdentDecl)
      • add

        @CanIgnoreReturnValue
        @Deprecated
        public Env add​(java.lang.String name,
                       dev.cel.expr.Type type)
        Deprecated.
        Migrate to the CEL-Java fluent APIs and leverage the publicly available native types (e.g: CelCompilerFactory accepts CelFunctionDecl and CelVarDecl).
        Adds simple name declaration to the environment for a non-function.
      • tryLookupCelFunction

        public @Nullable CelFunctionDecl tryLookupCelFunction​(dev.cel.common.CelContainer container,
                                                              java.lang.String name)
        Try to lookup a function with the given name within a container.

        For protos, the container may be a package or message name. The code tries to resolve the name first in the container, then within the container parent, and so on until the root package is reached. If container starts with ., the resolution is in the root container only.

        Returns null if the function cannot be found.

      • tryLookupCelIdent

        public @Nullable CelIdentDecl tryLookupCelIdent​(dev.cel.common.CelContainer container,
                                                        java.lang.String name)
        Try to lookup an identifier with the given name within a container.

        For protos, the container may be a package or message name. The code tries to resolve the name first in the container, then within the container parent, and so on until the root package is reached. If container starts with ., the resolution is in the root container only.

        Returns null if the ident cannot be found.

      • reportError

        @Deprecated
        public void reportError​(int position,
                                java.lang.String message,
                                java.lang.Object... args)
        Deprecated.
        Note: Used by legacy type-checker users
      • reportError

        public void reportError​(long exprId,
                                int position,
                                java.lang.String message,
                                java.lang.Object... args)
        Reports an error.