Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove create modifiers from list,struct,map methods #321

Merged
merged 1 commit into from
Apr 30, 2024
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
2 changes: 1 addition & 1 deletion bundle/src/test/java/dev/cel/bundle/CelImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public void compile_withOptionalTypes() throws Exception {

CelAbstractSyntaxTree ast = cel.compile("[?a]").getAst();

CelList createList = ast.getExpr().createList();
CelList createList = ast.getExpr().list();
assertThat(createList.optionalIndices()).containsExactly(0);
assertThat(createList.elements()).containsExactly(CelExpr.ofIdent(2, "a"));
}
Expand Down
22 changes: 11 additions & 11 deletions checker/src/main/java/dev/cel/checker/ExprChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ public CelExpr visit(CelExpr expr) {
case CALL:
return visit(expr, expr.call());
case LIST:
return visit(expr, expr.createList());
return visit(expr, expr.list());
case STRUCT:
return visit(expr, expr.createStruct());
return visit(expr, expr.struct());
case MAP:
return visit(expr, expr.createMap());
return visit(expr, expr.map());
case COMPREHENSION:
return visit(expr, expr.comprehension());
default:
Expand Down Expand Up @@ -848,32 +848,32 @@ private static CelExpr replaceCallSubtree(CelExpr expr, CelExpr target) {
}

private static CelExpr replaceListElementSubtree(CelExpr expr, CelExpr element, int index) {
CelExpr.CelList newList = expr.createList().toBuilder().setElement(index, element).build();
return expr.toBuilder().setCreateList(newList).build();
CelExpr.CelList newList = expr.list().toBuilder().setElement(index, element).build();
return expr.toBuilder().setList(newList).build();
}

private static CelExpr replaceStructEntryValueSubtree(CelExpr expr, CelExpr newValue, int index) {
CelExpr.CelStruct createStruct = expr.createStruct();
CelExpr.CelStruct createStruct = expr.struct();
CelExpr.CelStruct.Entry newEntry =
createStruct.entries().get(index).toBuilder().setValue(newValue).build();
createStruct = createStruct.toBuilder().setEntry(index, newEntry).build();
return expr.toBuilder().setCreateStruct(createStruct).build();
return expr.toBuilder().setStruct(createStruct).build();
}

private static CelExpr replaceMapEntryKeySubtree(CelExpr expr, CelExpr newKey, int index) {
CelExpr.CelMap createMap = expr.createMap();
CelExpr.CelMap createMap = expr.map();
CelExpr.CelMap.Entry newEntry =
createMap.entries().get(index).toBuilder().setKey(newKey).build();
createMap = createMap.toBuilder().setEntry(index, newEntry).build();
return expr.toBuilder().setCreateMap(createMap).build();
return expr.toBuilder().setMap(createMap).build();
}

private static CelExpr replaceMapEntryValueSubtree(CelExpr expr, CelExpr newValue, int index) {
CelExpr.CelMap createMap = expr.createMap();
CelExpr.CelMap createMap = expr.map();
CelExpr.CelMap.Entry newEntry =
createMap.entries().get(index).toBuilder().setValue(newValue).build();
createMap = createMap.toBuilder().setEntry(index, newEntry).build();
return expr.toBuilder().setCreateMap(createMap).build();
return expr.toBuilder().setMap(createMap).build();
}

private static CelExpr replaceComprehensionAccuInitSubtree(CelExpr expr, CelExpr newAccuInit) {
Expand Down
93 changes: 60 additions & 33 deletions common/src/main/java/dev/cel/common/ast/CelExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,33 +90,60 @@ public CelCall call() {
return exprKind().call();
}

/**
* @deprecated Use {@link #list()} instead.
*/
@Deprecated
@InlineMe(replacement = "this.list()")
public final CelList createList() {
return list();
}

/**
* {@inheritDoc}
*
* @throws UnsupportedOperationException if expression is not {@link Kind#LIST}.
*/
@Override
public CelList createList() {
public CelList list() {
return exprKind().createList();
}

/**
* @deprecated Use {@link #list()} instead.
*/
@Deprecated
@InlineMe(replacement = "this.struct()")
public final CelStruct createStruct() {
return struct();
}

/**
* {@inheritDoc}
*
* @throws UnsupportedOperationException if expression is not {@link Kind#STRUCT}.
*/
@Override
public CelStruct createStruct() {
public CelStruct struct() {
return exprKind().createStruct();
}

/**
* @deprecated Use {@link #list()} instead.
*/
@Deprecated
@InlineMe(replacement = "this.map()")
public final CelMap createMap() {
return map();
}

/**
* {@inheritDoc}
*
* @throws UnsupportedOperationException if expression is not {@link Kind#createMap}.
*/
@Override
public CelMap createMap() {
public CelMap map() {
return exprKind().createMap();
}

Expand Down Expand Up @@ -171,30 +198,30 @@ public CelCall callOrDefault() {
}

/**
* Gets the underlying createList expression or a default instance of one if expression is not
* {@link Kind#LIST}.
* Gets the underlying list expression or a default instance of one if expression is not {@link
* Kind#LIST}.
*/
public CelList createListOrDefault() {
public CelList listOrDefault() {
return exprKind().getKind().equals(ExprKind.Kind.LIST)
? exprKind().createList()
: CelList.newBuilder().build();
}

/**
* Gets the underlying createStruct expression or a default instance of one if expression is not
* {@link Kind#STRUCT}.
* Gets the underlying struct expression or a default instance of one if expression is not {@link
* Kind#STRUCT}.
*/
public CelStruct createStructOrDefault() {
public CelStruct structOrDefault() {
return exprKind().getKind().equals(ExprKind.Kind.STRUCT)
? exprKind().createStruct()
: CelStruct.newBuilder().build();
}

/**
* Gets the underlying createMap expression or a default instance of one if expression is not
* {@link Kind#MAP}.
* Gets the underlying map expression or a default instance of one if expression is not {@link
* Kind#MAP}.
*/
public CelMap createMapOrDefault() {
public CelMap mapOrDefault() {
return exprKind().getKind().equals(ExprKind.Kind.MAP)
? exprKind().createMap()
: CelMap.newBuilder().build();
Expand Down Expand Up @@ -259,30 +286,30 @@ public CelCall call() {
}

/**
* Gets the underlying createList expression.
* Gets the underlying list expression.
*
* @throws UnsupportedOperationException if expression is not {@link Kind#LIST}.
*/
public CelList createList() {
return exprKind().createList();
public CelList list() {
return exprKind().list();
}

/**
* Gets the underlying createStruct expression.
* Gets the underlying struct expression.
*
* @throws UnsupportedOperationException if expression is not {@link Kind#STRUCT}.
*/
public CelStruct createStruct() {
return exprKind().createStruct();
public CelStruct struct() {
return exprKind().struct();
}

/**
* Gets the underlying createMap expression.
* Gets the underlying map expression.
*
* @throws UnsupportedOperationException if expression is not {@link Kind#createMap}.
* @throws UnsupportedOperationException if expression is not {@link Kind#MAP}.
*/
public CelMap createMap() {
return exprKind().createMap();
public CelMap map() {
return exprKind().map();
}

/**
Expand Down Expand Up @@ -315,18 +342,18 @@ public Builder setSelect(CelSelect select) {
}

@CanIgnoreReturnValue
public Builder setCreateList(CelList createList) {
return setExprKind(AutoOneOf_CelExpr_ExprKind.list(createList));
public Builder setList(CelList list) {
return setExprKind(AutoOneOf_CelExpr_ExprKind.list(list));
}

@CanIgnoreReturnValue
public Builder setCreateStruct(CelStruct createStruct) {
return setExprKind(AutoOneOf_CelExpr_ExprKind.struct(createStruct));
public Builder setStruct(CelStruct struct) {
return setExprKind(AutoOneOf_CelExpr_ExprKind.struct(struct));
}

@CanIgnoreReturnValue
public Builder setCreateMap(CelMap createMap) {
return setExprKind(AutoOneOf_CelExpr_ExprKind.map(createMap));
public Builder setMap(CelMap map) {
return setExprKind(AutoOneOf_CelExpr_ExprKind.map(map));
}

@CanIgnoreReturnValue
Expand Down Expand Up @@ -1040,7 +1067,7 @@ public static CelExpr ofCall(
.build();
}

public static CelExpr ofCreateList(
public static CelExpr ofList(
long id, ImmutableList<CelExpr> elements, ImmutableList<Integer> optionalIndices) {
return newBuilder()
.setId(id)
Expand All @@ -1053,7 +1080,7 @@ public static CelExpr ofCreateList(
.build();
}

public static CelExpr ofCreateStruct(
public static CelExpr ofStruct(
long id, String messageName, ImmutableList<CelStruct.Entry> entries) {
return newBuilder()
.setId(id)
Expand All @@ -1063,15 +1090,15 @@ public static CelExpr ofCreateStruct(
.build();
}

public static CelExpr ofCreateMap(long id, ImmutableList<CelMap.Entry> entries) {
public static CelExpr ofMap(long id, ImmutableList<CelMap.Entry> entries) {
return newBuilder()
.setId(id)
.setExprKind(
AutoOneOf_CelExpr_ExprKind.map(CelMap.newBuilder().addEntries(entries).build()))
.build();
}

public static CelStruct.Entry ofCreateStructEntry(
public static CelStruct.Entry ofStructEntry(
long id, String fieldKey, CelExpr value, boolean isOptionalEntry) {
return CelStruct.Entry.newBuilder()
.setId(id)
Expand All @@ -1081,7 +1108,7 @@ public static CelStruct.Entry ofCreateStructEntry(
.build();
}

public static CelMap.Entry ofCreateMapEntry(
public static CelMap.Entry ofMapEntry(
long id, CelExpr mapKey, CelExpr value, boolean isOptionalEntry) {
return CelMap.Entry.newBuilder()
.setId(id)
Expand Down
10 changes: 5 additions & 5 deletions common/src/main/java/dev/cel/common/ast/CelExprConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static CelExpr fromExpr(Expr expr) {
fromExprList(callExpr.getArgsList()));
case LIST_EXPR:
CreateList createListExpr = expr.getListExpr();
return CelExpr.ofCreateList(
return CelExpr.ofList(
expr.getId(),
fromExprList(createListExpr.getElementsList()),
ImmutableList.copyOf(createListExpr.getOptionalIndicesList()));
Expand Down Expand Up @@ -209,14 +209,14 @@ private static CelExpr exprStructToCelStruct(long id, CreateStruct structExpr) {
"Unexpected struct key kind case: " + structExprEntry.getKeyKindCase());
}
entries.add(
CelExpr.ofCreateStructEntry(
CelExpr.ofStructEntry(
structExprEntry.getId(),
structExprEntry.getFieldKey(),
fromExpr(structExprEntry.getValue()),
structExprEntry.getOptionalEntry()));
}

return CelExpr.ofCreateStruct(id, structExpr.getMessageName(), entries.build());
return CelExpr.ofStruct(id, structExpr.getMessageName(), entries.build());
} else {
ImmutableList.Builder<CelExpr.CelMap.Entry> entries = ImmutableList.builder();
for (Entry mapExprEntry : structExpr.getEntriesList()) {
Expand All @@ -225,14 +225,14 @@ private static CelExpr exprStructToCelStruct(long id, CreateStruct structExpr) {
"Unexpected map key kind case: " + mapExprEntry.getKeyKindCase());
}
entries.add(
CelExpr.ofCreateMapEntry(
CelExpr.ofMapEntry(
mapExprEntry.getId(),
fromExpr(mapExprEntry.getMapKey()),
fromExpr(mapExprEntry.getValue()),
mapExprEntry.getOptionalEntry()));
}

return CelExpr.ofCreateMap(id, entries.build());
return CelExpr.ofMap(id, entries.build());
}
}

Expand Down
6 changes: 3 additions & 3 deletions common/src/main/java/dev/cel/common/ast/CelExprFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public final CelExpr newList(CelExpr... elements) {
public final CelExpr newList(Iterable<CelExpr> elements) {
return CelExpr.newBuilder()
.setId(nextExprId())
.setCreateList(CelExpr.CelList.newBuilder().addElements(elements).build())
.setList(CelExpr.CelList.newBuilder().addElements(elements).build())
.build();
}

Expand All @@ -109,7 +109,7 @@ public final CelExpr newMap(CelExpr.CelMap.Entry... entries) {
public final CelExpr newMap(Iterable<CelExpr.CelMap.Entry> entries) {
return CelExpr.newBuilder()
.setId(nextExprId())
.setCreateMap(CelExpr.CelMap.newBuilder().addEntries(entries).build())
.setMap(CelExpr.CelMap.newBuilder().addEntries(entries).build())
.build();
}

Expand All @@ -132,7 +132,7 @@ public final CelExpr newMessage(String typeName, Iterable<CelExpr.CelStruct.Entr
checkArgument(!isNullOrEmpty(typeName));
return CelExpr.newBuilder()
.setId(nextExprId())
.setCreateStruct(
.setStruct(
CelExpr.CelStruct.newBuilder().setMessageName(typeName).addEntries(fields).build())
.build();
}
Expand Down
6 changes: 3 additions & 3 deletions common/src/main/java/dev/cel/common/ast/CelExprFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ private void formatExpr(CelExpr celExpr) {
appendCall(celExpr.call());
break;
case LIST:
appendCreateList(celExpr.createList());
appendCreateList(celExpr.list());
break;
case STRUCT:
appendCreateStruct(celExpr.createStruct());
appendCreateStruct(celExpr.struct());
break;
case MAP:
appendCreateMap(celExpr.createMap());
appendCreateMap(celExpr.map());
break;
case COMPREHENSION:
appendComprehension(celExpr.comprehension());
Expand Down
Loading
Loading