From 8c3fb025f1692c2694782c45a46fdcadb5c9a82c Mon Sep 17 00:00:00 2001 From: Sokwhan Huh Date: Tue, 30 Apr 2024 14:54:56 -0700 Subject: [PATCH] Remove create modifiers from list,struct,map methods PiperOrigin-RevId: 629537717 --- .../test/java/dev/cel/bundle/CelImplTest.java | 2 +- .../java/dev/cel/checker/ExprChecker.java | 22 +-- .../main/java/dev/cel/common/ast/CelExpr.java | 93 ++++++++----- .../dev/cel/common/ast/CelExprConverter.java | 10 +- .../dev/cel/common/ast/CelExprFactory.java | 6 +- .../dev/cel/common/ast/CelExprFormatter.java | 6 +- .../common/ast/CelExprV1Alpha1Converter.java | 10 +- .../dev/cel/common/ast/CelExprVisitor.java | 6 +- .../dev/cel/common/ast/CelMutableExpr.java | 54 ++++---- .../common/ast/CelMutableExprConverter.java | 27 ++-- .../java/dev/cel/common/ast/Expression.java | 10 +- .../navigation/CelNavigableExprVisitor.java | 6 +- .../navigation/ExprPropertyCalculator.java | 6 +- .../cel/common/ast/CelExprConverterTest.java | 20 +-- .../java/dev/cel/common/ast/CelExprTest.java | 56 ++++---- .../ast/CelExprV1Alpha1ConverterTest.java | 20 +-- .../cel/common/ast/CelExprVisitorTest.java | 38 +++--- .../ast/CelMutableExprConverterTest.java | 36 ++--- .../cel/common/ast/CelMutableExprTest.java | 128 +++++++++--------- .../CelNavigableExprVisitorTest.java | 31 ++--- .../CelNavigableMutableExprTest.java | 12 +- .../dev/cel/extensions/CelMathExtensions.java | 4 +- .../java/dev/cel/optimizer/AstMutator.java | 8 +- .../dev/cel/optimizer/MutableExprVisitor.java | 6 +- .../optimizers/ConstantFoldingOptimizer.java | 20 ++- .../optimizers/SubexpressionOptimizer.java | 4 +- .../dev/cel/optimizer/AstMutatorTest.java | 2 +- .../dev/cel/parser/CelMacroExprFactory.java | 16 +-- .../src/main/java/dev/cel/parser/Parser.java | 6 +- .../cel/parser/CelMacroExprFactoryTest.java | 10 +- .../dev/cel/parser/CelUnparserImplTest.java | 4 +- .../dev/cel/runtime/DefaultInterpreter.java | 10 +- .../java/dev/cel/runtime/CelRuntimeTest.java | 6 +- .../HomogeneousLiteralValidator.java | 6 +- 34 files changed, 357 insertions(+), 344 deletions(-) diff --git a/bundle/src/test/java/dev/cel/bundle/CelImplTest.java b/bundle/src/test/java/dev/cel/bundle/CelImplTest.java index de36d93b9..fc4304657 100644 --- a/bundle/src/test/java/dev/cel/bundle/CelImplTest.java +++ b/bundle/src/test/java/dev/cel/bundle/CelImplTest.java @@ -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")); } diff --git a/checker/src/main/java/dev/cel/checker/ExprChecker.java b/checker/src/main/java/dev/cel/checker/ExprChecker.java index 777dd8119..dd5d79f35 100644 --- a/checker/src/main/java/dev/cel/checker/ExprChecker.java +++ b/checker/src/main/java/dev/cel/checker/ExprChecker.java @@ -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: @@ -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) { 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 bac1410bf..0868daa13 100644 --- a/common/src/main/java/dev/cel/common/ast/CelExpr.java +++ b/common/src/main/java/dev/cel/common/ast/CelExpr.java @@ -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(); } @@ -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(); @@ -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(); } /** @@ -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 @@ -1040,7 +1067,7 @@ public static CelExpr ofCall( .build(); } - public static CelExpr ofCreateList( + public static CelExpr ofList( long id, ImmutableList elements, ImmutableList optionalIndices) { return newBuilder() .setId(id) @@ -1053,7 +1080,7 @@ public static CelExpr ofCreateList( .build(); } - public static CelExpr ofCreateStruct( + public static CelExpr ofStruct( long id, String messageName, ImmutableList entries) { return newBuilder() .setId(id) @@ -1063,7 +1090,7 @@ public static CelExpr ofCreateStruct( .build(); } - public static CelExpr ofCreateMap(long id, ImmutableList entries) { + public static CelExpr ofMap(long id, ImmutableList entries) { return newBuilder() .setId(id) .setExprKind( @@ -1071,7 +1098,7 @@ public static CelExpr ofCreateMap(long id, ImmutableList entries) .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) @@ -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) 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 cc7942415..994ea3210 100644 --- a/common/src/main/java/dev/cel/common/ast/CelExprConverter.java +++ b/common/src/main/java/dev/cel/common/ast/CelExprConverter.java @@ -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())); @@ -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 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.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()); } } diff --git a/common/src/main/java/dev/cel/common/ast/CelExprFactory.java b/common/src/main/java/dev/cel/common/ast/CelExprFactory.java index 6e8a08619..814efc82b 100644 --- a/common/src/main/java/dev/cel/common/ast/CelExprFactory.java +++ b/common/src/main/java/dev/cel/common/ast/CelExprFactory.java @@ -96,7 +96,7 @@ public final CelExpr newList(CelExpr... elements) { public final CelExpr newList(Iterable elements) { return CelExpr.newBuilder() .setId(nextExprId()) - .setCreateList(CelExpr.CelList.newBuilder().addElements(elements).build()) + .setList(CelExpr.CelList.newBuilder().addElements(elements).build()) .build(); } @@ -109,7 +109,7 @@ public final CelExpr newMap(CelExpr.CelMap.Entry... entries) { public final CelExpr newMap(Iterable entries) { return CelExpr.newBuilder() .setId(nextExprId()) - .setCreateMap(CelExpr.CelMap.newBuilder().addEntries(entries).build()) + .setMap(CelExpr.CelMap.newBuilder().addEntries(entries).build()) .build(); } @@ -132,7 +132,7 @@ public final CelExpr newMessage(String typeName, Iterable 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.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()); } } diff --git a/common/src/main/java/dev/cel/common/ast/CelExprVisitor.java b/common/src/main/java/dev/cel/common/ast/CelExprVisitor.java index e35b19aca..2dc1074eb 100644 --- a/common/src/main/java/dev/cel/common/ast/CelExprVisitor.java +++ b/common/src/main/java/dev/cel/common/ast/CelExprVisitor.java @@ -61,13 +61,13 @@ public void visit(CelExpr expr) { visit(expr, expr.call()); break; case LIST: - visit(expr, expr.createList()); + visit(expr, expr.list()); break; case STRUCT: - visit(expr, expr.createStruct()); + visit(expr, expr.struct()); break; case MAP: - visit(expr, expr.createMap()); + visit(expr, expr.map()); break; case COMPREHENSION: visit(expr, expr.comprehension()); diff --git a/common/src/main/java/dev/cel/common/ast/CelMutableExpr.java b/common/src/main/java/dev/cel/common/ast/CelMutableExpr.java index 1ea48d420..d267d7b8b 100644 --- a/common/src/main/java/dev/cel/common/ast/CelMutableExpr.java +++ b/common/src/main/java/dev/cel/common/ast/CelMutableExpr.java @@ -85,19 +85,19 @@ public CelMutableCall call() { } @Override - public CelMutableList createList() { + public CelMutableList list() { checkExprKind(Kind.LIST); return (CelMutableList) exprValue; } @Override - public CelMutableStruct createStruct() { + public CelMutableStruct struct() { checkExprKind(Kind.STRUCT); return (CelMutableStruct) exprValue; } @Override - public CelMutableMap createMap() { + public CelMutableMap map() { checkExprKind(Kind.MAP); return (CelMutableMap) exprValue; } @@ -128,19 +128,19 @@ public void setCall(CelMutableCall call) { this.exprValue = checkNotNull(call); } - public void setCreateList(CelMutableList createList) { + public void setList(CelMutableList list) { this.exprKind = ExprKind.Kind.LIST; - this.exprValue = checkNotNull(createList); + this.exprValue = checkNotNull(list); } - public void setCreateStruct(CelMutableStruct createStruct) { + public void setStruct(CelMutableStruct struct) { this.exprKind = ExprKind.Kind.STRUCT; - this.exprValue = checkNotNull(createStruct); + this.exprValue = checkNotNull(struct); } - public void setCreateMap(CelMutableMap createMap) { + public void setMap(CelMutableMap map) { this.exprKind = ExprKind.Kind.MAP; - this.exprValue = checkNotNull(createMap); + this.exprValue = checkNotNull(map); } public void setComprehension(CelMutableComprehension comprehension) { @@ -973,27 +973,27 @@ public static CelMutableExpr ofCall(long id, CelMutableCall mutableCall) { return new CelMutableExpr(id, mutableCall); } - public static CelMutableExpr ofCreateList(CelMutableList mutableCreateList) { - return ofCreateList(0, mutableCreateList); + public static CelMutableExpr ofList(CelMutableList mutableCreateList) { + return ofList(0, mutableCreateList); } - public static CelMutableExpr ofCreateList(long id, CelMutableList mutableCreateList) { + public static CelMutableExpr ofList(long id, CelMutableList mutableCreateList) { return new CelMutableExpr(id, mutableCreateList); } - public static CelMutableExpr ofCreateStruct(CelMutableStruct mutableCreateStruct) { - return ofCreateStruct(0, mutableCreateStruct); + public static CelMutableExpr ofStruct(CelMutableStruct mutableCreateStruct) { + return ofStruct(0, mutableCreateStruct); } - public static CelMutableExpr ofCreateStruct(long id, CelMutableStruct mutableCreateStruct) { + public static CelMutableExpr ofStruct(long id, CelMutableStruct mutableCreateStruct) { return new CelMutableExpr(id, mutableCreateStruct); } - public static CelMutableExpr ofCreateMap(CelMutableMap mutableCreateMap) { - return ofCreateMap(0, mutableCreateMap); + public static CelMutableExpr ofMap(CelMutableMap mutableCreateMap) { + return ofMap(0, mutableCreateMap); } - public static CelMutableExpr ofCreateMap(long id, CelMutableMap mutableCreateMap) { + public static CelMutableExpr ofMap(long id, CelMutableMap mutableCreateMap) { return new CelMutableExpr(id, mutableCreateMap); } @@ -1029,17 +1029,17 @@ private CelMutableExpr(long id, CelMutableCall mutableCall) { private CelMutableExpr(long id, CelMutableList mutableCreateList) { this.id = id; - setCreateList(mutableCreateList); + setList(mutableCreateList); } private CelMutableExpr(long id, CelMutableStruct mutableCreateStruct) { this.id = id; - setCreateStruct(mutableCreateStruct); + setStruct(mutableCreateStruct); } private CelMutableExpr(long id, CelMutableMap mutableCreateMap) { this.id = id; - setCreateMap(mutableCreateMap); + setMap(mutableCreateMap); } private CelMutableExpr(long id, CelMutableComprehension mutableComprehension) { @@ -1078,13 +1078,13 @@ private CelMutableExpr(CelMutableExpr other) { this.exprValue = other.call().deepCopy(); break; case LIST: - this.exprValue = other.createList().deepCopy(); + this.exprValue = other.list().deepCopy(); break; case STRUCT: - this.exprValue = other.createStruct().deepCopy(); + this.exprValue = other.struct().deepCopy(); break; case MAP: - this.exprValue = other.createMap().deepCopy(); + this.exprValue = other.map().deepCopy(); break; case COMPREHENSION: this.exprValue = other.comprehension().deepCopy(); @@ -1107,11 +1107,11 @@ private Object exprValue() { case CALL: return call(); case LIST: - return createList(); + return list(); case STRUCT: - return createStruct(); + return struct(); case MAP: - return createMap(); + return map(); case COMPREHENSION: return comprehension(); } 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 a7c51342d..57d4e9dc8 100644 --- a/common/src/main/java/dev/cel/common/ast/CelMutableExprConverter.java +++ b/common/src/main/java/dev/cel/common/ast/CelMutableExprConverter.java @@ -66,17 +66,16 @@ public static CelMutableExpr fromCelExpr(CelExpr celExpr) { return CelMutableExpr.ofCall(celExpr.id(), mutableCall); case LIST: - CelList createList = celExpr.createList(); - return CelMutableExpr.ofCreateList( + CelList createList = celExpr.list(); + return CelMutableExpr.ofList( celExpr.id(), CelMutableList.create( fromCelExprList(createList.elements()), createList.optionalIndices())); case STRUCT: - return CelMutableExpr.ofCreateStruct( - celExpr.id(), fromCelStructToMutableStruct(celExpr.createStruct())); + return CelMutableExpr.ofStruct( + celExpr.id(), fromCelStructToMutableStruct(celExpr.struct())); case MAP: - return CelMutableExpr.ofCreateMap( - celExpr.id(), fromCelMapToMutableMap(celExpr.createMap())); + return CelMutableExpr.ofMap(celExpr.id(), fromCelMapToMutableMap(celExpr.map())); case COMPREHENSION: CelComprehension celComprehension = celExprKind.comprehension(); CelMutableComprehension mutableComprehension = @@ -154,22 +153,22 @@ public static CelExpr fromMutableExpr(CelMutableExpr mutableExpr) { mutableCall.target().map(CelMutableExprConverter::fromMutableExpr); return CelExpr.ofCall(id, targetExpr, mutableCall.function(), args); case LIST: - CelMutableList mutableCreateList = mutableExpr.createList(); - return CelExpr.ofCreateList( + CelMutableList mutableCreateList = mutableExpr.list(); + return CelExpr.ofList( id, fromMutableExprList(mutableCreateList.elements()), ImmutableList.copyOf(mutableCreateList.optionalIndices())); case STRUCT: - CelMutableStruct mutableCreateStruct = mutableExpr.createStruct(); + CelMutableStruct mutableCreateStruct = mutableExpr.struct(); return CelExpr.newBuilder() .setId(id) - .setCreateStruct(fromMutableStructToCelStruct(mutableCreateStruct)) + .setStruct(fromMutableStructToCelStruct(mutableCreateStruct)) .build(); case MAP: - CelMutableMap mutableCreateMap = mutableExpr.createMap(); + CelMutableMap mutableCreateMap = mutableExpr.map(); return CelExpr.newBuilder() .setId(id) - .setCreateMap(fromMutableMapToCelMap(mutableCreateMap)) + .setMap(fromMutableMapToCelMap(mutableCreateMap)) .build(); case COMPREHENSION: CelMutableComprehension mutableComprehension = mutableExpr.comprehension(); @@ -202,7 +201,7 @@ private static CelStruct fromMutableStructToCelStruct(CelMutableStruct mutableCr List entries = new ArrayList<>(); for (CelMutableStruct.Entry mutableStructEntry : mutableCreateStruct.entries()) { entries.add( - CelExpr.ofCreateStructEntry( + CelExpr.ofStructEntry( mutableStructEntry.id(), mutableStructEntry.fieldKey(), fromMutableExpr(mutableStructEntry.value()), @@ -219,7 +218,7 @@ private static CelMap fromMutableMapToCelMap(CelMutableMap mutableCreateMap) { List entries = new ArrayList<>(); for (CelMutableMap.Entry mutableMapEntry : mutableCreateMap.entries()) { entries.add( - CelExpr.ofCreateMapEntry( + CelExpr.ofMapEntry( mutableMapEntry.id(), fromMutableExpr(mutableMapEntry.key()), fromMutableExpr(mutableMapEntry.value()), diff --git a/common/src/main/java/dev/cel/common/ast/Expression.java b/common/src/main/java/dev/cel/common/ast/Expression.java index 16852a15c..ed06af8b9 100644 --- a/common/src/main/java/dev/cel/common/ast/Expression.java +++ b/common/src/main/java/dev/cel/common/ast/Expression.java @@ -54,16 +54,16 @@ public interface Expression { Call call(); /** Gets the underlying identifier expression. */ - List createList(); + List list(); /** Gets the underlying select expression. */ Select select(); - /** Gets the underlying createStruct expression. */ - Struct> createStruct(); + /** Gets the underlying struct expression. */ + Struct> struct(); - /** Gets the underlying createMap expression. */ - Map> createMap(); + /** Gets the underlying map expression. */ + Map> map(); /** Gets the underlying comprehension expression. */ Comprehension comprehension(); diff --git a/common/src/main/java/dev/cel/common/navigation/CelNavigableExprVisitor.java b/common/src/main/java/dev/cel/common/navigation/CelNavigableExprVisitor.java index 41e9802a0..b59acdd13 100644 --- a/common/src/main/java/dev/cel/common/navigation/CelNavigableExprVisitor.java +++ b/common/src/main/java/dev/cel/common/navigation/CelNavigableExprVisitor.java @@ -106,16 +106,16 @@ private void visit(T navigableExpr) { visit(navigableExpr, navigableExpr.expr().call()); break; case LIST: - visit(navigableExpr, navigableExpr.expr().createList()); + visit(navigableExpr, navigableExpr.expr().list()); break; case SELECT: visit(navigableExpr, navigableExpr.expr().select()); break; case STRUCT: - visitStruct(navigableExpr, navigableExpr.expr().createStruct()); + visitStruct(navigableExpr, navigableExpr.expr().struct()); break; case MAP: - visitMap(navigableExpr, navigableExpr.expr().createMap()); + visitMap(navigableExpr, navigableExpr.expr().map()); break; case COMPREHENSION: visit(navigableExpr, navigableExpr.expr().comprehension()); diff --git a/common/src/main/java/dev/cel/common/navigation/ExprPropertyCalculator.java b/common/src/main/java/dev/cel/common/navigation/ExprPropertyCalculator.java index 7c59682f8..b35682ef3 100644 --- a/common/src/main/java/dev/cel/common/navigation/ExprPropertyCalculator.java +++ b/common/src/main/java/dev/cel/common/navigation/ExprPropertyCalculator.java @@ -55,16 +55,16 @@ private ExprProperty visit(E expr) { visitedProperty = visit(expr.call()); break; case LIST: - visitedProperty = visit(expr.createList()); + visitedProperty = visit(expr.list()); break; case SELECT: visitedProperty = visit(expr.select()); break; case STRUCT: - visitedProperty = visitStruct(expr.createStruct()); + visitedProperty = visitStruct(expr.struct()); break; case MAP: - visitedProperty = visitMap(expr.createMap()); + visitedProperty = visitMap(expr.map()); break; case COMPREHENSION: visitedProperty = visit(expr.comprehension()); 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 424031dd4..8cac69522 100644 --- a/common/src/test/java/dev/cel/common/ast/CelExprConverterTest.java +++ b/common/src/test/java/dev/cel/common/ast/CelExprConverterTest.java @@ -191,7 +191,7 @@ public void convertExprList_toCelList() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateList( + CelExpr.ofList( 1, ImmutableList.of( CelExpr.ofConstant(2, CelConstant.ofValue(10)), @@ -221,11 +221,11 @@ public void convertExprStructExpr_toCelStruct() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateStruct( + CelExpr.ofStruct( 1, "messageName", ImmutableList.of( - CelExpr.ofCreateStructEntry( + CelExpr.ofStructEntry( 2, "fieldKey", CelExpr.ofConstant(3, CelConstant.ofValue(10)), true)))); } @@ -299,10 +299,10 @@ public void convertExprStructExpr_toCelMap() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateMap( + CelExpr.ofMap( 1, ImmutableList.of( - CelExpr.ofCreateMapEntry( + CelExpr.ofMapEntry( 2, CelExpr.ofConstant(3, CelConstant.ofValue(15)), CelExpr.ofConstant(4, CelConstant.ofValue(10)), @@ -453,7 +453,7 @@ public void convertCelCall_toExprCall() { @Test public void convertCelList_toExprList() { CelExpr celExpr = - CelExpr.ofCreateList( + CelExpr.ofList( 1, ImmutableList.of( CelExpr.ofConstant(2, CelConstant.ofValue(10)), @@ -478,11 +478,11 @@ public void convertCelList_toExprList() { @Test public void convertCelStructExpr_toExprStruct_withFieldKey() { CelExpr celExpr = - CelExpr.ofCreateStruct( + CelExpr.ofStruct( 1, "messageName", ImmutableList.of( - CelExpr.ofCreateStructEntry( + CelExpr.ofStructEntry( 2, "fieldKey", CelExpr.ofConstant(3, CelConstant.ofValue(10)), true))); Expr expr = CelExprConverter.fromCelExpr(celExpr); @@ -508,10 +508,10 @@ public void convertCelStructExpr_toExprStruct_withFieldKey() { @Test public void convertCelMapExpr_toExprStruct() { CelExpr celExpr = - CelExpr.ofCreateMap( + CelExpr.ofMap( 1, ImmutableList.of( - CelExpr.ofCreateMapEntry( + CelExpr.ofMapEntry( 2, CelExpr.ofConstant(3, CelConstant.ofValue(15)), CelExpr.ofConstant(4, CelConstant.ofValue(10)), 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 5df979e41..ec4cceeab 100644 --- a/common/src/test/java/dev/cel/common/ast/CelExprTest.java +++ b/common/src/test/java/dev/cel/common/ast/CelExprTest.java @@ -66,11 +66,10 @@ private enum BuilderExprKindTestCase { .build()) .build(), Kind.SELECT), - CREATE_MAP(CelExpr.newBuilder().setCreateMap(CelMap.newBuilder().build()).build(), Kind.MAP), - CREATE_LIST( - CelExpr.newBuilder().setCreateList(CelList.newBuilder().build()).build(), Kind.LIST), + CREATE_MAP(CelExpr.newBuilder().setMap(CelMap.newBuilder().build()).build(), Kind.MAP), + CREATE_LIST(CelExpr.newBuilder().setList(CelList.newBuilder().build()).build(), Kind.LIST), CREATE_STRUCT( - CelExpr.newBuilder().setCreateStruct(CelStruct.newBuilder().build()).build(), Kind.STRUCT), + CelExpr.newBuilder().setStruct(CelStruct.newBuilder().build()).build(), Kind.STRUCT), COMPREHENSION( CelExpr.newBuilder() .setComprehension( @@ -202,10 +201,10 @@ public void celExprBuilder_setSelect() { public void celExprBuilder_setCreateList() { CelList celCreateList = CelList.newBuilder().addElements(CelExpr.ofConstant(1, CelConstant.ofValue(2))).build(); - CelExpr celExpr = CelExpr.newBuilder().setCreateList(celCreateList).build(); + CelExpr celExpr = CelExpr.newBuilder().setList(celCreateList).build(); - assertThat(celExpr.createList()).isEqualTo(celCreateList); - assertThat(celExpr.toBuilder().createList()).isEqualTo(celCreateList); + assertThat(celExpr.list()).isEqualTo(celCreateList); + assertThat(celExpr.toBuilder().list()).isEqualTo(celCreateList); } @Test @@ -228,13 +227,13 @@ public void celExprBuilder_setCreateList_setElementByIndex() { CelExpr celExpr = CelExpr.newBuilder() - .setCreateList( + .setList( celCreateList.toBuilder() .setElement(1, CelExpr.ofConstant(7, CelConstant.ofValue("world"))) .build()) .build(); - assertThat(celExpr.createList()) + assertThat(celExpr.list()) .isEqualTo( CelList.newBuilder() .addElements( @@ -254,11 +253,11 @@ public void celExprBuilder_setCreateStruct() { .setFieldKey("field_key") .build()) .build(); - CelExpr celExpr = CelExpr.newBuilder().setCreateStruct(celCreateStruct).build(); + CelExpr celExpr = CelExpr.newBuilder().setStruct(celCreateStruct).build(); - assertThat(celExpr.createStruct().entries().get(0).optionalEntry()).isFalse(); - assertThat(celExpr.createStruct()).isEqualTo(celCreateStruct); - assertThat(celExpr.toBuilder().createStruct()).isEqualTo(celCreateStruct); + assertThat(celExpr.struct().entries().get(0).optionalEntry()).isFalse(); + assertThat(celExpr.struct()).isEqualTo(celCreateStruct); + assertThat(celExpr.toBuilder().struct()).isEqualTo(celCreateStruct); } @Test @@ -302,7 +301,7 @@ public void celExprBuilder_setCreateStruct_setEntryByIndex() { CelExpr celExpr = CelExpr.newBuilder() - .setCreateStruct( + .setStruct( celCreateStruct.toBuilder() .setEntry( 1, @@ -316,7 +315,7 @@ public void celExprBuilder_setCreateStruct_setEntryByIndex() { .build()) .build(); - assertThat(celExpr.createStruct()) + assertThat(celExpr.struct()) .isEqualTo( CelStruct.newBuilder() .addEntries( @@ -378,19 +377,16 @@ public void getUnderlyingExpression_unmatchedKind_throws( assertThrows(UnsupportedOperationException.class, () -> testCase.expr.toBuilder().call()); } if (!testCase.expectedExprKind.equals(Kind.LIST)) { - assertThrows(UnsupportedOperationException.class, testCase.expr::createList); - assertThrows( - UnsupportedOperationException.class, () -> testCase.expr.toBuilder().createList()); + assertThrows(UnsupportedOperationException.class, testCase.expr::list); + assertThrows(UnsupportedOperationException.class, () -> testCase.expr.toBuilder().list()); } if (!testCase.expectedExprKind.equals(Kind.STRUCT)) { - assertThrows(UnsupportedOperationException.class, testCase.expr::createStruct); - assertThrows( - UnsupportedOperationException.class, () -> testCase.expr.toBuilder().createStruct()); + assertThrows(UnsupportedOperationException.class, testCase.expr::struct); + assertThrows(UnsupportedOperationException.class, () -> testCase.expr.toBuilder().struct()); } if (!testCase.expectedExprKind.equals(Kind.MAP)) { - assertThrows(UnsupportedOperationException.class, testCase.expr::createMap); - assertThrows( - UnsupportedOperationException.class, () -> testCase.expr.toBuilder().createMap()); + assertThrows(UnsupportedOperationException.class, testCase.expr::map); + assertThrows(UnsupportedOperationException.class, () -> testCase.expr.toBuilder().map()); } if (!testCase.expectedExprKind.equals(Kind.COMPREHENSION)) { assertThrows(UnsupportedOperationException.class, testCase.expr::comprehension); @@ -415,13 +411,13 @@ public void getDefault_unmatchedKind_returnsDefaultInstance( assertThat(testCase.expr.callOrDefault()).isEqualTo(CelCall.newBuilder().build()); } if (!testCase.expectedExprKind.equals(Kind.LIST)) { - assertThat(testCase.expr.createListOrDefault()).isEqualTo(CelList.newBuilder().build()); + assertThat(testCase.expr.listOrDefault()).isEqualTo(CelList.newBuilder().build()); } if (!testCase.expectedExprKind.equals(Kind.STRUCT)) { - assertThat(testCase.expr.createStructOrDefault()).isEqualTo(CelStruct.newBuilder().build()); + assertThat(testCase.expr.structOrDefault()).isEqualTo(CelStruct.newBuilder().build()); } if (!testCase.expectedExprKind.equals(Kind.MAP)) { - assertThat(testCase.expr.createMapOrDefault()).isEqualTo(CelMap.newBuilder().build()); + assertThat(testCase.expr.mapOrDefault()).isEqualTo(CelMap.newBuilder().build()); } if (!testCase.expectedExprKind.equals(Kind.COMPREHENSION)) { assertThat(testCase.expr.comprehensionOrDefault()) @@ -449,13 +445,13 @@ public void getDefault_matchedKind_returnsUnderlyingExpression( assertThat(testCase.expr.callOrDefault()).isEqualTo(testCase.expr.call()); break; case LIST: - assertThat(testCase.expr.createListOrDefault()).isEqualTo(testCase.expr.createList()); + assertThat(testCase.expr.listOrDefault()).isEqualTo(testCase.expr.list()); break; case STRUCT: - assertThat(testCase.expr.createStructOrDefault()).isEqualTo(testCase.expr.createStruct()); + assertThat(testCase.expr.structOrDefault()).isEqualTo(testCase.expr.struct()); break; case MAP: - assertThat(testCase.expr.createMapOrDefault()).isEqualTo(testCase.expr.createMap()); + assertThat(testCase.expr.mapOrDefault()).isEqualTo(testCase.expr.map()); break; case COMPREHENSION: assertThat(testCase.expr.comprehensionOrDefault()).isEqualTo(testCase.expr.comprehension()); 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 8a5461a11..28df2285d 100644 --- a/common/src/test/java/dev/cel/common/ast/CelExprV1Alpha1ConverterTest.java +++ b/common/src/test/java/dev/cel/common/ast/CelExprV1Alpha1ConverterTest.java @@ -191,7 +191,7 @@ public void convertExprList_toCelList() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateList( + CelExpr.ofList( 1, ImmutableList.of( CelExpr.ofConstant(2, CelConstant.ofValue(10)), @@ -221,11 +221,11 @@ public void convertExprStructExpr_toCelStruct() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateStruct( + CelExpr.ofStruct( 1, "messageName", ImmutableList.of( - CelExpr.ofCreateStructEntry( + CelExpr.ofStructEntry( 2, "fieldKey", CelExpr.ofConstant(3, CelConstant.ofValue(10)), true)))); } @@ -299,10 +299,10 @@ public void convertExprStructExpr_toCelMap() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateMap( + CelExpr.ofMap( 1, ImmutableList.of( - CelExpr.ofCreateMapEntry( + CelExpr.ofMapEntry( 2, CelExpr.ofConstant(3, CelConstant.ofValue(15)), CelExpr.ofConstant(4, CelConstant.ofValue(10)), @@ -453,7 +453,7 @@ public void convertCelCall_toExprCall() { @Test public void convertCelList_toExprList() { CelExpr celExpr = - CelExpr.ofCreateList( + CelExpr.ofList( 1, ImmutableList.of( CelExpr.ofConstant(2, CelConstant.ofValue(10)), @@ -478,11 +478,11 @@ public void convertCelList_toExprList() { @Test public void convertCelStructExpr_toExprStruct_withFieldKey() { CelExpr celExpr = - CelExpr.ofCreateStruct( + CelExpr.ofStruct( 1, "messageName", ImmutableList.of( - CelExpr.ofCreateStructEntry( + CelExpr.ofStructEntry( 2, "fieldKey", CelExpr.ofConstant(3, CelConstant.ofValue(10)), true))); Expr expr = CelExprV1Alpha1Converter.fromCelExpr(celExpr); @@ -508,10 +508,10 @@ public void convertCelStructExpr_toExprStruct_withFieldKey() { @Test public void convertCelMapExpr_toExprStruct() { CelExpr celExpr = - CelExpr.ofCreateMap( + CelExpr.ofMap( 1, ImmutableList.of( - CelExpr.ofCreateMapEntry( + CelExpr.ofMapEntry( 2, CelExpr.ofConstant(3, CelConstant.ofValue(15)), CelExpr.ofConstant(4, CelConstant.ofValue(10)), 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 cec7fa4fa..2ba8da806 100644 --- a/common/src/test/java/dev/cel/common/ast/CelExprVisitorTest.java +++ b/common/src/test/java/dev/cel/common/ast/CelExprVisitorTest.java @@ -53,11 +53,11 @@ public abstract static class VisitedReference { public abstract Optional call(); - public abstract Optional createStruct(); + public abstract Optional struct(); - public abstract Optional createMap(); + public abstract Optional map(); - public abstract Optional createList(); + public abstract Optional list(); public abstract Optional comprehension(); @@ -73,11 +73,11 @@ public abstract static class Builder { public abstract Builder setCall(CelCall value); - public abstract Builder setCreateStruct(CelStruct value); + public abstract Builder setStruct(CelStruct value); - public abstract Builder setCreateMap(CelMap value); + public abstract Builder setMap(CelMap value); - public abstract Builder setCreateList(CelList value); + public abstract Builder setList(CelList value); public abstract Builder setComprehension(CelComprehension value); @@ -125,19 +125,19 @@ protected void visit(CelExpr expr, CelCall call) { @Override protected void visit(CelExpr expr, CelStruct createStruct) { - visitedReference.setCreateStruct(createStruct); + visitedReference.setStruct(createStruct); super.visit(expr, createStruct); } @Override protected void visit(CelExpr expr, CelMap createMap) { - visitedReference.setCreateMap(createMap); + visitedReference.setMap(createMap); super.visit(expr, createMap); } @Override protected void visit(CelExpr expr, CelList createList) { - visitedReference.setCreateList(createList); + visitedReference.setList(createList); super.visit(expr, createList); } @@ -204,13 +204,13 @@ public void visitSelect() throws Exception { assertThat(visited) .isEqualTo( VisitedReference.newBuilder() - .setCreateStruct(CelStruct.newBuilder().setMessageName("TestAllTypes").build()) + .setStruct(CelStruct.newBuilder().setMessageName("TestAllTypes").build()) .setSelect( CelSelect.newBuilder() .setOperand( CelExpr.newBuilder() .setId(1) - .setCreateStruct( + .setStruct( CelStruct.newBuilder().setMessageName("TestAllTypes").build()) .build()) .setField("single_int64") @@ -242,7 +242,7 @@ public void visitCall() throws Exception { } @Test - public void visitCreateStruct_fieldkey() throws Exception { + public void visitStruct_fieldkey() throws Exception { CelCompiler celCompiler = CelCompilerFactory.standardCelCompilerBuilder() .addMessageTypes(TestAllTypes.getDescriptor()) @@ -258,7 +258,7 @@ public void visitCreateStruct_fieldkey() throws Exception { .isEqualTo( VisitedReference.newBuilder() .setConstant(longConstant) - .setCreateStruct( + .setStruct( CelStruct.newBuilder() .addEntries( Entry.newBuilder() @@ -272,7 +272,7 @@ public void visitCreateStruct_fieldkey() throws Exception { } @Test - public void visitCreateMap() throws Exception { + public void visitMap() throws Exception { CelCompiler celCompiler = CelCompilerFactory.standardCelCompilerBuilder().build(); CelAbstractSyntaxTree ast = celCompiler.compile("{'a': 'b'}").getAst(); @@ -283,7 +283,7 @@ public void visitCreateMap() throws Exception { .isEqualTo( VisitedReference.newBuilder() .setConstant(CelConstant.ofValue("b")) - .setCreateMap( + .setMap( CelMap.newBuilder() .addEntries( CelMap.Entry.newBuilder() @@ -296,7 +296,7 @@ public void visitCreateMap() throws Exception { } @Test - public void visitCreateList() throws Exception { + public void visitList() throws Exception { CelCompiler celCompiler = CelCompilerFactory.standardCelCompilerBuilder().build(); CelAbstractSyntaxTree ast = celCompiler.compile("[1, 1]").getAst(); @@ -308,7 +308,7 @@ public void visitCreateList() throws Exception { .isEqualTo( VisitedReference.newBuilder() .setConstant(integerVal) - .setCreateList( + .setList( CelList.newBuilder() .addElements(CelExpr.newBuilder().setId(2).setConstant(integerVal).build()) .addElements(CelExpr.newBuilder().setId(3).setConstant(integerVal).build()) @@ -334,14 +334,14 @@ public void visitComprehension() throws Exception { CelExpr.ofConstant(3, CelConstant.ofValue(1))); assertThat(comprehension.iterVar()).isEqualTo("x"); - assertThat(comprehension.iterRange().createList().elements()).isEqualTo(iterRangeElements); + assertThat(comprehension.iterRange().list().elements()).isEqualTo(iterRangeElements); assertThat(comprehension.accuInit().constant()).isEqualTo(CelConstant.ofValue(true)); assertThat(comprehension.loopCondition().call().function()) .isEqualTo(Operator.NOT_STRICTLY_FALSE.getFunction()); assertThat(comprehension.loopStep().call().function()) .isEqualTo(Operator.LOGICAL_AND.getFunction()); assertThat(comprehension.loopStep().call().args()).hasSize(2); - assertThat(visitedReference.createList().get().elements()).isEqualTo(iterRangeElements); + assertThat(visitedReference.list().get().elements()).isEqualTo(iterRangeElements); assertThat(visitedReference.identifier()) .hasValue(CelIdent.newBuilder().setName("__result__").build()); assertThat(visitedReference.arguments()).hasSize(10); 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 927c10243..9fb2140a0 100644 --- a/common/src/test/java/dev/cel/common/ast/CelMutableExprConverterTest.java +++ b/common/src/test/java/dev/cel/common/ast/CelMutableExprConverterTest.java @@ -201,7 +201,7 @@ public void convertCelCall_toMutableCall() { @Test public void convertMutableCreateList_toCelList() { CelMutableExpr mutableExpr = - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( 1L, CelMutableList.create( ImmutableList.of( @@ -213,7 +213,7 @@ public void convertMutableCreateList_toCelList() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateList( + CelExpr.ofList( 1L, ImmutableList.of( CelExpr.ofConstant(2L, CelConstant.ofValue("element1")), @@ -224,7 +224,7 @@ public void convertMutableCreateList_toCelList() { @Test public void convertCelList_toMutableCreateList() { CelExpr celExpr = - CelExpr.ofCreateList( + CelExpr.ofList( 1L, ImmutableList.of( CelExpr.ofConstant(2L, CelConstant.ofValue("element1")), @@ -235,7 +235,7 @@ public void convertCelList_toMutableCreateList() { assertThat(mutableExpr) .isEqualTo( - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( 1L, CelMutableList.create( ImmutableList.of( @@ -247,7 +247,7 @@ public void convertCelList_toMutableCreateList() { @Test public void convertMutableCreateStruct_toCelStruct() { CelMutableExpr mutableExpr = - CelMutableExpr.ofCreateStruct( + CelMutableExpr.ofStruct( 8L, CelMutableStruct.create( "message", @@ -262,7 +262,7 @@ public void convertMutableCreateStruct_toCelStruct() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateStruct( + CelExpr.ofStruct( 8L, "message", ImmutableList.of( @@ -277,7 +277,7 @@ public void convertMutableCreateStruct_toCelStruct() { @Test public void convertCelStruct_toMutableCreateStruct() { CelExpr celExpr = - CelExpr.ofCreateStruct( + CelExpr.ofStruct( 8L, "message", ImmutableList.of( @@ -292,7 +292,7 @@ public void convertCelStruct_toMutableCreateStruct() { assertThat(mutableExpr) .isEqualTo( - CelMutableExpr.ofCreateStruct( + CelMutableExpr.ofStruct( 8L, CelMutableStruct.create( "message", @@ -307,7 +307,7 @@ public void convertCelStruct_toMutableCreateStruct() { @Test public void convertMutableCreateMap_toCelMap() { CelMutableExpr mutableExpr = - CelMutableExpr.ofCreateMap( + CelMutableExpr.ofMap( 9L, CelMutableMap.create( ImmutableList.of( @@ -321,10 +321,10 @@ public void convertMutableCreateMap_toCelMap() { assertThat(celExpr) .isEqualTo( - CelExpr.ofCreateMap( + CelExpr.ofMap( 9L, ImmutableList.of( - CelExpr.ofCreateMapEntry( + CelExpr.ofMapEntry( 10L, CelExpr.ofConstant(11L, CelConstant.ofValue("key")), CelExpr.ofConstant(12L, CelConstant.ofValue("value")), @@ -334,10 +334,10 @@ public void convertMutableCreateMap_toCelMap() { @Test public void convertCelMap_toMutableCreateMap() { CelExpr celExpr = - CelExpr.ofCreateMap( + CelExpr.ofMap( 9L, ImmutableList.of( - CelExpr.ofCreateMapEntry( + CelExpr.ofMapEntry( 10L, CelExpr.ofConstant(11L, CelConstant.ofValue("key")), CelExpr.ofConstant(12L, CelConstant.ofValue("value")), @@ -347,7 +347,7 @@ public void convertCelMap_toMutableCreateMap() { assertThat(mutableExpr) .isEqualTo( - CelMutableExpr.ofCreateMap( + CelMutableExpr.ofMap( 9L, CelMutableMap.create( ImmutableList.of( @@ -365,7 +365,7 @@ public void convertMutableComprehension_toCelComprehension() { 1L, CelMutableComprehension.create( "iterVar", - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( 2L, CelMutableList.create( CelMutableExpr.ofConstant(3L, CelConstant.ofValue(true)))), @@ -384,7 +384,7 @@ public void convertMutableComprehension_toCelComprehension() { "iterVar", CelExpr.newBuilder() .setId(2L) - .setCreateList( + .setList( CelList.newBuilder() .addElements(CelExpr.ofConstant(3L, CelConstant.ofValue(true))) .build()) @@ -404,7 +404,7 @@ public void convertCelComprehension_toMutableComprehension() { "iterVar", CelExpr.newBuilder() .setId(2L) - .setCreateList( + .setList( CelList.newBuilder() .addElements(CelExpr.ofConstant(3L, CelConstant.ofValue(true))) .build()) @@ -423,7 +423,7 @@ public void convertCelComprehension_toMutableComprehension() { 1L, CelMutableComprehension.create( "iterVar", - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( 2L, CelMutableList.create( CelMutableExpr.ofConstant(3L, CelConstant.ofValue(true)))), diff --git a/common/src/test/java/dev/cel/common/ast/CelMutableExprTest.java b/common/src/test/java/dev/cel/common/ast/CelMutableExprTest.java index 620fe2e8b..906c3dab8 100644 --- a/common/src/test/java/dev/cel/common/ast/CelMutableExprTest.java +++ b/common/src/test/java/dev/cel/common/ast/CelMutableExprTest.java @@ -314,26 +314,26 @@ public void mutableCall_setFunction() { } @Test - public void ofCreateList() { + public void ofList() { CelMutableExpr mutableExpr = - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create( CelMutableExpr.ofConstant(CelConstant.ofValue("element1")), CelMutableExpr.ofConstant(CelConstant.ofValue("element2")))); assertThat(mutableExpr.id()).isEqualTo(0L); - assertThat(mutableExpr.createList().elements()) + assertThat(mutableExpr.list().elements()) .containsExactly( CelMutableExpr.ofConstant(CelConstant.ofValue("element1")), CelMutableExpr.ofConstant(CelConstant.ofValue("element2"))) .inOrder(); - assertThat(mutableExpr.createList().optionalIndices()).isEmpty(); + assertThat(mutableExpr.list().optionalIndices()).isEmpty(); } @Test - public void ofCreateList_withId() { + public void ofList_withId() { CelMutableExpr mutableExpr = - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( 1L, CelMutableList.create( ImmutableList.of( @@ -342,12 +342,12 @@ public void ofCreateList_withId() { ImmutableList.of(0, 1))); assertThat(mutableExpr.id()).isEqualTo(1L); - assertThat(mutableExpr.createList().elements()) + assertThat(mutableExpr.list().elements()) .containsExactly( CelMutableExpr.ofConstant(CelConstant.ofValue("element1")), CelMutableExpr.ofConstant(CelConstant.ofValue("element2"))) .inOrder(); - assertThat(mutableExpr.createList().optionalIndices()).containsExactly(0, 1).inOrder(); + assertThat(mutableExpr.list().optionalIndices()).containsExactly(0, 1).inOrder(); } @Test @@ -366,7 +366,7 @@ public void mutableCreateList_setElementAtIndex() { @SuppressWarnings("ReferenceEquality") // test only on iterating through elements public void mutableCreateList_deepCopy() { CelMutableExpr mutableExpr = - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create( CelMutableExpr.ofConstant(CelConstant.ofValue("element1")), CelMutableExpr.ofConstant(CelConstant.ofValue("element2")))); @@ -374,31 +374,31 @@ public void mutableCreateList_deepCopy() { CelMutableExpr deepCopiedExpr = CelMutableExpr.newInstance(mutableExpr); assertThat(mutableExpr).isEqualTo(deepCopiedExpr); - assertThat(mutableExpr.createList()).isEqualTo(deepCopiedExpr.createList()); + assertThat(mutableExpr.list()).isEqualTo(deepCopiedExpr.list()); assertThat(mutableExpr).isNotSameInstanceAs(deepCopiedExpr); - assertThat(mutableExpr.createList()).isNotSameInstanceAs(deepCopiedExpr.createList()); - assertThat(mutableExpr.createList().elements()) + assertThat(mutableExpr.list()).isNotSameInstanceAs(deepCopiedExpr.list()); + assertThat(mutableExpr.list().elements()) .comparingElementsUsing( Correspondence.from( (e1, e2) -> e1 != e2 && e1.equals(e2), "are only value equal and not referentially equal")) - .containsExactlyElementsIn(deepCopiedExpr.createList().elements()); + .containsExactlyElementsIn(deepCopiedExpr.list().elements()); } @Test - public void ofCreateStruct() { + public void ofStruct() { CelMutableExpr mutableExpr = - CelMutableExpr.ofCreateStruct(CelMutableStruct.create("message", ImmutableList.of())); + CelMutableExpr.ofStruct(CelMutableStruct.create("message", ImmutableList.of())); assertThat(mutableExpr.id()).isEqualTo(0L); - assertThat(mutableExpr.createStruct().messageName()).isEqualTo("message"); - assertThat(mutableExpr.createStruct().entries()).isEmpty(); + assertThat(mutableExpr.struct().messageName()).isEqualTo("message"); + assertThat(mutableExpr.struct().entries()).isEmpty(); } @Test - public void ofCreateStruct_withId() { + public void ofStruct_withId() { CelMutableExpr mutableExpr = - CelMutableExpr.ofCreateStruct( + CelMutableExpr.ofStruct( 8L, CelMutableStruct.create( "message", @@ -410,8 +410,8 @@ public void ofCreateStruct_withId() { /* optionalEntry= */ true)))); assertThat(mutableExpr.id()).isEqualTo(8L); - assertThat(mutableExpr.createStruct().messageName()).isEqualTo("message"); - assertThat(mutableExpr.createStruct().entries()) + assertThat(mutableExpr.struct().messageName()).isEqualTo("message"); + assertThat(mutableExpr.struct().entries()) .containsExactly( CelMutableStruct.Entry.create( 9L, @@ -461,7 +461,7 @@ public void mutableCreateStructEntry_setters() { @SuppressWarnings("ReferenceEquality") // test only on iterating through elements public void mutableCreateStruct_deepCopy() { CelMutableExpr mutableExpr = - CelMutableExpr.ofCreateStruct( + CelMutableExpr.ofStruct( 8L, CelMutableStruct.create( "message", @@ -475,12 +475,12 @@ public void mutableCreateStruct_deepCopy() { CelMutableExpr deepCopiedExpr = CelMutableExpr.newInstance(mutableExpr); assertThat(mutableExpr).isEqualTo(deepCopiedExpr); - assertThat(mutableExpr.createStruct()).isEqualTo(deepCopiedExpr.createStruct()); + assertThat(mutableExpr.struct()).isEqualTo(deepCopiedExpr.struct()); assertThat(mutableExpr).isNotSameInstanceAs(deepCopiedExpr); - assertThat(mutableExpr.createStruct()).isNotSameInstanceAs(deepCopiedExpr.createStruct()); - assertThat(mutableExpr.createStruct().entries()) - .isNotSameInstanceAs(deepCopiedExpr.createStruct().entries()); - assertThat(mutableExpr.createStruct().entries()) + assertThat(mutableExpr.struct()).isNotSameInstanceAs(deepCopiedExpr.struct()); + assertThat(mutableExpr.struct().entries()) + .isNotSameInstanceAs(deepCopiedExpr.struct().entries()); + assertThat(mutableExpr.struct().entries()) .comparingElementsUsing( Correspondence.from( (e1, e2) -> @@ -489,22 +489,21 @@ public void mutableCreateStruct_deepCopy() { && e1.value() != e2.value() && e1.value().equals(e2.value()), "are only value equal and not referentially equal")) - .containsExactlyElementsIn(deepCopiedExpr.createStruct().entries()); + .containsExactlyElementsIn(deepCopiedExpr.struct().entries()); } @Test - public void ofCreateMap() { - CelMutableExpr mutableExpr = - CelMutableExpr.ofCreateMap(CelMutableMap.create(ImmutableList.of())); + public void ofMap() { + CelMutableExpr mutableExpr = CelMutableExpr.ofMap(CelMutableMap.create(ImmutableList.of())); assertThat(mutableExpr.id()).isEqualTo(0L); - assertThat(mutableExpr.createMap().entries()).isEmpty(); + assertThat(mutableExpr.map().entries()).isEmpty(); } @Test - public void ofCreateMap_withId() { + public void ofMap_withId() { CelMutableExpr mutableExpr = - CelMutableExpr.ofCreateMap( + CelMutableExpr.ofMap( 9L, CelMutableMap.create( ImmutableList.of( @@ -515,7 +514,7 @@ public void ofCreateMap_withId() { /* optionalEntry= */ true)))); assertThat(mutableExpr.id()).isEqualTo(9L); - assertThat(mutableExpr.createMap().entries()) + assertThat(mutableExpr.map().entries()) .containsExactly( CelMutableMap.Entry.create( 10L, @@ -571,7 +570,7 @@ public void mutableCreateMapEntry_setters() { @SuppressWarnings("ReferenceEquality") // test only on iterating through elements public void mutableCreateMap_deepCopy() { CelMutableExpr mutableExpr = - CelMutableExpr.ofCreateMap( + CelMutableExpr.ofMap( 9L, CelMutableMap.create( ImmutableList.of( @@ -584,10 +583,10 @@ public void mutableCreateMap_deepCopy() { CelMutableExpr deepCopiedExpr = CelMutableExpr.newInstance(mutableExpr); assertThat(mutableExpr).isEqualTo(deepCopiedExpr); - assertThat(mutableExpr.createMap()).isEqualTo(deepCopiedExpr.createMap()); + assertThat(mutableExpr.map()).isEqualTo(deepCopiedExpr.map()); assertThat(mutableExpr).isNotSameInstanceAs(deepCopiedExpr); - assertThat(mutableExpr.createMap()).isNotSameInstanceAs(deepCopiedExpr.createMap()); - assertThat(mutableExpr.createMap().entries()) + assertThat(mutableExpr.map()).isNotSameInstanceAs(deepCopiedExpr.map()); + assertThat(mutableExpr.map().entries()) .comparingElementsUsing( Correspondence.from( (e1, e2) -> @@ -598,7 +597,7 @@ public void mutableCreateMap_deepCopy() { && e1.value() != e2.value() && e1.value().equals(e2.value()), "are only value equal and not referentially equal")) - .containsExactlyElementsIn(deepCopiedExpr.createMap().entries()); + .containsExactlyElementsIn(deepCopiedExpr.map().entries()); } @Test @@ -608,7 +607,7 @@ public void ofComprehension_withId() { 10L, CelMutableComprehension.create( "iterVar", - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create(CelMutableExpr.ofConstant(CelConstant.ofValue(true)))), "accuVar", CelMutableExpr.ofConstant(CelConstant.ofValue(true)), @@ -621,7 +620,7 @@ public void ofComprehension_withId() { .isEqualTo( CelMutableComprehension.create( "iterVar", - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create(CelMutableExpr.ofConstant(CelConstant.ofValue(true)))), "accuVar", CelMutableExpr.ofConstant(CelConstant.ofValue(true)), @@ -645,7 +644,7 @@ public void mutableComprehension_setters() { mutableComprehension.setIterVar("iterVar2"); mutableComprehension.setAccuVar("accuVar2"); mutableComprehension.setIterRange( - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create(CelMutableExpr.ofConstant(CelConstant.ofValue(true))))); mutableComprehension.setAccuInit(CelMutableExpr.ofConstant(CelConstant.ofValue(true))); mutableComprehension.setLoopCondition(CelMutableExpr.ofConstant(CelConstant.ofValue(true))); @@ -656,7 +655,7 @@ public void mutableComprehension_setters() { .isEqualTo( CelMutableComprehension.create( "iterVar2", - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create(CelMutableExpr.ofConstant(CelConstant.ofValue(true)))), "accuVar2", CelMutableExpr.ofConstant(CelConstant.ofValue(true)), @@ -672,7 +671,7 @@ public void mutableComprehension_deepCopy() { 10L, CelMutableComprehension.create( "iterVar", - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create(CelMutableExpr.ofConstant(CelConstant.ofValue(true)))), "accuVar", CelMutableExpr.ofConstant(CelConstant.ofValue(true)), @@ -740,22 +739,22 @@ public void equalityTest() { CelMutableExpr.ofConstant(CelConstant.ofValue("target")), "function", CelMutableExpr.ofConstant(CelConstant.ofValue("arg"))))) - .addEqualityGroup(CelMutableExpr.ofCreateList(CelMutableList.create())) + .addEqualityGroup(CelMutableExpr.ofList(CelMutableList.create())) .addEqualityGroup( - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( 6L, CelMutableList.create( CelMutableExpr.ofConstant(CelConstant.ofValue("element1")), CelMutableExpr.ofConstant(CelConstant.ofValue("element2")))), - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( 6L, CelMutableList.create( CelMutableExpr.ofConstant(CelConstant.ofValue("element1")), CelMutableExpr.ofConstant(CelConstant.ofValue("element2"))))) .addEqualityGroup( - CelMutableExpr.ofCreateStruct(CelMutableStruct.create("message", ImmutableList.of()))) + CelMutableExpr.ofStruct(CelMutableStruct.create("message", ImmutableList.of()))) .addEqualityGroup( - CelMutableExpr.ofCreateStruct( + CelMutableExpr.ofStruct( 7L, CelMutableStruct.create( "message", @@ -765,7 +764,7 @@ public void equalityTest() { "field", CelMutableExpr.ofConstant(CelConstant.ofValue("value")), /* optionalEntry= */ true)))), - CelMutableExpr.ofCreateStruct( + CelMutableExpr.ofStruct( 7L, CelMutableStruct.create( "message", @@ -775,7 +774,7 @@ public void equalityTest() { "field", CelMutableExpr.ofConstant(CelConstant.ofValue("value")), /* optionalEntry= */ true))))) - .addEqualityGroup(CelMutableExpr.ofCreateMap(CelMutableMap.create(ImmutableList.of()))) + .addEqualityGroup(CelMutableExpr.ofMap(CelMutableMap.create(ImmutableList.of()))) .addEqualityGroup( CelMutableMap.create( ImmutableList.of( @@ -807,7 +806,7 @@ public void equalityTest() { 11L, CelMutableComprehension.create( "iterVar", - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create( CelMutableExpr.ofConstant(CelConstant.ofValue(true)))), "accuVar", @@ -819,7 +818,7 @@ public void equalityTest() { 11L, CelMutableComprehension.create( "iterVar", - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create( CelMutableExpr.ofConstant(CelConstant.ofValue(true)))), "accuVar", @@ -837,10 +836,9 @@ private enum MutableExprKindTestCase { IDENT(CelMutableExpr.ofIdent("test")), SELECT(CelMutableExpr.ofSelect(CelMutableSelect.create(CelMutableExpr.ofNotSet(), "field"))), CALL(CelMutableExpr.ofCall(CelMutableCall.create("call"))), - CREATE_LIST(CelMutableExpr.ofCreateList(CelMutableList.create())), - CREATE_STRUCT( - CelMutableExpr.ofCreateStruct(CelMutableStruct.create("message", ImmutableList.of()))), - CREATE_MAP(CelMutableExpr.ofCreateMap(CelMutableMap.create(ImmutableList.of()))), + CREATE_LIST(CelMutableExpr.ofList(CelMutableList.create())), + CREATE_STRUCT(CelMutableExpr.ofStruct(CelMutableStruct.create("message", ImmutableList.of()))), + CREATE_MAP(CelMutableExpr.ofMap(CelMutableMap.create(ImmutableList.of()))), COMPREHENSION( CelMutableExpr.ofComprehension( 10L, @@ -880,13 +878,13 @@ public void getExprValue_invalidKind_throws(@TestParameter MutableExprKindTestCa assertThrows(IllegalArgumentException.class, testCase.mutableExpr::call); } if (!testCaseKind.equals(Kind.LIST)) { - assertThrows(IllegalArgumentException.class, testCase.mutableExpr::createList); + assertThrows(IllegalArgumentException.class, testCase.mutableExpr::list); } if (!testCaseKind.equals(Kind.STRUCT)) { - assertThrows(IllegalArgumentException.class, testCase.mutableExpr::createStruct); + assertThrows(IllegalArgumentException.class, testCase.mutableExpr::struct); } if (!testCaseKind.equals(Kind.MAP)) { - assertThrows(IllegalArgumentException.class, testCase.mutableExpr::createMap); + assertThrows(IllegalArgumentException.class, testCase.mutableExpr::map); } if (!testCaseKind.equals(Kind.COMPREHENSION)) { assertThrows(IllegalArgumentException.class, testCase.mutableExpr::comprehension); @@ -912,14 +910,14 @@ private enum HashCodeTestCase { CelMutableExpr.ofConstant(CelConstant.ofValue("arg")))), -1735261193), CREATE_LIST( - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( 6L, CelMutableList.create( CelMutableExpr.ofConstant(CelConstant.ofValue("element1")), CelMutableExpr.ofConstant(CelConstant.ofValue("element2")))), 165341403), CREATE_STRUCT( - CelMutableExpr.ofCreateStruct( + CelMutableExpr.ofStruct( 7L, CelMutableStruct.create( "message", @@ -931,7 +929,7 @@ private enum HashCodeTestCase { /* optionalEntry= */ true)))), 2064611987), CREATE_MAP( - CelMutableExpr.ofCreateMap( + CelMutableExpr.ofMap( 8L, CelMutableMap.create( ImmutableList.of( @@ -946,7 +944,7 @@ private enum HashCodeTestCase { 10L, CelMutableComprehension.create( "iterVar", - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create(CelMutableExpr.ofConstant(CelConstant.ofValue(true)))), "accuVar", CelMutableExpr.ofConstant(CelConstant.ofValue(true)), 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 e2429c7db..c22471c05 100644 --- a/common/src/test/java/dev/cel/common/navigation/CelNavigableExprVisitorTest.java +++ b/common/src/test/java/dev/cel/common/navigation/CelNavigableExprVisitorTest.java @@ -592,11 +592,10 @@ public void messageConstruction_allNodesReturned() throws Exception { assertThat(allNodes) .containsExactly( constExpr, - CelExpr.ofCreateStruct( + CelExpr.ofStruct( 1, "TestAllTypes", - ImmutableList.of( - CelExpr.ofCreateStructEntry(2, "single_int64", constExpr, false)))); + ImmutableList.of(CelExpr.ofStructEntry(2, "single_int64", constExpr, false)))); } @Test @@ -619,11 +618,11 @@ public void messageConstruction_filterCreateStruct_allNodesReturned() throws Exc assertThat(allNodes).hasSize(1); assertThat(allNodes.get(0).expr()) .isEqualTo( - CelExpr.ofCreateStruct( + CelExpr.ofStruct( 1, "TestAllTypes", ImmutableList.of( - CelExpr.ofCreateStructEntry( + CelExpr.ofStructEntry( 2, "single_int64", CelExpr.ofConstant(3, CelConstant.ofValue(1)), false)))); } @@ -704,8 +703,8 @@ public void mapConstruction_allNodesReturned() throws Exception { .containsExactly( mapKeyExpr, mapValueExpr, - CelExpr.ofCreateMap( - 1, ImmutableList.of(CelExpr.ofCreateMapEntry(2, mapKeyExpr, mapValueExpr, false)))); + CelExpr.ofMap( + 1, ImmutableList.of(CelExpr.ofMapEntry(2, mapKeyExpr, mapValueExpr, false)))); } @Test @@ -726,8 +725,8 @@ public void mapConstruction_filterCreateMap_allNodesReturned() throws Exception CelExpr mapValueExpr = CelExpr.ofConstant(4, CelConstant.ofValue(2)); assertThat(allNodes.get(0).expr()) .isEqualTo( - CelExpr.ofCreateMap( - 1, ImmutableList.of(CelExpr.ofCreateMapEntry(2, mapKeyExpr, mapValueExpr, false)))); + CelExpr.ofMap( + 1, ImmutableList.of(CelExpr.ofMapEntry(2, mapKeyExpr, mapValueExpr, false)))); } @Test @@ -804,7 +803,7 @@ public void emptyMapConstruction_allNodesReturned() throws Exception { navigableAst.getRoot().allNodes().collect(toImmutableList()); assertThat(allNodes).hasSize(1); - assertThat(allNodes.get(0).expr()).isEqualTo(CelExpr.ofCreateMap(1, ImmutableList.of())); + assertThat(allNodes.get(0).expr()).isEqualTo(CelExpr.ofMap(1, ImmutableList.of())); } @Test @@ -824,8 +823,7 @@ public void comprehension_preOrder_allNodesReturned() throws Exception { .collect(toImmutableList()); CelExpr iterRangeConstExpr = CelExpr.ofConstant(2, CelConstant.ofValue(true)); - CelExpr iterRange = - CelExpr.ofCreateList(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); + CelExpr iterRange = CelExpr.ofList(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); CelExpr accuInit = CelExpr.ofConstant(6, CelConstant.ofValue(false)); CelExpr loopConditionIdentExpr = CelExpr.ofIdent(7, "__result__"); CelExpr loopConditionCallExpr = @@ -886,8 +884,7 @@ public void comprehension_postOrder_allNodesReturned() throws Exception { .collect(toImmutableList()); CelExpr iterRangeConstExpr = CelExpr.ofConstant(2, CelConstant.ofValue(true)); - CelExpr iterRange = - CelExpr.ofCreateList(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); + CelExpr iterRange = CelExpr.ofList(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); CelExpr accuInit = CelExpr.ofConstant(6, CelConstant.ofValue(false)); CelExpr loopConditionIdentExpr = CelExpr.ofIdent(7, "__result__"); CelExpr loopConditionCallExpr = @@ -1019,8 +1016,7 @@ public void comprehension_allNodes_parentsPopulated() throws Exception { ImmutableList allNodes = navigableAst.getRoot().allNodes(TraversalOrder.PRE_ORDER).collect(toImmutableList()); CelExpr iterRangeConstExpr = CelExpr.ofConstant(2, CelConstant.ofValue(true)); - CelExpr iterRange = - CelExpr.ofCreateList(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); + CelExpr iterRange = CelExpr.ofList(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); CelExpr accuInit = CelExpr.ofConstant(6, CelConstant.ofValue(false)); CelExpr loopConditionIdentExpr = CelExpr.ofIdent(7, "__result__"); CelExpr loopConditionCallExpr = @@ -1083,8 +1079,7 @@ public void comprehension_filterComprehension_allNodesReturned() throws Exceptio .collect(toImmutableList()); CelExpr iterRangeConstExpr = CelExpr.ofConstant(2, CelConstant.ofValue(true)); - CelExpr iterRange = - CelExpr.ofCreateList(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); + CelExpr iterRange = CelExpr.ofList(1, ImmutableList.of(iterRangeConstExpr), ImmutableList.of()); CelExpr accuInit = CelExpr.ofConstant(6, CelConstant.ofValue(false)); CelExpr loopConditionIdentExpr = CelExpr.ofIdent(7, "__result__"); CelExpr loopConditionCallExpr = diff --git a/common/src/test/java/dev/cel/common/navigation/CelNavigableMutableExprTest.java b/common/src/test/java/dev/cel/common/navigation/CelNavigableMutableExprTest.java index a4e8d455a..6900d41aa 100644 --- a/common/src/test/java/dev/cel/common/navigation/CelNavigableMutableExprTest.java +++ b/common/src/test/java/dev/cel/common/navigation/CelNavigableMutableExprTest.java @@ -80,10 +80,10 @@ public void builderFromInstance_sameAsStaticBuilder() { public void allNodes_filteredConstants_returnsAllConstants() { CelNavigableMutableExpr mutableExpr = CelNavigableMutableExpr.fromExpr( - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create( CelMutableExpr.ofConstant(CelConstant.ofValue("element1")), - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create( CelMutableExpr.ofConstant(CelConstant.ofValue("element2"))))))); @@ -105,10 +105,10 @@ public void allNodes_filteredConstants_returnsAllConstants() { public void descendants_filteredConstants_returnsAllConstants() { CelNavigableMutableExpr mutableExpr = CelNavigableMutableExpr.fromExpr( - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create( CelMutableExpr.ofConstant(CelConstant.ofValue("element1")), - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create( CelMutableExpr.ofConstant(CelConstant.ofValue("element2"))))))); @@ -130,10 +130,10 @@ public void descendants_filteredConstants_returnsAllConstants() { public void children_filteredConstants_returnsSingleConstant() { CelNavigableMutableExpr mutableExpr = CelNavigableMutableExpr.fromExpr( - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create( CelMutableExpr.ofConstant(CelConstant.ofValue("element1")), - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create( CelMutableExpr.ofConstant(CelConstant.ofValue("element2"))))))); diff --git a/extensions/src/main/java/dev/cel/extensions/CelMathExtensions.java b/extensions/src/main/java/dev/cel/extensions/CelMathExtensions.java index 59e51e366..c6423a05a 100644 --- a/extensions/src/main/java/dev/cel/extensions/CelMathExtensions.java +++ b/extensions/src/main/java/dev/cel/extensions/CelMathExtensions.java @@ -527,12 +527,12 @@ private static Optional checkInvalidArgument( private static Optional checkInvalidArgumentSingleArg( CelMacroExprFactory exprFactory, String functionName, CelExpr argument) { if (argument.exprKind().getKind() == Kind.LIST) { - if (argument.createList().elements().isEmpty()) { + if (argument.list().elements().isEmpty()) { return newError( exprFactory, String.format("%s invalid single argument value", functionName), argument); } - return checkInvalidArgument(exprFactory, functionName, argument.createList().elements()); + return checkInvalidArgument(exprFactory, functionName, argument.list().elements()); } if (isArgumentValidType(argument)) { return Optional.empty(); diff --git a/optimizer/src/main/java/dev/cel/optimizer/AstMutator.java b/optimizer/src/main/java/dev/cel/optimizer/AstMutator.java index 2159b14a8..e439c87cc 100644 --- a/optimizer/src/main/java/dev/cel/optimizer/AstMutator.java +++ b/optimizer/src/main/java/dev/cel/optimizer/AstMutator.java @@ -90,7 +90,7 @@ public CelMutableAst wrapAstWithNewCelBlock( ++maxId, CelMutableCall.create( celBlockFunction, - CelMutableExpr.ofCreateList(++maxId, CelMutableList.create(subexpressions)), + CelMutableExpr.ofList(++maxId, CelMutableList.create(subexpressions)), ast.expr())); return CelMutableAst.of(blockExpr, ast.source()); @@ -569,7 +569,7 @@ private CelMutableExpr newBindMacroExpr( comprehensionId, CelMutableComprehension.create( "#unused", - CelMutableExpr.ofCreateList(iterRangeId, CelMutableList.create()), + CelMutableExpr.ofList(iterRangeId, CelMutableList.create()), varName, varInit, CelMutableExpr.ofConstant(loopConditionId, CelConstant.ofValue(false)), @@ -758,7 +758,7 @@ private CelMutableSource normalizeMacroSource( private static void unwrapListArgumentsInMacroCallExpr( CelMutableComprehension comprehension, CelMutableExpr newMacroCallExpr) { CelMutableExpr accuInit = comprehension.accuInit(); - if (!accuInit.getKind().equals(Kind.LIST) || !accuInit.createList().elements().isEmpty()) { + if (!accuInit.getKind().equals(Kind.LIST) || !accuInit.list().elements().isEmpty()) { // Does not contain an extraneous list. return; } @@ -779,7 +779,7 @@ private static void unwrapListArgumentsInMacroCallExpr( : CelMutableCall.create(existingMacroCall.function()); newMacroCall.addArgs( existingMacroCall.args().get(0)); // iter_var is first argument of the call by convention - newMacroCall.addArgs(loopStepArgs.get(1).createList().elements()); + newMacroCall.addArgs(loopStepArgs.get(1).list().elements()); newMacroCallExpr.setCall(newMacroCall); } diff --git a/optimizer/src/main/java/dev/cel/optimizer/MutableExprVisitor.java b/optimizer/src/main/java/dev/cel/optimizer/MutableExprVisitor.java index d9ecb70c9..6d37246fc 100644 --- a/optimizer/src/main/java/dev/cel/optimizer/MutableExprVisitor.java +++ b/optimizer/src/main/java/dev/cel/optimizer/MutableExprVisitor.java @@ -71,11 +71,11 @@ CelMutableExpr visit(CelMutableExpr root) { case CALL: return visit(root, root.call()); case LIST: - return visit(root, root.createList()); + return visit(root, root.list()); case STRUCT: - return visit(root, root.createStruct()); + return visit(root, root.struct()); case MAP: - return visit(root, root.createMap()); + return visit(root, root.map()); case COMPREHENSION: return visit(root, root.comprehension()); case CONSTANT: // Fall-through is intended diff --git a/optimizer/src/main/java/dev/cel/optimizer/optimizers/ConstantFoldingOptimizer.java b/optimizer/src/main/java/dev/cel/optimizer/optimizers/ConstantFoldingOptimizer.java index bef87765b..485ded5e4 100644 --- a/optimizer/src/main/java/dev/cel/optimizer/optimizers/ConstantFoldingOptimizer.java +++ b/optimizer/src/main/java/dev/cel/optimizer/optimizers/ConstantFoldingOptimizer.java @@ -258,7 +258,7 @@ private Optional maybeAdaptEvaluatedResult(Object result) { listElements.add(adaptedExpr); } - return Optional.of(CelMutableExpr.ofCreateList(CelMutableList.create(listElements))); + return Optional.of(CelMutableExpr.ofList(CelMutableList.create(listElements))); } else if (result instanceof Map) { Map map = (Map) result; List mapEntries = new ArrayList<>(); @@ -275,7 +275,7 @@ private Optional maybeAdaptEvaluatedResult(Object result) { mapEntries.add(CelMutableMap.Entry.create(adaptedKey, adaptedValue)); } - return Optional.of(CelMutableExpr.ofCreateMap(CelMutableMap.create(mapEntries))); + return Optional.of(CelMutableExpr.ofMap(CelMutableMap.create(mapEntries))); } // Evaluated result cannot be folded (e.g: unknowns) @@ -339,7 +339,7 @@ private Optional maybePruneBranches( return Optional.empty(); } - CelMutableList haystack = callArg.createList(); + CelMutableList haystack = callArg.list(); if (haystack.elements().isEmpty()) { return Optional.of( astMutator.replaceSubtree( @@ -438,7 +438,7 @@ private CelMutableAst pruneOptionalElements(CelMutableAst ast) { } private CelMutableAst pruneOptionalListElements(CelMutableAst mutableAst, CelMutableExpr expr) { - CelMutableList createList = expr.createList(); + CelMutableList createList = expr.list(); if (createList.optionalIndices().isEmpty()) { return mutableAst; } @@ -477,13 +477,13 @@ private CelMutableAst pruneOptionalListElements(CelMutableAst mutableAst, CelMut return astMutator.replaceSubtree( mutableAst, - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create(updatedElemBuilder.build(), updatedIndicesBuilder.build())), expr.id()); } private CelMutableAst pruneOptionalMapElements(CelMutableAst ast, CelMutableExpr expr) { - CelMutableMap createMap = expr.createMap(); + CelMutableMap createMap = expr.map(); ImmutableList.Builder updatedEntryBuilder = new ImmutableList.Builder<>(); boolean modified = false; for (CelMutableMap.Entry entry : createMap.entries()) { @@ -519,16 +519,14 @@ private CelMutableAst pruneOptionalMapElements(CelMutableAst ast, CelMutableExpr if (modified) { return astMutator.replaceSubtree( - ast, - CelMutableExpr.ofCreateMap(CelMutableMap.create(updatedEntryBuilder.build())), - expr.id()); + ast, CelMutableExpr.ofMap(CelMutableMap.create(updatedEntryBuilder.build())), expr.id()); } return ast; } private CelMutableAst pruneOptionalStructElements(CelMutableAst ast, CelMutableExpr expr) { - CelMutableStruct createStruct = expr.createStruct(); + CelMutableStruct createStruct = expr.struct(); ImmutableList.Builder updatedEntryBuilder = new ImmutableList.Builder<>(); boolean modified = false; @@ -563,7 +561,7 @@ private CelMutableAst pruneOptionalStructElements(CelMutableAst ast, CelMutableE if (modified) { return astMutator.replaceSubtree( ast, - CelMutableExpr.ofCreateStruct( + CelMutableExpr.ofStruct( CelMutableStruct.create(createStruct.messageName(), updatedEntryBuilder.build())), expr.id()); } diff --git a/optimizer/src/main/java/dev/cel/optimizer/optimizers/SubexpressionOptimizer.java b/optimizer/src/main/java/dev/cel/optimizer/optimizers/SubexpressionOptimizer.java index e60fd47b2..967c68d3c 100644 --- a/optimizer/src/main/java/dev/cel/optimizer/optimizers/SubexpressionOptimizer.java +++ b/optimizer/src/main/java/dev/cel/optimizer/optimizers/SubexpressionOptimizer.java @@ -259,7 +259,7 @@ static void verifyOptimizedAstCorrectness(CelAbstractSyntaxTree ast) { // Assert correctness on block indices used in subexpressions CelCall celBlockCall = celBlockExpr.call(); - ImmutableList subexprs = celBlockCall.args().get(0).createList().elements(); + ImmutableList subexprs = celBlockCall.args().get(0).list().elements(); for (int i = 0; i < subexprs.size(); i++) { verifyBlockIndex(subexprs.get(i), i); } @@ -558,7 +558,7 @@ private boolean canEliminate( && navigableExpr.expr().ident().name().startsWith(BIND_IDENTIFIER_PREFIX)) // Exclude empty lists (cel.bind sets this for iterRange). && !(navigableExpr.getKind().equals(Kind.LIST) - && navigableExpr.expr().createList().elements().isEmpty()) + && navigableExpr.expr().list().elements().isEmpty()) && containsEliminableFunctionOnly(navigableExpr) && !ineligibleExprs.contains(navigableExpr.expr()); } diff --git a/optimizer/src/test/java/dev/cel/optimizer/AstMutatorTest.java b/optimizer/src/test/java/dev/cel/optimizer/AstMutatorTest.java index 24084156e..5e1d98be9 100644 --- a/optimizer/src/test/java/dev/cel/optimizer/AstMutatorTest.java +++ b/optimizer/src/test/java/dev/cel/optimizer/AstMutatorTest.java @@ -490,7 +490,7 @@ public void replaceSubtree_replaceExtraneousListCreatedByMacro_unparseSuccess() AST_MUTATOR .replaceSubtree( mutableAst, - CelMutableExpr.ofCreateList( + CelMutableExpr.ofList( CelMutableList.create(CelMutableExpr.ofConstant(CelConstant.ofValue(2L)))), 9L) .toParsedAst(); diff --git a/parser/src/main/java/dev/cel/parser/CelMacroExprFactory.java b/parser/src/main/java/dev/cel/parser/CelMacroExprFactory.java index 70adbf510..d7c917c29 100644 --- a/parser/src/main/java/dev/cel/parser/CelMacroExprFactory.java +++ b/parser/src/main/java/dev/cel/parser/CelMacroExprFactory.java @@ -88,18 +88,18 @@ public final CelExpr copy(CelExpr expr) { case LIST: { CelExpr.CelList.Builder listBuilder = - CelExpr.CelList.newBuilder().addOptionalIndices(expr.createList().optionalIndices()); - for (CelExpr element : expr.createList().elements()) { + CelExpr.CelList.newBuilder().addOptionalIndices(expr.list().optionalIndices()); + for (CelExpr element : expr.list().elements()) { listBuilder.addElements(copy(element)); } - builder.setCreateList(listBuilder.build()); + builder.setList(listBuilder.build()); } break; case STRUCT: { CelExpr.CelStruct.Builder structBuilder = - CelExpr.CelStruct.newBuilder().setMessageName(expr.createStruct().messageName()); - for (CelExpr.CelStruct.Entry entry : expr.createStruct().entries()) { + CelExpr.CelStruct.newBuilder().setMessageName(expr.struct().messageName()); + for (CelExpr.CelStruct.Entry entry : expr.struct().entries()) { structBuilder.addEntries( CelExpr.CelStruct.Entry.newBuilder() .setId(copyExprId(entry.id())) @@ -108,13 +108,13 @@ public final CelExpr copy(CelExpr expr) { .setOptionalEntry(entry.optionalEntry()) .build()); } - builder.setCreateStruct(structBuilder.build()); + builder.setStruct(structBuilder.build()); } break; case MAP: { CelExpr.CelMap.Builder mapBuilder = CelExpr.CelMap.newBuilder(); - for (CelExpr.CelMap.Entry entry : expr.createMap().entries()) { + for (CelExpr.CelMap.Entry entry : expr.map().entries()) { mapBuilder.addEntries( CelExpr.CelMap.Entry.newBuilder() .setId(copyExprId(entry.id())) @@ -123,7 +123,7 @@ public final CelExpr copy(CelExpr expr) { .setOptionalEntry(entry.optionalEntry()) .build()); } - builder.setCreateMap(mapBuilder.build()); + builder.setMap(mapBuilder.build()); } break; case COMPREHENSION: diff --git a/parser/src/main/java/dev/cel/parser/Parser.java b/parser/src/main/java/dev/cel/parser/Parser.java index c4b3dffb6..b98a748d5 100644 --- a/parser/src/main/java/dev/cel/parser/Parser.java +++ b/parser/src/main/java/dev/cel/parser/Parser.java @@ -525,7 +525,7 @@ public CelExpr visitCreateMessage(CreateMessageContext context) { CelExpr.Builder exprBuilder = exprFactory.newExprBuilder(context.op); CelExpr.CelStruct.Builder structExpr = visitStructFields(context.entries); - return exprBuilder.setCreateStruct(structExpr.setMessageName(messageName).build()).build(); + return exprBuilder.setStruct(structExpr.setMessageName(messageName).build()).build(); } @Override @@ -566,7 +566,7 @@ public CelExpr visitCreateList(CreateListContext context) { CelExpr.Builder exprBuilder = exprFactory.newExprBuilder(context.op); CelExpr.CelList createListExpr = visitListInitElements(context.listInit()); - return exprBuilder.setCreateList(createListExpr).build(); + return exprBuilder.setList(createListExpr).build(); } private CelExpr.CelList visitListInitElements(ListInitContext context) { @@ -596,7 +596,7 @@ public CelExpr visitCreateMap(CreateMapContext context) { checkNotNull(context); CelExpr.Builder exprBuilder = exprFactory.newExprBuilder(context.op); CelExpr.CelMap.Builder createMapExpr = visitMapEntries(context.entries); - return exprBuilder.setCreateMap(createMapExpr.build()).build(); + return exprBuilder.setMap(createMapExpr.build()).build(); } private CelExpr buildMacroCallArgs(CelExpr expr) { diff --git a/parser/src/test/java/dev/cel/parser/CelMacroExprFactoryTest.java b/parser/src/test/java/dev/cel/parser/CelMacroExprFactoryTest.java index c14d22c6b..4d110b79e 100644 --- a/parser/src/test/java/dev/cel/parser/CelMacroExprFactoryTest.java +++ b/parser/src/test/java/dev/cel/parser/CelMacroExprFactoryTest.java @@ -156,8 +156,8 @@ public void newList_returnsList() { CelExpr expr = exprFactory.newList(element); assertThat(expr.id()).isEqualTo(2L); assertThat(expr.exprKind().getKind()).isEqualTo(Kind.LIST); - assertThat(expr.createList().elements()).hasSize(1); - assertThat(expr.createList().elements()).containsExactly(element); + assertThat(expr.list().elements()).hasSize(1); + assertThat(expr.list().elements()).containsExactly(element); } @Test @@ -169,7 +169,7 @@ public void newMap_returnsMap() { CelExpr expr = exprFactory.newMap(entry); assertThat(expr.id()).isEqualTo(4L); assertThat(expr.exprKind().getKind()).isEqualTo(Kind.MAP); - assertThat(expr.createMap().entries()).containsExactly(entry); + assertThat(expr.map().entries()).containsExactly(entry); } @Test @@ -189,8 +189,8 @@ public void newMessage_returnsMessage() { CelExpr expr = exprFactory.newMessage("google.example.Baz", field); assertThat(expr.id()).isEqualTo(3L); assertThat(expr.exprKind().getKind()).isEqualTo(Kind.STRUCT); - assertThat(expr.createStruct().messageName()).isEqualTo("google.example.Baz"); - assertThat(expr.createStruct().entries()).containsExactly(field); + assertThat(expr.struct().messageName()).isEqualTo("google.example.Baz"); + assertThat(expr.struct().entries()).containsExactly(field); } @Test diff --git a/parser/src/test/java/dev/cel/parser/CelUnparserImplTest.java b/parser/src/test/java/dev/cel/parser/CelUnparserImplTest.java index 321db78ef..be95fcaef 100644 --- a/parser/src/test/java/dev/cel/parser/CelUnparserImplTest.java +++ b/parser/src/test/java/dev/cel/parser/CelUnparserImplTest.java @@ -196,7 +196,7 @@ public List provideValues(Context context) { .build()) .build(), // bad args CelExpr.newBuilder() - .setCreateStruct( + .setStruct( CelStruct.newBuilder() .setMessageName("Msg") .addEntries( @@ -208,7 +208,7 @@ public List provideValues(Context context) { .build()) .build(), // bad struct CelExpr.newBuilder() - .setCreateMap( + .setMap( CelMap.newBuilder() .addEntries( CelMap.Entry.newBuilder() diff --git a/runtime/src/main/java/dev/cel/runtime/DefaultInterpreter.java b/runtime/src/main/java/dev/cel/runtime/DefaultInterpreter.java index b535028b0..a7f2efe8d 100644 --- a/runtime/src/main/java/dev/cel/runtime/DefaultInterpreter.java +++ b/runtime/src/main/java/dev/cel/runtime/DefaultInterpreter.java @@ -202,13 +202,13 @@ private IntermediateResult evalInternal(ExecutionFrame frame, CelExpr expr) result = evalCall(frame, expr, expr.call()); break; case LIST: - result = evalList(frame, expr, expr.createList()); + result = evalList(frame, expr, expr.list()); break; case STRUCT: - result = evalStruct(frame, expr, expr.createStruct()); + result = evalStruct(frame, expr, expr.struct()); break; case MAP: - result = evalMap(frame, expr.createMap()); + result = evalMap(frame, expr.map()); break; case COMPREHENSION: result = evalComprehension(frame, expr, expr.comprehension()); @@ -901,7 +901,7 @@ private IntermediateResult evalComprehension( private IntermediateResult evalCelBlock( ExecutionFrame frame, CelExpr unusedExpr, CelCall blockCall) throws InterpreterException { - CelList exprList = blockCall.args().get(0).createList(); + CelList exprList = blockCall.args().get(0).list(); Map blockList = new HashMap<>(); for (int index = 0; index < exprList.elements().size(); index++) { // Register the block indices as lazily evaluated expressions stored as unique identifiers. @@ -934,7 +934,7 @@ private static boolean isLazilyEvaluable(CelComprehension comprehension) { && !comprehension.loopCondition().constant().booleanValue() && comprehension.iterVar().equals("#unused") && comprehension.iterRange().exprKind().getKind().equals(ExprKind.Kind.LIST) - && comprehension.iterRange().createList().elements().isEmpty(); + && comprehension.iterRange().list().elements().isEmpty(); } private LazyExpression(CelExpr celExpr) { diff --git a/runtime/src/test/java/dev/cel/runtime/CelRuntimeTest.java b/runtime/src/test/java/dev/cel/runtime/CelRuntimeTest.java index f66690912..074405c20 100644 --- a/runtime/src/test/java/dev/cel/runtime/CelRuntimeTest.java +++ b/runtime/src/test/java/dev/cel/runtime/CelRuntimeTest.java @@ -293,7 +293,7 @@ public void trace_createStruct() throws Exception { CelEvaluationListener listener = (expr, res) -> { assertThat(res).isEqualTo(TestAllTypes.getDefaultInstance()); - assertThat(expr.createStruct().messageName()).isEqualTo("TestAllTypes"); + assertThat(expr.struct().messageName()).isEqualTo("TestAllTypes"); }; Cel cel = CelFactory.standardCelBuilder() @@ -314,7 +314,7 @@ public void trace_createList() throws Exception { (expr, res) -> { if (expr.exprKind().getKind().equals(Kind.LIST)) { assertThat((List) res).containsExactly(1L, 2L, 3L); - assertThat(expr.createList().elements()).hasSize(3); + assertThat(expr.list().elements()).hasSize(3); } }; Cel cel = CelFactory.standardCelBuilder().build(); @@ -332,7 +332,7 @@ public void trace_createMap() throws Exception { (expr, res) -> { if (expr.exprKind().getKind().equals(Kind.MAP)) { assertThat((Map) res).containsExactly(1L, "a"); - assertThat(expr.createMap().entries()).hasSize(1); + assertThat(expr.map().entries()).hasSize(1); } }; Cel cel = CelFactory.standardCelBuilder().build(); diff --git a/validator/src/main/java/dev/cel/validator/validators/HomogeneousLiteralValidator.java b/validator/src/main/java/dev/cel/validator/validators/HomogeneousLiteralValidator.java index b47251ccf..58947f0fb 100644 --- a/validator/src/main/java/dev/cel/validator/validators/HomogeneousLiteralValidator.java +++ b/validator/src/main/java/dev/cel/validator/validators/HomogeneousLiteralValidator.java @@ -73,8 +73,8 @@ public void validate(CelNavigableAst navigableAst, Cel cel, IssuesFactory issues private void validateList(CelAbstractSyntaxTree ast, IssuesFactory issuesFactory, CelExpr expr) { CelType previousType = null; - HashSet optionalIndices = new HashSet<>(expr.createList().optionalIndices()); - ImmutableList elements = expr.createList().elements(); + HashSet optionalIndices = new HashSet<>(expr.list().optionalIndices()); + ImmutableList elements = expr.list().elements(); for (int i = 0; i < elements.size(); i++) { CelExpr element = elements.get(i); CelType currentType = ast.getType(element.id()).get(); @@ -94,7 +94,7 @@ private void validateList(CelAbstractSyntaxTree ast, IssuesFactory issuesFactory private void validateMap(CelAbstractSyntaxTree ast, IssuesFactory issuesFactory, CelExpr expr) { CelType previousKeyType = null; CelType previousValueType = null; - for (CelMap.Entry entry : expr.createMap().entries()) { + for (CelMap.Entry entry : expr.map().entries()) { CelType currentKeyType = ast.getType(entry.key().id()).get(); CelType currentValueType = ast.getType(entry.value().id()).get(); if (entry.optionalEntry()) {