Skip to content

Commit 7b5aa7b

Browse files
l46kokcopybara-github
authored andcommitted
Internal Changes
PiperOrigin-RevId: 815965947
1 parent 1fc8922 commit 7b5aa7b

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

bundle/src/main/java/dev/cel/bundle/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ java_library(
2525
"//checker:checker_builder",
2626
"//checker:checker_legacy_environment",
2727
"//checker:proto_type_mask",
28+
"//checker:standard_decl",
2829
"//common:cel_ast",
2930
"//common:cel_source",
3031
"//common:compiler_common",
@@ -42,6 +43,7 @@ java_library(
4243
"//parser:parser_builder",
4344
"//runtime",
4445
"//runtime:function_binding",
46+
"//runtime:standard_functions",
4547
"@cel_spec//proto/cel/expr:checked_java_proto",
4648
"@maven//:com_google_code_findbugs_annotations",
4749
"@maven//:com_google_errorprone_error_prone_annotations",

bundle/src/main/java/dev/cel/bundle/CelBuilder.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.protobuf.Descriptors.FileDescriptor;
2323
import com.google.protobuf.ExtensionRegistry;
2424
import com.google.protobuf.Message;
25+
import dev.cel.checker.CelStandardDeclarations;
2526
import dev.cel.checker.ProtoTypeMask;
2627
import dev.cel.checker.TypeProvider;
2728
import dev.cel.common.CelContainer;
@@ -36,6 +37,7 @@
3637
import dev.cel.parser.CelStandardMacro;
3738
import dev.cel.runtime.CelFunctionBinding;
3839
import dev.cel.runtime.CelRuntimeLibrary;
40+
import dev.cel.runtime.CelStandardFunctions;
3941
import java.util.function.Function;
4042

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

87-
/*
89+
/**
8890
* Set the {@link CelContainer} to use as the namespace for resolving CEL expression variables and
8991
* functions.
9092
*/
@@ -299,6 +301,24 @@ public interface CelBuilder {
299301
@CanIgnoreReturnValue
300302
CelBuilder addRuntimeLibraries(Iterable<CelRuntimeLibrary> libraries);
301303

304+
/**
305+
* Override the standard declarations for the type-checker. This can be used to subset the
306+
* standard environment to only expose the desired declarations to the type-checker. {@link
307+
* #setStandardEnvironmentEnabled(boolean)} must be set to false for this to take effect.
308+
*/
309+
@CanIgnoreReturnValue
310+
CelBuilder setStandardDeclarations(CelStandardDeclarations standardDeclarations);
311+
312+
/**
313+
* Override the standard functions for the runtime. This can be used to subset the standard
314+
* environment to only expose the desired function overloads to the runtime.
315+
*
316+
* <p>{@link #setStandardEnvironmentEnabled(boolean)} must be set to false for this to take
317+
* effect.
318+
*/
319+
@CanIgnoreReturnValue
320+
CelBuilder setStandardFunctions(CelStandardFunctions standardFunctions);
321+
302322
/**
303323
* Sets a proto ExtensionRegistry to assist with unpacking Any messages containing a proto2
304324
extension field.

bundle/src/main/java/dev/cel/bundle/CelImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.protobuf.ExtensionRegistry;
2929
import com.google.protobuf.Message;
3030
import dev.cel.checker.CelCheckerBuilder;
31+
import dev.cel.checker.CelStandardDeclarations;
3132
import dev.cel.checker.ProtoTypeMask;
3233
import dev.cel.checker.TypeProvider;
3334
import dev.cel.common.CelAbstractSyntaxTree;
@@ -54,6 +55,7 @@
5455
import dev.cel.runtime.CelRuntime;
5556
import dev.cel.runtime.CelRuntimeBuilder;
5657
import dev.cel.runtime.CelRuntimeLibrary;
58+
import dev.cel.runtime.CelStandardFunctions;
5759
import java.util.Arrays;
5860
import java.util.function.Function;
5961

@@ -382,6 +384,20 @@ public CelBuilder addRuntimeLibraries(Iterable<CelRuntimeLibrary> libraries) {
382384
return this;
383385
}
384386

387+
@Override
388+
public CelBuilder setStandardDeclarations(CelStandardDeclarations standardDeclarations) {
389+
checkNotNull(standardDeclarations);
390+
compilerBuilder.setStandardDeclarations(standardDeclarations);
391+
return this;
392+
}
393+
394+
@Override
395+
public CelBuilder setStandardFunctions(CelStandardFunctions standardFunctions) {
396+
checkNotNull(standardFunctions);
397+
runtimeBuilder.setStandardFunctions(standardFunctions);
398+
return this;
399+
}
400+
385401
@Override
386402
public CelBuilder setExtensionRegistry(ExtensionRegistry extensionRegistry) {
387403
checkNotNull(extensionRegistry);

0 commit comments

Comments
 (0)