Skip to content

Commit 04be92b

Browse files
l46kokcopybara-github
authored andcommitted
Remove deprecated ExprFeatures
PiperOrigin-RevId: 716771447
1 parent 6dd63e0 commit 04be92b

12 files changed

Lines changed: 31 additions & 435 deletions

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ java_library(
173173
"//:auto_value",
174174
"//common",
175175
"//common:compiler_common",
176-
"//common:features",
177176
"//common:options",
178177
"//common:proto_ast",
179178
"//common/annotations",

checker/src/main/java/dev/cel/checker/Env.java

Lines changed: 30 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import dev.cel.expr.Decl.FunctionDecl.Overload;
2020
import dev.cel.expr.Expr;
2121
import dev.cel.expr.Type;
22+
import com.google.common.annotations.VisibleForTesting;
2223
import com.google.common.base.Preconditions;
2324
import com.google.common.collect.ImmutableList;
2425
import com.google.common.collect.ImmutableMap;
@@ -32,7 +33,6 @@
3233
import dev.cel.common.CelFunctionDecl;
3334
import dev.cel.common.CelOptions;
3435
import dev.cel.common.CelOverloadDecl;
35-
import dev.cel.common.ExprFeatures;
3636
import dev.cel.common.annotations.Internal;
3737
import dev.cel.common.ast.CelConstant;
3838
import dev.cel.common.ast.CelExpr;
@@ -97,6 +97,12 @@ public class Env {
9797
/** CEL Feature flags. */
9898
private final CelOptions celOptions;
9999

100+
private static final CelOptions LEGACY_TYPE_CHECKER_OPTIONS =
101+
CelOptions.newBuilder()
102+
.disableCelStandardEquality(false)
103+
.enableNamespacedDeclarations(false)
104+
.build();
105+
100106
private Env(
101107
Errors errors, TypeProvider typeProvider, DeclGroup declGroup, CelOptions celOptions) {
102108
this.celOptions = celOptions;
@@ -106,111 +112,51 @@ private Env(
106112
}
107113

108114
/**
109-
* Creates an unconfigured {@code Env} value without the standard CEL types, functions, and
110-
* operators with a reference to the feature flags enabled in the environment.
111-
*
112-
* @deprecated use {@code unconfigured} with {@code CelOptions} instead.
113-
*/
114-
@Deprecated
115-
public static Env unconfigured(Errors errors, ExprFeatures... exprFeatures) {
116-
return unconfigured(errors, new DescriptorTypeProvider(), ImmutableSet.copyOf(exprFeatures));
117-
}
118-
119-
/**
120-
* Creates an unconfigured {@code Env} value without the standard CEL types, functions, and
121-
* operators using a custom {@code typeProvider}.
122-
*
123-
* @deprecated use {@code unconfigured} with {@code CelOptions} instead.
124-
*/
125-
@Deprecated
126-
public static Env unconfigured(
127-
Errors errors, TypeProvider typeProvider, ExprFeatures... exprFeatures) {
128-
return unconfigured(errors, typeProvider, ImmutableSet.copyOf(exprFeatures));
129-
}
130-
131-
/**
132-
* Creates an unconfigured {@code Env} value without the standard CEL types, functions, and
133-
* operators using a custom {@code typeProvider}. The set of enabled {@code exprFeatures} is also
134-
* provided.
135-
*
136-
* @deprecated use {@code unconfigured} with {@code CelOptions} instead.
115+
* @deprecated Do not use. This exists for compatibility reasons. Migrate to CEL-Java fluent APIs.
116+
* See {@code CelCompilerFactory}.
137117
*/
138118
@Deprecated
139-
public static Env unconfigured(
140-
Errors errors, TypeProvider typeProvider, ImmutableSet<ExprFeatures> exprFeatures) {
141-
return unconfigured(errors, typeProvider, CelOptions.fromExprFeatures(exprFeatures));
119+
public static Env unconfigured(Errors errors) {
120+
return unconfigured(errors, LEGACY_TYPE_CHECKER_OPTIONS);
142121
}
143122

144123
/**
145124
* Creates an unconfigured {@code Env} value without the standard CEL types, functions, and
146125
* operators with a reference to the configured {@code celOptions}.
147126
*/
148-
public static Env unconfigured(Errors errors, CelOptions celOptions) {
127+
@VisibleForTesting
128+
static Env unconfigured(Errors errors, CelOptions celOptions) {
149129
return unconfigured(errors, new DescriptorTypeProvider(), celOptions);
150130
}
151131

152132
/**
153133
* Creates an unconfigured {@code Env} value without the standard CEL types, functions, and
154-
* operators using a custom {@code typeProvider}. The {@code CelOptions} are provided as well.
155-
*/
156-
public static Env unconfigured(Errors errors, TypeProvider typeProvider, CelOptions celOptions) {
157-
return new Env(errors, typeProvider, new DeclGroup(), celOptions);
158-
}
159-
160-
/**
161-
* Creates an {@code Env} value configured with the standard types, functions, and operators with
162-
* a reference to the set of {@code exprFeatures} enabled in the environment.
163-
*
164-
* <p>Note: standard declarations are configured in an isolated scope, and may be shadowed by
165-
* subsequent declarations.
134+
* operators using a custom {@code typeProvider}.
166135
*
167-
* @deprecated use {@code standard} with {@code CelOptions} instead.
136+
* @deprecated Do not use. This exists for compatibility reasons. Migrate to CEL-Java fluent APIs.
137+
* See {@code CelCompilerFactory}.
168138
*/
169139
@Deprecated
170-
public static Env standard(Errors errors, ExprFeatures... exprFeatures) {
171-
return standard(errors, new DescriptorTypeProvider(), exprFeatures);
140+
public static Env unconfigured(Errors errors, TypeProvider typeProvider, CelOptions celOptions) {
141+
return new Env(errors, typeProvider, new DeclGroup(), celOptions);
172142
}
173143

174144
/**
175-
* Creates an {@code Env} value configured with the standard types, functions, and operators,
176-
* configured with a custom {@code typeProvider}.
177-
*
178-
* <p>Note: standard declarations are configured in an isolated scope, and may be shadowed by
179-
* subsequent declarations with the same signature.
180-
*
181-
* @deprecated use {@code standard} with {@code CelOptions} instead.
145+
* @deprecated Do not use. This exists for compatibility reasons. Migrate to CEL-Java fluent APIs.
146+
* See {@code CelCompilerFactory}.
182147
*/
183148
@Deprecated
184-
public static Env standard(
185-
Errors errors, TypeProvider typeProvider, ExprFeatures... exprFeatures) {
186-
return standard(errors, typeProvider, ImmutableSet.copyOf(exprFeatures));
149+
public static Env standard(Errors errors) {
150+
return standard(errors, new DescriptorTypeProvider());
187151
}
188152

189153
/**
190-
* Creates an {@code Env} value configured with the standard types, functions, and operators,
191-
* configured with a custom {@code typeProvider} and a reference to the set of {@code
192-
* exprFeatures} enabled in the environment.
193-
*
194-
* <p>Note: standard declarations are configured in an isolated scope, and may be shadowed by
195-
* subsequent declarations with the same signature.
196-
*
197-
* @deprecated use {@code standard} with {@code CelOptions} instead.
154+
* @deprecated Do not use. This exists for compatibility reasons. Migrate to CEL-Java fluent APIs.
155+
* See {@code CelCompilerFactory}.
198156
*/
199157
@Deprecated
200-
public static Env standard(
201-
Errors errors, TypeProvider typeProvider, ImmutableSet<ExprFeatures> exprFeatures) {
202-
return standard(errors, typeProvider, CelOptions.fromExprFeatures(exprFeatures));
203-
}
204-
205-
/**
206-
* Creates an {@code Env} value configured with the standard types, functions, and operators and a
207-
* reference to the configured {@code celOptions}.
208-
*
209-
* <p>Note: standard declarations are configured in an isolated scope, and may be shadowed by
210-
* subsequent declarations with the same signature.
211-
*/
212-
public static Env standard(Errors errors, CelOptions celOptions) {
213-
return standard(errors, new DescriptorTypeProvider(), celOptions);
158+
public static Env standard(Errors errors, TypeProvider typeProvider) {
159+
return standard(errors, typeProvider, LEGACY_TYPE_CHECKER_OPTIONS);
214160
}
215161

216162
/**
@@ -220,7 +166,11 @@ public static Env standard(Errors errors, CelOptions celOptions) {
220166
*
221167
* <p>Note: standard declarations are configured in an isolated scope, and may be shadowed by
222168
* subsequent declarations with the same signature.
169+
*
170+
* @deprecated Do not use. This exists for compatibility reasons. Migrate to CEL-Java fluent APIs.
171+
* See {@code CelCompilerFactory}.
223172
*/
173+
@Deprecated
224174
public static Env standard(Errors errors, TypeProvider typeProvider, CelOptions celOptions) {
225175
CelStandardDeclarations celStandardDeclaration =
226176
CelStandardDeclarations.newBuilder()

common/BUILD.bazel

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ java_library(
2525
exports = ["//common/src/main/java/dev/cel/common:options"],
2626
)
2727

28-
java_library(
29-
name = "features",
30-
exports = ["//common/src/main/java/dev/cel/common:features"],
31-
)
32-
3328
java_library(
3429
name = "proto_ast",
3530
exports = ["//common/src/main/java/dev/cel/common:proto_ast"],

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,12 @@ java_library(
9595
tags = [
9696
],
9797
deps = [
98-
":features",
9998
"//:auto_value",
10099
"@maven//:com_google_errorprone_error_prone_annotations",
101100
"@maven//:com_google_guava_guava",
102101
],
103102
)
104103

105-
java_library(
106-
name = "features",
107-
srcs = ["ExprFeatures.java"],
108-
tags = [
109-
],
110-
deps = [
111-
"@maven//:com_google_guava_guava",
112-
],
113-
)
114-
115104
java_library(
116105
name = "proto_ast",
117106
srcs = PROTO_AST_SOURCE,

common/src/main/java/dev/cel/common/CelOptions.java

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package dev.cel.common;
1616

1717
import com.google.auto.value.AutoValue;
18-
import com.google.common.collect.ImmutableSet;
1918
import com.google.errorprone.annotations.CheckReturnValue;
2019
import com.google.errorprone.annotations.Immutable;
2120

@@ -125,60 +124,6 @@ public enum ProtoUnsetFieldOptions {
125124

126125
public abstract Builder toBuilder();
127126

128-
public ImmutableSet<ExprFeatures> toExprFeatures() {
129-
ImmutableSet.Builder<ExprFeatures> features = ImmutableSet.builder();
130-
if (enableCompileTimeOverloadResolution()) {
131-
features.add(ExprFeatures.COMPILE_TIME_OVERLOAD_RESOLUTION);
132-
}
133-
if (disableCelStandardEquality()) {
134-
features.add(ExprFeatures.LEGACY_JAVA_EQUALITY);
135-
}
136-
if (enableHomogeneousLiterals()) {
137-
features.add(ExprFeatures.HOMOGENEOUS_LITERALS);
138-
}
139-
if (enableRegexPartialMatch()) {
140-
features.add(ExprFeatures.REGEX_PARTIAL_MATCH);
141-
}
142-
if (enableReservedIds()) {
143-
features.add(ExprFeatures.RESERVED_IDS);
144-
}
145-
if (enableUnsignedComparisonAndArithmeticIsUnsigned()) {
146-
features.add(ExprFeatures.UNSIGNED_COMPARISON_AND_ARITHMETIC_IS_UNSIGNED);
147-
}
148-
if (retainRepeatedUnaryOperators()) {
149-
features.add(ExprFeatures.RETAIN_REPEATED_UNARY_OPERATORS);
150-
}
151-
if (retainUnbalancedLogicalExpressions()) {
152-
features.add(ExprFeatures.RETAIN_UNBALANCED_LOGICAL_EXPRESSIONS);
153-
}
154-
if (errorOnIntWrap()) {
155-
features.add(ExprFeatures.ERROR_ON_WRAP);
156-
}
157-
if (errorOnDuplicateMapKeys()) {
158-
features.add(ExprFeatures.ERROR_ON_DUPLICATE_KEYS);
159-
}
160-
if (populateMacroCalls()) {
161-
features.add(ExprFeatures.POPULATE_MACRO_CALLS);
162-
}
163-
if (enableTimestampEpoch()) {
164-
features.add(ExprFeatures.ENABLE_TIMESTAMP_EPOCH);
165-
}
166-
if (enableHeterogeneousNumericComparisons()) {
167-
features.add(ExprFeatures.ENABLE_HETEROGENEOUS_NUMERIC_COMPARISONS);
168-
}
169-
if (enableNamespacedDeclarations()) {
170-
features.add(ExprFeatures.ENABLE_NAMESPACED_DECLARATIONS);
171-
}
172-
if (enableUnsignedLongs()) {
173-
features.add(ExprFeatures.ENABLE_UNSIGNED_LONGS);
174-
}
175-
if (enableProtoDifferencerEquality()) {
176-
features.add(ExprFeatures.PROTO_DIFFERENCER_EQUALITY);
177-
}
178-
179-
return features.build();
180-
}
181-
182127
/**
183128
* Return an unconfigured {@code Builder}. This is equivalent to preserving all legacy behaviors,
184129
* both good and bad, of the original CEL implementation.
@@ -240,33 +185,6 @@ public static Builder current() {
240185
.disableCelStandardEquality(false);
241186
}
242187

243-
public static CelOptions fromExprFeatures(ImmutableSet<ExprFeatures> features) {
244-
return newBuilder()
245-
.enableCompileTimeOverloadResolution(
246-
features.contains(ExprFeatures.COMPILE_TIME_OVERLOAD_RESOLUTION))
247-
.disableCelStandardEquality(features.contains(ExprFeatures.LEGACY_JAVA_EQUALITY))
248-
.enableHomogeneousLiterals(features.contains(ExprFeatures.HOMOGENEOUS_LITERALS))
249-
.enableRegexPartialMatch(features.contains(ExprFeatures.REGEX_PARTIAL_MATCH))
250-
.enableReservedIds(features.contains(ExprFeatures.RESERVED_IDS))
251-
.enableUnsignedComparisonAndArithmeticIsUnsigned(
252-
features.contains(ExprFeatures.UNSIGNED_COMPARISON_AND_ARITHMETIC_IS_UNSIGNED))
253-
.retainRepeatedUnaryOperators(
254-
features.contains(ExprFeatures.RETAIN_REPEATED_UNARY_OPERATORS))
255-
.retainUnbalancedLogicalExpressions(
256-
features.contains(ExprFeatures.RETAIN_UNBALANCED_LOGICAL_EXPRESSIONS))
257-
.errorOnIntWrap(features.contains(ExprFeatures.ERROR_ON_WRAP))
258-
.errorOnDuplicateMapKeys(features.contains(ExprFeatures.ERROR_ON_DUPLICATE_KEYS))
259-
.populateMacroCalls(features.contains(ExprFeatures.POPULATE_MACRO_CALLS))
260-
.enableTimestampEpoch(features.contains(ExprFeatures.ENABLE_TIMESTAMP_EPOCH))
261-
.enableHeterogeneousNumericComparisons(
262-
features.contains(ExprFeatures.ENABLE_HETEROGENEOUS_NUMERIC_COMPARISONS))
263-
.enableNamespacedDeclarations(
264-
features.contains(ExprFeatures.ENABLE_NAMESPACED_DECLARATIONS))
265-
.enableUnsignedLongs(features.contains(ExprFeatures.ENABLE_UNSIGNED_LONGS))
266-
.enableProtoDifferencerEquality(features.contains(ExprFeatures.PROTO_DIFFERENCER_EQUALITY))
267-
.build();
268-
}
269-
270188
/** Builder for configuring the {@code CelOptions}. */
271189
@AutoValue.Builder
272190
public abstract static class Builder {

0 commit comments

Comments
 (0)