diff --git a/.bazelrc b/.bazelrc
new file mode 100644
index 000000000..0e8299f1d
--- /dev/null
+++ b/.bazelrc
@@ -0,0 +1,3 @@
+build --cxxopt=-std=c++14
+build --host_cxxopt=-std=c++14
+common --noenable_bzlmod
diff --git a/README.md b/README.md
index 7d673e4db..01e0a1450 100644
--- a/README.md
+++ b/README.md
@@ -55,14 +55,14 @@ CEL-Java is available in Maven Central Repository. [Download the JARs here][8] o
dev.cel
cel
- 0.7.1
+ 0.8.0
```
**Gradle**
```gradle
-implementation 'dev.cel:cel:0.7.1'
+implementation 'dev.cel:cel:0.8.0'
```
Then run this example:
diff --git a/WORKSPACE b/WORKSPACE
index 4dc16ce61..97ecd141a 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -73,20 +73,20 @@ maven_install(
"com.google.auto.value:auto-value:1.11.0",
"com.google.auto.value:auto-value-annotations:1.11.0",
"com.google.code.findbugs:annotations:3.0.1",
- "com.google.errorprone:error_prone_annotations:2.30.0",
- "com.google.guava:guava:33.3.0-jre",
- "com.google.guava:guava-testlib:33.3.0-jre",
- "com.google.protobuf:protobuf-java:4.28.0",
- "com.google.protobuf:protobuf-java-util:4.28.0",
+ "com.google.errorprone:error_prone_annotations:2.33.0",
+ "com.google.guava:guava:33.3.1-jre",
+ "com.google.guava:guava-testlib:33.3.1-jre",
+ "com.google.protobuf:protobuf-java:4.28.2",
+ "com.google.protobuf:protobuf-java-util:4.28.2",
"com.google.re2j:re2j:1.7",
- "com.google.testparameterinjector:test-parameter-injector:1.15",
- "com.google.truth.extensions:truth-java8-extension:1.4.2",
- "com.google.truth.extensions:truth-proto-extension:1.4.2",
- "com.google.truth:truth:1.4.2",
+ "com.google.testparameterinjector:test-parameter-injector:1.18",
+ "com.google.truth.extensions:truth-java8-extension:1.4.4",
+ "com.google.truth.extensions:truth-proto-extension:1.4.4",
+ "com.google.truth:truth:1.4.4",
"org.antlr:antlr4-runtime:" + ANTLR4_VERSION,
"org.jspecify:jspecify:1.0.0",
"org.threeten:threeten-extra:1.8.0",
- "org.yaml:snakeyaml:2.2",
+ "org.yaml:snakeyaml:2.3",
],
repositories = [
"https://maven.google.com",
@@ -96,9 +96,9 @@ maven_install(
http_archive(
name = "com_google_protobuf",
- sha256 = "13e7749c30bc24af6ee93e092422f9dc08491c7097efa69461f88eb5f61805ce",
- strip_prefix = "protobuf-28.0",
- urls = ["https://github.com/protocolbuffers/protobuf/archive/v28.0.tar.gz"],
+ sha256 = "b2340aa47faf7ef10a0328190319d3f3bee1b24f426d4ce8f4253b6f27ce16db",
+ strip_prefix = "protobuf-28.2",
+ urls = ["https://github.com/protocolbuffers/protobuf/archive/v28.2.tar.gz"],
)
# Required by com_google_protobuf
diff --git a/bundle/BUILD.bazel b/bundle/BUILD.bazel
index e562cff00..91336cdf5 100644
--- a/bundle/BUILD.bazel
+++ b/bundle/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"],
diff --git a/bundle/src/main/java/dev/cel/bundle/BUILD.bazel b/bundle/src/main/java/dev/cel/bundle/BUILD.bazel
index 70744129c..b6f170ee4 100644
--- a/bundle/src/main/java/dev/cel/bundle/BUILD.bazel
+++ b/bundle/src/main/java/dev/cel/bundle/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = ["//:license"],
default_visibility = [
@@ -37,10 +39,10 @@ java_library(
"//parser:macro",
"//parser:parser_builder",
"//runtime",
- "@@protobuf~//java/core",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_code_findbugs_annotations",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
diff --git a/bundle/src/test/java/dev/cel/bundle/BUILD.bazel b/bundle/src/test/java/dev/cel/bundle/BUILD.bazel
index 3ca1dd570..be643cce7 100644
--- a/bundle/src/test/java/dev/cel/bundle/BUILD.bazel
+++ b/bundle/src/test/java/dev/cel/bundle/BUILD.bazel
@@ -1,3 +1,4 @@
+load("@rules_java//java:defs.bzl", "java_library")
load("//:testing.bzl", "junit4_test_suites")
package(default_applicable_licenses = [
@@ -32,7 +33,6 @@ java_library(
"//parser:macro",
"//runtime",
"//runtime:unknown_attributes",
- "@@protobuf~//java/core",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/test/v1/proto2:test_all_types_java_proto",
"@cel_spec//proto/test/v1/proto3:test_all_types_java_proto",
@@ -40,6 +40,7 @@ java_library(
"@com_google_googleapis//google/type:type_java_proto",
"@maven//:com_google_guava_guava",
"@maven//:com_google_guava_guava_testlib",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_protobuf_protobuf_java_util",
"@maven//:com_google_testparameterinjector_test_parameter_injector",
"@maven//:com_google_truth_extensions_truth_proto_extension",
diff --git a/checker/BUILD.bazel b/checker/BUILD.bazel
index 25fc8d739..8add14f59 100644
--- a/checker/BUILD.bazel
+++ b/checker/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"],
diff --git a/checker/src/main/java/dev/cel/checker/BUILD.bazel b/checker/src/main/java/dev/cel/checker/BUILD.bazel
index 039eb7f6c..05671f426 100644
--- a/checker/src/main/java/dev/cel/checker/BUILD.bazel
+++ b/checker/src/main/java/dev/cel/checker/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = [
"//:license",
@@ -50,10 +52,10 @@ java_library(
"//common/types",
"//common/types:cel_types",
"//common/types:type_providers",
- "@@protobuf~//java/core",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_jspecify_jspecify",
],
)
@@ -73,6 +75,7 @@ java_library(
"//common",
"//common:compiler_common",
"//common:options",
+ "//common:source_location",
"//common/annotations",
"//common/ast:expr_converter",
"//common/internal:env_visitor",
@@ -81,10 +84,10 @@ java_library(
"//common/types:cel_types",
"//common/types:message_type_provider",
"//common/types:type_providers",
- "@@protobuf~//java/core",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
@@ -100,9 +103,9 @@ java_library(
"//common:compiler_common",
"//common:options",
"//common/types:type_providers",
- "@@protobuf~//java/core",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_errorprone_error_prone_annotations",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
@@ -113,9 +116,9 @@ java_library(
],
deps = [
"//:auto_value",
- "@@protobuf~//java/core",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
@@ -166,6 +169,7 @@ java_library(
deps = [
":cel_ident_decl",
"//:auto_value",
+ "//common",
"//common:compiler_common",
"//common:features",
"//common:options",
@@ -180,10 +184,10 @@ java_library(
"//common/types:type_providers",
"//parser:macro",
"//parser:operator",
- "@@protobuf~//java/core",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_jspecify_jspecify",
],
)
@@ -212,5 +216,6 @@ java_library(
deps = [
":checker_legacy_environment",
"//common",
+ "//common:proto_ast",
],
)
diff --git a/checker/src/test/java/dev/cel/checker/BUILD.bazel b/checker/src/test/java/dev/cel/checker/BUILD.bazel
index ff4b87a34..e3e410429 100644
--- a/checker/src/test/java/dev/cel/checker/BUILD.bazel
+++ b/checker/src/test/java/dev/cel/checker/BUILD.bazel
@@ -1,3 +1,4 @@
+load("@rules_java//java:defs.bzl", "java_library")
load("//:testing.bzl", "junit4_test_suites")
package(default_applicable_licenses = [
@@ -10,7 +11,7 @@ java_library(
srcs = glob(["*Test.java"]),
resources = ["//checker/src/test/resources:baselines"],
deps = [
- "@@protobuf~//java/core",
+ "@maven//:com_google_protobuf_protobuf_java",
# "//java/com/google/testing/testsize:annotations",
"//:auto_value",
"//checker",
diff --git a/codelab/BUILD.bazel b/codelab/BUILD.bazel
index eea160dc4..95bb127b6 100644
--- a/codelab/BUILD.bazel
+++ b/codelab/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//codelab:__subpackages__"],
diff --git a/codelab/src/main/codelab/BUILD.bazel b/codelab/src/main/codelab/BUILD.bazel
index 7b3065e47..adeb3b5dd 100644
--- a/codelab/src/main/codelab/BUILD.bazel
+++ b/codelab/src/main/codelab/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = [
"//:license",
@@ -33,9 +35,9 @@ java_library(
"//validator/validators:homogeneous_literal", # unuseddeps: keep
"//validator/validators:regex", # unuseddeps: keep
"//validator/validators:timestamp", # unuseddeps: keep
- "@@protobuf~//java/core", # unuseddeps: keep
"@com_google_googleapis//google/rpc/context:attribute_context_java_proto", # unuseddeps: keep
"@maven//:com_google_guava_guava", # unuseddeps: keep
+ "@maven//:com_google_protobuf_protobuf_java", # unuseddeps: keep
"@maven//:com_google_protobuf_protobuf_java_util", # unuseddeps: keep
],
)
diff --git a/codelab/src/main/codelab/solutions/BUILD.bazel b/codelab/src/main/codelab/solutions/BUILD.bazel
index 42820a846..458fbe0b4 100644
--- a/codelab/src/main/codelab/solutions/BUILD.bazel
+++ b/codelab/src/main/codelab/solutions/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = [
"//:license",
@@ -33,9 +35,9 @@ java_library(
"//validator/validators:homogeneous_literal",
"//validator/validators:regex",
"//validator/validators:timestamp",
- "@@protobuf~//java/core",
"@com_google_googleapis//google/rpc/context:attribute_context_java_proto",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_protobuf_protobuf_java_util",
],
)
diff --git a/codelab/src/test/codelab/BUILD.bazel b/codelab/src/test/codelab/BUILD.bazel
index 84363646a..0cfccfcaa 100644
--- a/codelab/src/test/codelab/BUILD.bazel
+++ b/codelab/src/test/codelab/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_test")
+
package(default_applicable_licenses = [
"//:license",
])
@@ -27,9 +29,9 @@ java_test(
"//codelab",
"//common",
"//common/types",
- "@@protobuf~//java/core",
"@com_google_googleapis//google/rpc/context:attribute_context_java_proto",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_testparameterinjector_test_parameter_injector",
"@maven//:junit_junit",
],
@@ -58,9 +60,9 @@ java_test(
"//:java_truth",
"//codelab",
"//common",
- "@@protobuf~//java/core",
"@com_google_googleapis//google/rpc/context:attribute_context_java_proto",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_testparameterinjector_test_parameter_injector",
"@maven//:junit_junit",
],
@@ -91,9 +93,9 @@ java_test(
"//:java_truth",
"//codelab",
"//common",
- "@@protobuf~//java/core",
"@com_google_googleapis//google/rpc/context:attribute_context_java_proto",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_protobuf_protobuf_java_util",
"@maven//:com_google_testparameterinjector_test_parameter_injector",
"@maven//:junit_junit",
diff --git a/codelab/src/test/codelab/solutions/BUILD.bazel b/codelab/src/test/codelab/solutions/BUILD.bazel
index be146d8f9..09e89dc51 100644
--- a/codelab/src/test/codelab/solutions/BUILD.bazel
+++ b/codelab/src/test/codelab/solutions/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_test")
+
package(default_applicable_licenses = [
"//:license",
])
@@ -25,9 +27,9 @@ java_test(
"//codelab:solutions",
"//common",
"//common/types",
- "@@protobuf~//java/core",
"@com_google_googleapis//google/rpc/context:attribute_context_java_proto",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_testparameterinjector_test_parameter_injector",
"@maven//:junit_junit",
],
@@ -54,9 +56,9 @@ java_test(
"//:java_truth",
"//codelab:solutions",
"//common",
- "@@protobuf~//java/core",
"@com_google_googleapis//google/rpc/context:attribute_context_java_proto",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_testparameterinjector_test_parameter_injector",
"@maven//:junit_junit",
],
@@ -85,9 +87,9 @@ java_test(
"//:java_truth",
"//codelab:solutions",
"//common",
- "@@protobuf~//java/core",
"@com_google_googleapis//google/rpc/context:attribute_context_java_proto",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_protobuf_protobuf_java_util",
"@maven//:com_google_testparameterinjector_test_parameter_injector",
"@maven//:junit_junit",
diff --git a/common/BUILD.bazel b/common/BUILD.bazel
index 3af0c0c66..af0bf8abb 100644
--- a/common/BUILD.bazel
+++ b/common/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"],
@@ -5,10 +7,7 @@ package(
java_library(
name = "common",
- exports = [
- "//common/src/main/java/dev/cel/common",
- "//common/src/main/java/dev/cel/common:source_location", # TODO: Split callers
- ],
+ exports = ["//common/src/main/java/dev/cel/common"],
)
java_library(
diff --git a/common/annotations/BUILD.bazel b/common/annotations/BUILD.bazel
index 62a6ccfd9..046955e82 100644
--- a/common/annotations/BUILD.bazel
+++ b/common/annotations/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"],
diff --git a/common/ast/BUILD.bazel b/common/ast/BUILD.bazel
index 5400e6a8e..0a27ae0bc 100644
--- a/common/ast/BUILD.bazel
+++ b/common/ast/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"],
diff --git a/common/internal/BUILD.bazel b/common/internal/BUILD.bazel
index 6293804f2..63c8bcbf0 100644
--- a/common/internal/BUILD.bazel
+++ b/common/internal/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"],
diff --git a/common/navigation/BUILD.bazel b/common/navigation/BUILD.bazel
index df3447513..1dba25b8e 100644
--- a/common/navigation/BUILD.bazel
+++ b/common/navigation/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"],
diff --git a/common/src/main/java/dev/cel/common/BUILD.bazel b/common/src/main/java/dev/cel/common/BUILD.bazel
index 4706fb93d..9e4fa12fd 100644
--- a/common/src/main/java/dev/cel/common/BUILD.bazel
+++ b/common/src/main/java/dev/cel/common/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = ["//:license"],
default_visibility = [
@@ -12,7 +14,6 @@ COMMON_SOURCES = [
"CelDescriptorUtil.java",
"CelDescriptors.java",
"CelException.java",
- "CelProtoAbstractSyntaxTree.java", # TODO Split target after migrating callers
"CelSource.java",
]
@@ -32,6 +33,11 @@ SOURCE_SOURCES = [
"Source.java",
]
+# keep sorted
+PROTO_AST_SOURCE = [
+ "CelProtoAbstractSyntaxTree.java",
+]
+
# keep sorted
PROTO_V1ALPHA1_AST_SOURCE = [
"CelProtoV1Alpha1AbstractSyntaxTree.java",
@@ -49,16 +55,15 @@ java_library(
"//:auto_value",
"//common/annotations",
"//common/ast",
- "//common/ast:expr_converter",
"//common/internal",
"//common/internal:file_descriptor_converter",
"//common/types",
"//common/types:cel_types",
"//common/types:type_providers",
- "@@protobuf~//java/core",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
@@ -108,7 +113,17 @@ java_library(
java_library(
name = "proto_ast",
- exports = [":common"], # TODO Split target after migrating callers
+ srcs = PROTO_AST_SOURCE,
+ tags = [
+ ],
+ deps = [
+ "//common",
+ "//common/ast:expr_converter",
+ "//common/types:cel_types",
+ "@cel_spec//proto/cel/expr:expr_java_proto",
+ "@maven//:com_google_errorprone_error_prone_annotations",
+ "@maven//:com_google_guava_guava",
+ ],
)
java_library(
@@ -178,9 +193,9 @@ java_library(
tags = [
],
deps = [
- "@@protobuf~//java/core",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_protobuf_protobuf_java_util",
],
)
diff --git a/common/src/main/java/dev/cel/common/CelAbstractSyntaxTree.java b/common/src/main/java/dev/cel/common/CelAbstractSyntaxTree.java
index 3d55bde38..59023adfd 100644
--- a/common/src/main/java/dev/cel/common/CelAbstractSyntaxTree.java
+++ b/common/src/main/java/dev/cel/common/CelAbstractSyntaxTree.java
@@ -15,6 +15,7 @@
package dev.cel.common;
import dev.cel.expr.Type;
+import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.errorprone.annotations.Immutable;
@@ -36,16 +37,17 @@
*
Note: Use {@link CelProtoAbstractSyntaxTree} if you need access to the protobuf equivalent
* ASTs, such as ParsedExpr and CheckedExpr from syntax.proto or checked.proto.
*/
+@AutoValue
@Immutable
-public final class CelAbstractSyntaxTree {
+public abstract class CelAbstractSyntaxTree {
- private final CelSource celSource;
+ abstract CelSource celSource();
- private final CelExpr celExpr;
+ abstract CelExpr celExpr();
- private final ImmutableMap references;
+ abstract ImmutableMap references();
- private final ImmutableMap types;
+ abstract ImmutableMap types();
/**
* Constructs a new instance of CelAbstractSyntaxTree that represent a parsed expression.
@@ -54,7 +56,8 @@ public final class CelAbstractSyntaxTree {
* validating or optimizing an AST.
*/
public static CelAbstractSyntaxTree newParsedAst(CelExpr celExpr, CelSource celSource) {
- return new CelAbstractSyntaxTree(celExpr, celSource);
+ return new AutoValue_CelAbstractSyntaxTree(
+ celSource, celExpr, ImmutableMap.of(), ImmutableMap.of());
}
/**
@@ -69,32 +72,18 @@ public static CelAbstractSyntaxTree newCheckedAst(
CelSource celSource,
Map references,
Map types) {
- return new CelAbstractSyntaxTree(celExpr, celSource, references, types);
- }
-
- private CelAbstractSyntaxTree(CelExpr celExpr, CelSource celSource) {
- this(celExpr, celSource, ImmutableMap.of(), ImmutableMap.of());
- }
-
- private CelAbstractSyntaxTree(
- CelExpr celExpr,
- CelSource celSource,
- Map references,
- Map types) {
- this.celExpr = celExpr;
- this.celSource = celSource;
- this.references = ImmutableMap.copyOf(references);
- this.types = ImmutableMap.copyOf(types);
+ return new AutoValue_CelAbstractSyntaxTree(
+ celSource, celExpr, ImmutableMap.copyOf(references), ImmutableMap.copyOf(types));
}
/** Returns the underlying {@link CelExpr} representation of the abstract syntax tree. */
public CelExpr getExpr() {
- return celExpr;
+ return celExpr();
}
/** Tests whether the underlying abstract syntax tree has been type checked or not. */
public boolean isChecked() {
- return !types.isEmpty();
+ return !types().isEmpty();
}
/**
@@ -117,23 +106,23 @@ public Type getProtoResultType() {
* Returns the {@link CelSource} that was used during construction of the abstract syntax tree.
*/
public CelSource getSource() {
- return celSource;
+ return celSource();
}
public Optional getType(long exprId) {
- return Optional.ofNullable(types.get(exprId));
+ return Optional.ofNullable(types().get(exprId));
}
public ImmutableMap getTypeMap() {
- return types;
+ return types();
}
public Optional getReference(long exprId) {
- return Optional.ofNullable(references.get(exprId));
+ return Optional.ofNullable(references().get(exprId));
}
public ImmutableMap getReferenceMap() {
- return references;
+ return references();
}
public CelReference getReferenceOrThrow(long exprId) {
@@ -142,12 +131,12 @@ public CelReference getReferenceOrThrow(long exprId) {
}
Optional findEnumValue(long exprId) {
- CelReference ref = references.get(exprId);
+ CelReference ref = references().get(exprId);
return ref != null ? ref.value() : Optional.empty();
}
Optional> findOverloadIDs(long exprId) {
- CelReference ref = references.get(exprId);
+ CelReference ref = references().get(exprId);
return ref != null && !ref.value().isPresent()
? Optional.of(ref.overloadIds())
: Optional.empty();
diff --git a/common/src/main/java/dev/cel/common/CelSource.java b/common/src/main/java/dev/cel/common/CelSource.java
index 1c8d4dbe8..2678a0a2c 100644
--- a/common/src/main/java/dev/cel/common/CelSource.java
+++ b/common/src/main/java/dev/cel/common/CelSource.java
@@ -36,37 +36,34 @@
/** Represents the source content of an expression and related metadata. */
@Immutable
-public final class CelSource implements Source {
-
- private final CelCodePointArray codePoints;
- private final String description;
- private final ImmutableList lineOffsets;
- private final ImmutableMap positions;
- private final ImmutableMap macroCalls;
- private final ImmutableSet extensions;
-
- private CelSource(Builder builder) {
- this.codePoints = checkNotNull(builder.codePoints);
- this.description = checkNotNull(builder.description);
- this.positions = checkNotNull(ImmutableMap.copyOf(builder.positions));
- this.lineOffsets = checkNotNull(ImmutableList.copyOf(builder.lineOffsets));
- this.macroCalls = checkNotNull(ImmutableMap.copyOf(builder.macroCalls));
- this.extensions = checkNotNull(builder.extensions.build());
- }
+@AutoValue
+public abstract class CelSource implements Source {
+
+ abstract CelCodePointArray codePoints();
+
+ abstract String description();
+
+ abstract ImmutableList lineOffsets();
+
+ abstract ImmutableMap positions();
+
+ abstract ImmutableMap macroCalls();
+
+ abstract ImmutableSet extensions();
@Override
public CelCodePointArray getContent() {
- return codePoints;
+ return codePoints();
}
@Override
public String getDescription() {
- return description;
+ return description();
}
@Override
public ImmutableMap getPositionsMap() {
- return positions;
+ return positions();
}
/**
@@ -76,15 +73,15 @@ public ImmutableMap getPositionsMap() {
* NOTE: The indices point to the index just after the '\n' not the index of '\n' itself.
*/
public ImmutableList getLineOffsets() {
- return lineOffsets;
+ return lineOffsets();
}
public ImmutableMap getMacroCalls() {
- return macroCalls;
+ return macroCalls();
}
public ImmutableSet getExtensions() {
- return extensions;
+ return extensions();
}
/** See {@link #getLocationOffset(int, int)}. */
@@ -101,19 +98,19 @@ public Optional getLocationOffset(CelSourceLocation location) {
* @param column the column number starting from 0
*/
public Optional getLocationOffset(int line, int column) {
- return getLocationOffsetImpl(lineOffsets, line, column);
+ return getLocationOffsetImpl(lineOffsets(), line, column);
}
/**
* Get the line and column in the source expression text for the given code point {@code offset}.
*/
public Optional getOffsetLocation(int offset) {
- return CelSourceHelper.getOffsetLocation(codePoints, offset);
+ return CelSourceHelper.getOffsetLocation(codePoints(), offset);
}
@Override
public Optional getSnippet(int line) {
- return CelSourceHelper.getSnippet(codePoints, line);
+ return CelSourceHelper.getSnippet(codePoints(), line);
}
/**
@@ -136,11 +133,11 @@ private static Optional getLocationOffsetImpl(
}
public Builder toBuilder() {
- return new Builder(codePoints, lineOffsets)
- .setDescription(description)
- .addPositionsMap(positions)
- .addAllExtensions(extensions)
- .addAllMacroCalls(macroCalls);
+ return new Builder(codePoints(), lineOffsets())
+ .setDescription(description())
+ .addPositionsMap(positions())
+ .addAllExtensions(extensions())
+ .addAllMacroCalls(macroCalls());
}
public static Builder newBuilder() {
@@ -236,12 +233,6 @@ public Builder addAllMacroCalls(Map macroCalls) {
return this;
}
- @CanIgnoreReturnValue
- public Builder clearMacroCall(long exprId) {
- this.macroCalls.remove(exprId);
- return this;
- }
-
public ImmutableSet getExtensions() {
return extensions.build();
}
@@ -308,7 +299,13 @@ public boolean containsMacroCalls(long exprId) {
@CheckReturnValue
public CelSource build() {
- return new CelSource(this);
+ return new AutoValue_CelSource(
+ codePoints,
+ description,
+ ImmutableList.copyOf(lineOffsets),
+ ImmutableMap.copyOf(positions),
+ ImmutableMap.copyOf(macroCalls),
+ extensions.build());
}
}
@@ -369,7 +366,7 @@ public enum Component {
/** Type checker. Checks that references in an AST are defined and types agree. */
COMPONENT_TYPE_CHECKER,
/** Runtime. Evaluates a parsed and optionally checked CEL AST against a context. */
- COMPONENT_RUNTIME;
+ COMPONENT_RUNTIME
}
@CheckReturnValue
diff --git a/common/src/main/java/dev/cel/common/annotations/BUILD.bazel b/common/src/main/java/dev/cel/common/annotations/BUILD.bazel
index 434eede90..cdfa32938 100644
--- a/common/src/main/java/dev/cel/common/annotations/BUILD.bazel
+++ b/common/src/main/java/dev/cel/common/annotations/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = [
"//:license",
diff --git a/common/src/main/java/dev/cel/common/ast/BUILD.bazel b/common/src/main/java/dev/cel/common/ast/BUILD.bazel
index 6c1709f1a..a5736cff9 100644
--- a/common/src/main/java/dev/cel/common/ast/BUILD.bazel
+++ b/common/src/main/java/dev/cel/common/ast/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = [
"//:license",
@@ -46,9 +48,9 @@ java_library(
deps = [
"//:auto_value",
"//common/annotations",
- "@@protobuf~//java/core",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_jspecify_jspecify",
],
)
@@ -96,8 +98,8 @@ java_library(
deps = [
":ast",
"//common/annotations",
- "@@protobuf~//java/core",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
diff --git a/common/src/main/java/dev/cel/common/internal/BUILD.bazel b/common/src/main/java/dev/cel/common/internal/BUILD.bazel
index 70a91fc8c..6b83b441a 100644
--- a/common/src/main/java/dev/cel/common/internal/BUILD.bazel
+++ b/common/src/main/java/dev/cel/common/internal/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = [
"//:license",
@@ -40,9 +42,9 @@ java_library(
"//:auto_value",
"//common/annotations",
"//common/ast",
- "@@protobuf~//java/core",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_antlr_antlr4_runtime",
],
)
@@ -103,8 +105,8 @@ java_library(
],
deps = [
"//common/annotations",
- "@@protobuf~//java/core",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
@@ -124,11 +126,11 @@ java_library(
"//common:proto_json_adapter",
"//common:runtime_exception",
"//common/annotations",
- "@@protobuf~//java/core",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_code_findbugs_annotations",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_jspecify_jspecify",
],
)
@@ -142,9 +144,9 @@ java_library(
":dynamic_proto",
"//:auto_value",
"//common/annotations",
- "@@protobuf~//java/core",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_jspecify_jspecify",
],
)
@@ -158,9 +160,9 @@ java_library(
],
deps = [
"//:auto_value",
- "@@protobuf~//java/core",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
@@ -182,8 +184,8 @@ java_library(
],
deps = [
"//common/annotations",
- "@@protobuf~//java/core",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
@@ -197,7 +199,7 @@ java_library(
":default_instance_message_factory",
":proto_message_factory",
"//common/annotations",
- "@@protobuf~//java/core",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
@@ -208,9 +210,9 @@ java_library(
],
deps = [
":cel_descriptor_pools",
- "@@protobuf~//java/core",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
@@ -223,9 +225,9 @@ java_library(
":well_known_proto",
"//common",
"//common/annotations",
- "@@protobuf~//java/core",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
diff --git a/common/src/main/java/dev/cel/common/internal/BasicCodePointArray.java b/common/src/main/java/dev/cel/common/internal/BasicCodePointArray.java
index 251f09d61..a240df763 100644
--- a/common/src/main/java/dev/cel/common/internal/BasicCodePointArray.java
+++ b/common/src/main/java/dev/cel/common/internal/BasicCodePointArray.java
@@ -18,6 +18,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkPositionIndexes;
+import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.Immutable;
@@ -32,50 +33,40 @@
@Immutable
@VisibleForTesting
@Internal
-public final class BasicCodePointArray extends CelCodePointArray {
+@AutoValue
+@AutoValue.CopyAnnotations
+@SuppressWarnings("Immutable") // char[] is not exposed externally, thus cannot be mutated.
+public abstract class BasicCodePointArray extends CelCodePointArray {
- @SuppressWarnings("Immutable")
- private final char[] codePoints;
+ @SuppressWarnings("AutoValueImmutableFields")
+ abstract char[] codePoints();
- private final int offset;
- private final int size;
- private final ImmutableList lineOffsets;
+ abstract int offset();
- BasicCodePointArray(char[] codePoints, int size, ImmutableList lineOffsets) {
- this(codePoints, 0, lineOffsets, size);
+ static BasicCodePointArray create(
+ char[] codePoints, int size, ImmutableList lineOffsets) {
+ return create(codePoints, 0, lineOffsets, size);
}
- BasicCodePointArray(char[] codePoints, int offset, ImmutableList lineOffsets, int size) {
- this.codePoints = checkNotNull(codePoints);
- this.offset = offset;
- this.size = size;
- this.lineOffsets = lineOffsets;
+ static BasicCodePointArray create(
+ char[] codePoints, int offset, ImmutableList lineOffsets, int size) {
+ return new AutoValue_BasicCodePointArray(size, checkNotNull(lineOffsets), codePoints, offset);
}
@Override
public BasicCodePointArray slice(int i, int j) {
checkPositionIndexes(i, j, size());
- return new BasicCodePointArray(codePoints, offset + i, lineOffsets, j - i);
+ return create(codePoints(), offset() + i, lineOffsets(), j - i);
}
@Override
public int get(int index) {
checkElementIndex(index, size());
- return codePoints[offset + index] & 0xffff;
+ return codePoints()[offset() + index] & 0xffff;
}
@Override
- public int size() {
- return size;
- }
-
- @Override
- public ImmutableList lineOffsets() {
- return lineOffsets;
- }
-
- @Override
- public String toString() {
- return new String(codePoints, offset, size);
+ public final String toString() {
+ return new String(codePoints(), offset(), size());
}
}
diff --git a/common/src/main/java/dev/cel/common/internal/CelCodePointArray.java b/common/src/main/java/dev/cel/common/internal/CelCodePointArray.java
index 94d94b5dc..1f3124c93 100644
--- a/common/src/main/java/dev/cel/common/internal/CelCodePointArray.java
+++ b/common/src/main/java/dev/cel/common/internal/CelCodePointArray.java
@@ -101,11 +101,12 @@ public static CelCodePointArray fromString(String text) {
intArray[intIndex++] = codePoint;
}
- return new SupplementalCodePointArray(
+ return SupplementalCodePointArray.create(
intArray, intIndex, lineOffsetContext.buildLineOffsets());
}
- return new BasicCodePointArray(charArray, charIndex, lineOffsetContext.buildLineOffsets());
+ return BasicCodePointArray.create(
+ charArray, charIndex, lineOffsetContext.buildLineOffsets());
}
int[] intArray = new int[text.length()];
int intIndex = 0;
@@ -120,11 +121,11 @@ public static CelCodePointArray fromString(String text) {
intArray[intIndex++] = codePoint;
}
- return new SupplementalCodePointArray(
+ return SupplementalCodePointArray.create(
intArray, intIndex, lineOffsetContext.buildLineOffsets());
}
- return new Latin1CodePointArray(byteArray, byteIndex, lineOffsetContext.buildLineOffsets());
+ return Latin1CodePointArray.create(byteArray, byteIndex, lineOffsetContext.buildLineOffsets());
}
private static class LineOffsetContext {
diff --git a/common/src/main/java/dev/cel/common/internal/Latin1CodePointArray.java b/common/src/main/java/dev/cel/common/internal/Latin1CodePointArray.java
index a06448aba..9e54c3a6c 100644
--- a/common/src/main/java/dev/cel/common/internal/Latin1CodePointArray.java
+++ b/common/src/main/java/dev/cel/common/internal/Latin1CodePointArray.java
@@ -19,6 +19,7 @@
import static com.google.common.base.Preconditions.checkPositionIndexes;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
+import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.Immutable;
@@ -32,51 +33,40 @@
@Immutable
@VisibleForTesting
@Internal
-public final class Latin1CodePointArray extends CelCodePointArray {
+@AutoValue
+@AutoValue.CopyAnnotations
+@SuppressWarnings("Immutable") // byte[] is not exposed externally, thus cannot be mutated.
+public abstract class Latin1CodePointArray extends CelCodePointArray {
- @SuppressWarnings("Immutable")
- private final byte[] codePoints;
+ @SuppressWarnings("AutoValueImmutableFields")
+ abstract byte[] codePoints();
- private final int offset;
- private final int size;
- private final ImmutableList lineOffsets;
+ abstract int offset();
- Latin1CodePointArray(byte[] codePoints, int size, ImmutableList lineOffsets) {
- this(codePoints, 0, lineOffsets, size);
+ static Latin1CodePointArray create(
+ byte[] codePoints, int size, ImmutableList lineOffsets) {
+ return create(codePoints, 0, lineOffsets, size);
}
- Latin1CodePointArray(
+ static Latin1CodePointArray create(
byte[] codePoints, int offset, ImmutableList lineOffsets, int size) {
- this.codePoints = checkNotNull(codePoints);
- this.offset = offset;
- this.size = size;
- this.lineOffsets = lineOffsets;
+ return new AutoValue_Latin1CodePointArray(size, checkNotNull(lineOffsets), codePoints, offset);
}
@Override
public Latin1CodePointArray slice(int i, int j) {
checkPositionIndexes(i, j, size());
- return new Latin1CodePointArray(codePoints, offset + i, lineOffsets, j - i);
+ return create(codePoints(), offset() + i, lineOffsets(), j - i);
}
@Override
public int get(int index) {
checkElementIndex(index, size());
- return Byte.toUnsignedInt(codePoints[offset + index]);
+ return Byte.toUnsignedInt(codePoints()[offset() + index]);
}
@Override
- public int size() {
- return size;
- }
-
- @Override
- public ImmutableList lineOffsets() {
- return lineOffsets;
- }
-
- @Override
- public String toString() {
- return new String(codePoints, offset, size, ISO_8859_1);
+ public final String toString() {
+ return new String(codePoints(), offset(), size(), ISO_8859_1);
}
}
diff --git a/common/src/main/java/dev/cel/common/internal/SupplementalCodePointArray.java b/common/src/main/java/dev/cel/common/internal/SupplementalCodePointArray.java
index 30f2fce27..dc3cb10a4 100644
--- a/common/src/main/java/dev/cel/common/internal/SupplementalCodePointArray.java
+++ b/common/src/main/java/dev/cel/common/internal/SupplementalCodePointArray.java
@@ -18,6 +18,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkPositionIndexes;
+import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.Immutable;
@@ -32,51 +33,41 @@
@Immutable
@VisibleForTesting
@Internal
-public final class SupplementalCodePointArray extends CelCodePointArray {
+@AutoValue
+@AutoValue.CopyAnnotations
+@SuppressWarnings("Immutable") // int[] is not exposed externally, thus cannot be mutated.
+public abstract class SupplementalCodePointArray extends CelCodePointArray {
- @SuppressWarnings("Immutable")
- private final int[] codePoints;
+ @SuppressWarnings("AutoValueImmutableFields")
+ abstract int[] codePoints();
- private final int offset;
- private final int size;
- private final ImmutableList lineOffsets;
+ abstract int offset();
- SupplementalCodePointArray(int[] codePoints, int size, ImmutableList lineOffsets) {
- this(codePoints, 0, lineOffsets, size);
+ static SupplementalCodePointArray create(
+ int[] codePoints, int size, ImmutableList lineOffsets) {
+ return create(codePoints, 0, lineOffsets, size);
}
- SupplementalCodePointArray(
+ static SupplementalCodePointArray create(
int[] codePoints, int offset, ImmutableList lineOffsets, int size) {
- this.codePoints = checkNotNull(codePoints);
- this.offset = offset;
- this.size = size;
- this.lineOffsets = lineOffsets;
+ return new AutoValue_SupplementalCodePointArray(
+ size, checkNotNull(lineOffsets), codePoints, offset);
}
@Override
public SupplementalCodePointArray slice(int i, int j) {
checkPositionIndexes(i, j, size());
- return new SupplementalCodePointArray(codePoints, offset + i, lineOffsets, j - i);
+ return create(codePoints(), offset() + i, lineOffsets(), j - i);
}
@Override
public int get(int index) {
checkElementIndex(index, size());
- return codePoints[offset + index];
+ return codePoints()[offset() + index];
}
@Override
- public int size() {
- return size;
- }
-
- @Override
- public ImmutableList lineOffsets() {
- return lineOffsets;
- }
-
- @Override
- public String toString() {
- return new String(codePoints, offset, size);
+ public final String toString() {
+ return new String(codePoints(), offset(), size());
}
}
diff --git a/common/src/main/java/dev/cel/common/navigation/BUILD.bazel b/common/src/main/java/dev/cel/common/navigation/BUILD.bazel
index b3bccf67b..2c5a80fe7 100644
--- a/common/src/main/java/dev/cel/common/navigation/BUILD.bazel
+++ b/common/src/main/java/dev/cel/common/navigation/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = [
"//:license",
diff --git a/common/src/main/java/dev/cel/common/testing/BUILD.bazel b/common/src/main/java/dev/cel/common/testing/BUILD.bazel
index a5b967b16..574638e35 100644
--- a/common/src/main/java/dev/cel/common/testing/BUILD.bazel
+++ b/common/src/main/java/dev/cel/common/testing/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = [
"//:license",
diff --git a/common/src/main/java/dev/cel/common/types/BUILD.bazel b/common/src/main/java/dev/cel/common/types/BUILD.bazel
index 19c741e0f..4f4029419 100644
--- a/common/src/main/java/dev/cel/common/types/BUILD.bazel
+++ b/common/src/main/java/dev/cel/common/types/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = [
"//:license",
@@ -73,9 +75,9 @@ java_library(
":type_providers",
":types",
"//common/annotations",
- "@@protobuf~//java/core",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
@@ -88,9 +90,9 @@ java_library(
":type_providers",
":types",
"//common/annotations",
- "@@protobuf~//java/core",
"@com_google_googleapis//google/api/expr/v1alpha1:expr_java_proto",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
@@ -132,8 +134,8 @@ java_library(
"//:auto_value",
"//common",
"//common/internal:file_descriptor_converter",
- "@@protobuf~//java/core",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
diff --git a/common/src/main/java/dev/cel/common/values/BUILD.bazel b/common/src/main/java/dev/cel/common/values/BUILD.bazel
index fcb1269fa..c9e233108 100644
--- a/common/src/main/java/dev/cel/common/values/BUILD.bazel
+++ b/common/src/main/java/dev/cel/common/values/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = [
"//:license",
@@ -114,9 +116,9 @@ java_library(
"//common/types:cel_types",
"//common/types:type_providers",
"//common/values:cel_byte_string",
- "@@protobuf~//java/core",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_protobuf_protobuf_java_util",
"@maven//:org_jspecify_jspecify",
],
@@ -137,7 +139,7 @@ java_library(
"//common/annotations",
"//common/internal:dynamic_proto",
"//common/internal:proto_message_factory",
- "@@protobuf~//java/core",
"@maven//:com_google_errorprone_error_prone_annotations",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
diff --git a/common/src/test/java/dev/cel/common/BUILD.bazel b/common/src/test/java/dev/cel/common/BUILD.bazel
index f5c08b3b4..bac8affe1 100644
--- a/common/src/test/java/dev/cel/common/BUILD.bazel
+++ b/common/src/test/java/dev/cel/common/BUILD.bazel
@@ -1,3 +1,4 @@
+load("@rules_java//java:defs.bzl", "java_library")
load("//:testing.bzl", "junit4_test_suites")
package(default_applicable_licenses = [
@@ -14,18 +15,24 @@ java_library(
"//common:compiler_common",
"//common:features",
"//common:options",
+ "//common:proto_ast",
"//common:proto_json_adapter",
"//common:proto_v1alpha1_ast",
+ "//common:source_location",
"//common/ast",
"//common/internal",
"//common/types",
"//common/types:cel_types",
"//common/types:cel_v1alpha1_types",
- "@@protobuf~//java/core",
+ "//compiler",
+ "//compiler:compiler_builder",
+ "//parser:macro",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@com_google_googleapis//google/api/expr/v1alpha1:expr_java_proto",
"@com_google_googleapis//google/rpc/context:attribute_context_java_proto",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_guava_guava_testlib",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_testparameterinjector_test_parameter_injector",
"@maven//:com_google_truth_extensions_truth_proto_extension",
"@maven//:junit_junit",
diff --git a/common/src/test/java/dev/cel/common/CelAbstractSyntaxTreeTest.java b/common/src/test/java/dev/cel/common/CelAbstractSyntaxTreeTest.java
index 48e28894a..2cdf81380 100644
--- a/common/src/test/java/dev/cel/common/CelAbstractSyntaxTreeTest.java
+++ b/common/src/test/java/dev/cel/common/CelAbstractSyntaxTreeTest.java
@@ -26,10 +26,14 @@
import dev.cel.expr.SourceInfo;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.testing.EqualsTester;
import dev.cel.common.ast.CelConstant;
import dev.cel.common.ast.CelExpr;
import dev.cel.common.types.CelTypes;
import dev.cel.common.types.SimpleType;
+import dev.cel.compiler.CelCompiler;
+import dev.cel.compiler.CelCompilerFactory;
+import dev.cel.parser.CelStandardMacro;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -146,6 +150,30 @@ public void getSource_hasDescriptionEqualToSourceLocation() {
assertThat(PARSED_AST.getSource().getDescription()).isEqualTo("test/location.cel");
}
+ @Test
+ public void equalityTest() throws Exception {
+ CelCompiler celCompiler =
+ CelCompilerFactory.standardCelCompilerBuilder()
+ .setStandardMacros(CelStandardMacro.STANDARD_MACROS)
+ .setOptions(CelOptions.current().populateMacroCalls(true).build())
+ .build();
+ new EqualsTester()
+ .addEqualityGroup(
+ CelAbstractSyntaxTree.newParsedAst(
+ CelExpr.newBuilder().build(), CelSource.newBuilder().build()))
+ .addEqualityGroup(
+ celCompiler.compile("'foo'").getAst(), celCompiler.compile("'foo'").getAst()) // ASCII
+ .addEqualityGroup(
+ celCompiler.compile("'가나다'").getAst(), celCompiler.compile("'가나다'").getAst()) // BMP
+ .addEqualityGroup(
+ celCompiler.compile("'😦😁😑'").getAst(),
+ celCompiler.compile("'😦😁😑'").getAst()) // SMP
+ .addEqualityGroup(
+ celCompiler.compile("[1,2,3].exists(x, x > 0)").getAst(),
+ celCompiler.compile("[1,2,3].exists(x, x > 0)").getAst())
+ .testEquals();
+ }
+
@Test
public void parsedExpression_createAst() {
CelExpr celExpr = CelExpr.newBuilder().setId(1).setConstant(CelConstant.ofValue(2)).build();
diff --git a/common/src/test/java/dev/cel/common/ast/BUILD.bazel b/common/src/test/java/dev/cel/common/ast/BUILD.bazel
index 2097a25f7..848920037 100644
--- a/common/src/test/java/dev/cel/common/ast/BUILD.bazel
+++ b/common/src/test/java/dev/cel/common/ast/BUILD.bazel
@@ -1,3 +1,4 @@
+load("@rules_java//java:defs.bzl", "java_library")
load("//:testing.bzl", "junit4_test_suites")
package(default_applicable_licenses = [
@@ -28,12 +29,12 @@ java_library(
"//extensions:optional_library",
"//parser:macro",
"//parser:operator",
- "@@protobuf~//java/core",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/test/v1/proto3:test_all_types_java_proto",
"@com_google_googleapis//google/api/expr/v1alpha1:expr_java_proto",
"@maven//:com_google_guava_guava",
"@maven//:com_google_guava_guava_testlib",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_testparameterinjector_test_parameter_injector",
"@maven//:junit_junit",
],
diff --git a/common/src/test/java/dev/cel/common/internal/BUILD.bazel b/common/src/test/java/dev/cel/common/internal/BUILD.bazel
index fa46ced6d..d29f67a50 100644
--- a/common/src/test/java/dev/cel/common/internal/BUILD.bazel
+++ b/common/src/test/java/dev/cel/common/internal/BUILD.bazel
@@ -1,3 +1,4 @@
+load("@rules_java//java:defs.bzl", "java_library")
load("//:testing.bzl", "junit4_test_suites")
package(default_applicable_licenses = [
@@ -30,11 +31,11 @@ java_library(
"//common/src/test/resources:service_conflicting_name_java_proto",
"//common/src/test/resources:single_file_java_proto",
"//common/testing",
- "@@protobuf~//java/core",
"@cel_spec//proto/test/v1/proto2:test_all_types_java_proto",
"@cel_spec//proto/test/v1/proto3:test_all_types_java_proto",
"@com_google_googleapis//google/type:type_java_proto",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_testparameterinjector_test_parameter_injector",
"@maven//:junit_junit",
],
diff --git a/common/src/test/java/dev/cel/common/navigation/BUILD.bazel b/common/src/test/java/dev/cel/common/navigation/BUILD.bazel
index c754e80df..f269a0ce3 100644
--- a/common/src/test/java/dev/cel/common/navigation/BUILD.bazel
+++ b/common/src/test/java/dev/cel/common/navigation/BUILD.bazel
@@ -1,3 +1,4 @@
+load("@rules_java//java:defs.bzl", "java_library")
load("//:testing.bzl", "junit4_test_suites")
package(default_applicable_licenses = ["//:license"])
diff --git a/common/src/test/java/dev/cel/common/types/BUILD.bazel b/common/src/test/java/dev/cel/common/types/BUILD.bazel
index 432ff1570..a084efd62 100644
--- a/common/src/test/java/dev/cel/common/types/BUILD.bazel
+++ b/common/src/test/java/dev/cel/common/types/BUILD.bazel
@@ -1,3 +1,4 @@
+load("@rules_java//java:defs.bzl", "java_library")
load("//:testing.bzl", "junit4_test_suites")
package(default_applicable_licenses = ["//:license"])
diff --git a/common/src/test/java/dev/cel/common/values/BUILD.bazel b/common/src/test/java/dev/cel/common/values/BUILD.bazel
index 92b71c6db..48e90e120 100644
--- a/common/src/test/java/dev/cel/common/values/BUILD.bazel
+++ b/common/src/test/java/dev/cel/common/values/BUILD.bazel
@@ -1,3 +1,4 @@
+load("@rules_java//java:defs.bzl", "java_library")
load("//:testing.bzl", "junit4_test_suites")
package(default_applicable_licenses = ["//:license"])
@@ -24,10 +25,10 @@ java_library(
"//common/values:cel_value_provider",
"//common/values:proto_message_value",
"//common/values:proto_message_value_provider",
- "@@protobuf~//java/core",
"@cel_spec//proto/test/v1/proto2:test_all_types_java_proto",
"@maven//:com_google_guava_guava",
"@maven//:com_google_guava_guava_testlib",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_protobuf_protobuf_java_util",
"@maven//:com_google_testparameterinjector_test_parameter_injector",
"@maven//:junit_junit",
diff --git a/common/testing/BUILD.bazel b/common/testing/BUILD.bazel
index b98bc4c68..a88ccf4f9 100644
--- a/common/testing/BUILD.bazel
+++ b/common/testing/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = ["//:license"],
default_testonly = True,
diff --git a/common/types/BUILD.bazel b/common/types/BUILD.bazel
index af81a975b..76904d76b 100644
--- a/common/types/BUILD.bazel
+++ b/common/types/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"],
diff --git a/common/values/BUILD.bazel b/common/values/BUILD.bazel
index 931999b4c..c7efe7dee 100644
--- a/common/values/BUILD.bazel
+++ b/common/values/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"], # TODO: Expose to public when ready
diff --git a/compiler/BUILD.bazel b/compiler/BUILD.bazel
index e5e41e0a5..5bb7d7129 100644
--- a/compiler/BUILD.bazel
+++ b/compiler/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"],
diff --git a/compiler/src/main/java/dev/cel/compiler/BUILD.bazel b/compiler/src/main/java/dev/cel/compiler/BUILD.bazel
index 1f58aafe9..22d403b6c 100644
--- a/compiler/src/main/java/dev/cel/compiler/BUILD.bazel
+++ b/compiler/src/main/java/dev/cel/compiler/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = [
"//:license",
@@ -42,10 +44,10 @@ java_library(
"//parser",
"//parser:macro",
"//parser:parser_builder",
- "@@protobuf~//java/core",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
@@ -64,8 +66,8 @@ java_library(
"//common/types:type_providers",
"//parser:macro",
"//parser:parser_builder",
- "@@protobuf~//java/core",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_errorprone_error_prone_annotations",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
diff --git a/conformance/src/test/java/dev/cel/conformance/BUILD.bazel b/conformance/src/test/java/dev/cel/conformance/BUILD.bazel
index 6b60d77d4..57a83b955 100644
--- a/conformance/src/test/java/dev/cel/conformance/BUILD.bazel
+++ b/conformance/src/test/java/dev/cel/conformance/BUILD.bazel
@@ -1,3 +1,4 @@
+load("@rules_java//java:defs.bzl", "java_library")
load("//conformance/src/test/java/dev/cel/conformance:conformance_test.bzl", "conformance_test")
package(default_applicable_licenses = [
@@ -29,13 +30,13 @@ java_library(
"//parser:macro",
"//parser:parser_builder",
"//runtime",
- "@@protobuf~//java/core",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/test/v1:simple_java_proto",
"@cel_spec//proto/test/v1/proto2:test_all_types_java_proto",
"@cel_spec//proto/test/v1/proto3:test_all_types_java_proto",
"@com_google_googleapis//google/api/expr/v1alpha1:expr_java_proto",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_truth_extensions_truth_proto_extension",
"@maven//:junit_junit",
],
diff --git a/extensions/BUILD.bazel b/extensions/BUILD.bazel
index 70956e336..5f520c418 100644
--- a/extensions/BUILD.bazel
+++ b/extensions/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"],
diff --git a/extensions/src/main/java/dev/cel/extensions/BUILD.bazel b/extensions/src/main/java/dev/cel/extensions/BUILD.bazel
index 7f6652666..e14421c9b 100644
--- a/extensions/src/main/java/dev/cel/extensions/BUILD.bazel
+++ b/extensions/src/main/java/dev/cel/extensions/BUILD.bazel
@@ -1,3 +1,5 @@
+load("@rules_java//java:defs.bzl", "java_library")
+
package(
default_applicable_licenses = [
"//:license",
@@ -102,9 +104,9 @@ java_library(
"//common/types",
"//compiler:compiler_builder",
"//runtime",
- "@@protobuf~//java/core",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
@@ -125,8 +127,8 @@ java_library(
"//parser:operator",
"//parser:parser_builder",
"//runtime",
- "@@protobuf~//java/core",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
diff --git a/extensions/src/main/java/dev/cel/extensions/CelOptionalLibrary.java b/extensions/src/main/java/dev/cel/extensions/CelOptionalLibrary.java
index dad6e0a97..6398f9965 100644
--- a/extensions/src/main/java/dev/cel/extensions/CelOptionalLibrary.java
+++ b/extensions/src/main/java/dev/cel/extensions/CelOptionalLibrary.java
@@ -16,6 +16,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.ImmutableList.toImmutableList;
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.UnsignedLong;
@@ -58,6 +59,7 @@ public enum Function {
HAS_VALUE("hasValue"),
OPTIONAL_NONE("optional.none"),
OPTIONAL_OF("optional.of"),
+ OPTIONAL_UNWRAP("optional.unwrap"),
OPTIONAL_OF_NON_ZERO_VALUE("optional.ofNonZeroValue"),
OR("or"),
OR_VALUE("orValue");
@@ -117,6 +119,10 @@ public void setCheckerOptions(CelCheckerBuilder checkerBuilder) {
CelFunctionDecl.newFunctionDeclaration(
Function.HAS_VALUE.getFunction(),
CelOverloadDecl.newMemberOverload("optional_hasValue", SimpleType.BOOL, optionalTypeV)),
+ CelFunctionDecl.newFunctionDeclaration(
+ Function.OPTIONAL_UNWRAP.getFunction(),
+ CelOverloadDecl.newGlobalOverload(
+ "optional_unwrap_list", listTypeV, ListType.create(optionalTypeV))),
// Note: Implementation of "or" and "orValue" are special-cased inside the interpreter.
// Hence, their bindings are not provided here.
CelFunctionDecl.newFunctionDeclaration(
@@ -165,6 +171,7 @@ public void setCheckerOptions(CelCheckerBuilder checkerBuilder) {
}
@Override
+ @SuppressWarnings("unchecked")
public void setRuntimeOptions(CelRuntimeBuilder runtimeBuilder) {
runtimeBuilder.addFunctionBindings(
CelRuntime.CelFunctionBinding.from("optional_of", Object.class, Optional::of),
@@ -177,6 +184,8 @@ public void setRuntimeOptions(CelRuntimeBuilder runtimeBuilder) {
}
return Optional.of(val);
}),
+ CelRuntime.CelFunctionBinding.from(
+ "optional_unwrap_list", Collection.class, CelOptionalLibrary::elideOptionalCollection),
CelRuntime.CelFunctionBinding.from(
"optional_none", ImmutableList.of(), val -> Optional.empty()),
CelRuntime.CelFunctionBinding.from(
@@ -185,6 +194,10 @@ public void setRuntimeOptions(CelRuntimeBuilder runtimeBuilder) {
"optional_hasValue", Object.class, val -> ((Optional>) val).isPresent()));
}
+ private static ImmutableList