Skip to content

Commit 0ab74f8

Browse files
l46kokcopybara-github
authored andcommitted
Internal Changes
PiperOrigin-RevId: 834975953
1 parent 0082ec4 commit 0ab74f8

24 files changed

+1989
-55
lines changed

common/src/main/java/dev/cel/common/values/CelValueConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
@SuppressWarnings("unchecked") // Unchecked cast of generics due to type-erasure (ex: MapValue).
3434
@Internal
3535
@Immutable
36-
abstract class CelValueConverter {
36+
public abstract class CelValueConverter {
3737

3838
/** Adapts a {@link CelValue} to a plain old Java Object. */
3939
public Object unwrap(CelValue celValue) {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ java_library(
128128
":resolved_overload",
129129
"//:auto_value",
130130
"//common:error_codes",
131+
"//common/annotations",
131132
"@maven//:com_google_code_findbugs_annotations",
132133
"@maven//:com_google_errorprone_error_prone_annotations",
133134
"@maven//:com_google_guava_guava",
@@ -146,6 +147,7 @@ cel_android_library(
146147
":resolved_overload_android",
147148
"//:auto_value",
148149
"//common:error_codes",
150+
"//common/annotations",
149151
"@maven//:com_google_code_findbugs_annotations",
150152
"@maven//:com_google_errorprone_error_prone_annotations",
151153
"@maven_android//:com_google_guava_guava",
@@ -577,11 +579,13 @@ java_library(
577579
java_library(
578580
name = "interpretable",
579581
srcs = INTERPRABLE_SOURCES,
582+
tags = [
583+
],
580584
deps = [
581585
":evaluation_exception",
582-
":evaluation_listener",
583586
":function_resolver",
584587
"//common/annotations",
588+
"//runtime:evaluation_listener",
585589
"@maven//:com_google_errorprone_error_prone_annotations",
586590
"@maven//:org_jspecify_jspecify",
587591
],
@@ -877,6 +881,7 @@ java_library(
877881
"//common/values:cel_value_provider",
878882
"//runtime/standard:standard_function",
879883
"@maven//:com_google_code_findbugs_annotations",
884+
"@maven//:com_google_errorprone_error_prone_annotations",
880885
"@maven//:com_google_guava_guava",
881886
],
882887
)
@@ -1172,6 +1177,7 @@ java_library(
11721177
":function_overload",
11731178
":unknown_attributes",
11741179
"//:auto_value",
1180+
"//common/annotations",
11751181
"@maven//:com_google_errorprone_error_prone_annotations",
11761182
"@maven//:com_google_guava_guava",
11771183
],
@@ -1186,6 +1192,7 @@ cel_android_library(
11861192
":function_overload_android",
11871193
":unknown_attributes_android",
11881194
"//:auto_value",
1195+
"//common/annotations",
11891196
"@maven//:com_google_errorprone_error_prone_annotations",
11901197
"@maven_android//:com_google_guava_guava",
11911198
],

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.google.auto.value.AutoValue;
1818
import com.google.common.collect.ImmutableList;
1919
import com.google.errorprone.annotations.Immutable;
20+
import dev.cel.common.annotations.Internal;
2021
import java.util.List;
2122
import java.util.Map;
2223

@@ -26,7 +27,8 @@
2627
*/
2728
@AutoValue
2829
@Immutable
29-
abstract class CelResolvedOverload {
30+
@Internal
31+
public abstract class CelResolvedOverload {
3032

3133
/** The overload id of the function. */
3234
public abstract String getOverloadId();
@@ -78,7 +80,14 @@ public static CelResolvedOverload of(
7880
* Returns true if the overload's expected argument types match the types of the given arguments.
7981
*/
8082
boolean canHandle(Object[] arguments) {
81-
ImmutableList<Class<?>> parameterTypes = getParameterTypes();
83+
return canHandle(arguments, getParameterTypes(), isStrict());
84+
}
85+
86+
/**
87+
* Returns true if the overload's expected argument types match the types of the given arguments.
88+
*/
89+
public static boolean canHandle(
90+
Object[] arguments, ImmutableList<Class<?>> parameterTypes, boolean isStrict) {
8291
if (parameterTypes.size() != arguments.length) {
8392
return false;
8493
}
@@ -96,7 +105,7 @@ boolean canHandle(Object[] arguments) {
96105

97106
if (arg instanceof Exception || arg instanceof CelUnknownSet) {
98107
// Only non-strict functions can accept errors/unknowns as arguments to a function
99-
if (!isStrict()) {
108+
if (!isStrict) {
100109
// Skip assignability check below, but continue to validate remaining args
101110
continue;
102111
}

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package dev.cel.runtime;
1616

17+
import static com.google.common.base.Preconditions.checkArgument;
1718
import static com.google.common.base.Preconditions.checkNotNull;
1819

1920
import com.google.auto.value.AutoBuilder;
@@ -22,17 +23,27 @@
2223
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2324
import com.google.errorprone.annotations.Immutable;
2425
import dev.cel.common.CelErrorCode;
26+
import dev.cel.common.annotations.Internal;
2527
import java.util.ArrayList;
2628
import java.util.List;
2729
import java.util.Map;
2830
import java.util.Optional;
2931

30-
/** Default implementation of dispatcher. */
32+
/**
33+
* Default implementation of dispatcher.
34+
*
35+
* <p>CEL Library Internals. Do Not Use.
36+
*/
3137
@Immutable
32-
final class DefaultDispatcher implements CelFunctionResolver {
38+
@Internal
39+
public final class DefaultDispatcher implements CelFunctionResolver {
3340

3441
private final ImmutableMap<String, CelResolvedOverload> overloads;
3542

43+
public Optional<CelResolvedOverload> findOverload(String functionName) {
44+
return Optional.ofNullable(overloads.get(functionName));
45+
}
46+
3647
@Override
3748
public Optional<CelResolvedOverload> findOverloadMatchingArgs(
3849
String functionName, List<String> overloadIds, Object[] args) throws CelEvaluationException {
@@ -101,24 +112,26 @@ Optional<CelResolvedOverload> findSingleNonStrictOverload(List<String> overloadI
101112
return Optional.empty();
102113
}
103114

104-
static Builder newBuilder() {
115+
public static Builder newBuilder() {
105116
return new AutoBuilder_DefaultDispatcher_Builder();
106117
}
107118

119+
/** Builder for {@link DefaultDispatcher}. */
108120
@AutoBuilder(ofClass = DefaultDispatcher.class)
109-
abstract static class Builder {
121+
public abstract static class Builder {
110122

111123
abstract ImmutableMap<String, CelResolvedOverload> overloads();
112124

113125
abstract ImmutableMap.Builder<String, CelResolvedOverload> overloadsBuilder();
114126

115127
@CanIgnoreReturnValue
116-
Builder addOverload(
128+
public Builder addOverload(
117129
String overloadId,
118130
List<Class<?>> argTypes,
119131
boolean isStrict,
120132
CelFunctionOverload overload) {
121133
checkNotNull(overloadId);
134+
checkArgument(!overloadId.isEmpty(), "Overload ID cannot be empty.");
122135
checkNotNull(argTypes);
123136
checkNotNull(overload);
124137

@@ -127,7 +140,7 @@ Builder addOverload(
127140
return this;
128141
}
129142

130-
abstract DefaultDispatcher build();
143+
public abstract DefaultDispatcher build();
131144
}
132145

133146
DefaultDispatcher(ImmutableMap<String, CelResolvedOverload> overloads) {

0 commit comments

Comments
 (0)