Skip to content
Merged
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
3 changes: 3 additions & 0 deletions bundle/src/main/java/dev/cel/bundle/CelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public interface CelBuilder {
@Deprecated
CelBuilder setContainer(String container);

/** Retrieves the currently configured {@link CelContainer} in the builder. */
CelContainer container();

/**
* Set the {@link CelContainer} to use as the namespace for resolving CEL expression variables and
* functions.
Expand Down
5 changes: 5 additions & 0 deletions bundle/src/main/java/dev/cel/bundle/CelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ public CelBuilder setContainer(String container) {
return this;
}

@Override
public CelContainer container() {
return compilerBuilder.container();
}

@Override
public CelBuilder setContainer(CelContainer container) {
compilerBuilder.setContainer(container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public interface CelCompilerBuilder {
@CanIgnoreReturnValue
CelCompilerBuilder setContainer(CelContainer container);

/** Retrieves the currently configured {@link CelContainer} in the builder. */
CelContainer container();

/** Add a variable declaration with a given {@code name} and proto based {@link Type}. */
@CanIgnoreReturnValue
CelCompilerBuilder addVar(String name, Type type);
Expand Down
5 changes: 5 additions & 0 deletions compiler/src/main/java/dev/cel/compiler/CelCompilerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ public CelCompilerBuilder setContainer(CelContainer container) {
return this;
}

@Override
public CelContainer container() {
return checkerBuilder.container();
}

@Override
public CelCompilerBuilder addVar(String name, Type type) {
return addVar(name, CelProtoTypes.typeToCelType(type));
Expand Down
25 changes: 22 additions & 3 deletions policy/src/main/java/dev/cel/policy/CelPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import dev.cel.common.formats.ValueString;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;

Expand Down Expand Up @@ -76,13 +80,23 @@ public abstract static class Builder {

public abstract Builder setMetadata(ImmutableMap<String, Object> value);

abstract ImmutableList.Builder<Import> importsBuilder();
private final ArrayList<Import> importList = new ArrayList<>();

abstract Builder setImports(ImmutableList<Import> value);

public List<Import> imports() {
return Collections.unmodifiableList(importList);
}

@CanIgnoreReturnValue
public Builder addImport(Import value) {
importsBuilder().add(value);
importList.add(value);
return this;
}

@CanIgnoreReturnValue
public Builder addImports(Collection<Import> values) {
importList.addAll(values);
return this;
}

Expand All @@ -98,7 +112,12 @@ public Builder putMetadata(Map<String, Object> map) {
return this;
}

public abstract CelPolicy build();
abstract CelPolicy autoBuild();

public CelPolicy build() {
setImports(ImmutableList.copyOf(importList));
return autoBuild();
}
}

/**
Expand Down