From 93acd07d536a055283583303ea281e4c13219ce6 Mon Sep 17 00:00:00 2001 From: Sokwhan Huh Date: Wed, 24 Apr 2024 11:27:25 -0700 Subject: [PATCH] Drop expr suffix from CelExpr static constructors PiperOrigin-RevId: 627794357 --- .../test/java/dev/cel/bundle/CelImplTest.java | 2 +- .../main/java/dev/cel/common/ast/CelExpr.java | 19 +- .../dev/cel/common/ast/CelExprConverter.java | 18 +- .../common/ast/CelExprV1Alpha1Converter.java | 18 +- .../common/ast/CelMutableExprConverter.java | 14 +- .../cel/common/ast/CelExprConverterTest.java | 99 +++++---- .../java/dev/cel/common/ast/CelExprTest.java | 42 ++-- .../ast/CelExprV1Alpha1ConverterTest.java | 99 +++++---- .../cel/common/ast/CelExprVisitorTest.java | 16 +- .../ast/CelMutableExprConverterTest.java | 90 ++++----- .../navigation/CelNavigableAstTest.java | 2 +- .../navigation/CelNavigableExprTest.java | 6 +- .../CelNavigableExprVisitorTest.java | 189 +++++++++--------- .../dev/cel/optimizer/AstMutatorTest.java | 4 +- .../cel/optimizer/CelOptimizerImplTest.java | 2 +- .../SubexpressionOptimizerTest.java | 5 +- 16 files changed, 304 insertions(+), 321 deletions(-) diff --git a/bundle/src/test/java/dev/cel/bundle/CelImplTest.java b/bundle/src/test/java/dev/cel/bundle/CelImplTest.java index 3beeb3af9..1eded3ce9 100644 --- a/bundle/src/test/java/dev/cel/bundle/CelImplTest.java +++ b/bundle/src/test/java/dev/cel/bundle/CelImplTest.java @@ -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 diff --git a/common/src/main/java/dev/cel/common/ast/CelExpr.java b/common/src/main/java/dev/cel/common/ast/CelExpr.java index 2ea228268..c0651ccb3 100644 --- a/common/src/main/java/dev/cel/common/ast/CelExpr.java +++ b/common/src/main/java/dev/cel/common/ast/CelExpr.java @@ -983,14 +983,14 @@ 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( @@ -998,8 +998,7 @@ public static CelExpr ofIdentExpr(long id, String identName) { .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( @@ -1012,7 +1011,7 @@ public static CelExpr ofSelectExpr( .build(); } - public static CelExpr ofCallExpr( + public static CelExpr ofCall( long id, Optional targetExpr, String function, ImmutableList arguments) { CelCall.Builder celCallBuilder = CelCall.newBuilder().setFunction(function).addArgs(arguments); @@ -1023,7 +1022,7 @@ public static CelExpr ofCallExpr( .build(); } - public static CelExpr ofCreateListExpr( + public static CelExpr ofCreateList( long id, ImmutableList elements, ImmutableList optionalIndices) { return newBuilder() .setId(id) @@ -1036,7 +1035,7 @@ public static CelExpr ofCreateListExpr( .build(); } - public static CelExpr ofCreateStructExpr( + public static CelExpr ofCreateStruct( long id, String messageName, ImmutableList entries) { return newBuilder() .setId(id) @@ -1049,7 +1048,7 @@ public static CelExpr ofCreateStructExpr( .build(); } - public static CelExpr ofCreateMapExpr(long id, ImmutableList entries) { + public static CelExpr ofCreateMap(long id, ImmutableList entries) { return newBuilder() .setId(id) .setExprKind( @@ -1058,7 +1057,7 @@ public static CelExpr ofCreateMapExpr(long id, ImmutableList .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) @@ -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) diff --git a/common/src/main/java/dev/cel/common/ast/CelExprConverter.java b/common/src/main/java/dev/cel/common/ast/CelExprConverter.java index a17350cc2..b2d8489a3 100644 --- a/common/src/main/java/dev/cel/common/ast/CelExprConverter.java +++ b/common/src/main/java/dev/cel/common/ast/CelExprConverter.java @@ -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())); @@ -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 entries = ImmutableList.builder(); for (Entry mapExprEntry : structExpr.getEntriesList()) { @@ -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()); } } diff --git a/common/src/main/java/dev/cel/common/ast/CelExprV1Alpha1Converter.java b/common/src/main/java/dev/cel/common/ast/CelExprV1Alpha1Converter.java index 377910c04..b22daf514 100644 --- a/common/src/main/java/dev/cel/common/ast/CelExprV1Alpha1Converter.java +++ b/common/src/main/java/dev/cel/common/ast/CelExprV1Alpha1Converter.java @@ -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())); @@ -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 entries = ImmutableList.builder(); for (Entry mapExprEntry : structExpr.getEntriesList()) { @@ -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()); } } diff --git a/common/src/main/java/dev/cel/common/ast/CelMutableExprConverter.java b/common/src/main/java/dev/cel/common/ast/CelMutableExprConverter.java index 2e6ffdadd..1f72f0132 100644 --- a/common/src/main/java/dev/cel/common/ast/CelMutableExprConverter.java +++ b/common/src/main/java/dev/cel/common/ast/CelMutableExprConverter.java @@ -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 args = @@ -153,10 +153,10 @@ public static CelExpr fromMutableExpr(CelMutableExpr mutableExpr) { .collect(toImmutableList()); Optional 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())); @@ -204,7 +204,7 @@ private static CelCreateStruct fromMutableStructToCelStruct( List entries = new ArrayList<>(); for (CelMutableCreateStruct.Entry mutableStructEntry : mutableCreateStruct.entries()) { entries.add( - CelExpr.ofCreateStructEntryExpr( + CelExpr.ofCreateStructEntry( mutableStructEntry.id(), mutableStructEntry.fieldKey(), fromMutableExpr(mutableStructEntry.value()), @@ -221,7 +221,7 @@ private static CelCreateMap fromMutableMapToCelMap(CelMutableCreateMap mutableCr List entries = new ArrayList<>(); for (CelMutableCreateMap.Entry mutableMapEntry : mutableCreateMap.entries()) { entries.add( - CelExpr.ofCreateMapEntryExpr( + CelExpr.ofCreateMapEntry( mutableMapEntry.id(), fromMutableExpr(mutableMapEntry.key()), fromMutableExpr(mutableMapEntry.value()), diff --git a/common/src/test/java/dev/cel/common/ast/CelExprConverterTest.java b/common/src/test/java/dev/cel/common/ast/CelExprConverterTest.java index 55820c3a3..424031dd4 100644 --- a/common/src/test/java/dev/cel/common/ast/CelExprConverterTest.java +++ b/common/src/test/java/dev/cel/common/ast/CelExprConverterTest.java @@ -43,50 +43,50 @@ public class CelExprConverterTest { private enum ConstantTestCase { NOT_SET( Expr.newBuilder().setId(1).setConstExpr(Constant.getDefaultInstance()).build(), - CelExpr.ofConstantExpr(1, CelConstant.ofNotSet())), + CelExpr.ofConstant(1, CelConstant.ofNotSet())), NULL( Expr.newBuilder() .setId(1) .setConstExpr(Constant.newBuilder().setNullValue(NullValue.NULL_VALUE).build()) .build(), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(NullValue.NULL_VALUE))), + CelExpr.ofConstant(1, CelConstant.ofValue(NullValue.NULL_VALUE))), BOOLEAN( Expr.newBuilder() .setId(1) .setConstExpr(Constant.newBuilder().setBoolValue(true).build()) .build(), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(true))), + CelExpr.ofConstant(1, CelConstant.ofValue(true))), INT64( Expr.newBuilder() .setId(1) .setConstExpr(Constant.newBuilder().setInt64Value(10).build()) .build(), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(10))), + CelExpr.ofConstant(1, CelConstant.ofValue(10))), UINT64( Expr.newBuilder() .setId(1) .setConstExpr(Constant.newBuilder().setUint64Value(15).build()) .build(), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(UnsignedLong.valueOf(15)))), + CelExpr.ofConstant(1, CelConstant.ofValue(UnsignedLong.valueOf(15)))), DOUBLE( Expr.newBuilder() .setId(1) .setConstExpr(Constant.newBuilder().setDoubleValue(1.5).build()) .build(), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(1.5))), + CelExpr.ofConstant(1, CelConstant.ofValue(1.5))), STRING( Expr.newBuilder() .setId(1) .setConstExpr(Constant.newBuilder().setStringValue("Test").build()) .build(), - CelExpr.ofConstantExpr(1, CelConstant.ofValue("Test"))), + CelExpr.ofConstant(1, CelConstant.ofValue("Test"))), BYTES( Expr.newBuilder() .setId(1) .setConstExpr( Constant.newBuilder().setBytesValue(ByteString.copyFromUtf8("TEST")).build()) .build(), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(ByteString.copyFromUtf8("TEST")))); + CelExpr.ofConstant(1, CelConstant.ofValue(ByteString.copyFromUtf8("TEST")))); final Expr protoExpr; final CelExpr celExpr; @@ -122,7 +122,7 @@ public void convertExprIdent_toCelIdent() { CelExpr celExpr = CelExprConverter.fromExpr(expr); - assertThat(celExpr).isEqualTo(CelExpr.ofIdentExpr(2, "Test")); + assertThat(celExpr).isEqualTo(CelExpr.ofIdent(2, "Test")); } @Test @@ -146,8 +146,8 @@ public void convertExprSelect_toCelSelect(boolean isTestOnly) { assertThat(celExpr) .isEqualTo( - CelExpr.ofSelectExpr( - 3, CelExpr.ofConstantExpr(4, CelConstant.ofValue(true)), "field", isTestOnly)); + CelExpr.ofSelect( + 3, CelExpr.ofConstant(4, CelConstant.ofValue(true)), "field", isTestOnly)); } @Test @@ -167,11 +167,11 @@ public void convertExprCall_toCelCall() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCallExpr( + CelExpr.ofCall( 1, - Optional.of(CelExpr.ofConstantExpr(2, CelConstant.ofValue(10))), + Optional.of(CelExpr.ofConstant(2, CelConstant.ofValue(10))), "func", - ImmutableList.of(CelExpr.ofConstantExpr(3, CelConstant.ofValue(20))))); + ImmutableList.of(CelExpr.ofConstant(3, CelConstant.ofValue(20))))); } @Test @@ -191,11 +191,11 @@ public void convertExprList_toCelList() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateListExpr( + CelExpr.ofCreateList( 1, ImmutableList.of( - CelExpr.ofConstantExpr(2, CelConstant.ofValue(10)), - CelExpr.ofConstantExpr(3, CelConstant.ofValue(15))), + CelExpr.ofConstant(2, CelConstant.ofValue(10)), + CelExpr.ofConstant(3, CelConstant.ofValue(15))), ImmutableList.of(1))); } @@ -221,12 +221,12 @@ public void convertExprStructExpr_toCelStruct() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateStructExpr( + CelExpr.ofCreateStruct( 1, "messageName", ImmutableList.of( - CelExpr.ofCreateStructEntryExpr( - 2, "fieldKey", CelExpr.ofConstantExpr(3, CelConstant.ofValue(10)), true)))); + CelExpr.ofCreateStructEntry( + 2, "fieldKey", CelExpr.ofConstant(3, CelConstant.ofValue(10)), true)))); } @Test @@ -299,13 +299,13 @@ public void convertExprStructExpr_toCelMap() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateMapExpr( + CelExpr.ofCreateMap( 1, ImmutableList.of( - CelExpr.ofCreateMapEntryExpr( + CelExpr.ofCreateMapEntry( 2, - CelExpr.ofConstantExpr(3, CelConstant.ofValue(15)), - CelExpr.ofConstantExpr(4, CelConstant.ofValue(10)), + CelExpr.ofConstant(3, CelConstant.ofValue(15)), + CelExpr.ofConstant(4, CelConstant.ofValue(10)), true)))); } @@ -341,12 +341,12 @@ public void convertExprComprehensionExpr_toCelComprehension() { CelExpr.ofComprehension( 1, "iterVar", - CelExpr.ofConstantExpr(2, CelConstant.ofValue(10)), + CelExpr.ofConstant(2, CelConstant.ofValue(10)), "accuVar", - CelExpr.ofConstantExpr(3, CelConstant.ofValue(20)), - CelExpr.ofCallExpr(4, Optional.empty(), "testCondition", ImmutableList.of()), - CelExpr.ofCallExpr(5, Optional.empty(), "testStep", ImmutableList.of()), - CelExpr.ofConstantExpr(6, CelConstant.ofValue(30)))); + CelExpr.ofConstant(3, CelConstant.ofValue(20)), + CelExpr.ofCall(4, Optional.empty(), "testCondition", ImmutableList.of()), + CelExpr.ofCall(5, Optional.empty(), "testStep", ImmutableList.of()), + CelExpr.ofConstant(6, CelConstant.ofValue(30)))); } @Test @@ -390,7 +390,7 @@ public void convertCelNotSet_toExprNotSet() { @Test public void convertCelIdent_toExprIdent() { - CelExpr celExpr = CelExpr.ofIdentExpr(2, "Test"); + CelExpr celExpr = CelExpr.ofIdent(2, "Test"); Expr expr = CelExprConverter.fromCelExpr(celExpr); @@ -407,8 +407,7 @@ public void convertCelIdent_toExprIdent() { @TestParameters("{isTestOnly: false}") public void convertCelSelect_toExprSelect(boolean isTestOnly) { CelExpr celExpr = - CelExpr.ofSelectExpr( - 3, CelExpr.ofConstantExpr(4, CelConstant.ofValue(true)), "field", isTestOnly); + CelExpr.ofSelect(3, CelExpr.ofConstant(4, CelConstant.ofValue(true)), "field", isTestOnly); Expr expr = CelExprConverter.fromCelExpr(celExpr); @@ -430,11 +429,11 @@ public void convertCelSelect_toExprSelect(boolean isTestOnly) { @Test public void convertCelCall_toExprCall() { CelExpr celExpr = - CelExpr.ofCallExpr( + CelExpr.ofCall( 1, - Optional.of(CelExpr.ofConstantExpr(2, CelConstant.ofValue(10))), + Optional.of(CelExpr.ofConstant(2, CelConstant.ofValue(10))), "func", - ImmutableList.of(CelExpr.ofConstantExpr(3, CelConstant.ofValue(20)))); + ImmutableList.of(CelExpr.ofConstant(3, CelConstant.ofValue(20)))); Expr expr = CelExprConverter.fromCelExpr(celExpr); @@ -454,11 +453,11 @@ public void convertCelCall_toExprCall() { @Test public void convertCelList_toExprList() { CelExpr celExpr = - CelExpr.ofCreateListExpr( + CelExpr.ofCreateList( 1, ImmutableList.of( - CelExpr.ofConstantExpr(2, CelConstant.ofValue(10)), - CelExpr.ofConstantExpr(3, CelConstant.ofValue(15))), + CelExpr.ofConstant(2, CelConstant.ofValue(10)), + CelExpr.ofConstant(3, CelConstant.ofValue(15))), ImmutableList.of(1)); Expr expr = CelExprConverter.fromCelExpr(celExpr); @@ -479,12 +478,12 @@ public void convertCelList_toExprList() { @Test public void convertCelStructExpr_toExprStruct_withFieldKey() { CelExpr celExpr = - CelExpr.ofCreateStructExpr( + CelExpr.ofCreateStruct( 1, "messageName", ImmutableList.of( - CelExpr.ofCreateStructEntryExpr( - 2, "fieldKey", CelExpr.ofConstantExpr(3, CelConstant.ofValue(10)), true))); + CelExpr.ofCreateStructEntry( + 2, "fieldKey", CelExpr.ofConstant(3, CelConstant.ofValue(10)), true))); Expr expr = CelExprConverter.fromCelExpr(celExpr); @@ -509,13 +508,13 @@ public void convertCelStructExpr_toExprStruct_withFieldKey() { @Test public void convertCelMapExpr_toExprStruct() { CelExpr celExpr = - CelExpr.ofCreateMapExpr( + CelExpr.ofCreateMap( 1, ImmutableList.of( - CelExpr.ofCreateMapEntryExpr( + CelExpr.ofCreateMapEntry( 2, - CelExpr.ofConstantExpr(3, CelConstant.ofValue(15)), - CelExpr.ofConstantExpr(4, CelConstant.ofValue(10)), + CelExpr.ofConstant(3, CelConstant.ofValue(15)), + CelExpr.ofConstant(4, CelConstant.ofValue(10)), true))); Expr expr = CelExprConverter.fromCelExpr(celExpr); @@ -543,12 +542,12 @@ public void convertCelComprehensionExpr_toExprComprehension() { CelExpr.ofComprehension( 1, "iterVar", - CelExpr.ofConstantExpr(2, CelConstant.ofValue(10)), + CelExpr.ofConstant(2, CelConstant.ofValue(10)), "accuVar", - CelExpr.ofConstantExpr(3, CelConstant.ofValue(20)), - CelExpr.ofCallExpr(4, Optional.empty(), "testCondition", ImmutableList.of()), - CelExpr.ofCallExpr(5, Optional.empty(), "testStep", ImmutableList.of()), - CelExpr.ofConstantExpr(6, CelConstant.ofValue(30))); + CelExpr.ofConstant(3, CelConstant.ofValue(20)), + CelExpr.ofCall(4, Optional.empty(), "testCondition", ImmutableList.of()), + CelExpr.ofCall(5, Optional.empty(), "testStep", ImmutableList.of()), + CelExpr.ofConstant(6, CelConstant.ofValue(30))); Expr expr = CelExprConverter.fromCelExpr(celExpr); diff --git a/common/src/test/java/dev/cel/common/ast/CelExprTest.java b/common/src/test/java/dev/cel/common/ast/CelExprTest.java index 2e252e459..c9663978c 100644 --- a/common/src/test/java/dev/cel/common/ast/CelExprTest.java +++ b/common/src/test/java/dev/cel/common/ast/CelExprTest.java @@ -141,7 +141,7 @@ public void celExprBuilder_setCall_clearTarget() { CelCall celCall = CelCall.newBuilder() .setFunction("function") - .setTarget(CelExpr.ofConstantExpr(1, CelConstant.ofValue("test"))) + .setTarget(CelExpr.ofConstant(1, CelConstant.ofValue("test"))) .build(); CelExpr celExpr = CelExpr.newBuilder().setCall(celCall.toBuilder().clearTarget().build()).build(); @@ -156,11 +156,11 @@ public void callBuilder_getArgs() { CelCall celCall = CelCall.newBuilder() .setFunction("function") - .addArgs(CelExpr.ofConstantExpr(1, CelConstant.ofValue("test"))) + .addArgs(CelExpr.ofConstant(1, CelConstant.ofValue("test"))) .build(); assertThat(celCall.toBuilder().getArgs()) - .containsExactly(CelExpr.ofConstantExpr(1, CelConstant.ofValue("test"))); + .containsExactly(CelExpr.ofConstant(1, CelConstant.ofValue("test"))); } @Test @@ -169,15 +169,15 @@ public void celExprBuilder_setCall_setArgByIndex() { CelCall.newBuilder() .setFunction("function") .addArgs( - CelExpr.ofConstantExpr(5, CelConstant.ofValue("hello")), - CelExpr.ofConstantExpr(6, CelConstant.ofValue(5))) + CelExpr.ofConstant(5, CelConstant.ofValue("hello")), + CelExpr.ofConstant(6, CelConstant.ofValue(5))) .build(); CelExpr celExpr = CelExpr.newBuilder() .setCall( celCall.toBuilder() - .setArg(1, CelExpr.ofConstantExpr(7, CelConstant.ofValue("world"))) + .setArg(1, CelExpr.ofConstant(7, CelConstant.ofValue("world"))) .build()) .build(); @@ -186,8 +186,8 @@ public void celExprBuilder_setCall_setArgByIndex() { CelCall.newBuilder() .setFunction("function") .addArgs( - CelExpr.ofConstantExpr(5, CelConstant.ofValue("hello")), - CelExpr.ofConstantExpr(7, CelConstant.ofValue("world"))) + CelExpr.ofConstant(5, CelConstant.ofValue("hello")), + CelExpr.ofConstant(7, CelConstant.ofValue("world"))) .build()); } @@ -206,7 +206,7 @@ public void celExprBuilder_setSelect() { public void celExprBuilder_setCreateList() { CelCreateList celCreateList = CelCreateList.newBuilder() - .addElements(CelExpr.ofConstantExpr(1, CelConstant.ofValue(2))) + .addElements(CelExpr.ofConstant(1, CelConstant.ofValue(2))) .build(); CelExpr celExpr = CelExpr.newBuilder().setCreateList(celCreateList).build(); @@ -218,11 +218,11 @@ public void celExprBuilder_setCreateList() { public void createListBuilder_getArgs() { CelCreateList celCreateList = CelCreateList.newBuilder() - .addElements(CelExpr.ofConstantExpr(1, CelConstant.ofValue(2))) + .addElements(CelExpr.ofConstant(1, CelConstant.ofValue(2))) .build(); assertThat(celCreateList.toBuilder().getElements()) - .containsExactly(CelExpr.ofConstantExpr(1, CelConstant.ofValue(2))); + .containsExactly(CelExpr.ofConstant(1, CelConstant.ofValue(2))); } @Test @@ -230,15 +230,15 @@ public void celExprBuilder_setCreateList_setElementByIndex() { CelCreateList celCreateList = CelCreateList.newBuilder() .addElements( - CelExpr.ofConstantExpr(5, CelConstant.ofValue("hello")), - CelExpr.ofConstantExpr(6, CelConstant.ofValue(5))) + CelExpr.ofConstant(5, CelConstant.ofValue("hello")), + CelExpr.ofConstant(6, CelConstant.ofValue(5))) .build(); CelExpr celExpr = CelExpr.newBuilder() .setCreateList( celCreateList.toBuilder() - .setElement(1, CelExpr.ofConstantExpr(7, CelConstant.ofValue("world"))) + .setElement(1, CelExpr.ofConstant(7, CelConstant.ofValue("world"))) .build()) .build(); @@ -246,8 +246,8 @@ public void celExprBuilder_setCreateList_setElementByIndex() { .isEqualTo( CelCreateList.newBuilder() .addElements( - CelExpr.ofConstantExpr(5, CelConstant.ofValue("hello")), - CelExpr.ofConstantExpr(7, CelConstant.ofValue("world"))) + CelExpr.ofConstant(5, CelConstant.ofValue("hello")), + CelExpr.ofConstant(7, CelConstant.ofValue("world"))) .build()); } @@ -298,13 +298,13 @@ public void celExprBuilder_setCreateStruct_setEntryByIndex() { CelCreateStruct.Entry.newBuilder() .setId(2) .setValue( - CelExpr.ofConstantExpr(5, CelConstant.ofValue("hello")).toBuilder().build()) + CelExpr.ofConstant(5, CelConstant.ofValue("hello")).toBuilder().build()) .setFieldKey("field_key") .build(), CelCreateStruct.Entry.newBuilder() .setId(3) .setValue( - CelExpr.ofConstantExpr(6, CelConstant.ofValue(100)).toBuilder().build()) + CelExpr.ofConstant(6, CelConstant.ofValue(100)).toBuilder().build()) .setFieldKey("field_key") .build()) .build(); @@ -318,7 +318,7 @@ public void celExprBuilder_setCreateStruct_setEntryByIndex() { CelCreateStruct.Entry.newBuilder() .setId(4) .setValue( - CelExpr.ofConstantExpr(6, CelConstant.ofValue("world")).toBuilder() + CelExpr.ofConstant(6, CelConstant.ofValue("world")).toBuilder() .build()) .setFieldKey("field_key") .build()) @@ -332,14 +332,14 @@ public void celExprBuilder_setCreateStruct_setEntryByIndex() { CelCreateStruct.Entry.newBuilder() .setId(2) .setValue( - CelExpr.ofConstantExpr(5, CelConstant.ofValue("hello")).toBuilder() + CelExpr.ofConstant(5, CelConstant.ofValue("hello")).toBuilder() .build()) .setFieldKey("field_key") .build(), CelCreateStruct.Entry.newBuilder() .setId(4) .setValue( - CelExpr.ofConstantExpr(6, CelConstant.ofValue("world")).toBuilder() + CelExpr.ofConstant(6, CelConstant.ofValue("world")).toBuilder() .build()) .setFieldKey("field_key") .build()) diff --git a/common/src/test/java/dev/cel/common/ast/CelExprV1Alpha1ConverterTest.java b/common/src/test/java/dev/cel/common/ast/CelExprV1Alpha1ConverterTest.java index 283fecafa..8a5461a11 100644 --- a/common/src/test/java/dev/cel/common/ast/CelExprV1Alpha1ConverterTest.java +++ b/common/src/test/java/dev/cel/common/ast/CelExprV1Alpha1ConverterTest.java @@ -43,50 +43,50 @@ public class CelExprV1Alpha1ConverterTest { private enum ConstantTestCase { NOT_SET( Expr.newBuilder().setId(1).setConstExpr(Constant.getDefaultInstance()).build(), - CelExpr.ofConstantExpr(1, CelConstant.ofNotSet())), + CelExpr.ofConstant(1, CelConstant.ofNotSet())), NULL( Expr.newBuilder() .setId(1) .setConstExpr(Constant.newBuilder().setNullValue(NullValue.NULL_VALUE).build()) .build(), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(NullValue.NULL_VALUE))), + CelExpr.ofConstant(1, CelConstant.ofValue(NullValue.NULL_VALUE))), BOOLEAN( Expr.newBuilder() .setId(1) .setConstExpr(Constant.newBuilder().setBoolValue(true).build()) .build(), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(true))), + CelExpr.ofConstant(1, CelConstant.ofValue(true))), INT64( Expr.newBuilder() .setId(1) .setConstExpr(Constant.newBuilder().setInt64Value(10).build()) .build(), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(10))), + CelExpr.ofConstant(1, CelConstant.ofValue(10))), UINT64( Expr.newBuilder() .setId(1) .setConstExpr(Constant.newBuilder().setUint64Value(15).build()) .build(), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(UnsignedLong.valueOf(15)))), + CelExpr.ofConstant(1, CelConstant.ofValue(UnsignedLong.valueOf(15)))), DOUBLE( Expr.newBuilder() .setId(1) .setConstExpr(Constant.newBuilder().setDoubleValue(1.5).build()) .build(), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(1.5))), + CelExpr.ofConstant(1, CelConstant.ofValue(1.5))), STRING( Expr.newBuilder() .setId(1) .setConstExpr(Constant.newBuilder().setStringValue("Test").build()) .build(), - CelExpr.ofConstantExpr(1, CelConstant.ofValue("Test"))), + CelExpr.ofConstant(1, CelConstant.ofValue("Test"))), BYTES( Expr.newBuilder() .setId(1) .setConstExpr( Constant.newBuilder().setBytesValue(ByteString.copyFromUtf8("TEST")).build()) .build(), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(ByteString.copyFromUtf8("TEST")))); + CelExpr.ofConstant(1, CelConstant.ofValue(ByteString.copyFromUtf8("TEST")))); final Expr protoExpr; final CelExpr celExpr; @@ -122,7 +122,7 @@ public void convertExprIdent_toCelIdent() { CelExpr celExpr = CelExprV1Alpha1Converter.fromExpr(expr); - assertThat(celExpr).isEqualTo(CelExpr.ofIdentExpr(2, "Test")); + assertThat(celExpr).isEqualTo(CelExpr.ofIdent(2, "Test")); } @Test @@ -146,8 +146,8 @@ public void convertExprSelect_toCelSelect(boolean isTestOnly) { assertThat(celExpr) .isEqualTo( - CelExpr.ofSelectExpr( - 3, CelExpr.ofConstantExpr(4, CelConstant.ofValue(true)), "field", isTestOnly)); + CelExpr.ofSelect( + 3, CelExpr.ofConstant(4, CelConstant.ofValue(true)), "field", isTestOnly)); } @Test @@ -167,11 +167,11 @@ public void convertExprCall_toCelCall() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCallExpr( + CelExpr.ofCall( 1, - Optional.of(CelExpr.ofConstantExpr(2, CelConstant.ofValue(10))), + Optional.of(CelExpr.ofConstant(2, CelConstant.ofValue(10))), "func", - ImmutableList.of(CelExpr.ofConstantExpr(3, CelConstant.ofValue(20))))); + ImmutableList.of(CelExpr.ofConstant(3, CelConstant.ofValue(20))))); } @Test @@ -191,11 +191,11 @@ public void convertExprList_toCelList() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateListExpr( + CelExpr.ofCreateList( 1, ImmutableList.of( - CelExpr.ofConstantExpr(2, CelConstant.ofValue(10)), - CelExpr.ofConstantExpr(3, CelConstant.ofValue(15))), + CelExpr.ofConstant(2, CelConstant.ofValue(10)), + CelExpr.ofConstant(3, CelConstant.ofValue(15))), ImmutableList.of(1))); } @@ -221,12 +221,12 @@ public void convertExprStructExpr_toCelStruct() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateStructExpr( + CelExpr.ofCreateStruct( 1, "messageName", ImmutableList.of( - CelExpr.ofCreateStructEntryExpr( - 2, "fieldKey", CelExpr.ofConstantExpr(3, CelConstant.ofValue(10)), true)))); + CelExpr.ofCreateStructEntry( + 2, "fieldKey", CelExpr.ofConstant(3, CelConstant.ofValue(10)), true)))); } @Test @@ -299,13 +299,13 @@ public void convertExprStructExpr_toCelMap() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateMapExpr( + CelExpr.ofCreateMap( 1, ImmutableList.of( - CelExpr.ofCreateMapEntryExpr( + CelExpr.ofCreateMapEntry( 2, - CelExpr.ofConstantExpr(3, CelConstant.ofValue(15)), - CelExpr.ofConstantExpr(4, CelConstant.ofValue(10)), + CelExpr.ofConstant(3, CelConstant.ofValue(15)), + CelExpr.ofConstant(4, CelConstant.ofValue(10)), true)))); } @@ -341,12 +341,12 @@ public void convertExprComprehensionExpr_toCelComprehension() { CelExpr.ofComprehension( 1, "iterVar", - CelExpr.ofConstantExpr(2, CelConstant.ofValue(10)), + CelExpr.ofConstant(2, CelConstant.ofValue(10)), "accuVar", - CelExpr.ofConstantExpr(3, CelConstant.ofValue(20)), - CelExpr.ofCallExpr(4, Optional.empty(), "testCondition", ImmutableList.of()), - CelExpr.ofCallExpr(5, Optional.empty(), "testStep", ImmutableList.of()), - CelExpr.ofConstantExpr(6, CelConstant.ofValue(30)))); + CelExpr.ofConstant(3, CelConstant.ofValue(20)), + CelExpr.ofCall(4, Optional.empty(), "testCondition", ImmutableList.of()), + CelExpr.ofCall(5, Optional.empty(), "testStep", ImmutableList.of()), + CelExpr.ofConstant(6, CelConstant.ofValue(30)))); } @Test @@ -390,7 +390,7 @@ public void convertCelNotSet_toExprNotSet() { @Test public void convertCelIdent_toExprIdent() { - CelExpr celExpr = CelExpr.ofIdentExpr(2, "Test"); + CelExpr celExpr = CelExpr.ofIdent(2, "Test"); Expr expr = CelExprV1Alpha1Converter.fromCelExpr(celExpr); @@ -407,8 +407,7 @@ public void convertCelIdent_toExprIdent() { @TestParameters("{isTestOnly: false}") public void convertCelSelect_toExprSelect(boolean isTestOnly) { CelExpr celExpr = - CelExpr.ofSelectExpr( - 3, CelExpr.ofConstantExpr(4, CelConstant.ofValue(true)), "field", isTestOnly); + CelExpr.ofSelect(3, CelExpr.ofConstant(4, CelConstant.ofValue(true)), "field", isTestOnly); Expr expr = CelExprV1Alpha1Converter.fromCelExpr(celExpr); @@ -430,11 +429,11 @@ public void convertCelSelect_toExprSelect(boolean isTestOnly) { @Test public void convertCelCall_toExprCall() { CelExpr celExpr = - CelExpr.ofCallExpr( + CelExpr.ofCall( 1, - Optional.of(CelExpr.ofConstantExpr(2, CelConstant.ofValue(10))), + Optional.of(CelExpr.ofConstant(2, CelConstant.ofValue(10))), "func", - ImmutableList.of(CelExpr.ofConstantExpr(3, CelConstant.ofValue(20)))); + ImmutableList.of(CelExpr.ofConstant(3, CelConstant.ofValue(20)))); Expr expr = CelExprV1Alpha1Converter.fromCelExpr(celExpr); @@ -454,11 +453,11 @@ public void convertCelCall_toExprCall() { @Test public void convertCelList_toExprList() { CelExpr celExpr = - CelExpr.ofCreateListExpr( + CelExpr.ofCreateList( 1, ImmutableList.of( - CelExpr.ofConstantExpr(2, CelConstant.ofValue(10)), - CelExpr.ofConstantExpr(3, CelConstant.ofValue(15))), + CelExpr.ofConstant(2, CelConstant.ofValue(10)), + CelExpr.ofConstant(3, CelConstant.ofValue(15))), ImmutableList.of(1)); Expr expr = CelExprV1Alpha1Converter.fromCelExpr(celExpr); @@ -479,12 +478,12 @@ public void convertCelList_toExprList() { @Test public void convertCelStructExpr_toExprStruct_withFieldKey() { CelExpr celExpr = - CelExpr.ofCreateStructExpr( + CelExpr.ofCreateStruct( 1, "messageName", ImmutableList.of( - CelExpr.ofCreateStructEntryExpr( - 2, "fieldKey", CelExpr.ofConstantExpr(3, CelConstant.ofValue(10)), true))); + CelExpr.ofCreateStructEntry( + 2, "fieldKey", CelExpr.ofConstant(3, CelConstant.ofValue(10)), true))); Expr expr = CelExprV1Alpha1Converter.fromCelExpr(celExpr); @@ -509,13 +508,13 @@ public void convertCelStructExpr_toExprStruct_withFieldKey() { @Test public void convertCelMapExpr_toExprStruct() { CelExpr celExpr = - CelExpr.ofCreateMapExpr( + CelExpr.ofCreateMap( 1, ImmutableList.of( - CelExpr.ofCreateMapEntryExpr( + CelExpr.ofCreateMapEntry( 2, - CelExpr.ofConstantExpr(3, CelConstant.ofValue(15)), - CelExpr.ofConstantExpr(4, CelConstant.ofValue(10)), + CelExpr.ofConstant(3, CelConstant.ofValue(15)), + CelExpr.ofConstant(4, CelConstant.ofValue(10)), true))); Expr expr = CelExprV1Alpha1Converter.fromCelExpr(celExpr); @@ -543,12 +542,12 @@ public void convertCelComprehensionExpr_toExprComprehension() { CelExpr.ofComprehension( 1, "iterVar", - CelExpr.ofConstantExpr(2, CelConstant.ofValue(10)), + CelExpr.ofConstant(2, CelConstant.ofValue(10)), "accuVar", - CelExpr.ofConstantExpr(3, CelConstant.ofValue(20)), - CelExpr.ofCallExpr(4, Optional.empty(), "testCondition", ImmutableList.of()), - CelExpr.ofCallExpr(5, Optional.empty(), "testStep", ImmutableList.of()), - CelExpr.ofConstantExpr(6, CelConstant.ofValue(30))); + CelExpr.ofConstant(3, CelConstant.ofValue(20)), + CelExpr.ofCall(4, Optional.empty(), "testCondition", ImmutableList.of()), + CelExpr.ofCall(5, Optional.empty(), "testStep", ImmutableList.of()), + CelExpr.ofConstant(6, CelConstant.ofValue(30))); Expr expr = CelExprV1Alpha1Converter.fromCelExpr(celExpr); diff --git a/common/src/test/java/dev/cel/common/ast/CelExprVisitorTest.java b/common/src/test/java/dev/cel/common/ast/CelExprVisitorTest.java index 1926eb31e..5cfcef44e 100644 --- a/common/src/test/java/dev/cel/common/ast/CelExprVisitorTest.java +++ b/common/src/test/java/dev/cel/common/ast/CelExprVisitorTest.java @@ -237,10 +237,10 @@ public void visitCall() throws Exception { .setCall( CelCall.newBuilder() .setFunction("contains") - .setTarget(CelExpr.ofConstantExpr(1, CelConstant.ofValue("hi"))) - .addArgs(CelExpr.ofConstantExpr(3, stringVal)) + .setTarget(CelExpr.ofConstant(1, CelConstant.ofValue("hi"))) + .addArgs(CelExpr.ofConstant(3, stringVal)) .build()) - .addArguments(CelExpr.ofConstantExpr(3, stringVal)) + .addArguments(CelExpr.ofConstant(3, stringVal)) .build()); } @@ -267,7 +267,7 @@ public void visitCreateStruct_fieldkey() throws Exception { Entry.newBuilder() .setId(2) .setFieldKey("single_int64") - .setValue(CelExpr.ofConstantExpr(3, longConstant)) + .setValue(CelExpr.ofConstant(3, longConstant)) .build()) .setMessageName("TestAllTypes") .build()) @@ -291,8 +291,8 @@ public void visitCreateMap() throws Exception { .addEntries( CelCreateMap.Entry.newBuilder() .setId(2) - .setKey(CelExpr.ofConstantExpr(3, CelConstant.ofValue("a"))) - .setValue(CelExpr.ofConstantExpr(4, CelConstant.ofValue("b"))) + .setKey(CelExpr.ofConstant(3, CelConstant.ofValue("a"))) + .setValue(CelExpr.ofConstant(4, CelConstant.ofValue("b"))) .build()) .build()) .build()); @@ -333,8 +333,8 @@ public void visitComprehension() throws Exception { CelComprehension comprehension = visitedReference.comprehension().get(); ImmutableList iterRangeElements = ImmutableList.of( - CelExpr.ofConstantExpr(2, CelConstant.ofValue(1)), - CelExpr.ofConstantExpr(3, CelConstant.ofValue(1))); + CelExpr.ofConstant(2, CelConstant.ofValue(1)), + CelExpr.ofConstant(3, CelConstant.ofValue(1))); assertThat(comprehension.iterVar()).isEqualTo("x"); assertThat(comprehension.iterRange().createList().elements()).isEqualTo(iterRangeElements); diff --git a/common/src/test/java/dev/cel/common/ast/CelMutableExprConverterTest.java b/common/src/test/java/dev/cel/common/ast/CelMutableExprConverterTest.java index 44a020a0e..06e8ff41e 100644 --- a/common/src/test/java/dev/cel/common/ast/CelMutableExprConverterTest.java +++ b/common/src/test/java/dev/cel/common/ast/CelMutableExprConverterTest.java @@ -40,28 +40,28 @@ public class CelMutableExprConverterTest { private enum ConstantTestCase { NOT_SET( CelMutableExpr.ofConstant(1, CelConstant.ofNotSet()), - CelExpr.ofConstantExpr(1, CelConstant.ofNotSet())), + CelExpr.ofConstant(1, CelConstant.ofNotSet())), NULL( CelMutableExpr.ofConstant(1, CelConstant.ofValue(NullValue.NULL_VALUE)), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(NullValue.NULL_VALUE))), + CelExpr.ofConstant(1, CelConstant.ofValue(NullValue.NULL_VALUE))), BOOLEAN( CelMutableExpr.ofConstant(1, CelConstant.ofValue(true)), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(true))), + CelExpr.ofConstant(1, CelConstant.ofValue(true))), INT64( CelMutableExpr.ofConstant(1, CelConstant.ofValue(10)), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(10))), + CelExpr.ofConstant(1, CelConstant.ofValue(10))), UINT64( CelMutableExpr.ofConstant(1, CelConstant.ofValue(UnsignedLong.valueOf(15))), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(UnsignedLong.valueOf(15)))), + CelExpr.ofConstant(1, CelConstant.ofValue(UnsignedLong.valueOf(15)))), DOUBLE( CelMutableExpr.ofConstant(1, CelConstant.ofValue(1.5)), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(1.5))), + CelExpr.ofConstant(1, CelConstant.ofValue(1.5))), STRING( CelMutableExpr.ofConstant(1, CelConstant.ofValue("Test")), - CelExpr.ofConstantExpr(1, CelConstant.ofValue("Test"))), + CelExpr.ofConstant(1, CelConstant.ofValue("Test"))), BYTES( CelMutableExpr.ofConstant(1, CelConstant.ofValue(ByteString.copyFromUtf8("TEST"))), - CelExpr.ofConstantExpr(1, CelConstant.ofValue(ByteString.copyFromUtf8("TEST")))); + CelExpr.ofConstant(1, CelConstant.ofValue(ByteString.copyFromUtf8("TEST")))); final CelMutableExpr mutableExpr; final CelExpr celExpr; @@ -107,12 +107,12 @@ public void convertMutableIdent_toCelIdent() { CelExpr celExpr = CelMutableExprConverter.fromMutableExpr(mutableExpr); - assertThat(celExpr).isEqualTo(CelExpr.ofIdentExpr(1L, "x")); + assertThat(celExpr).isEqualTo(CelExpr.ofIdent(1L, "x")); } @Test public void convertCelIdent_toMutableIdent() { - CelExpr celExpr = CelExpr.ofIdentExpr(1L, "x"); + CelExpr celExpr = CelExpr.ofIdent(1L, "x"); CelMutableExpr mutableExpr = CelMutableExprConverter.fromCelExpr(celExpr); @@ -130,15 +130,13 @@ public void convertMutableSelect_toCelSelect() { CelExpr celExpr = CelMutableExprConverter.fromMutableExpr(mutableExpr); assertThat(celExpr) - .isEqualTo( - CelExpr.ofSelectExpr( - 1L, CelExpr.ofIdentExpr(2L, "x"), "field", /* isTestOnly= */ true)); + .isEqualTo(CelExpr.ofSelect(1L, CelExpr.ofIdent(2L, "x"), "field", /* isTestOnly= */ true)); } @Test public void convertCelSelect_toMutableSelect() { CelExpr celExpr = - CelExpr.ofSelectExpr(1L, CelExpr.ofIdentExpr(2L, "x"), "field", /* isTestOnly= */ true); + CelExpr.ofSelect(1L, CelExpr.ofIdent(2L, "x"), "field", /* isTestOnly= */ true); CelMutableExpr mutableExpr = CelMutableExprConverter.fromCelExpr(celExpr); @@ -169,8 +167,8 @@ public void convertMutableCall_toCelCall() { .setCall( CelCall.newBuilder() .setFunction("function") - .setTarget(CelExpr.ofConstantExpr(2L, CelConstant.ofValue("target"))) - .addArgs(CelExpr.ofConstantExpr(3L, CelConstant.ofValue("arg"))) + .setTarget(CelExpr.ofConstant(2L, CelConstant.ofValue("target"))) + .addArgs(CelExpr.ofConstant(3L, CelConstant.ofValue("arg"))) .build()) .build()); } @@ -183,8 +181,8 @@ public void convertCelCall_toMutableCall() { .setCall( CelCall.newBuilder() .setFunction("function") - .setTarget(CelExpr.ofConstantExpr(2L, CelConstant.ofValue("target"))) - .addArgs(CelExpr.ofConstantExpr(3L, CelConstant.ofValue("arg"))) + .setTarget(CelExpr.ofConstant(2L, CelConstant.ofValue("target"))) + .addArgs(CelExpr.ofConstant(3L, CelConstant.ofValue("arg"))) .build()) .build(); @@ -215,22 +213,22 @@ public void convertMutableCreateList_toCelCreateList() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateListExpr( + CelExpr.ofCreateList( 1L, ImmutableList.of( - CelExpr.ofConstantExpr(2L, CelConstant.ofValue("element1")), - CelExpr.ofConstantExpr(3L, CelConstant.ofValue("element2"))), + CelExpr.ofConstant(2L, CelConstant.ofValue("element1")), + CelExpr.ofConstant(3L, CelConstant.ofValue("element2"))), ImmutableList.of(0, 1))); } @Test public void convertCelCreateList_toMutableCreateList() { CelExpr celExpr = - CelExpr.ofCreateListExpr( + CelExpr.ofCreateList( 1L, ImmutableList.of( - CelExpr.ofConstantExpr(2L, CelConstant.ofValue("element1")), - CelExpr.ofConstantExpr(3L, CelConstant.ofValue("element2"))), + CelExpr.ofConstant(2L, CelConstant.ofValue("element1")), + CelExpr.ofConstant(3L, CelConstant.ofValue("element2"))), ImmutableList.of(0, 1)); CelMutableExpr mutableExpr = CelMutableExprConverter.fromCelExpr(celExpr); @@ -264,14 +262,14 @@ public void convertMutableCreateStruct_toCelCreateStruct() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateStructExpr( + CelExpr.ofCreateStruct( 8L, "message", ImmutableList.of( CelCreateStruct.Entry.newBuilder() .setId(9L) .setFieldKey("field") - .setValue(CelExpr.ofConstantExpr(10L, CelConstant.ofValue("value"))) + .setValue(CelExpr.ofConstant(10L, CelConstant.ofValue("value"))) .setOptionalEntry(true) .build()))); } @@ -279,14 +277,14 @@ public void convertMutableCreateStruct_toCelCreateStruct() { @Test public void convertCelCreateStruct_toMutableCreateStruct() { CelExpr celExpr = - CelExpr.ofCreateStructExpr( + CelExpr.ofCreateStruct( 8L, "message", ImmutableList.of( CelCreateStruct.Entry.newBuilder() .setId(9L) .setFieldKey("field") - .setValue(CelExpr.ofConstantExpr(10L, CelConstant.ofValue("value"))) + .setValue(CelExpr.ofConstant(10L, CelConstant.ofValue("value"))) .setOptionalEntry(true) .build())); @@ -323,26 +321,26 @@ public void convertMutableCreateMap_toCelCreateMap() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateMapExpr( + CelExpr.ofCreateMap( 9L, ImmutableList.of( - CelExpr.ofCreateMapEntryExpr( + CelExpr.ofCreateMapEntry( 10L, - CelExpr.ofConstantExpr(11L, CelConstant.ofValue("key")), - CelExpr.ofConstantExpr(12L, CelConstant.ofValue("value")), + CelExpr.ofConstant(11L, CelConstant.ofValue("key")), + CelExpr.ofConstant(12L, CelConstant.ofValue("value")), true)))); } @Test public void convertCelCreateMap_toMutableCreateMap() { CelExpr celExpr = - CelExpr.ofCreateMapExpr( + CelExpr.ofCreateMap( 9L, ImmutableList.of( - CelExpr.ofCreateMapEntryExpr( + CelExpr.ofCreateMapEntry( 10L, - CelExpr.ofConstantExpr(11L, CelConstant.ofValue("key")), - CelExpr.ofConstantExpr(12L, CelConstant.ofValue("value")), + CelExpr.ofConstant(11L, CelConstant.ofValue("key")), + CelExpr.ofConstant(12L, CelConstant.ofValue("value")), true))); CelMutableExpr mutableExpr = CelMutableExprConverter.fromCelExpr(celExpr); @@ -388,14 +386,14 @@ public void convertMutableComprehension_toCelComprehension() { .setId(2L) .setCreateList( CelCreateList.newBuilder() - .addElements(CelExpr.ofConstantExpr(3L, CelConstant.ofValue(true))) + .addElements(CelExpr.ofConstant(3L, CelConstant.ofValue(true))) .build()) .build(), "accuVar", - CelExpr.ofConstantExpr(4L, CelConstant.ofValue(true)), - CelExpr.ofConstantExpr(5L, CelConstant.ofValue(true)), - CelExpr.ofConstantExpr(6L, CelConstant.ofValue(true)), - CelExpr.ofIdentExpr(7L, "__result__"))); + CelExpr.ofConstant(4L, CelConstant.ofValue(true)), + CelExpr.ofConstant(5L, CelConstant.ofValue(true)), + CelExpr.ofConstant(6L, CelConstant.ofValue(true)), + CelExpr.ofIdent(7L, "__result__"))); } @Test @@ -408,14 +406,14 @@ public void convertCelComprehension_toMutableComprehension() { .setId(2L) .setCreateList( CelCreateList.newBuilder() - .addElements(CelExpr.ofConstantExpr(3L, CelConstant.ofValue(true))) + .addElements(CelExpr.ofConstant(3L, CelConstant.ofValue(true))) .build()) .build(), "accuVar", - CelExpr.ofConstantExpr(4L, CelConstant.ofValue(true)), - CelExpr.ofConstantExpr(5L, CelConstant.ofValue(true)), - CelExpr.ofConstantExpr(6L, CelConstant.ofValue(true)), - CelExpr.ofIdentExpr(7L, "__result__")); + CelExpr.ofConstant(4L, CelConstant.ofValue(true)), + CelExpr.ofConstant(5L, CelConstant.ofValue(true)), + CelExpr.ofConstant(6L, CelConstant.ofValue(true)), + CelExpr.ofIdent(7L, "__result__")); CelMutableExpr mutableExpr = CelMutableExprConverter.fromCelExpr(celExpr); diff --git a/common/src/test/java/dev/cel/common/navigation/CelNavigableAstTest.java b/common/src/test/java/dev/cel/common/navigation/CelNavigableAstTest.java index 40f772810..6fa4cd203 100644 --- a/common/src/test/java/dev/cel/common/navigation/CelNavigableAstTest.java +++ b/common/src/test/java/dev/cel/common/navigation/CelNavigableAstTest.java @@ -37,7 +37,7 @@ public void construct_success() throws Exception { assertThat(navigableAst.getAst()).isEqualTo(ast); assertThat(navigableAst.getRoot().expr()) - .isEqualTo(CelExpr.ofConstantExpr(1, CelConstant.ofValue("Hello World"))); + .isEqualTo(CelExpr.ofConstant(1, CelConstant.ofValue("Hello World"))); assertThat(navigableAst.getRoot().parent()).isEmpty(); assertThat(navigableAst.getRoot().depth()).isEqualTo(0); } diff --git a/common/src/test/java/dev/cel/common/navigation/CelNavigableExprTest.java b/common/src/test/java/dev/cel/common/navigation/CelNavigableExprTest.java index 261524df0..69b244708 100644 --- a/common/src/test/java/dev/cel/common/navigation/CelNavigableExprTest.java +++ b/common/src/test/java/dev/cel/common/navigation/CelNavigableExprTest.java @@ -27,7 +27,7 @@ public class CelNavigableExprTest { @Test public void construct_withoutParent_success() { - CelExpr constExpr = CelExpr.ofConstantExpr(1, CelConstant.ofValue("test")); + CelExpr constExpr = CelExpr.ofConstant(1, CelConstant.ofValue("test")); CelNavigableExpr navigableExpr = CelNavigableExpr.builder().setExpr(constExpr).setDepth(2).build(); @@ -38,8 +38,8 @@ public void construct_withoutParent_success() { @Test public void construct_withParent_success() { - CelExpr constExpr = CelExpr.ofConstantExpr(1, CelConstant.ofValue("test")); - CelExpr identExpr = CelExpr.ofIdentExpr(2, "a"); + CelExpr constExpr = CelExpr.ofConstant(1, CelConstant.ofValue("test")); + CelExpr identExpr = CelExpr.ofIdent(2, "a"); CelNavigableExpr parentExpr = CelNavigableExpr.builder().setExpr(identExpr).setDepth(1).build(); CelNavigableExpr navigableExpr = CelNavigableExpr.builder().setExpr(constExpr).setDepth(2).setParent(parentExpr).build(); diff --git a/common/src/test/java/dev/cel/common/navigation/CelNavigableExprVisitorTest.java b/common/src/test/java/dev/cel/common/navigation/CelNavigableExprVisitorTest.java index 4af7a7e83..18c71cb28 100644 --- a/common/src/test/java/dev/cel/common/navigation/CelNavigableExprVisitorTest.java +++ b/common/src/test/java/dev/cel/common/navigation/CelNavigableExprVisitorTest.java @@ -85,26 +85,26 @@ public void add_allNodes_allNodesReturned() throws Exception { navigableAst.getRoot().allNodes().map(CelNavigableExpr::expr).collect(toImmutableList()); CelExpr childAddCall = - CelExpr.ofCallExpr( + CelExpr.ofCall( 2, Optional.empty(), Operator.ADD.getFunction(), ImmutableList.of( - CelExpr.ofConstantExpr(1, CelConstant.ofValue(1)), // 1 + a - CelExpr.ofIdentExpr(3, "a"))); + CelExpr.ofConstant(1, CelConstant.ofValue(1)), // 1 + a + CelExpr.ofIdent(3, "a"))); CelExpr rootAddCall = - CelExpr.ofCallExpr( + CelExpr.ofCall( 4, Optional.empty(), Operator.ADD.getFunction(), - ImmutableList.of(childAddCall, CelExpr.ofConstantExpr(5, CelConstant.ofValue(2)))); + ImmutableList.of(childAddCall, CelExpr.ofConstant(5, CelConstant.ofValue(2)))); assertThat(allNodes) .containsExactly( rootAddCall, childAddCall, - CelExpr.ofConstantExpr(1, CelConstant.ofValue(1)), - CelExpr.ofIdentExpr(3, "a"), - CelExpr.ofConstantExpr(5, CelConstant.ofValue(2))); + CelExpr.ofConstant(1, CelConstant.ofValue(1)), + CelExpr.ofIdent(3, "a"), + CelExpr.ofConstant(5, CelConstant.ofValue(2))); } @Test @@ -310,10 +310,8 @@ public void add_filterConstants_allNodesReturned() throws Exception { .collect(toImmutableList()); assertThat(allConstants).hasSize(2); - assertThat(allConstants.get(0).expr()) - .isEqualTo(CelExpr.ofConstantExpr(1, CelConstant.ofValue(1))); - assertThat(allConstants.get(1).expr()) - .isEqualTo(CelExpr.ofConstantExpr(5, CelConstant.ofValue(2))); + assertThat(allConstants.get(0).expr()).isEqualTo(CelExpr.ofConstant(1, CelConstant.ofValue(1))); + assertThat(allConstants.get(1).expr()).isEqualTo(CelExpr.ofConstant(5, CelConstant.ofValue(2))); } @Test @@ -339,20 +337,19 @@ public void add_filterConstants_parentsPopulated() throws Exception { CelExpr rootAddCall = allConstants.get(1).parent().get().expr(); // childAddCall + 2 assertThat(childAddCall) .isEqualTo( - CelExpr.ofCallExpr( + CelExpr.ofCall( 2, Optional.empty(), Operator.ADD.getFunction(), ImmutableList.of( - CelExpr.ofConstantExpr(1, CelConstant.ofValue(1)), - CelExpr.ofIdentExpr(3, "a")))); + CelExpr.ofConstant(1, CelConstant.ofValue(1)), CelExpr.ofIdent(3, "a")))); assertThat(rootAddCall) .isEqualTo( - CelExpr.ofCallExpr( + CelExpr.ofCall( 4, Optional.empty(), Operator.ADD.getFunction(), - ImmutableList.of(childAddCall, CelExpr.ofConstantExpr(5, CelConstant.ofValue(2))))); + ImmutableList.of(childAddCall, CelExpr.ofConstant(5, CelConstant.ofValue(2))))); } @Test @@ -374,8 +371,7 @@ public void add_filterConstants_singleChildReturned() throws Exception { .collect(toImmutableList()); assertThat(allConstants).hasSize(1); - assertThat(allConstants.get(0).expr()) - .isEqualTo(CelExpr.ofConstantExpr(5, CelConstant.ofValue(2))); + assertThat(allConstants.get(0).expr()).isEqualTo(CelExpr.ofConstant(5, CelConstant.ofValue(2))); } @Test @@ -427,7 +423,7 @@ public void add_childrenOfMiddleBranch_success() throws Exception { // Assert that the children of add call in the middle branch are const(1) and ident("a") assertThat(children).hasSize(2); - assertThat(children.get(0).expr()).isEqualTo(CelExpr.ofConstantExpr(1, CelConstant.ofValue(1))); + assertThat(children.get(0).expr()).isEqualTo(CelExpr.ofConstant(1, CelConstant.ofValue(1))); assertThat(children.get(1).expr()).isEqualTo(ident.expr()); } @@ -498,9 +494,9 @@ public void message_allNodesReturned() throws Exception { ImmutableList allNodes = navigableAst.getRoot().allNodes().map(CelNavigableExpr::expr).collect(toImmutableList()); - CelExpr operand = CelExpr.ofIdentExpr(1, "msg"); + CelExpr operand = CelExpr.ofIdent(1, "msg"); assertThat(allNodes) - .containsExactly(operand, CelExpr.ofSelectExpr(2, operand, "single_int64", false)); + .containsExactly(operand, CelExpr.ofSelect(2, operand, "single_int64", false)); } @Test @@ -522,9 +518,9 @@ public void nestedMessage_filterSelect_allNodesReturned() throws Exception { .collect(toImmutableList()); CelExpr innerSelect = - CelExpr.ofSelectExpr( - 2, CelExpr.ofIdentExpr(1, "msg"), "standalone_message", false); // msg.standalone - CelExpr outerSelect = CelExpr.ofSelectExpr(3, innerSelect, "bb", false); // innerSelect.bb + CelExpr.ofSelect( + 2, CelExpr.ofIdent(1, "msg"), "standalone_message", false); // msg.standalone + CelExpr outerSelect = CelExpr.ofSelect(3, innerSelect, "bb", false); // innerSelect.bb assertThat(allSelects).containsExactly(innerSelect, outerSelect); } @@ -552,9 +548,9 @@ public void nestedMessage_filterSelect_singleChildReturned() throws Exception { assertThat(allSelects).hasSize(1); CelExpr innerSelect = - CelExpr.ofSelectExpr( - 4, CelExpr.ofIdentExpr(3, "msg"), "standalone_message", false); // msg.standalone - CelExpr outerSelect = CelExpr.ofSelectExpr(5, innerSelect, "bb", false); // innerSelect.bb + CelExpr.ofSelect( + 4, CelExpr.ofIdent(3, "msg"), "standalone_message", false); // msg.standalone + CelExpr outerSelect = CelExpr.ofSelect(5, innerSelect, "bb", false); // innerSelect.bb assertThat(allSelects.get(0).expr()).isEqualTo(outerSelect); } @@ -575,8 +571,8 @@ public void presenceTest_allNodesReturned() throws Exception { assertThat(allNodes).hasSize(2); assertThat(allNodes) .containsExactly( - CelExpr.ofIdentExpr(2, "msg"), - CelExpr.ofSelectExpr(4, CelExpr.ofIdentExpr(2, "msg"), "standalone_message", true)); + CelExpr.ofIdent(2, "msg"), + CelExpr.ofSelect(4, CelExpr.ofIdent(2, "msg"), "standalone_message", true)); } @Test @@ -592,15 +588,15 @@ public void messageConstruction_allNodesReturned() throws Exception { ImmutableList allNodes = navigableAst.getRoot().allNodes().map(CelNavigableExpr::expr).collect(toImmutableList()); - CelExpr constExpr = CelExpr.ofConstantExpr(3, CelConstant.ofValue(1)); + CelExpr constExpr = CelExpr.ofConstant(3, CelConstant.ofValue(1)); assertThat(allNodes) .containsExactly( constExpr, - CelExpr.ofCreateStructExpr( + CelExpr.ofCreateStruct( 1, "TestAllTypes", ImmutableList.of( - CelExpr.ofCreateStructEntryExpr(2, "single_int64", constExpr, false)))); + CelExpr.ofCreateStructEntry(2, "single_int64", constExpr, false)))); } @Test @@ -623,15 +619,12 @@ public void messageConstruction_filterCreateStruct_allNodesReturned() throws Exc assertThat(allNodes).hasSize(1); assertThat(allNodes.get(0).expr()) .isEqualTo( - CelExpr.ofCreateStructExpr( + CelExpr.ofCreateStruct( 1, "TestAllTypes", ImmutableList.of( - CelExpr.ofCreateStructEntryExpr( - 2, - "single_int64", - CelExpr.ofConstantExpr(3, CelConstant.ofValue(1)), - false)))); + CelExpr.ofCreateStructEntry( + 2, "single_int64", CelExpr.ofConstant(3, CelConstant.ofValue(1)), false)))); } @Test @@ -705,16 +698,14 @@ public void mapConstruction_allNodesReturned() throws Exception { navigableAst.getRoot().allNodes().map(CelNavigableExpr::expr).collect(toImmutableList()); assertThat(allNodes).hasSize(3); - CelExpr mapKeyExpr = CelExpr.ofConstantExpr(3, CelConstant.ofValue("key")); - CelExpr mapValueExpr = CelExpr.ofConstantExpr(4, CelConstant.ofValue(2)); + CelExpr mapKeyExpr = CelExpr.ofConstant(3, CelConstant.ofValue("key")); + CelExpr mapValueExpr = CelExpr.ofConstant(4, CelConstant.ofValue(2)); assertThat(allNodes) .containsExactly( mapKeyExpr, mapValueExpr, - CelExpr.ofCreateMapExpr( - 1, - ImmutableList.of( - CelExpr.ofCreateMapEntryExpr(2, mapKeyExpr, mapValueExpr, false)))); + CelExpr.ofCreateMap( + 1, ImmutableList.of(CelExpr.ofCreateMapEntry(2, mapKeyExpr, mapValueExpr, false)))); } @Test @@ -731,14 +722,12 @@ public void mapConstruction_filterCreateMap_allNodesReturned() throws Exception .collect(toImmutableList()); assertThat(allNodes).hasSize(1); - CelExpr mapKeyExpr = CelExpr.ofConstantExpr(3, CelConstant.ofValue("key")); - CelExpr mapValueExpr = CelExpr.ofConstantExpr(4, CelConstant.ofValue(2)); + CelExpr mapKeyExpr = CelExpr.ofConstant(3, CelConstant.ofValue("key")); + CelExpr mapValueExpr = CelExpr.ofConstant(4, CelConstant.ofValue(2)); assertThat(allNodes.get(0).expr()) .isEqualTo( - CelExpr.ofCreateMapExpr( - 1, - ImmutableList.of( - CelExpr.ofCreateMapEntryExpr(2, mapKeyExpr, mapValueExpr, false)))); + CelExpr.ofCreateMap( + 1, ImmutableList.of(CelExpr.ofCreateMapEntry(2, mapKeyExpr, mapValueExpr, false)))); } @Test @@ -815,7 +804,7 @@ public void emptyMapConstruction_allNodesReturned() throws Exception { navigableAst.getRoot().allNodes().collect(toImmutableList()); assertThat(allNodes).hasSize(1); - assertThat(allNodes.get(0).expr()).isEqualTo(CelExpr.ofCreateMapExpr(1, ImmutableList.of())); + assertThat(allNodes.get(0).expr()).isEqualTo(CelExpr.ofCreateMap(1, ImmutableList.of())); } @Test @@ -834,32 +823,32 @@ public void comprehension_preOrder_allNodesReturned() throws Exception { .map(CelNavigableExpr::expr) .collect(toImmutableList()); - CelExpr iterRangeConstExpr = CelExpr.ofConstantExpr(2, CelConstant.ofValue(true)); + CelExpr iterRangeConstExpr = CelExpr.ofConstant(2, CelConstant.ofValue(true)); CelExpr iterRange = - CelExpr.ofCreateListExpr(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); - CelExpr accuInit = CelExpr.ofConstantExpr(6, CelConstant.ofValue(false)); - CelExpr loopConditionIdentExpr = CelExpr.ofIdentExpr(7, "__result__"); + CelExpr.ofCreateList(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); + CelExpr accuInit = CelExpr.ofConstant(6, CelConstant.ofValue(false)); + CelExpr loopConditionIdentExpr = CelExpr.ofIdent(7, "__result__"); CelExpr loopConditionCallExpr = - CelExpr.ofCallExpr( + CelExpr.ofCall( 8, Optional.empty(), Operator.LOGICAL_NOT.getFunction(), ImmutableList.of(loopConditionIdentExpr)); CelExpr loopCondition = - CelExpr.ofCallExpr( + CelExpr.ofCall( 9, Optional.empty(), Operator.NOT_STRICTLY_FALSE.getFunction(), ImmutableList.of(loopConditionCallExpr)); - CelExpr loopStepResultExpr = CelExpr.ofIdentExpr(10, "__result__"); - CelExpr loopStepVarExpr = CelExpr.ofIdentExpr(5, "i"); + CelExpr loopStepResultExpr = CelExpr.ofIdent(10, "__result__"); + CelExpr loopStepVarExpr = CelExpr.ofIdent(5, "i"); CelExpr loopStep = - CelExpr.ofCallExpr( + CelExpr.ofCall( 11, Optional.empty(), Operator.LOGICAL_OR.getFunction(), ImmutableList.of(loopStepResultExpr, loopStepVarExpr)); - CelExpr result = CelExpr.ofIdentExpr(12, "__result__"); + CelExpr result = CelExpr.ofIdent(12, "__result__"); CelExpr comprehension = CelExpr.ofComprehension( 13, "i", iterRange, "__result__", accuInit, loopCondition, loopStep, result); @@ -896,32 +885,32 @@ public void comprehension_postOrder_allNodesReturned() throws Exception { .map(CelNavigableExpr::expr) .collect(toImmutableList()); - CelExpr iterRangeConstExpr = CelExpr.ofConstantExpr(2, CelConstant.ofValue(true)); + CelExpr iterRangeConstExpr = CelExpr.ofConstant(2, CelConstant.ofValue(true)); CelExpr iterRange = - CelExpr.ofCreateListExpr(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); - CelExpr accuInit = CelExpr.ofConstantExpr(6, CelConstant.ofValue(false)); - CelExpr loopConditionIdentExpr = CelExpr.ofIdentExpr(7, "__result__"); + CelExpr.ofCreateList(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); + CelExpr accuInit = CelExpr.ofConstant(6, CelConstant.ofValue(false)); + CelExpr loopConditionIdentExpr = CelExpr.ofIdent(7, "__result__"); CelExpr loopConditionCallExpr = - CelExpr.ofCallExpr( + CelExpr.ofCall( 8, Optional.empty(), Operator.LOGICAL_NOT.getFunction(), ImmutableList.of(loopConditionIdentExpr)); CelExpr loopCondition = - CelExpr.ofCallExpr( + CelExpr.ofCall( 9, Optional.empty(), Operator.NOT_STRICTLY_FALSE.getFunction(), ImmutableList.of(loopConditionCallExpr)); - CelExpr loopStepResultExpr = CelExpr.ofIdentExpr(10, "__result__"); - CelExpr loopStepVarExpr = CelExpr.ofIdentExpr(5, "i"); + CelExpr loopStepResultExpr = CelExpr.ofIdent(10, "__result__"); + CelExpr loopStepVarExpr = CelExpr.ofIdent(5, "i"); CelExpr loopStep = - CelExpr.ofCallExpr( + CelExpr.ofCall( 11, Optional.empty(), Operator.LOGICAL_OR.getFunction(), ImmutableList.of(loopStepResultExpr, loopStepVarExpr)); - CelExpr result = CelExpr.ofIdentExpr(12, "__result__"); + CelExpr result = CelExpr.ofIdent(12, "__result__"); CelExpr comprehension = CelExpr.ofComprehension( 13, "i", iterRange, "__result__", accuInit, loopCondition, loopStep, result); @@ -1029,32 +1018,32 @@ public void comprehension_allNodes_parentsPopulated() throws Exception { ImmutableList allNodes = navigableAst.getRoot().allNodes(TraversalOrder.PRE_ORDER).collect(toImmutableList()); - CelExpr iterRangeConstExpr = CelExpr.ofConstantExpr(2, CelConstant.ofValue(true)); + CelExpr iterRangeConstExpr = CelExpr.ofConstant(2, CelConstant.ofValue(true)); CelExpr iterRange = - CelExpr.ofCreateListExpr(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); - CelExpr accuInit = CelExpr.ofConstantExpr(6, CelConstant.ofValue(false)); - CelExpr loopConditionIdentExpr = CelExpr.ofIdentExpr(7, "__result__"); + CelExpr.ofCreateList(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); + CelExpr accuInit = CelExpr.ofConstant(6, CelConstant.ofValue(false)); + CelExpr loopConditionIdentExpr = CelExpr.ofIdent(7, "__result__"); CelExpr loopConditionCallExpr = - CelExpr.ofCallExpr( + CelExpr.ofCall( 8, Optional.empty(), Operator.LOGICAL_NOT.getFunction(), ImmutableList.of(loopConditionIdentExpr)); CelExpr loopCondition = - CelExpr.ofCallExpr( + CelExpr.ofCall( 9, Optional.empty(), Operator.NOT_STRICTLY_FALSE.getFunction(), ImmutableList.of(loopConditionCallExpr)); - CelExpr loopStepResultExpr = CelExpr.ofIdentExpr(10, "__result__"); - CelExpr loopStepVarExpr = CelExpr.ofIdentExpr(5, "i"); + CelExpr loopStepResultExpr = CelExpr.ofIdent(10, "__result__"); + CelExpr loopStepVarExpr = CelExpr.ofIdent(5, "i"); CelExpr loopStep = - CelExpr.ofCallExpr( + CelExpr.ofCall( 11, Optional.empty(), Operator.LOGICAL_OR.getFunction(), ImmutableList.of(loopStepResultExpr, loopStepVarExpr)); - CelExpr result = CelExpr.ofIdentExpr(12, "__result__"); + CelExpr result = CelExpr.ofIdent(12, "__result__"); CelExpr comprehension = CelExpr.ofComprehension( 13, "i", iterRange, "__result__", accuInit, loopCondition, loopStep, result); @@ -1093,32 +1082,32 @@ public void comprehension_filterComprehension_allNodesReturned() throws Exceptio .filter(x -> x.getKind().equals(Kind.COMPREHENSION)) .collect(toImmutableList()); - CelExpr iterRangeConstExpr = CelExpr.ofConstantExpr(2, CelConstant.ofValue(true)); + CelExpr iterRangeConstExpr = CelExpr.ofConstant(2, CelConstant.ofValue(true)); CelExpr iterRange = - CelExpr.ofCreateListExpr(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); - CelExpr accuInit = CelExpr.ofConstantExpr(6, CelConstant.ofValue(false)); - CelExpr loopConditionIdentExpr = CelExpr.ofIdentExpr(7, "__result__"); + CelExpr.ofCreateList(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); + CelExpr accuInit = CelExpr.ofConstant(6, CelConstant.ofValue(false)); + CelExpr loopConditionIdentExpr = CelExpr.ofIdent(7, "__result__"); CelExpr loopConditionCallExpr = - CelExpr.ofCallExpr( + CelExpr.ofCall( 8, Optional.empty(), Operator.LOGICAL_NOT.getFunction(), ImmutableList.of(loopConditionIdentExpr)); CelExpr loopCondition = - CelExpr.ofCallExpr( + CelExpr.ofCall( 9, Optional.empty(), Operator.NOT_STRICTLY_FALSE.getFunction(), ImmutableList.of(loopConditionCallExpr)); - CelExpr loopStepResultExpr = CelExpr.ofIdentExpr(10, "__result__"); - CelExpr loopStepVarExpr = CelExpr.ofIdentExpr(5, "i"); + CelExpr loopStepResultExpr = CelExpr.ofIdent(10, "__result__"); + CelExpr loopStepVarExpr = CelExpr.ofIdent(5, "i"); CelExpr loopStep = - CelExpr.ofCallExpr( + CelExpr.ofCall( 11, Optional.empty(), Operator.LOGICAL_OR.getFunction(), ImmutableList.of(loopStepResultExpr, loopStepVarExpr)); - CelExpr result = CelExpr.ofIdentExpr(12, "__result__"); + CelExpr result = CelExpr.ofIdent(12, "__result__"); CelExpr comprehension = CelExpr.ofComprehension( 13, "i", iterRange, "__result__", accuInit, loopCondition, loopStep, result); @@ -1150,12 +1139,12 @@ public void callExpr_preOrder() throws Exception { .map(CelNavigableExpr::expr) .collect(toImmutableList()); - CelExpr targetExpr = CelExpr.ofConstantExpr(1, CelConstant.ofValue("hello")); - CelExpr intArgExpr = CelExpr.ofConstantExpr(3, CelConstant.ofValue(5)); - CelExpr uintArgExpr = CelExpr.ofConstantExpr(4, CelConstant.ofValue(UnsignedLong.valueOf(6))); + CelExpr targetExpr = CelExpr.ofConstant(1, CelConstant.ofValue("hello")); + CelExpr intArgExpr = CelExpr.ofConstant(3, CelConstant.ofValue(5)); + CelExpr uintArgExpr = CelExpr.ofConstant(4, CelConstant.ofValue(UnsignedLong.valueOf(6))); assertThat(allNodes) .containsExactly( - CelExpr.ofCallExpr( + CelExpr.ofCall( 2, Optional.of(targetExpr), "test", ImmutableList.of(intArgExpr, uintArgExpr)), targetExpr, intArgExpr, @@ -1187,15 +1176,15 @@ public void callExpr_postOrder() throws Exception { .map(CelNavigableExpr::expr) .collect(toImmutableList()); - CelExpr targetExpr = CelExpr.ofConstantExpr(1, CelConstant.ofValue("hello")); - CelExpr intArgExpr = CelExpr.ofConstantExpr(3, CelConstant.ofValue(5)); - CelExpr uintArgExpr = CelExpr.ofConstantExpr(4, CelConstant.ofValue(UnsignedLong.valueOf(6))); + CelExpr targetExpr = CelExpr.ofConstant(1, CelConstant.ofValue("hello")); + CelExpr intArgExpr = CelExpr.ofConstant(3, CelConstant.ofValue(5)); + CelExpr uintArgExpr = CelExpr.ofConstant(4, CelConstant.ofValue(UnsignedLong.valueOf(6))); assertThat(allNodes) .containsExactly( targetExpr, intArgExpr, uintArgExpr, - CelExpr.ofCallExpr( + CelExpr.ofCall( 2, Optional.of(targetExpr), "test", ImmutableList.of(intArgExpr, uintArgExpr))) .inOrder(); } diff --git a/optimizer/src/test/java/dev/cel/optimizer/AstMutatorTest.java b/optimizer/src/test/java/dev/cel/optimizer/AstMutatorTest.java index b3c6313da..e199ea6e2 100644 --- a/optimizer/src/test/java/dev/cel/optimizer/AstMutatorTest.java +++ b/optimizer/src/test/java/dev/cel/optimizer/AstMutatorTest.java @@ -82,7 +82,7 @@ public void replaceSubtree_replaceConst() throws Exception { AST_MUTATOR.replaceSubtree(mutableAst, newBooleanConst, mutableAst.expr().id()); assertThat(result.toParsedAst().getExpr()) - .isEqualTo(CelExpr.ofConstantExpr(3, CelConstant.ofValue(true))); + .isEqualTo(CelExpr.ofConstant(3, CelConstant.ofValue(true))); } @Test @@ -519,7 +519,7 @@ public void globalCallExpr_replaceRoot() throws Exception { CelMutableAst result = AST_MUTATOR.replaceSubtree(mutableAst, newExpr, mutableAst.expr().id()); assertThat(result.toParsedAst().getExpr()) - .isEqualTo(CelExpr.ofConstantExpr(7, CelConstant.ofValue(10))); + .isEqualTo(CelExpr.ofConstant(7, CelConstant.ofValue(10))); } @Test diff --git a/optimizer/src/test/java/dev/cel/optimizer/CelOptimizerImplTest.java b/optimizer/src/test/java/dev/cel/optimizer/CelOptimizerImplTest.java index 570233dd6..cb0bff6c6 100644 --- a/optimizer/src/test/java/dev/cel/optimizer/CelOptimizerImplTest.java +++ b/optimizer/src/test/java/dev/cel/optimizer/CelOptimizerImplTest.java @@ -115,7 +115,7 @@ public void optimizedAst_failsToTypeCheck_throwsException() { (navigableAst, cel) -> OptimizationResult.create( CelAbstractSyntaxTree.newParsedAst( - CelExpr.ofIdentExpr(1, "undeclared_ident"), + CelExpr.ofIdent(1, "undeclared_ident"), CelSource.newBuilder().build()))) .build(); diff --git a/optimizer/src/test/java/dev/cel/optimizer/optimizers/SubexpressionOptimizerTest.java b/optimizer/src/test/java/dev/cel/optimizer/optimizers/SubexpressionOptimizerTest.java index 8d657cd0a..f4cec706d 100644 --- a/optimizer/src/test/java/dev/cel/optimizer/optimizers/SubexpressionOptimizerTest.java +++ b/optimizer/src/test/java/dev/cel/optimizer/optimizers/SubexpressionOptimizerTest.java @@ -218,13 +218,12 @@ public void cse_applyConstFoldingAfter() throws Exception { assertThat(optimizedAst.getExpr()) .isEqualTo( - CelExpr.ofCallExpr( + CelExpr.ofCall( 1L, Optional.empty(), Operator.ADD.getFunction(), ImmutableList.of( - CelExpr.ofConstantExpr(2L, CelConstant.ofValue(6L)), - CelExpr.ofIdentExpr(3L, "x")))); + CelExpr.ofConstant(2L, CelConstant.ofValue(6L)), CelExpr.ofIdent(3L, "x")))); assertThat(CEL_UNPARSER.unparse(optimizedAst)).isEqualTo("6 + x"); }