Interface CelBuilder
-
public interface CelBuilderInterface for building an instance of Cel.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description CelBuilderaddCompilerLibraries(CelCompilerLibrary... libraries)Adds one or more libraries for parsing and type-checking.CelBuilderaddCompilerLibraries(java.lang.Iterable<CelCompilerLibrary> libraries)Adds a collection of libraries for parsing and type-checking.CelBuilderaddDeclarations(Decl... declarations)Add variable and functiondeclarationsto the CEL environment.CelBuilderaddDeclarations(java.lang.Iterable<Decl> declarations)Add variable and functiondeclarationsto the CEL environment.CelBuilderaddFileTypes(DescriptorProtos.FileDescriptorSet fileDescriptorSet)Add all of theDescriptors.FileDescriptors in aFileDescriptorSetto the use for type-checking, and for object creation at interpretation time.CelBuilderaddFileTypes(Descriptors.FileDescriptor... fileDescriptors)AddDescriptors.FileDescriptors to the use for type-checking, and for object creation at interpretation time.CelBuilderaddFileTypes(java.lang.Iterable<Descriptors.FileDescriptor> fileDescriptors)AddDescriptors.FileDescriptors to the use for type-checking, and for object creation at interpretation time.CelBuilderaddFunctionBindings(CelRuntime.CelFunctionBinding... bindings)Add one or moreCelRuntime.CelFunctionBindingobjects to the CEL runtime.CelBuilderaddFunctionBindings(java.lang.Iterable<CelRuntime.CelFunctionBinding> bindings)Bind a collection ofCelRuntime.CelFunctionBindingobjects to the runtime.CelBuilderaddFunctionDeclarations(CelFunctionDecl... celFunctionDecls)Add function declarationCelFunctionDeclto the CEL environment.CelBuilderaddFunctionDeclarations(java.lang.Iterable<CelFunctionDecl> celFunctionDecls)Add function declarationCelFunctionDeclto the CEL environment.CelBuilderaddMacros(CelMacro... macros)Registers the given macros, replacing any previous macros with the same key.CelBuilderaddMacros(java.lang.Iterable<CelMacro> macros)Registers the given macros, replacing any previous macros with the same key.CelBuilderaddMessageTypes(Descriptors.Descriptor... descriptors)Add messageDescriptors.Descriptors to the use for type-checking and object creation at interpretation time.CelBuilderaddMessageTypes(java.lang.Iterable<Descriptors.Descriptor> descriptors)Add messageDescriptors.Descriptors to the use for type-checking and object creation at interpretation time.CelBuilderaddProtoTypeMasks(ProtoTypeMask... typeMasks)Add one or moreProtoTypeMaskvalues.CelBuilderaddProtoTypeMasks(java.lang.Iterable<ProtoTypeMask> typeMasks)Add one or moreProtoTypeMaskvalues.CelBuilderaddRuntimeLibraries(CelRuntimeLibrary... libraries)Adds one or more libraries for runtime.CelBuilderaddRuntimeLibraries(java.lang.Iterable<CelRuntimeLibrary> libraries)Adds a collection of libraries for runtime.CelBuilderaddVar(java.lang.String name, CelType type)Add a variable declaration with a givennameandCelType.CelBuilderaddVar(java.lang.String name, Type type)Add a variable declaration with a givennameandType.CelBuilderaddVarDeclarations(CelVarDecl... celVarDecls)Add variable declarationCelVarDeclto the CEL environment.CelBuilderaddVarDeclarations(java.lang.Iterable<CelVarDecl> celVarDecls)Add variable declarationCelVarDeclto the CEL environment.Celbuild()Construct a newCelinstance from the provided configuration.CelBuildersetContainer(java.lang.String container)Set thecontainername to use as the namespace for resolving CEL expression variables and functions.CelBuildersetExtensionRegistry(ExtensionRegistry extensionRegistry)Sets a proto ExtensionRegistry to assist with unpacking Any messages containing a proto2 extension field.CelBuildersetOptions(CelOptions options)Set theCelOptionsused to enable fixes and feautres for this CEL instance.CelBuildersetProtoResultType(Type resultType)Set the expectedresultTypein proto format described in checked.proto for the type-checked expression.CelBuildersetResultType(CelType resultType)Set the expectedresultTypefor the type-checked expression.CelBuildersetStandardEnvironmentEnabled(boolean value)Enable or disable the standard CEL library functions and variablesCelBuildersetStandardMacros(CelStandardMacro... macros)Set theCelStandardMacrovalues for use with this instance.CelBuildersetStandardMacros(java.lang.Iterable<CelStandardMacro> macros)Set theCelStandardMacrovalues for use with this instance.CelBuildersetTypeFactory(java.util.function.Function<java.lang.String,Message.Builder> typeFactory)Set a custom type factory for the runtime.CelBuildersetTypeProvider(TypeProvider typeProvider)Deprecated.UsesetTypeProvider(CelTypeProvider)instead.CelBuildersetTypeProvider(CelTypeProvider celTypeProvider)Set thecelTypeProviderfor use with type-checking expressions.CelBuildersetValueProvider(CelValueProvider celValueProvider)Sets thecelValueProviderfor resolving values during evaluation.
-
-
-
Method Detail
-
setOptions
@CanIgnoreReturnValue CelBuilder setOptions(CelOptions options)
Set theCelOptionsused to enable fixes and feautres for this CEL instance.
-
setStandardMacros
@CanIgnoreReturnValue CelBuilder setStandardMacros(CelStandardMacro... macros)
Set theCelStandardMacrovalues for use with this instance.
-
setStandardMacros
@CanIgnoreReturnValue CelBuilder setStandardMacros(java.lang.Iterable<CelStandardMacro> macros)
Set theCelStandardMacrovalues for use with this instance.
-
addMacros
@CanIgnoreReturnValue CelBuilder addMacros(CelMacro... macros)
Registers the given macros, replacing any previous macros with the same key.Use this to register a set of user-defined custom macro implementation for the parser. For registering macros defined as part of CEL standard library, use
setStandardMacros(dev.cel.parser.CelStandardMacro...)instead.Custom macros should not use the same function names as the ones found in
CelStandardMacro(ex: has, all, exists, etc.). Build method will throw if both standard macros and custom macros are set with the same name.
-
addMacros
@CanIgnoreReturnValue CelBuilder addMacros(java.lang.Iterable<CelMacro> macros)
Registers the given macros, replacing any previous macros with the same key.Use this to register a set of user-defined custom macro implementation for the parser. For registering macros defined as part of CEL standard library, use
setStandardMacros(dev.cel.parser.CelStandardMacro...)instead.Custom macros should not use the same function names as the ones found in
CelStandardMacro(ex: has, all, exists, etc.). Build method will throw if both standard macros and custom macros are set with the same name.
-
setContainer
@CanIgnoreReturnValue CelBuilder setContainer(java.lang.String container)
Set thecontainername to use as the namespace for resolving CEL expression variables and functions.
-
addVar
@CanIgnoreReturnValue CelBuilder addVar(java.lang.String name, Type type)
Add a variable declaration with a givennameandType.
-
addVar
@CanIgnoreReturnValue CelBuilder addVar(java.lang.String name, CelType type)
Add a variable declaration with a givennameandCelType.
-
addDeclarations
@CanIgnoreReturnValue CelBuilder addDeclarations(Decl... declarations)
Add variable and functiondeclarationsto the CEL environment.
-
addDeclarations
@CanIgnoreReturnValue CelBuilder addDeclarations(java.lang.Iterable<Decl> declarations)
Add variable and functiondeclarationsto the CEL environment.
-
addFunctionDeclarations
@CanIgnoreReturnValue CelBuilder addFunctionDeclarations(CelFunctionDecl... celFunctionDecls)
Add function declarationCelFunctionDeclto the CEL environment.
-
addFunctionDeclarations
@CanIgnoreReturnValue CelBuilder addFunctionDeclarations(java.lang.Iterable<CelFunctionDecl> celFunctionDecls)
Add function declarationCelFunctionDeclto the CEL environment.
-
addVarDeclarations
@CanIgnoreReturnValue CelBuilder addVarDeclarations(CelVarDecl... celVarDecls)
Add variable declarationCelVarDeclto the CEL environment.
-
addVarDeclarations
@CanIgnoreReturnValue CelBuilder addVarDeclarations(java.lang.Iterable<CelVarDecl> celVarDecls)
Add variable declarationCelVarDeclto the CEL environment.
-
addProtoTypeMasks
@CanIgnoreReturnValue CelBuilder addProtoTypeMasks(ProtoTypeMask... typeMasks)
Add one or moreProtoTypeMaskvalues. TheProtoTypeMaskvalues will be used to compute a set ofDeclvalues using a protobuf message's fields as the names and types of the variables ifProtoTypeMask.fieldsAreVariableDeclarations()istrue.Note, this feature may not work with custom
TypeProviderimplementations out of the box, as it requires the implementation ofTypeProvider.lookupFieldNames(dev.cel.expr.Type)to return the set of all fields declared on the protobuf type.
-
addProtoTypeMasks
@CanIgnoreReturnValue CelBuilder addProtoTypeMasks(java.lang.Iterable<ProtoTypeMask> typeMasks)
Add one or moreProtoTypeMaskvalues. TheProtoTypeMaskvalues will be used to compute a set ofDeclvalues using a protobuf message's fields as the names and types of the variables ifProtoTypeMask.fieldsAreVariableDeclarations()istrue.Note, this feature may not work with custom
TypeProviderimplementations out of the box, as it requires the implementation ofTypeProvider.lookupFieldNames(dev.cel.expr.Type)to return the set of all fields declared on the protobuf type.
-
addFunctionBindings
@CanIgnoreReturnValue CelBuilder addFunctionBindings(CelRuntime.CelFunctionBinding... bindings)
Add one or moreCelRuntime.CelFunctionBindingobjects to the CEL runtime.Functions with duplicate overload ids will be replaced in favor of the new overload.
-
addFunctionBindings
@CanIgnoreReturnValue CelBuilder addFunctionBindings(java.lang.Iterable<CelRuntime.CelFunctionBinding> bindings)
Bind a collection ofCelRuntime.CelFunctionBindingobjects to the runtime.Functions with duplicate overload ids will be replaced in favor of the new overload.
-
setResultType
@CanIgnoreReturnValue CelBuilder setResultType(CelType resultType)
Set the expectedresultTypefor the type-checked expression.
-
setProtoResultType
@CanIgnoreReturnValue CelBuilder setProtoResultType(Type resultType)
Set the expectedresultTypein proto format described in checked.proto for the type-checked expression.
-
setTypeFactory
@CanIgnoreReturnValue CelBuilder setTypeFactory(java.util.function.Function<java.lang.String,Message.Builder> typeFactory)
Set a custom type factory for the runtime.Note: it is valid to combine type factory methods within the runtime. Only the options which have been configured will be used.
The type creation search order is as follows:
-
Custom type factory (
setTypeFactory(java.util.function.Function<java.lang.String, com.google.protobuf.Message.Builder>)) Custom descriptor set {addMessageTypes(com.google.protobuf.Descriptors.Descriptor...))
-
setValueProvider
@CanIgnoreReturnValue CelBuilder setValueProvider(CelValueProvider celValueProvider)
Sets thecelValueProviderfor resolving values during evaluation. The provided value provider will be used first before falling back to the built-inProtoMessageValueProviderfor resolving protobuf messages.Note that
CelOptions.enableCelValue()must be enabled or this method will be a no-op.
-
setTypeProvider
@CanIgnoreReturnValue @Deprecated CelBuilder setTypeProvider(TypeProvider typeProvider)
Deprecated.UsesetTypeProvider(CelTypeProvider)instead.Set thetypeProviderfor use with type-checking expressions.
-
setTypeProvider
@CanIgnoreReturnValue CelBuilder setTypeProvider(CelTypeProvider celTypeProvider)
Set thecelTypeProviderfor use with type-checking expressions.
-
addMessageTypes
@CanIgnoreReturnValue CelBuilder addMessageTypes(Descriptors.Descriptor... descriptors)
Add messageDescriptors.Descriptors to the use for type-checking and object creation at interpretation time.This method may be safely combined with
setTypeFactory(java.util.function.Function<java.lang.String, com.google.protobuf.Message.Builder>),setTypeProvider(dev.cel.checker.TypeProvider), andaddFileTypes(com.google.protobuf.Descriptors.FileDescriptor...)calls.If either a
typeFactoryortypeProviderare configured, these classes will take precedence over any dynamic resolution of data related to the descriptors.
-
addMessageTypes
@CanIgnoreReturnValue CelBuilder addMessageTypes(java.lang.Iterable<Descriptors.Descriptor> descriptors)
Add messageDescriptors.Descriptors to the use for type-checking and object creation at interpretation time.This method may be safely combined with
setTypeFactory(java.util.function.Function<java.lang.String, com.google.protobuf.Message.Builder>),setTypeProvider(dev.cel.checker.TypeProvider), andaddFileTypes(com.google.protobuf.Descriptors.FileDescriptor...)calls.If either a
typeFactoryortypeProviderare configured, these classes will take precedence over any dynamic resolution of data related to the descriptors.
-
addFileTypes
@CanIgnoreReturnValue CelBuilder addFileTypes(Descriptors.FileDescriptor... fileDescriptors)
AddDescriptors.FileDescriptors to the use for type-checking, and for object creation at interpretation time.This method may be safely combined with
setTypeFactory(java.util.function.Function<java.lang.String, com.google.protobuf.Message.Builder>),setTypeProvider(dev.cel.checker.TypeProvider), andaddMessageTypes(com.google.protobuf.Descriptors.Descriptor...)calls.If either a
typeFactoryortypeProviderare configured, these classes will take precedence over any dynamic resolution of data related to the descriptors.
-
addFileTypes
@CanIgnoreReturnValue CelBuilder addFileTypes(java.lang.Iterable<Descriptors.FileDescriptor> fileDescriptors)
AddDescriptors.FileDescriptors to the use for type-checking, and for object creation at interpretation time.This method may be safely combined with
setTypeFactory(java.util.function.Function<java.lang.String, com.google.protobuf.Message.Builder>),setTypeProvider(dev.cel.checker.TypeProvider), andaddMessageTypes(com.google.protobuf.Descriptors.Descriptor...)calls.If either a
typeFactoryortypeProviderare configured, these classes will take precedence over any dynamic resolution of data related to the descriptors.
-
addFileTypes
@CanIgnoreReturnValue CelBuilder addFileTypes(DescriptorProtos.FileDescriptorSet fileDescriptorSet)
Add all of theDescriptors.FileDescriptors in aFileDescriptorSetto the use for type-checking, and for object creation at interpretation time.This method may be safely combined with
setTypeFactory(java.util.function.Function<java.lang.String, com.google.protobuf.Message.Builder>),setTypeProvider(dev.cel.checker.TypeProvider), andaddMessageTypes(com.google.protobuf.Descriptors.Descriptor...)calls.If either a
typeFactoryortypeProviderare configured, these classes will take precedence over any dynamic resolution of data related to the descriptors.
-
setStandardEnvironmentEnabled
@CanIgnoreReturnValue CelBuilder setStandardEnvironmentEnabled(boolean value)
Enable or disable the standard CEL library functions and variables
-
addCompilerLibraries
@CanIgnoreReturnValue CelBuilder addCompilerLibraries(CelCompilerLibrary... libraries)
Adds one or more libraries for parsing and type-checking.
-
addCompilerLibraries
@CanIgnoreReturnValue CelBuilder addCompilerLibraries(java.lang.Iterable<CelCompilerLibrary> libraries)
Adds a collection of libraries for parsing and type-checking.
-
addRuntimeLibraries
@CanIgnoreReturnValue CelBuilder addRuntimeLibraries(CelRuntimeLibrary... libraries)
Adds one or more libraries for runtime.
-
addRuntimeLibraries
@CanIgnoreReturnValue CelBuilder addRuntimeLibraries(java.lang.Iterable<CelRuntimeLibrary> libraries)
Adds a collection of libraries for runtime.
-
setExtensionRegistry
@CanIgnoreReturnValue CelBuilder setExtensionRegistry(ExtensionRegistry extensionRegistry)
Sets a proto ExtensionRegistry to assist with unpacking Any messages containing a proto2 extension field.
-
build
Cel build()
Construct a newCelinstance from the provided configuration.
-
-