Skip to content

Commit 3135446

Browse files
l46kokcopybara-github
authored andcommitted
Internal Changes
PiperOrigin-RevId: 824719239
1 parent 0c00aaa commit 3135446

37 files changed

+2816
-38
lines changed

common/src/main/java/dev/cel/common/ast/CelConstant.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,26 @@ public static CelConstant ofObjectValue(Object value) {
207207

208208
throw new IllegalArgumentException("Value is not a CelConstant: " + value);
209209
}
210+
211+
/** Gets the underlying value held by this constant. */
212+
public Object objectValue() {
213+
switch (getKind()) {
214+
case NULL_VALUE:
215+
return nullValue();
216+
case BOOLEAN_VALUE:
217+
return booleanValue();
218+
case INT64_VALUE:
219+
return int64Value();
220+
case UINT64_VALUE:
221+
return uint64Value();
222+
case DOUBLE_VALUE:
223+
return doubleValue();
224+
case STRING_VALUE:
225+
return stringValue();
226+
case BYTES_VALUE:
227+
return bytesValue();
228+
default:
229+
throw new IllegalStateException("Unsupported kind: " + getKind());
230+
}
231+
}
210232
}

common/src/main/java/dev/cel/common/types/BUILD.bazel

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,20 @@ java_library(
183183
],
184184
)
185185

186+
java_library(
187+
name = "default_type_provider",
188+
srcs = [
189+
"DefaultTypeProvider.java",
190+
],
191+
tags = [
192+
],
193+
deps = [
194+
":type_providers",
195+
":types",
196+
"@maven//:com_google_guava_guava",
197+
],
198+
)
199+
186200
cel_android_library(
187201
name = "cel_types_android",
188202
srcs = ["CelTypes.java"],
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package dev.cel.common.types;
16+
17+
import com.google.common.collect.ImmutableCollection;
18+
import com.google.common.collect.ImmutableMap;
19+
import com.google.common.collect.Maps;
20+
import java.util.Map;
21+
import java.util.Optional;
22+
23+
/** TODO */
24+
public class DefaultTypeProvider implements CelTypeProvider {
25+
26+
private static final ImmutableMap<String, CelType> COMMON_TYPES =
27+
ImmutableMap.<String, CelType>builder()
28+
.put("bool", TypeType.create(SimpleType.BOOL))
29+
.put("bytes", TypeType.create(SimpleType.BYTES))
30+
.put("double", TypeType.create(SimpleType.DOUBLE))
31+
.put("int", TypeType.create(SimpleType.INT))
32+
.put("uint", TypeType.create(SimpleType.UINT))
33+
.put("string", TypeType.create(SimpleType.STRING))
34+
.put("null_type", TypeType.create(SimpleType.NULL_TYPE))
35+
.put("dyn", TypeType.create(SimpleType.DYN))
36+
.put("list", TypeType.create(ListType.create(SimpleType.DYN)))
37+
.put("map", TypeType.create(MapType.create(SimpleType.DYN, SimpleType.DYN)))
38+
.put("google.protobuf.Duration", TypeType.create(SimpleType.DURATION))
39+
.put("google.protobuf.Timestamp", TypeType.create(SimpleType.TIMESTAMP))
40+
.put(
41+
"optional_type",
42+
TypeType.create(
43+
OptionalType.create(
44+
SimpleType.DYN))) // TODO: Move to CelOptionalLibrary
45+
.buildOrThrow();
46+
47+
// private static final ImmutableMap<Class<?>, TypeType> EXTENDABLE_TYPES =
48+
// ImmutableMap.<Class<?>, TypeType>builder()
49+
// .put(Collection.class, TypeType.create(ListType.create(SimpleType.DYN)))
50+
// .put(ByteString.class, TypeType.create(SimpleType.BYTES))
51+
// .put(Map.class, TypeType.create(MapType.create(SimpleType.DYN, SimpleType.DYN)))
52+
// .buildOrThrow();
53+
54+
private static Map.Entry<String, TypeType> newTypeMapEntry(CelType type) {
55+
return Maps.immutableEntry(type.name(), TypeType.create(type));
56+
}
57+
58+
@Override
59+
public ImmutableCollection<CelType> types() {
60+
return COMMON_TYPES.values();
61+
}
62+
63+
@Override
64+
public Optional<CelType> findType(String typeName) {
65+
return Optional.ofNullable(COMMON_TYPES.get(typeName));
66+
}
67+
68+
public static DefaultTypeProvider create() {
69+
return new DefaultTypeProvider();
70+
}
71+
72+
private DefaultTypeProvider() {}
73+
}

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 fromCelValueToJavaObject(CelValue celValue) {

common/types/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ java_library(
5050
exports = ["//common/src/main/java/dev/cel/common/types:cel_proto_message_types"],
5151
)
5252

53+
java_library(
54+
name = "default_type_provider",
55+
visibility = ["//:internal"],
56+
exports = ["//common/src/main/java/dev/cel/common/types:default_type_provider"],
57+
)
58+
5359
java_library(
5460
name = "cel_v1alpha1_types",
5561
visibility = ["//:internal"],

runtime/BUILD.bazel

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ java_library(
1919
],
2020
)
2121

22+
java_library(
23+
name = "cel_value_dispatcher",
24+
visibility = ["//:internal"],
25+
exports = [
26+
"//runtime/src/main/java/dev/cel/runtime:cel_value_dispatcher",
27+
],
28+
)
29+
2230
java_library(
2331
name = "dispatcher",
2432
visibility = ["//:internal"],
@@ -233,6 +241,16 @@ java_library(
233241
exports = ["//runtime/src/main/java/dev/cel/runtime:resolved_overload_internal"],
234242
)
235243

244+
java_library(
245+
name = "cel_value_function_binding",
246+
exports = ["//runtime/src/main/java/dev/cel/runtime:cel_value_function_binding"],
247+
)
248+
249+
java_library(
250+
name = "cel_value_function_overload",
251+
exports = ["//runtime/src/main/java/dev/cel/runtime:cel_value_function_overload"],
252+
)
253+
236254
java_library(
237255
name = "internal_function_binder",
238256
visibility = ["//:internal"],
@@ -244,3 +262,14 @@ cel_android_library(
244262
visibility = ["//:internal"],
245263
exports = ["//runtime/src/main/java/dev/cel/runtime:internal_function_binder_andriod"],
246264
)
265+
266+
java_library(
267+
name = "program",
268+
visibility = ["//:internal"],
269+
exports = ["//runtime/src/main/java/dev/cel/runtime:program"],
270+
)
271+
272+
cel_android_library(
273+
name = "program_android",
274+
exports = ["//runtime/src/main/java/dev/cel/runtime:program_android"],
275+
)

runtime/planner/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
load("@rules_java//java:defs.bzl", "java_library")
2+
3+
package(
4+
default_applicable_licenses = ["//:license"],
5+
default_visibility = ["//:internal"],
6+
)
7+
8+
java_library(
9+
name = "program_planner",
10+
exports = ["//runtime/src/main/java/dev/cel/runtime/planner:program_planner"],
11+
)

0 commit comments

Comments
 (0)