Class CelCompilerImpl.Builder
- java.lang.Object
-
- dev.cel.compiler.CelCompilerImpl.Builder
-
- All Implemented Interfaces:
CelCompilerBuilder
- Enclosing class:
- CelCompilerImpl
public static final class CelCompilerImpl.Builder extends java.lang.Object implements CelCompilerBuilder
Builder forCelCompilerImpl
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description CelCompilerBuilder
addDeclarations(Decl... declarations)
Add variable and functiondeclarations
to the CEL environment.CelCompilerBuilder
addDeclarations(java.lang.Iterable<Decl> declarations)
Add variable and functiondeclarations
to the CEL environment.CelCompilerBuilder
addFileTypes(com.google.protobuf.DescriptorProtos.FileDescriptorSet fileDescriptorSet)
Add all of theDescriptors.FileDescriptor
s in aFileDescriptorSet
to the use for type-checking, and for object creation at interpretation time.CelCompilerBuilder
addFileTypes(com.google.protobuf.Descriptors.FileDescriptor... fileDescriptors)
AddDescriptors.FileDescriptor
s to the use for type-checking, and for object creation at interpretation time.CelCompilerBuilder
addFileTypes(java.lang.Iterable<com.google.protobuf.Descriptors.FileDescriptor> fileDescriptors)
AddDescriptors.FileDescriptor
s to the use for type-checking, and for object creation at interpretation time.CelCompilerBuilder
addFunctionDeclarations(CelFunctionDecl... celFunctionDecls)
Add function declarationCelFunctionDecl
to the CEL environmentCelCompilerBuilder
addFunctionDeclarations(java.lang.Iterable<CelFunctionDecl> celFunctionDecls)
Add function declarationCelFunctionDecl
to the CEL environmentCelCompilerBuilder
addLibraries(CelCompilerLibrary... libraries)
Adds one or more libraries for parsing and type-checking.CelCompilerBuilder
addLibraries(java.lang.Iterable<? extends CelCompilerLibrary> libraries)
Adds a collection of libraries for parsing and type-checking.CelCompilerBuilder
addMacros(CelMacro... macros)
Registers the given macros, replacing any previous macros with the same key.CelCompilerBuilder
addMacros(java.lang.Iterable<CelMacro> macros)
Registers the given macros, replacing any previous macros with the same key.CelCompilerBuilder
addMessageTypes(com.google.protobuf.Descriptors.Descriptor... descriptors)
Add messageDescriptors.Descriptor
s to the use for type-checking and object creation at interpretation time.CelCompilerBuilder
addMessageTypes(java.lang.Iterable<com.google.protobuf.Descriptors.Descriptor> descriptors)
Add messageDescriptors.Descriptor
s to the use for type-checking and object creation at interpretation time.CelCompilerBuilder
addProtoTypeMasks(ProtoTypeMask... typeMasks)
Add one or moreProtoTypeMask
values.CelCompilerBuilder
addProtoTypeMasks(java.lang.Iterable<ProtoTypeMask> typeMasks)
Add one or moreProtoTypeMask
values.CelCompilerBuilder
addVar(java.lang.String name, CelType type)
Add a variable declaration with a givenname
andCelType
.CelCompilerBuilder
addVar(java.lang.String name, Type type)
Add a variable declaration with a givenname
and proto basedType
.CelCompilerBuilder
addVarDeclarations(CelVarDecl... celVarDecls)
Add variable declarationCelVarDecl
to the CEL environment.CelCompilerBuilder
addVarDeclarations(java.lang.Iterable<CelVarDecl> celVarDecls)
Add variable declarationCelVarDecl
to the CEL environment.CelCompilerImpl
build()
Build a new instance of theCelCompiler
.CelCompilerBuilder
setContainer(java.lang.String container)
Set thecontainer
name to use as the namespace for resolving CEL expression variables and functions.CelCompilerBuilder
setOptions(CelOptions options)
Set theCelOptions
used to enable fixes and features for this CEL instances.CelCompilerBuilder
setProtoResultType(Type resultType)
Set the expectedresultType
in proto format described in checked.proto for the type-checked expression.CelCompilerBuilder
setResultType(CelType resultType)
Set the expectedresultType
for the type-checked expression.CelCompilerBuilder
setStandardEnvironmentEnabled(boolean value)
Enable or disable the standard CEL library functions and variablesCelCompilerBuilder
setStandardMacros(CelStandardMacro... macros)
Sets the macro set for the parser, replacing the macros from any prior call.CelCompilerBuilder
setStandardMacros(java.lang.Iterable<CelStandardMacro> macros)
Sets the macro set for the parser, replacing the macros from any prior call.CelCompilerBuilder
setTypeProvider(TypeProvider typeProvider)
Deprecated.CelCompilerBuilder
setTypeProvider(CelTypeProvider celTypeProvider)
Set thecelTypeProvider
for use with type-checking expressions.
-
-
-
Method Detail
-
setOptions
public CelCompilerBuilder setOptions(CelOptions options)
Description copied from interface:CelCompilerBuilder
Set theCelOptions
used to enable fixes and features for this CEL instances.- Specified by:
setOptions
in interfaceCelCompilerBuilder
-
setStandardMacros
public CelCompilerBuilder setStandardMacros(CelStandardMacro... macros)
Description copied from interface:CelCompilerBuilder
Sets the macro set for the parser, replacing the macros from any prior call.- Specified by:
setStandardMacros
in interfaceCelCompilerBuilder
-
setStandardMacros
public CelCompilerBuilder setStandardMacros(java.lang.Iterable<CelStandardMacro> macros)
Description copied from interface:CelCompilerBuilder
Sets the macro set for the parser, replacing the macros from any prior call.- Specified by:
setStandardMacros
in interfaceCelCompilerBuilder
-
addMacros
public CelCompilerBuilder addMacros(CelMacro... macros)
Description copied from interface:CelCompilerBuilder
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
CelCompilerBuilder.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.- Specified by:
addMacros
in interfaceCelCompilerBuilder
-
addMacros
public CelCompilerBuilder addMacros(java.lang.Iterable<CelMacro> macros)
Description copied from interface:CelCompilerBuilder
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
CelCompilerBuilder.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.- Specified by:
addMacros
in interfaceCelCompilerBuilder
-
setContainer
public CelCompilerBuilder setContainer(java.lang.String container)
Description copied from interface:CelCompilerBuilder
Set thecontainer
name to use as the namespace for resolving CEL expression variables and functions.- Specified by:
setContainer
in interfaceCelCompilerBuilder
-
addVar
public CelCompilerBuilder addVar(java.lang.String name, Type type)
Description copied from interface:CelCompilerBuilder
Add a variable declaration with a givenname
and proto basedType
.- Specified by:
addVar
in interfaceCelCompilerBuilder
-
addVar
public CelCompilerBuilder addVar(java.lang.String name, CelType type)
Description copied from interface:CelCompilerBuilder
Add a variable declaration with a givenname
andCelType
.- Specified by:
addVar
in interfaceCelCompilerBuilder
-
addDeclarations
public CelCompilerBuilder addDeclarations(Decl... declarations)
Description copied from interface:CelCompilerBuilder
Add variable and functiondeclarations
to the CEL environment.- Specified by:
addDeclarations
in interfaceCelCompilerBuilder
-
addDeclarations
public CelCompilerBuilder addDeclarations(java.lang.Iterable<Decl> declarations)
Description copied from interface:CelCompilerBuilder
Add variable and functiondeclarations
to the CEL environment.- Specified by:
addDeclarations
in interfaceCelCompilerBuilder
-
addFunctionDeclarations
public CelCompilerBuilder addFunctionDeclarations(CelFunctionDecl... celFunctionDecls)
Description copied from interface:CelCompilerBuilder
Add function declarationCelFunctionDecl
to the CEL environment- Specified by:
addFunctionDeclarations
in interfaceCelCompilerBuilder
-
addFunctionDeclarations
public CelCompilerBuilder addFunctionDeclarations(java.lang.Iterable<CelFunctionDecl> celFunctionDecls)
Description copied from interface:CelCompilerBuilder
Add function declarationCelFunctionDecl
to the CEL environment- Specified by:
addFunctionDeclarations
in interfaceCelCompilerBuilder
-
addVarDeclarations
public CelCompilerBuilder addVarDeclarations(CelVarDecl... celVarDecls)
Description copied from interface:CelCompilerBuilder
Add variable declarationCelVarDecl
to the CEL environment.- Specified by:
addVarDeclarations
in interfaceCelCompilerBuilder
-
addVarDeclarations
public CelCompilerBuilder addVarDeclarations(java.lang.Iterable<CelVarDecl> celVarDecls)
Description copied from interface:CelCompilerBuilder
Add variable declarationCelVarDecl
to the CEL environment.- Specified by:
addVarDeclarations
in interfaceCelCompilerBuilder
-
addProtoTypeMasks
public CelCompilerBuilder addProtoTypeMasks(ProtoTypeMask... typeMasks)
Description copied from interface:CelCompilerBuilder
Add one or moreProtoTypeMask
values. TheProtoTypeMask
values will be used to compute a set ofDecl
values 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
TypeProvider
implementations out of the box, as it requires the implementation ofTypeProvider#lookupFieldNames
to return the set of all fields declared on the protobuf type.- Specified by:
addProtoTypeMasks
in interfaceCelCompilerBuilder
-
addProtoTypeMasks
public CelCompilerBuilder addProtoTypeMasks(java.lang.Iterable<ProtoTypeMask> typeMasks)
Description copied from interface:CelCompilerBuilder
Add one or moreProtoTypeMask
values. TheProtoTypeMask
values will be used to compute a set ofDecl
values 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
TypeProvider
implementations out of the box, as it requires the implementation ofTypeProvider#lookupFieldNames
to return the set of all fields declared on the protobuf type.- Specified by:
addProtoTypeMasks
in interfaceCelCompilerBuilder
-
setResultType
public CelCompilerBuilder setResultType(CelType resultType)
Description copied from interface:CelCompilerBuilder
Set the expectedresultType
for the type-checked expression.- Specified by:
setResultType
in interfaceCelCompilerBuilder
-
setProtoResultType
public CelCompilerBuilder setProtoResultType(Type resultType)
Description copied from interface:CelCompilerBuilder
Set the expectedresultType
in proto format described in checked.proto for the type-checked expression.- Specified by:
setProtoResultType
in interfaceCelCompilerBuilder
-
setTypeProvider
@Deprecated public CelCompilerBuilder setTypeProvider(TypeProvider typeProvider)
Deprecated.Description copied from interface:CelCompilerBuilder
Set thetypeProvider
for use with type-checking expressions.- Specified by:
setTypeProvider
in interfaceCelCompilerBuilder
-
setTypeProvider
public CelCompilerBuilder setTypeProvider(CelTypeProvider celTypeProvider)
Description copied from interface:CelCompilerBuilder
Set thecelTypeProvider
for use with type-checking expressions.- Specified by:
setTypeProvider
in interfaceCelCompilerBuilder
-
addMessageTypes
public CelCompilerBuilder addMessageTypes(com.google.protobuf.Descriptors.Descriptor... descriptors)
Description copied from interface:CelCompilerBuilder
Add messageDescriptors.Descriptor
s to the use for type-checking and object creation at interpretation time.- Specified by:
addMessageTypes
in interfaceCelCompilerBuilder
-
addMessageTypes
public CelCompilerBuilder addMessageTypes(java.lang.Iterable<com.google.protobuf.Descriptors.Descriptor> descriptors)
Description copied from interface:CelCompilerBuilder
Add messageDescriptors.Descriptor
s to the use for type-checking and object creation at interpretation time.- Specified by:
addMessageTypes
in interfaceCelCompilerBuilder
-
addFileTypes
public CelCompilerBuilder addFileTypes(com.google.protobuf.Descriptors.FileDescriptor... fileDescriptors)
Description copied from interface:CelCompilerBuilder
AddDescriptors.FileDescriptor
s to the use for type-checking, and for object creation at interpretation time.- Specified by:
addFileTypes
in interfaceCelCompilerBuilder
-
addFileTypes
public CelCompilerBuilder addFileTypes(java.lang.Iterable<com.google.protobuf.Descriptors.FileDescriptor> fileDescriptors)
Description copied from interface:CelCompilerBuilder
AddDescriptors.FileDescriptor
s to the use for type-checking, and for object creation at interpretation time.- Specified by:
addFileTypes
in interfaceCelCompilerBuilder
-
addFileTypes
public CelCompilerBuilder addFileTypes(com.google.protobuf.DescriptorProtos.FileDescriptorSet fileDescriptorSet)
Description copied from interface:CelCompilerBuilder
Add all of theDescriptors.FileDescriptor
s in aFileDescriptorSet
to the use for type-checking, and for object creation at interpretation time.- Specified by:
addFileTypes
in interfaceCelCompilerBuilder
-
setStandardEnvironmentEnabled
public CelCompilerBuilder setStandardEnvironmentEnabled(boolean value)
Description copied from interface:CelCompilerBuilder
Enable or disable the standard CEL library functions and variables- Specified by:
setStandardEnvironmentEnabled
in interfaceCelCompilerBuilder
-
addLibraries
public CelCompilerBuilder addLibraries(CelCompilerLibrary... libraries)
Description copied from interface:CelCompilerBuilder
Adds one or more libraries for parsing and type-checking.- Specified by:
addLibraries
in interfaceCelCompilerBuilder
-
addLibraries
public CelCompilerBuilder addLibraries(java.lang.Iterable<? extends CelCompilerLibrary> libraries)
Description copied from interface:CelCompilerBuilder
Adds a collection of libraries for parsing and type-checking.- Specified by:
addLibraries
in interfaceCelCompilerBuilder
-
build
@CheckReturnValue public CelCompilerImpl build()
Description copied from interface:CelCompilerBuilder
Build a new instance of theCelCompiler
.- Specified by:
build
in interfaceCelCompilerBuilder
-
-