Skip to content

Commit 38d3d08

Browse files
l46kokcopybara-github
authored andcommitted
Consolidate CelIdentDecl into CelVarDecl, extract CelProtoDeclConverter
PiperOrigin-RevId: 982118176
1 parent 612f7de commit 38d3d08

23 files changed

Lines changed: 434 additions & 389 deletions

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ java_library(
108108
"//bundle:cel",
109109
"//checker:proto_type_mask",
110110
"//checker:standard_decl",
111-
"//common:compiler_common",
111+
"//common:cel_function_decl",
112+
"//common:cel_overload_decl",
113+
"//common:cel_var_decl",
112114
"//common:container",
113115
"//common:options",
114116
"//common:source",
@@ -172,10 +174,12 @@ java_library(
172174
"//bundle:cel",
173175
"//checker:checker_builder",
174176
"//checker:standard_decl",
175-
"//common:compiler_common",
177+
"//common:cel_function_decl",
178+
"//common:cel_overload_decl",
179+
"//common:cel_proto_decl_converter",
180+
"//common:cel_var_decl",
176181
"//common:options",
177182
"//common/internal:env_visitor",
178-
"//common/types:cel_proto_types",
179183
"//common/types:type_providers",
180184
"//compiler:compiler_builder",
181185
"//extensions",

bundle/src/main/java/dev/cel/bundle/CelEnvironment.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,11 @@ public static VariableDecl create(String name, TypeDecl type) {
478478

479479
/** Converts this policy variable declaration into a {@link CelVarDecl}. */
480480
public CelVarDecl toCelVarDecl(CelTypeProvider celTypeProvider) {
481-
return CelVarDecl.newVarDeclaration(name(), type().toCelType(celTypeProvider));
481+
return CelVarDecl.newBuilder()
482+
.setName(name())
483+
.setType(type().toCelType(celTypeProvider))
484+
.setDoc(description().orElse(""))
485+
.build();
482486
}
483487
}
484488

bundle/src/main/java/dev/cel/bundle/CelEnvironmentExporter.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
import dev.cel.common.CelFunctionDecl;
3838
import dev.cel.common.CelOptions;
3939
import dev.cel.common.CelOverloadDecl;
40+
import dev.cel.common.CelProtoDeclConverter;
4041
import dev.cel.common.CelVarDecl;
4142
import dev.cel.common.internal.EnvVisitable;
4243
import dev.cel.common.internal.EnvVisitor;
4344
import dev.cel.common.types.CelKind;
44-
import dev.cel.common.types.CelProtoTypes;
4545
import dev.cel.common.types.CelType;
4646
import dev.cel.compiler.CelCompiler;
4747
import dev.cel.extensions.CelExtensionLibrary;
@@ -262,13 +262,11 @@ public void visitDecl(String name, List<Decl> decls) {
262262
for (Overload overload : function.getOverloadsList()) {
263263
inventory.add(
264264
NamedOverload.create(
265-
decl.getName(), CelOverloadDecl.overloadToCelOverload(overload)));
265+
decl.getName(),
266+
CelProtoDeclConverter.overloadToCelOverload(overload)));
266267
}
267268
} else if (decl.hasIdent()) {
268-
inventory.add(
269-
CelVarDecl.newVarDeclaration(
270-
decl.getName(),
271-
CelProtoTypes.typeToCelType(decl.getIdent().getType())));
269+
inventory.add(CelProtoDeclConverter.declToCelVarDecl(decl));
272270
}
273271
}
274272
}
@@ -299,7 +297,7 @@ private void addExtensionConfigsAndRemoveFromInventory(
299297

300298
featureSets.sort(
301299
Comparator.comparing(NamedFeatureSet::name)
302-
.thenComparing(nfs -> nfs.featureSet().version())
300+
.thenComparingInt(nfs -> nfs.featureSet().version())
303301
.reversed());
304302

305303
Set<String> includedExtensions = new HashSet<>();
@@ -348,8 +346,7 @@ private void addStandardLibrarySubsetAndRemoveFromInventory(
348346
CelEnvironment.Builder envBuilder, Set<Object> inventory) {
349347
// Claim standard identifiers for the standard library
350348
for (StandardIdentifier value : StandardIdentifier.values()) {
351-
inventory.remove(
352-
CelVarDecl.newVarDeclaration(value.identDecl().name(), value.identDecl().type()));
349+
inventory.remove(value.identDecl());
353350
}
354351

355352
Set<String> excludedFunctions = new HashSet<>();
@@ -431,13 +428,13 @@ private ImmutableSet<FunctionSelector> buildFunctionSelectors(
431428
private void addCustomDecls(CelEnvironment.Builder envBuilder, Set<Object> inventory) {
432429
// Group "orphaned" function overloads and vars by their names
433430
ListMultimap<String, CelOverloadDecl> extraOverloads = ArrayListMultimap.create();
434-
Map<String, CelType> extraVars = new HashMap<>();
431+
Map<String, CelVarDecl> extraVars = new HashMap<>();
435432
for (Object item : inventory) {
436433
if (item instanceof NamedOverload) {
437434
extraOverloads.put(
438435
((NamedOverload) item).functionName(), ((NamedOverload) item).overload());
439436
} else if (item instanceof CelVarDecl) {
440-
extraVars.put(((CelVarDecl) item).name(), ((CelVarDecl) item).type());
437+
extraVars.put(((CelVarDecl) item).name(), (CelVarDecl) item);
441438
}
442439
}
443440

@@ -457,9 +454,15 @@ private void addCustomDecls(CelEnvironment.Builder envBuilder, Set<Object> inven
457454

458455
if (!extraVars.isEmpty()) {
459456
ImmutableSet.Builder<CelEnvironment.VariableDecl> varDeclBuilder = ImmutableSet.builder();
460-
for (String ident : extraVars.keySet()) {
461-
varDeclBuilder.add(
462-
CelEnvironment.VariableDecl.create(ident, toCelEnvTypeDecl(extraVars.get(ident))));
457+
for (CelVarDecl varDecl : extraVars.values()) {
458+
CelEnvironment.VariableDecl.Builder builder =
459+
CelEnvironment.VariableDecl.newBuilder()
460+
.setName(varDecl.name())
461+
.setType(toCelEnvTypeDecl(varDecl.type()));
462+
if (!varDecl.doc().isEmpty()) {
463+
builder.setDescription(varDecl.doc());
464+
}
465+
varDeclBuilder.add(builder.build());
463466
}
464467
envBuilder.setVariables(varDeclBuilder.build());
465468
}

checker/BUILD.bazel

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ java_library(
3232
exports = ["//checker/src/main/java/dev/cel/checker:type_provider_legacy_impl"],
3333
)
3434

35-
java_library(
36-
name = "cel_ident_decl",
37-
exports = ["//checker/src/main/java/dev/cel/checker:cel_ident_decl"],
38-
)
39-
4035
java_library(
4136
name = "checker_legacy_environment",
4237
deprecation = "See go/cel-java-migration-guide. Please use CEL-Java Fluent APIs //compiler instead",

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

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,23 @@ java_library(
6565
tags = [
6666
],
6767
deps = [
68-
":cel_ident_decl",
6968
":checker_builder",
7069
":checker_legacy_environment",
7170
":proto_type_mask",
7271
":standard_decl",
7372
":type_provider_legacy_impl",
74-
"//:auto_value",
7573
"//common:cel_ast",
7674
"//common:cel_descriptor_util",
75+
"//common:cel_function_decl",
76+
"//common:cel_issue",
77+
"//common:cel_proto_decl_converter",
7778
"//common:cel_source",
78-
"//common:compiler_common",
79+
"//common:cel_validation_result",
80+
"//common:cel_var_decl",
7981
"//common:container",
8082
"//common:options",
8183
"//common:source_location",
8284
"//common/annotations",
83-
"//common/ast:expr_converter",
8485
"//common/internal:env_visitor",
8586
"//common/internal:errors",
8687
"//common/types",
@@ -105,7 +106,9 @@ java_library(
105106
":proto_type_mask",
106107
":standard_decl",
107108
"//common:cel_ast",
108-
"//common:compiler_common",
109+
"//common:cel_function_decl",
110+
"//common:cel_validation_result",
111+
"//common:cel_var_decl",
109112
"//common:container",
110113
"//common:options",
111114
"//common/types:type_providers",
@@ -128,34 +131,13 @@ java_library(
128131
],
129132
)
130133

131-
java_library(
132-
name = "cel_ident_decl",
133-
srcs = [
134-
"CelIdentDecl.java",
135-
],
136-
tags = [
137-
],
138-
deps = [
139-
"//:auto_value",
140-
"//common/annotations",
141-
"//common/ast",
142-
"//common/ast:expr_converter",
143-
"//common/types:cel_proto_types",
144-
"//common/types:type_providers",
145-
"@cel_spec//proto/cel/expr:checked_java_proto",
146-
"@maven//:com_google_errorprone_error_prone_annotations",
147-
"@maven//:com_google_guava_guava",
148-
],
149-
)
150-
151134
java_library(
152135
name = "type_provider_legacy_impl",
153136
srcs = ["TypeProviderLegacyImpl.java"],
154137
tags = [
155138
],
156139
deps = [
157140
":checker_legacy_environment",
158-
"//:auto_value",
159141
"//common/annotations",
160142
"//common/types",
161143
"//common/types:cel_proto_types",
@@ -173,12 +155,14 @@ java_library(
173155
tags = [
174156
],
175157
deps = [
176-
":cel_ident_decl",
177158
":standard_decl",
178159
"//:auto_value",
179160
"//common:cel_ast",
161+
"//common:cel_function_decl",
162+
"//common:cel_overload_decl",
163+
"//common:cel_proto_decl_converter",
180164
"//common:cel_source",
181-
"//common:compiler_common",
165+
"//common:cel_var_decl",
182166
"//common:container",
183167
"//common:mutable_ast",
184168
"//common:operator",
@@ -240,8 +224,9 @@ java_library(
240224
tags = [
241225
],
242226
deps = [
243-
":cel_ident_decl",
244-
"//common:compiler_common",
227+
"//common:cel_function_decl",
228+
"//common:cel_overload_decl",
229+
"//common:cel_var_decl",
245230
"//common:operator",
246231
"//common/types",
247232
"//common/types:cel_types",

0 commit comments

Comments
 (0)