Class Env
- java.lang.Object
-
- dev.cel.checker.Env
-
@Internal public class Env extends java.lang.ObjectEnvironment 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEnv.DeclGroupObject for managing a group of declarations within a scope.static classEnv.FunctionBuilderDeprecated.UseCelFunctionDecl.newBuilder()instead.static classEnv.IdentBuilderDeprecated.UseCelVarDecl#newBuilder()instead.
-
Field Summary
Fields Modifier and Type Field Description static CelFunctionDeclERROR_FUNCTION_DECLA function declaration to represent an error.static CelIdentDeclERROR_IDENT_DECLAn ident declaration to represent an error.static intROOT_SCOPEThe top-most scope in the environment, for use withgetDeclGroup(int).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Envadd(CelIdentDecl celIdentDecl)Envadd(CelFunctionDecl celFunctionDecl)Envadd(dev.cel.expr.Decl decl)Deprecated.Migrate to the CEL-Java fluent APIs and leverage the publicly available native types (e.g:CelCompilerFactoryacceptsCelFunctionDeclandCelVarDecl).Envadd(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:CelCompilerFactoryacceptsCelFunctionDeclandCelVarDecl).voidenterScope()Enters a new scope.voidexitScope()Exits a previously opened scope, forgetting all declarations created in this scope.Env.DeclGroupgetDeclGroup()Returns the top-most declaration scope.Env.DeclGroupgetDeclGroup(int scopeDepth)Returns theDeclGroupat the givenscopeDepth, where depth of0represents root scope.ErrorsgetErrorContext()Returns the current Errors object.java.util.Map<java.lang.Long,dev.cel.common.ast.CelReference>getRefMap()Returns the reference map.dev.cel.expr.TypegetType(dev.cel.expr.Expr expr)Deprecated.Do not use.java.util.Map<java.lang.Long,dev.cel.common.types.CelType>getTypeMap()Returns the type map.TypeProvidergetTypeProvider()Returns theTypeProvider.CelFunctionDecllookupFunction(long exprId, int position, dev.cel.common.CelContainer container, java.lang.String name)Lookup a name liketryLookupCelFunction(dev.cel.common.CelContainer, java.lang.String)but report an error if the name is not found and return theERROR_FUNCTION_DECL.CelIdentDecllookupIdent(long exprId, int position, dev.cel.common.CelContainer container, java.lang.String name)Lookup a name liketryLookupCelIdent(dev.cel.common.CelContainer, java.lang.String), but report an error if the name is not found and return theERROR_IDENT_DECL.voidreportError(int position, java.lang.String message, java.lang.Object... args)Deprecated.Useinstead.voidreportError(long exprId, int position, java.lang.String message, java.lang.Object... args)Reports an error.voidresetTypeAndRefMaps()Reset type and ref maps.intscopeDepth()Return the current scope depth for the environment.static Envstandard(CelStandardDeclarations celStandardDeclaration, Errors errors, TypeProvider typeProvider, dev.cel.common.CelOptions celOptions)static Envstandard(Errors errors)Deprecated.Do not use.static Envstandard(Errors errors, TypeProvider typeProvider)Deprecated.Do not use.static Envstandard(Errors errors, TypeProvider typeProvider, dev.cel.common.CelOptions celOptions)Deprecated.Do not use.@Nullable CelFunctionDecltryLookupCelFunction(dev.cel.common.CelContainer container, java.lang.String name)Try to lookup a function with the givennamewithin acontainer.@Nullable CelIdentDecltryLookupCelIdent(dev.cel.common.CelContainer container, java.lang.String name)Try to lookup an identifier with the givennamewithin acontainer.@Nullable dev.cel.expr.DecltryLookupFunction(java.lang.String container, java.lang.String name)Deprecated.@Nullable dev.cel.expr.DecltryLookupIdent(dev.cel.common.CelContainer container, java.lang.String name)Deprecated.static Envunconfigured(Errors errors)Deprecated.Do not use.static Envunconfigured(Errors errors, TypeProvider typeProvider, dev.cel.common.CelOptions celOptions)Deprecated.Do not use.
-
-
-
Field Detail
-
ROOT_SCOPE
public static final int ROOT_SCOPE
The top-most scope in the environment, for use withgetDeclGroup(int).- See Also:
- Constant Field Values
-
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. SeeCelCompilerFactory.
-
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. SeeCelCompilerFactory.Creates an unconfiguredEnvvalue without the standard CEL types, functions, and operators using a customtypeProvider.
-
standard
@Deprecated public static Env standard(Errors errors)
Deprecated.Do not use. This exists for compatibility reasons. Migrate to CEL-Java fluent APIs. SeeCelCompilerFactory.
-
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. SeeCelCompilerFactory.
-
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. SeeCelCompilerFactory.Creates anEnvvalue configured with the standard types, functions, and operators, configured with a customtypeProviderand a reference to thecelOptionsto use within the environment.Note: standard declarations are configured in an isolated scope, and may be shadowed by subsequent declarations with the same signature.
-
standard
public static Env standard(CelStandardDeclarations celStandardDeclaration, Errors errors, TypeProvider typeProvider, dev.cel.common.CelOptions celOptions)
-
getErrorContext
public Errors getErrorContext()
Returns the current Errors object.
-
getTypeProvider
public TypeProvider getTypeProvider()
Returns theTypeProvider.
-
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 theDeclGroupat the givenscopeDepth, where depth of0represents 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:CelCompilerFactoryacceptsCelFunctionDeclandCelVarDecl).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(CelFunctionDecl celFunctionDecl)
-
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:CelCompilerFactoryacceptsCelFunctionDeclandCelVarDecl).Adds simple name declaration to the environment for a non-function.
-
tryLookupFunction
@Deprecated public @Nullable dev.cel.expr.Decl tryLookupFunction(java.lang.String container, java.lang.String name)Deprecated.Note: Used by legacy type-checker users
-
tryLookupCelFunction
public @Nullable CelFunctionDecl tryLookupCelFunction(dev.cel.common.CelContainer container, java.lang.String name)
Try to lookup a function with the givennamewithin acontainer.For protos, the
containermay be a package or message name. The code tries to resolve thenamefirst in the container, then within the container parent, and so on until the root package is reached. Ifcontainerstarts with., the resolution is in the root container only.Returns
nullif the function cannot be found.
-
tryLookupIdent
@Deprecated public @Nullable dev.cel.expr.Decl tryLookupIdent(dev.cel.common.CelContainer container, java.lang.String name)Deprecated.
-
tryLookupCelIdent
public @Nullable CelIdentDecl tryLookupCelIdent(dev.cel.common.CelContainer container, java.lang.String name)
Try to lookup an identifier with the givennamewithin acontainer.For protos, the
containermay be a package or message name. The code tries to resolve thenamefirst in the container, then within the container parent, and so on until the root package is reached. Ifcontainerstarts with., the resolution is in the root container only.Returns
nullif the ident cannot be found.
-
lookupIdent
public CelIdentDecl lookupIdent(long exprId, int position, dev.cel.common.CelContainer container, java.lang.String name)
Lookup a name liketryLookupCelIdent(dev.cel.common.CelContainer, java.lang.String), but report an error if the name is not found and return theERROR_IDENT_DECL.
-
lookupFunction
public CelFunctionDecl lookupFunction(long exprId, int position, dev.cel.common.CelContainer container, java.lang.String name)
Lookup a name liketryLookupCelFunction(dev.cel.common.CelContainer, java.lang.String)but report an error if the name is not found and return theERROR_FUNCTION_DECL.
-
reportError
@Deprecated public void reportError(int position, java.lang.String message, java.lang.Object... args)Deprecated.Useinstead.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.
-
-