Skip to content

Commit b071767

Browse files
l46kokcopybara-github
authored andcommitted
Create CelProtoMessageTypes for handling proto based types that require a full protobuf dependency
PiperOrigin-RevId: 720670672
1 parent 9faa264 commit b071767

File tree

6 files changed

+90
-1
lines changed

6 files changed

+90
-1
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ java_library(
9494
],
9595
)
9696

97+
java_library(
98+
name = "cel_proto_message_types",
99+
srcs = ["CelProtoMessageTypes.java"],
100+
tags = [
101+
],
102+
deps = [
103+
"//common/types:cel_proto_types",
104+
"@cel_spec//proto/cel/expr:expr_java_proto",
105+
"@maven//:com_google_protobuf_protobuf_java",
106+
],
107+
)
108+
97109
java_library(
98110
name = "cel_v1alpha1_types",
99111
srcs = ["CelV1AlphaTypes.java"],
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 dev.cel.expr.Type;
18+
import com.google.protobuf.Descriptors.Descriptor;
19+
20+
/**
21+
* Utility class for working with {@link Type} that require a full protobuf dependency (i.e:
22+
* descriptors).
23+
*/
24+
public final class CelProtoMessageTypes {
25+
26+
/** Create a message {@code Type} for {@code Descriptor}. */
27+
public static Type createMessage(Descriptor descriptor) {
28+
return CelProtoTypes.createMessage(descriptor.getFullName());
29+
}
30+
31+
private CelProtoMessageTypes() {}
32+
}

common/src/main/java/dev/cel/common/types/CelProtoTypes.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ public static Type createMessage(String messageName) {
112112
return Type.newBuilder().setMessageType(messageName).build();
113113
}
114114

115-
/** Create a message {@code Type} for {@code Descriptor}. */
115+
/**
116+
* @deprecated Use {@link CelProtoMessageTypes#createMessage} instead.
117+
*/
118+
@Deprecated
116119
public static Type createMessage(Descriptor descriptor) {
117120
return createMessage(descriptor.getFullName());
118121
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ java_library(
1111
"//:java_truth",
1212
"//common/types",
1313
"//common/types:cel_internal_types",
14+
"//common/types:cel_proto_message_types",
1415
"//common/types:cel_proto_types",
1516
"//common/types:cel_types",
1617
"//common/types:message_type_provider",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 static com.google.common.truth.Truth.assertThat;
18+
19+
import dev.cel.expr.Type;
20+
import com.google.testing.junit.testparameterinjector.TestParameterInjector;
21+
import dev.cel.expr.conformance.proto3.TestAllTypes;
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
25+
@RunWith(TestParameterInjector.class)
26+
public final class CelProtoMessageTypesTest {
27+
28+
@Test
29+
public void createMessage_fromDescriptor() {
30+
Type type = CelProtoMessageTypes.createMessage(TestAllTypes.getDescriptor());
31+
32+
assertThat(type)
33+
.isEqualTo(
34+
Type.newBuilder().setMessageType(TestAllTypes.getDescriptor().getFullName()).build());
35+
}
36+
}

common/types/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ java_library(
4444
exports = ["//common/src/main/java/dev/cel/common/types:cel_proto_types"],
4545
)
4646

47+
java_library(
48+
name = "cel_proto_message_types",
49+
exports = ["//common/src/main/java/dev/cel/common/types:cel_proto_message_types"],
50+
)
51+
4752
java_library(
4853
name = "cel_v1alpha1_types",
4954
visibility = ["//visibility:public"],

0 commit comments

Comments
 (0)