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
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 @@ -488,7 +488,7 @@ public void compile_withOptionalTypes() throws Exception {

CelCreateList createList = ast.getExpr().createList();
assertThat(createList.optionalIndices()).containsExactly(0);
assertThat(createList.elements()).containsExactly(CelExpr.ofIdentExpr(2, "a"));
assertThat(createList.elements()).containsExactly(CelExpr.ofIdent(2, "a"));
}

@Test
Expand Down
19 changes: 9 additions & 10 deletions common/src/main/java/dev/cel/common/ast/CelExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -983,23 +983,22 @@ public static CelExpr ofNotSet(long id) {
.build();
}

public static CelExpr ofConstantExpr(long id, CelConstant celConstant) {
public static CelExpr ofConstant(long id, CelConstant celConstant) {
return newBuilder()
.setId(id)
.setExprKind(AutoOneOf_CelExpr_ExprKind.constant(celConstant))
.build();
}

public static CelExpr ofIdentExpr(long id, String identName) {
public static CelExpr ofIdent(long id, String identName) {
return newBuilder()
.setId(id)
.setExprKind(
AutoOneOf_CelExpr_ExprKind.ident(CelIdent.newBuilder().setName(identName).build()))
.build();
}

public static CelExpr ofSelectExpr(
long id, CelExpr operandExpr, String field, boolean isTestOnly) {
public static CelExpr ofSelect(long id, CelExpr operandExpr, String field, boolean isTestOnly) {
return newBuilder()
.setId(id)
.setExprKind(
Expand All @@ -1012,7 +1011,7 @@ public static CelExpr ofSelectExpr(
.build();
}

public static CelExpr ofCallExpr(
public static CelExpr ofCall(
long id, Optional<CelExpr> targetExpr, String function, ImmutableList<CelExpr> arguments) {

CelCall.Builder celCallBuilder = CelCall.newBuilder().setFunction(function).addArgs(arguments);
Expand All @@ -1023,7 +1022,7 @@ public static CelExpr ofCallExpr(
.build();
}

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

public static CelExpr ofCreateStructExpr(
public static CelExpr ofCreateStruct(
long id, String messageName, ImmutableList<CelCreateStruct.Entry> entries) {
return newBuilder()
.setId(id)
Expand All @@ -1049,7 +1048,7 @@ public static CelExpr ofCreateStructExpr(
.build();
}

public static CelExpr ofCreateMapExpr(long id, ImmutableList<CelCreateMap.Entry> entries) {
public static CelExpr ofCreateMap(long id, ImmutableList<CelCreateMap.Entry> entries) {
return newBuilder()
.setId(id)
.setExprKind(
Expand All @@ -1058,7 +1057,7 @@ public static CelExpr ofCreateMapExpr(long id, ImmutableList<CelCreateMap.Entry>
.build();
}

public static CelCreateStruct.Entry ofCreateStructEntryExpr(
public static CelCreateStruct.Entry ofCreateStructEntry(
long id, String fieldKey, CelExpr value, boolean isOptionalEntry) {
return CelCreateStruct.Entry.newBuilder()
.setId(id)
Expand All @@ -1068,7 +1067,7 @@ public static CelCreateStruct.Entry ofCreateStructEntryExpr(
.build();
}

public static CelCreateMap.Entry ofCreateMapEntryExpr(
public static CelCreateMap.Entry ofCreateMapEntry(
long id, CelExpr mapKey, CelExpr value, boolean isOptionalEntry) {
return CelCreateMap.Entry.newBuilder()
.setId(id)
Expand Down
18 changes: 9 additions & 9 deletions common/src/main/java/dev/cel/common/ast/CelExprConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,26 @@ public static Expr fromCelExpr(CelExpr celExpr) {
public static CelExpr fromExpr(Expr expr) {
switch (expr.getExprKindCase()) {
case CONST_EXPR:
return CelExpr.ofConstantExpr(expr.getId(), exprConstantToCelConstant(expr.getConstExpr()));
return CelExpr.ofConstant(expr.getId(), exprConstantToCelConstant(expr.getConstExpr()));
case IDENT_EXPR:
return CelExpr.ofIdentExpr(expr.getId(), expr.getIdentExpr().getName());
return CelExpr.ofIdent(expr.getId(), expr.getIdentExpr().getName());
case SELECT_EXPR:
Select selectExpr = expr.getSelectExpr();
return CelExpr.ofSelectExpr(
return CelExpr.ofSelect(
expr.getId(),
fromExpr(selectExpr.getOperand()),
selectExpr.getField(),
selectExpr.getTestOnly());
case CALL_EXPR:
Call callExpr = expr.getCallExpr();
return CelExpr.ofCallExpr(
return CelExpr.ofCall(
expr.getId(),
callExpr.hasTarget() ? Optional.of(fromExpr(callExpr.getTarget())) : Optional.empty(),
callExpr.getFunction(),
fromExprList(callExpr.getArgsList()));
case LIST_EXPR:
CreateList createListExpr = expr.getListExpr();
return CelExpr.ofCreateListExpr(
return CelExpr.ofCreateList(
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.ofCreateStructEntryExpr(
CelExpr.ofCreateStructEntry(
structExprEntry.getId(),
structExprEntry.getFieldKey(),
fromExpr(structExprEntry.getValue()),
structExprEntry.getOptionalEntry()));
}

return CelExpr.ofCreateStructExpr(id, structExpr.getMessageName(), entries.build());
return CelExpr.ofCreateStruct(id, structExpr.getMessageName(), entries.build());
} else {
ImmutableList.Builder<CelExpr.CelCreateMap.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.ofCreateMapEntryExpr(
CelExpr.ofCreateMapEntry(
mapExprEntry.getId(),
fromExpr(mapExprEntry.getMapKey()),
fromExpr(mapExprEntry.getValue()),
mapExprEntry.getOptionalEntry()));
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,26 @@ public static Expr fromCelExpr(CelExpr celExpr) {
public static CelExpr fromExpr(Expr expr) {
switch (expr.getExprKindCase()) {
case CONST_EXPR:
return CelExpr.ofConstantExpr(expr.getId(), exprConstantToCelConstant(expr.getConstExpr()));
return CelExpr.ofConstant(expr.getId(), exprConstantToCelConstant(expr.getConstExpr()));
case IDENT_EXPR:
return CelExpr.ofIdentExpr(expr.getId(), expr.getIdentExpr().getName());
return CelExpr.ofIdent(expr.getId(), expr.getIdentExpr().getName());
case SELECT_EXPR:
Select selectExpr = expr.getSelectExpr();
return CelExpr.ofSelectExpr(
return CelExpr.ofSelect(
expr.getId(),
fromExpr(selectExpr.getOperand()),
selectExpr.getField(),
selectExpr.getTestOnly());
case CALL_EXPR:
Call callExpr = expr.getCallExpr();
return CelExpr.ofCallExpr(
return CelExpr.ofCall(
expr.getId(),
callExpr.hasTarget() ? Optional.of(fromExpr(callExpr.getTarget())) : Optional.empty(),
callExpr.getFunction(),
fromExprList(callExpr.getArgsList()));
case LIST_EXPR:
CreateList createListExpr = expr.getListExpr();
return CelExpr.ofCreateListExpr(
return CelExpr.ofCreateList(
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.ofCreateStructEntryExpr(
CelExpr.ofCreateStructEntry(
structExprEntry.getId(),
structExprEntry.getFieldKey(),
fromExpr(structExprEntry.getValue()),
structExprEntry.getOptionalEntry()));
}

return CelExpr.ofCreateStructExpr(id, structExpr.getMessageName(), entries.build());
return CelExpr.ofCreateStruct(id, structExpr.getMessageName(), entries.build());
} else {
ImmutableList.Builder<CelExpr.CelCreateMap.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.ofCreateMapEntryExpr(
CelExpr.ofCreateMapEntry(
mapExprEntry.getId(),
fromExpr(mapExprEntry.getMapKey()),
fromExpr(mapExprEntry.getValue()),
mapExprEntry.getOptionalEntry()));
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ public static CelExpr fromMutableExpr(CelMutableExpr mutableExpr) {
long id = mutableExpr.id();
switch (mutableExpr.getKind()) {
case CONSTANT:
return CelExpr.ofConstantExpr(id, mutableExpr.constant());
return CelExpr.ofConstant(id, mutableExpr.constant());
case IDENT:
return CelExpr.ofIdentExpr(id, mutableExpr.ident().name());
return CelExpr.ofIdent(id, mutableExpr.ident().name());
case SELECT:
CelMutableSelect select = mutableExpr.select();
CelExpr operand = fromMutableExpr(select.operand());
return CelExpr.ofSelectExpr(id, operand, select.field(), select.testOnly());
return CelExpr.ofSelect(id, operand, select.field(), select.testOnly());
case CALL:
CelMutableCall mutableCall = mutableExpr.call();
ImmutableList<CelExpr> args =
Expand All @@ -153,10 +153,10 @@ public static CelExpr fromMutableExpr(CelMutableExpr mutableExpr) {
.collect(toImmutableList());
Optional<CelExpr> targetExpr =
mutableCall.target().map(CelMutableExprConverter::fromMutableExpr);
return CelExpr.ofCallExpr(id, targetExpr, mutableCall.function(), args);
return CelExpr.ofCall(id, targetExpr, mutableCall.function(), args);
case CREATE_LIST:
CelMutableCreateList mutableCreateList = mutableExpr.createList();
return CelExpr.ofCreateListExpr(
return CelExpr.ofCreateList(
id,
fromMutableExprList(mutableCreateList.elements()),
ImmutableList.copyOf(mutableCreateList.optionalIndices()));
Expand Down Expand Up @@ -204,7 +204,7 @@ private static CelCreateStruct fromMutableStructToCelStruct(
List<CelCreateStruct.Entry> entries = new ArrayList<>();
for (CelMutableCreateStruct.Entry mutableStructEntry : mutableCreateStruct.entries()) {
entries.add(
CelExpr.ofCreateStructEntryExpr(
CelExpr.ofCreateStructEntry(
mutableStructEntry.id(),
mutableStructEntry.fieldKey(),
fromMutableExpr(mutableStructEntry.value()),
Expand All @@ -221,7 +221,7 @@ private static CelCreateMap fromMutableMapToCelMap(CelMutableCreateMap mutableCr
List<CelCreateMap.Entry> entries = new ArrayList<>();
for (CelMutableCreateMap.Entry mutableMapEntry : mutableCreateMap.entries()) {
entries.add(
CelExpr.ofCreateMapEntryExpr(
CelExpr.ofCreateMapEntry(
mutableMapEntry.id(),
fromMutableExpr(mutableMapEntry.key()),
fromMutableExpr(mutableMapEntry.value()),
Expand Down
Loading