Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions bundle/src/main/java/dev/cel/bundle/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ java_library(
"//bundle:cel",
"//checker:proto_type_mask",
"//checker:standard_decl",
"//common:compiler_common",
"//common:cel_function_decl",
"//common:cel_overload_decl",
"//common:cel_var_decl",
"//common:container",
"//common:options",
"//common:source",
Expand Down Expand Up @@ -172,10 +174,12 @@ java_library(
"//bundle:cel",
"//checker:checker_builder",
"//checker:standard_decl",
"//common:compiler_common",
"//common:cel_function_decl",
"//common:cel_overload_decl",
"//common:cel_proto_decl_converter",
"//common:cel_var_decl",
"//common:options",
"//common/internal:env_visitor",
"//common/types:cel_proto_types",
"//common/types:type_providers",
"//compiler:compiler_builder",
"//extensions",
Expand Down
6 changes: 5 additions & 1 deletion bundle/src/main/java/dev/cel/bundle/CelEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,11 @@ public static VariableDecl create(String name, TypeDecl type) {

/** Converts this policy variable declaration into a {@link CelVarDecl}. */
public CelVarDecl toCelVarDecl(CelTypeProvider celTypeProvider) {
return CelVarDecl.newVarDeclaration(name(), type().toCelType(celTypeProvider));
return CelVarDecl.newBuilder()
.setName(name())
.setType(type().toCelType(celTypeProvider))
.setDoc(description().orElse(""))
.build();
}
}

Expand Down
31 changes: 17 additions & 14 deletions bundle/src/main/java/dev/cel/bundle/CelEnvironmentExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
import dev.cel.common.CelFunctionDecl;
import dev.cel.common.CelOptions;
import dev.cel.common.CelOverloadDecl;
import dev.cel.common.CelProtoDeclConverter;
import dev.cel.common.CelVarDecl;
import dev.cel.common.internal.EnvVisitable;
import dev.cel.common.internal.EnvVisitor;
import dev.cel.common.types.CelKind;
import dev.cel.common.types.CelProtoTypes;
import dev.cel.common.types.CelType;
import dev.cel.compiler.CelCompiler;
import dev.cel.extensions.CelExtensionLibrary;
Expand Down Expand Up @@ -262,13 +262,11 @@ public void visitDecl(String name, List<Decl> decls) {
for (Overload overload : function.getOverloadsList()) {
inventory.add(
NamedOverload.create(
decl.getName(), CelOverloadDecl.overloadToCelOverload(overload)));
decl.getName(),
CelProtoDeclConverter.overloadToCelOverload(overload)));
}
} else if (decl.hasIdent()) {
inventory.add(
CelVarDecl.newVarDeclaration(
decl.getName(),
CelProtoTypes.typeToCelType(decl.getIdent().getType())));
inventory.add(CelProtoDeclConverter.declToCelVarDecl(decl));
}
}
}
Expand Down Expand Up @@ -299,7 +297,7 @@ private void addExtensionConfigsAndRemoveFromInventory(

featureSets.sort(
Comparator.comparing(NamedFeatureSet::name)
.thenComparing(nfs -> nfs.featureSet().version())
.thenComparingInt(nfs -> nfs.featureSet().version())
.reversed());

Set<String> includedExtensions = new HashSet<>();
Expand Down Expand Up @@ -348,8 +346,7 @@ private void addStandardLibrarySubsetAndRemoveFromInventory(
CelEnvironment.Builder envBuilder, Set<Object> inventory) {
// Claim standard identifiers for the standard library
for (StandardIdentifier value : StandardIdentifier.values()) {
inventory.remove(
CelVarDecl.newVarDeclaration(value.identDecl().name(), value.identDecl().type()));
inventory.remove(value.identDecl());
}

Set<String> excludedFunctions = new HashSet<>();
Expand Down Expand Up @@ -431,13 +428,13 @@ private ImmutableSet<FunctionSelector> buildFunctionSelectors(
private void addCustomDecls(CelEnvironment.Builder envBuilder, Set<Object> inventory) {
// Group "orphaned" function overloads and vars by their names
ListMultimap<String, CelOverloadDecl> extraOverloads = ArrayListMultimap.create();
Map<String, CelType> extraVars = new HashMap<>();
Map<String, CelVarDecl> extraVars = new HashMap<>();
for (Object item : inventory) {
if (item instanceof NamedOverload) {
extraOverloads.put(
((NamedOverload) item).functionName(), ((NamedOverload) item).overload());
} else if (item instanceof CelVarDecl) {
extraVars.put(((CelVarDecl) item).name(), ((CelVarDecl) item).type());
extraVars.put(((CelVarDecl) item).name(), (CelVarDecl) item);
}
}

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

if (!extraVars.isEmpty()) {
ImmutableSet.Builder<CelEnvironment.VariableDecl> varDeclBuilder = ImmutableSet.builder();
for (String ident : extraVars.keySet()) {
varDeclBuilder.add(
CelEnvironment.VariableDecl.create(ident, toCelEnvTypeDecl(extraVars.get(ident))));
for (CelVarDecl varDecl : extraVars.values()) {
CelEnvironment.VariableDecl.Builder builder =
CelEnvironment.VariableDecl.newBuilder()
.setName(varDecl.name())
.setType(toCelEnvTypeDecl(varDecl.type()));
if (!varDecl.doc().isEmpty()) {
builder.setDescription(varDecl.doc());
}
varDeclBuilder.add(builder.build());
}
envBuilder.setVariables(varDeclBuilder.build());
}
Expand Down
5 changes: 0 additions & 5 deletions checker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ java_library(
exports = ["//checker/src/main/java/dev/cel/checker:type_provider_legacy_impl"],
)

java_library(
name = "cel_ident_decl",
exports = ["//checker/src/main/java/dev/cel/checker:cel_ident_decl"],
)

java_library(
name = "checker_legacy_environment",
deprecation = "See go/cel-java-migration-guide. Please use CEL-Java Fluent APIs //compiler instead",
Expand Down
45 changes: 15 additions & 30 deletions checker/src/main/java/dev/cel/checker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,23 @@ java_library(
tags = [
],
deps = [
":cel_ident_decl",
":checker_builder",
":checker_legacy_environment",
":proto_type_mask",
":standard_decl",
":type_provider_legacy_impl",
"//:auto_value",
"//common:cel_ast",
"//common:cel_descriptor_util",
"//common:cel_function_decl",
"//common:cel_issue",
"//common:cel_proto_decl_converter",
"//common:cel_source",
"//common:compiler_common",
"//common:cel_validation_result",
"//common:cel_var_decl",
"//common:container",
"//common:options",
"//common:source_location",
"//common/annotations",
"//common/ast:expr_converter",
"//common/internal:env_visitor",
"//common/internal:errors",
"//common/types",
Expand All @@ -105,7 +106,9 @@ java_library(
":proto_type_mask",
":standard_decl",
"//common:cel_ast",
"//common:compiler_common",
"//common:cel_function_decl",
"//common:cel_validation_result",
"//common:cel_var_decl",
"//common:container",
"//common:options",
"//common/types:type_providers",
Expand All @@ -128,34 +131,13 @@ java_library(
],
)

java_library(
name = "cel_ident_decl",
srcs = [
"CelIdentDecl.java",
],
tags = [
],
deps = [
"//:auto_value",
"//common/annotations",
"//common/ast",
"//common/ast:expr_converter",
"//common/types:cel_proto_types",
"//common/types:type_providers",
"@cel_spec//proto/cel/expr:checked_java_proto",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
],
)

java_library(
name = "type_provider_legacy_impl",
srcs = ["TypeProviderLegacyImpl.java"],
tags = [
],
deps = [
":checker_legacy_environment",
"//:auto_value",
"//common/annotations",
"//common/types",
"//common/types:cel_proto_types",
Expand All @@ -173,12 +155,14 @@ java_library(
tags = [
],
deps = [
":cel_ident_decl",
":standard_decl",
"//:auto_value",
"//common:cel_ast",
"//common:cel_function_decl",
"//common:cel_overload_decl",
"//common:cel_proto_decl_converter",
"//common:cel_source",
"//common:compiler_common",
"//common:cel_var_decl",
"//common:container",
"//common:mutable_ast",
"//common:operator",
Expand Down Expand Up @@ -240,8 +224,9 @@ java_library(
tags = [
],
deps = [
":cel_ident_decl",
"//common:compiler_common",
"//common:cel_function_decl",
"//common:cel_overload_decl",
"//common:cel_var_decl",
"//common:operator",
"//common/types",
"//common/types:cel_types",
Expand Down
Loading
Loading