Add CelStandardDeclaration to allow environment subsetting for type-checker by copybara-service[bot] · Pull Request #448 · cel-expr/cel-java · GitHub
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
5 changes: 5 additions & 0 deletions checker/BUILD.bazel
23 changes: 22 additions & 1 deletion checker/src/main/java/dev/cel/checker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ CHECKER_LEGACY_ENV_SOURCES = [
"ExprChecker.java",
"ExprVisitor.java",
"InferenceContext.java",
"Standard.java",
"TypeFormatter.java",
"TypeProvider.java",
"Types.java",
Expand Down Expand Up @@ -70,6 +69,7 @@ java_library(
":checker_builder",
":checker_legacy_environment",
":proto_type_mask",
":standard_decl",
":type_provider_legacy_impl",
"//:auto_value",
"//common",
Expand Down Expand Up @@ -99,6 +99,7 @@ java_library(
deps = [
":checker_legacy_environment",
":proto_type_mask",
":standard_decl",
"//common",
"//common:compiler_common",
"//common:options",
Expand Down Expand Up @@ -168,6 +169,7 @@ java_library(
],
deps = [
":cel_ident_decl",
":standard_decl",
"//:auto_value",
"//common",
"//common:compiler_common",
Expand Down Expand Up @@ -219,3 +221,22 @@ java_library(
"//common:proto_ast",
],
)

java_library(
name = "standard_decl",
srcs = [
"CelStandardDeclarations.java",
],
tags = [
],
deps = [
":cel_ident_decl",
"//common:compiler_common",
"//common/types",
"//common/types:cel_types",
"//common/types:type_providers",
"//parser:operator",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
],
)
8 changes: 8 additions & 0 deletions checker/src/main/java/dev/cel/checker/CelCheckerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ public interface CelCheckerBuilder {
@CanIgnoreReturnValue
CelCheckerBuilder setStandardEnvironmentEnabled(boolean value);

/**
* 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
CelCheckerBuilder setStandardDeclarations(CelStandardDeclarations standardDeclarations);

/** Adds one or more libraries for parsing and type-checking. */
@CanIgnoreReturnValue
CelCheckerBuilder addLibraries(CelCheckerLibrary... libraries);
Expand Down
21 changes: 20 additions & 1 deletion checker/src/main/java/dev/cel/checker/CelCheckerLegacyImpl.java
Loading