Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bundle/src/main/java/dev/cel/bundle/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ java_library(
"//checker:checker_builder",
"//checker:checker_legacy_environment",
"//checker:proto_type_mask",
"//checker:standard_decl",
"//common:cel_ast",
"//common:cel_source",
"//common:compiler_common",
Expand All @@ -42,6 +43,7 @@ java_library(
"//parser:parser_builder",
"//runtime",
"//runtime:function_binding",
"//runtime:standard_functions",
"@cel_spec//proto/cel/expr:checked_java_proto",
"@maven//:com_google_code_findbugs_annotations",
"@maven//:com_google_errorprone_error_prone_annotations",
Expand Down
22 changes: 21 additions & 1 deletion bundle/src/main/java/dev/cel/bundle/CelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.protobuf.Descriptors.FileDescriptor;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
import dev.cel.checker.CelStandardDeclarations;
import dev.cel.checker.ProtoTypeMask;
import dev.cel.checker.TypeProvider;
import dev.cel.common.CelContainer;
Expand All @@ -36,6 +37,7 @@
import dev.cel.parser.CelStandardMacro;
import dev.cel.runtime.CelFunctionBinding;
import dev.cel.runtime.CelRuntimeLibrary;
import dev.cel.runtime.CelStandardFunctions;
import java.util.function.Function;

/** Interface for building an instance of Cel. */
Expand Down Expand Up @@ -84,7 +86,7 @@ public interface CelBuilder {
/** Retrieves the currently configured {@link CelContainer} in the builder. */
CelContainer container();

/*
/**
* Set the {@link CelContainer} to use as the namespace for resolving CEL expression variables and
* functions.
*/
Expand Down Expand Up @@ -299,6 +301,24 @@ public interface CelBuilder {
@CanIgnoreReturnValue
CelBuilder addRuntimeLibraries(Iterable<CelRuntimeLibrary> libraries);

/**
* Override the standard declarations for the type-checker. This can be used to subset the
* standard environment to only expose the desired declarations to the type-checker. {@link
* #setStandardEnvironmentEnabled(boolean)} must be set to false for this to take effect.
*/
@CanIgnoreReturnValue
CelBuilder setStandardDeclarations(CelStandardDeclarations standardDeclarations);

/**
* Override the standard functions for the runtime. This can be used to subset the standard
* environment to only expose the desired function overloads to the runtime.
*
* <p>{@link #setStandardEnvironmentEnabled(boolean)} must be set to false for this to take
* effect.
*/
@CanIgnoreReturnValue
CelBuilder setStandardFunctions(CelStandardFunctions standardFunctions);

/**
* Sets a proto ExtensionRegistry to assist with unpacking Any messages containing a proto2
extension field.
Expand Down
16 changes: 16 additions & 0 deletions bundle/src/main/java/dev/cel/bundle/CelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
import dev.cel.checker.CelCheckerBuilder;
import dev.cel.checker.CelStandardDeclarations;
import dev.cel.checker.ProtoTypeMask;
import dev.cel.checker.TypeProvider;
import dev.cel.common.CelAbstractSyntaxTree;
Expand All @@ -54,6 +55,7 @@
import dev.cel.runtime.CelRuntime;
import dev.cel.runtime.CelRuntimeBuilder;
import dev.cel.runtime.CelRuntimeLibrary;
import dev.cel.runtime.CelStandardFunctions;
import java.util.Arrays;
import java.util.function.Function;

Expand Down Expand Up @@ -382,6 +384,20 @@ public CelBuilder addRuntimeLibraries(Iterable<CelRuntimeLibrary> libraries) {
return this;
}

@Override
public CelBuilder setStandardDeclarations(CelStandardDeclarations standardDeclarations) {
checkNotNull(standardDeclarations);
compilerBuilder.setStandardDeclarations(standardDeclarations);
return this;
}

@Override
public CelBuilder setStandardFunctions(CelStandardFunctions standardFunctions) {
checkNotNull(standardFunctions);
runtimeBuilder.setStandardFunctions(standardFunctions);
return this;
}

@Override
public CelBuilder setExtensionRegistry(ExtensionRegistry extensionRegistry) {
checkNotNull(extensionRegistry);
Expand Down
Loading