Skip to content

Commit bf2c693

Browse files
l46kokcopybara-github
authored andcommitted
Switch CelStandardFunctions to use dev.cel.runtime.CelFunctionBinding
PiperOrigin-RevId: 725825697
1 parent 418fbbe commit bf2c693

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

runtime/BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ java_library(
1515
],
1616
)
1717

18+
java_library(
19+
name = "standard_functions",
20+
exports = [
21+
"//runtime/src/main/java/dev/cel/runtime:standard_functions",
22+
],
23+
)
24+
1825
java_library(
1926
name = "function_binding",
2027
visibility = ["//visibility:public"],

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ RUNTIME_SOURCES = [
200200
"CelRuntimeFactory.java",
201201
"CelRuntimeLegacyImpl.java",
202202
"CelRuntimeLibrary.java",
203-
"CelStandardFunctions.java",
204203
"CelVariableResolver.java",
205204
"HierarchicalVariableResolver.java",
206205
"UnknownContext.java",
@@ -247,6 +246,28 @@ java_library(
247246
],
248247
)
249248

249+
java_library(
250+
name = "standard_functions",
251+
srcs = ["CelStandardFunctions.java"],
252+
tags = [
253+
],
254+
deps = [
255+
":function_binding",
256+
":runtime_equality",
257+
":runtime_helpers",
258+
"//common:error_codes",
259+
"//common:options",
260+
"//common:runtime_exception",
261+
"//common/annotations",
262+
"//common/internal:comparison_functions",
263+
"//common/internal:safe_string_formatter",
264+
"@maven//:com_google_errorprone_error_prone_annotations",
265+
"@maven//:com_google_guava_guava",
266+
"@maven//:com_google_protobuf_protobuf_java",
267+
"@maven//:com_google_protobuf_protobuf_java_util",
268+
],
269+
)
270+
250271
java_library(
251272
name = "function_binding",
252273
srcs = [
@@ -310,29 +331,24 @@ java_library(
310331
":interpreter",
311332
":proto_message_runtime_equality",
312333
":runtime_equality",
313-
":runtime_helpers",
314334
":runtime_type_provider_legacy",
315335
":unknown_attributes",
316336
"//:auto_value",
317337
"//common",
318-
"//common:error_codes",
319338
"//common:options",
320-
"//common:runtime_exception",
321339
"//common/annotations",
322340
"//common/internal:cel_descriptor_pools",
323-
"//common/internal:comparison_functions",
324341
"//common/internal:default_message_factory",
325342
"//common/internal:dynamic_proto",
326343
"//common/internal:proto_message_factory",
327-
"//common/internal:safe_string_formatter",
328344
"//common/types:cel_types",
329345
"//common/values:cel_value_provider",
330346
"//common/values:proto_message_value_provider",
347+
"//runtime:standard_functions",
331348
"@maven//:com_google_code_findbugs_annotations",
332349
"@maven//:com_google_errorprone_error_prone_annotations",
333350
"@maven//:com_google_guava_guava",
334351
"@maven//:com_google_protobuf_protobuf_java",
335-
"@maven//:com_google_protobuf_protobuf_java_util",
336352
"@maven//:org_jspecify_jspecify",
337353
],
338354
)

runtime/src/main/java/dev/cel/runtime/CelRuntimeLegacyImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ public CelRuntimeLegacyImpl build() {
243243
DynamicProto dynamicProto = DynamicProto.create(runtimeTypeFactory);
244244
RuntimeEquality runtimeEquality = ProtoMessageRuntimeEquality.create(dynamicProto, options);
245245

246-
ImmutableMap.Builder<String, CelFunctionBinding> functionBindingsBuilder =
246+
ImmutableMap.Builder<String, dev.cel.runtime.CelFunctionBinding> functionBindingsBuilder =
247247
ImmutableMap.builder();
248-
for (CelFunctionBinding standardFunctionBinding :
248+
for (dev.cel.runtime.CelFunctionBinding standardFunctionBinding :
249249
newStandardFunctionBindings(runtimeEquality)) {
250250
functionBindingsBuilder.put(
251251
standardFunctionBinding.getOverloadId(), standardFunctionBinding);
@@ -257,7 +257,7 @@ public CelRuntimeLegacyImpl build() {
257257
functionBindingsBuilder
258258
.buildOrThrow()
259259
.forEach(
260-
(String overloadId, CelFunctionBinding func) ->
260+
(String overloadId, dev.cel.runtime.CelFunctionBinding func) ->
261261
dispatcher.add(
262262
overloadId, func.getArgTypes(), (args) -> func.getDefinition().apply(args)));
263263

@@ -288,7 +288,7 @@ public CelRuntimeLegacyImpl build() {
288288
this);
289289
}
290290

291-
private ImmutableSet<CelFunctionBinding> newStandardFunctionBindings(
291+
private ImmutableSet<dev.cel.runtime.CelFunctionBinding> newStandardFunctionBindings(
292292
RuntimeEquality runtimeEquality) {
293293
CelStandardFunctions celStandardFunctions;
294294
if (standardEnvironmentEnabled) {
@@ -381,6 +381,7 @@ private Builder(Builder builder) {
381381
this.extensionRegistry = builder.extensionRegistry;
382382
this.customTypeFactory = builder.customTypeFactory;
383383
this.standardEnvironmentEnabled = builder.standardEnvironmentEnabled;
384+
this.overriddenStandardFunctions = builder.overriddenStandardFunctions;
384385
this.celValueProvider = builder.celValueProvider;
385386
// The following needs to be deep copied as they are collection builders
386387
this.fileTypes = deepCopy(builder.fileTypes);

runtime/src/main/java/dev/cel/runtime/CelStandardFunctions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import dev.cel.common.annotations.Internal;
3535
import dev.cel.common.internal.ComparisonFunctions;
3636
import dev.cel.common.internal.SafeStringFormatter;
37-
import dev.cel.runtime.CelRuntime.CelFunctionBinding;
3837
import dev.cel.runtime.CelStandardFunctions.StandardFunction.Overload.Arithmetic;
3938
import dev.cel.runtime.CelStandardFunctions.StandardFunction.Overload.BooleanOperator;
4039
import dev.cel.runtime.CelStandardFunctions.StandardFunction.Overload.Comparison;
@@ -1939,6 +1938,7 @@ public CelStandardFunctions build() {
19391938
* Functional interface for filtering standard functions. Returning true in the callback will
19401939
* include the function in the environment.
19411940
*/
1941+
@SuppressWarnings("AndroidJdkLibsChecker") // FunctionalInterface added in 24
19421942
@FunctionalInterface
19431943
public interface FunctionFilter {
19441944
boolean include(StandardFunction standardFunction, StandardOverload standardOverload);
@@ -1961,6 +1961,7 @@ private FunctionBindingHelper(CelOptions celOptions, RuntimeEquality runtimeEqua
19611961
}
19621962
}
19631963

1964+
@SuppressWarnings("AndroidJdkLibsChecker") // FunctionalInterface added in 24
19641965
@FunctionalInterface
19651966
@Immutable
19661967
private interface FunctionBindingCreator {

runtime/src/test/java/dev/cel/runtime/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ java_library(
4949
"//runtime:proto_message_runtime_helpers",
5050
"//runtime:runtime_equality",
5151
"//runtime:runtime_helpers",
52+
"//runtime:standard_functions",
5253
"//runtime:type_resolver",
5354
"//runtime:unknown_attributes",
5455
"//runtime:unknown_options",

0 commit comments

Comments
 (0)