Skip to content
Open
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
11 changes: 10 additions & 1 deletion checker/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//:cel_android_rules.bzl", "cel_android_library")

package(
default_applicable_licenses = ["//:license"],
Expand Down Expand Up @@ -35,7 +36,10 @@ java_library(
java_library(
name = "checker_legacy_environment",
deprecation = "See go/cel-java-migration-guide. Please use CEL-Java Fluent APIs //compiler instead",
exports = ["//checker/src/main/java/dev/cel/checker:checker_legacy_environment"],
exports = [
":type_provider_legacy",
"//checker/src/main/java/dev/cel/checker:checker_legacy_environment",
],
)

java_library(
Expand All @@ -53,3 +57,8 @@ java_library(
name = "standard_decl",
exports = ["//checker/src/main/java/dev/cel/checker:standard_decl"],
)

cel_android_library(
name = "standard_decl_android",
exports = ["//checker/src/main/java/dev/cel/checker:standard_decl_android"],
)
33 changes: 25 additions & 8 deletions checker/src/main/java/dev/cel/checker/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//:cel_android_rules.bzl", "cel_android_library")

package(
default_applicable_licenses = [
Expand All @@ -25,14 +26,11 @@ CHECKER_BUILDER_SOURCES = [

# keep sorted
CHECKER_LEGACY_ENV_SOURCES = [
"DescriptorTypeProvider.java",
"Env.java",
"ExprChecker.java",
"ExprVisitor.java",
"InferenceContext.java",
"TypeFormatter.java",
"TypeProvider.java",
"Types.java",
]

java_library(
Expand Down Expand Up @@ -69,7 +67,7 @@ java_library(
":checker_legacy_environment",
":proto_type_mask",
":standard_decl",
":type_provider_legacy_impl",
":type_provider_legacy",
"//common:cel_ast",
"//common:cel_descriptor_util",
"//common:cel_function_decl",
Expand Down Expand Up @@ -102,9 +100,9 @@ java_library(
tags = [
],
deps = [
":checker_legacy_environment",
":proto_type_mask",
":standard_decl",
":type_provider_legacy",
"//common:cel_ast",
"//common:cel_function_decl",
"//common:cel_validation_result",
Expand Down Expand Up @@ -137,7 +135,7 @@ java_library(
tags = [
],
deps = [
":checker_legacy_environment",
":type_provider_legacy",
"//common/annotations",
"//common/types",
"//common/types:cel_proto_types",
Expand All @@ -156,6 +154,7 @@ java_library(
],
deps = [
":standard_decl",
":type_provider_legacy",
"//:auto_value",
"//common:cel_ast",
"//common:cel_function_decl",
Expand All @@ -173,7 +172,6 @@ java_library(
"//common/ast:expr_converter",
"//common/ast:mutable_expr",
"//common/internal:errors",
"//common/internal:file_descriptor_converter",
"//common/types",
"//common/types:cel_proto_types",
"//common/types:cel_types",
Expand All @@ -183,7 +181,6 @@ java_library(
"@cel_spec//proto/cel/expr:syntax_java_proto",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_jspecify_jspecify",
],
)
Expand Down Expand Up @@ -235,3 +232,23 @@ java_library(
"@maven//:com_google_guava_guava",
],
)

cel_android_library(
name = "standard_decl_android",
srcs = [
"CelStandardDeclarations.java",
],
tags = [
],
deps = [
"//common:cel_function_decl_android",
"//common:cel_overload_decl_android",
"//common:cel_var_decl_android",
"//common:operator_android",
"//common/types:cel_types_android",
"//common/types:type_providers_android",
"//common/types:types_android",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven_android//:com_google_guava_guava",
],
)
32 changes: 18 additions & 14 deletions checker/src/main/java/dev/cel/checker/CelCheckerLegacyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public final class CelCheckerLegacyImpl implements CelChecker, EnvVisitable {
private final Optional<CelType> expectedResultType;

@SuppressWarnings("Immutable")
private final TypeProvider typeProvider;
private final @Nullable TypeProvider typeProvider;

private final CelTypeProvider celTypeProvider;
private final boolean standardEnvironmentEnabled;
Expand Down Expand Up @@ -124,6 +124,10 @@ public CelCheckerBuilder toCheckerBuilder() {
.addFileTypes(fileDescriptors)
.addProtoTypeMasks(protoTypeMasks);

if (typeProvider != null) {
builder.setTypeProvider(typeProvider);
}

if (expectedResultType.isPresent()) {
builder.setResultType(expectedResultType.get());
}
Expand Down Expand Up @@ -162,11 +166,13 @@ public void accept(EnvVisitor envVisitor) {
private Env getEnv(Errors errors) {
Env env;
if (overriddenStandardDeclarations != null) {
env = Env.standard(overriddenStandardDeclarations, errors, typeProvider, celOptions);
env =
Env.standard(
overriddenStandardDeclarations, errors, celTypeProvider, typeProvider, celOptions);
} else if (standardEnvironmentEnabled) {
env = Env.standard(errors, typeProvider, celOptions);
env = Env.standard(errors, celTypeProvider, typeProvider, celOptions);
} else {
env = Env.unconfigured(errors, typeProvider, celOptions);
env = Env.unconfigured(errors, celTypeProvider, typeProvider, celOptions);
}
identDeclarations.forEach(env::add);
functionDeclarations.forEach(env::add);
Expand All @@ -190,7 +196,7 @@ public static final class Builder implements CelCheckerBuilder {
private CelContainer container;
private CelOptions celOptions;
private CelType expectedResultType;
private TypeProvider customTypeProvider;
private @Nullable TypeProvider customTypeProvider;
private CelTypeProvider celTypeProvider;
private boolean standardEnvironmentEnabled;
private CelStandardDeclarations standardDeclarations;
Expand Down Expand Up @@ -400,6 +406,11 @@ CelStandardDeclarations standardDeclarations() {
return this.standardDeclarations;
}

@VisibleForTesting
@Nullable TypeProvider customTypeProvider() {
return this.customTypeProvider;
}

@VisibleForTesting
CelTypeProvider celTypeProvider() {
return this.celTypeProvider;
Expand Down Expand Up @@ -459,20 +470,13 @@ public CelCheckerLegacyImpl build() {
messageTypeProvider = protoTypeMaskTypeProvider;
}

TypeProvider legacyProvider = new TypeProviderLegacyImpl(messageTypeProvider);
if (customTypeProvider != null) {
legacyProvider =
new TypeProvider.CombinedTypeProvider(
ImmutableList.of(customTypeProvider, legacyProvider));
}

return new CelCheckerLegacyImpl(
celOptions,
container,
identDeclarationSet,
functionDeclarations.build(),
Optional.fromNullable(expectedResultType),
legacyProvider,
customTypeProvider,
messageTypeProvider,
standardEnvironmentEnabled,
standardDeclarations,
Expand All @@ -499,7 +503,7 @@ private CelCheckerLegacyImpl(
ImmutableSet<CelVarDecl> identDeclarations,
ImmutableSet<CelFunctionDecl> functionDeclarations,
Optional<CelType> expectedResultType,
TypeProvider typeProvider,
@Nullable TypeProvider typeProvider,
CelTypeProvider celTypeProvider,
boolean standardEnvironmentEnabled,
@Nullable CelStandardDeclarations overriddenStandardDeclarations,
Expand Down
Loading
Loading