From b42be09c81f08371ff7bbb88a9eadaa164e20956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20Zim=C3=A1nyi?= Date: Fri, 11 Oct 2024 14:51:06 +0200 Subject: [PATCH 1/5] Add RangeTypeNode --- .../kie/dmn/feel/parser/feel11/FEEL_1_1.g4 | 1 + .../codegen/feel11/ASTCompilerHelper.java | 8 +++ .../codegen/feel11/ASTCompilerVisitor.java | 7 ++ .../codegen/feel11/DMNCodegenConstants.java | 3 + .../kie/dmn/feel/lang/ast/RangeTypeNode.java | 43 +++++++++++++ .../org/kie/dmn/feel/lang/ast/Visitor.java | 1 + .../lang/ast/visitor/DefaultedVisitor.java | 6 ++ .../kie/dmn/feel/lang/types/GenRangeType.java | 64 +++++++++++++++++++ .../feel/parser/feel11/ASTBuilderVisitor.java | 7 ++ .../dmn/feel/parser/feel11/ParserHelper.java | 5 ++ kie-dmn/kie-dmn-tck/pom.xml | 1 - 11 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeTypeNode.java create mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/types/GenRangeType.java diff --git a/kie-dmn/kie-dmn-feel/src/main/antlr4/org/kie/dmn/feel/parser/feel11/FEEL_1_1.g4 b/kie-dmn/kie-dmn-feel/src/main/antlr4/org/kie/dmn/feel/parser/feel11/FEEL_1_1.g4 index 4760125e128..9f04edc4532 100644 --- a/kie-dmn/kie-dmn-feel/src/main/antlr4/org/kie/dmn/feel/parser/feel11/FEEL_1_1.g4 +++ b/kie-dmn/kie-dmn-feel/src/main/antlr4/org/kie/dmn/feel/parser/feel11/FEEL_1_1.g4 @@ -135,6 +135,7 @@ type helper.popScope(); } : {_input.LT(1).getText().equals("list")}? sk=Identifier LT type GT #listType + | {_input.LT(1).getText().equals("range")}? sk=Identifier LT type GT #rangeType | {_input.LT(1).getText().equals("context")}? sk=Identifier LT Identifier COLON type ( COMMA Identifier COLON type )* GT #contextType | FUNCTION #qnType | FUNCTION LT (type ( COMMA type )*)? GT RARROW type #functionType diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ASTCompilerHelper.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ASTCompilerHelper.java index 30930577189..4959c38f541 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ASTCompilerHelper.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ASTCompilerHelper.java @@ -72,6 +72,7 @@ import org.kie.dmn.feel.lang.ast.QualifiedNameNode; import org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode; import org.kie.dmn.feel.lang.ast.RangeNode; +import org.kie.dmn.feel.lang.ast.RangeTypeNode; import org.kie.dmn.feel.lang.ast.SignedUnaryNode; import org.kie.dmn.feel.lang.ast.StringNode; import org.kie.dmn.feel.lang.ast.TemporalConstantNode; @@ -136,6 +137,7 @@ import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.QUALIFIEDNAMENODE_CT; import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.QUANTIFIEDEXPRESSIONNODE_CT; import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.RANGENODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.RANGETYPENODE_CT; import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.SIGNEDUNARYNODE_CT; import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.STRINGNODE_CT; import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.TEMPORALCONSTANTNODE_CT; @@ -431,6 +433,12 @@ public BlockStmt add(RangeNode n) { endExpression), n.getText()); } + public BlockStmt add(RangeTypeNode n) { + Expression genTypeNodeExpression = getNodeExpression(n.getGenTypeNode()); + return addVariableDeclaratorWithObjectCreation(RANGETYPENODE_CT, NodeList.nodeList(genTypeNodeExpression), + n.getText()); + } + public BlockStmt add(SignedUnaryNode n) { Expression signExpression = getEnumExpression(n.getSign()); Expression expressionExpression = getNodeExpression(n.getExpression()); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ASTCompilerVisitor.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ASTCompilerVisitor.java index 0a509bca667..a4bef5554d3 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ASTCompilerVisitor.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ASTCompilerVisitor.java @@ -50,6 +50,7 @@ import org.kie.dmn.feel.lang.ast.QualifiedNameNode; import org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode; import org.kie.dmn.feel.lang.ast.RangeNode; +import org.kie.dmn.feel.lang.ast.RangeTypeNode; import org.kie.dmn.feel.lang.ast.SignedUnaryNode; import org.kie.dmn.feel.lang.ast.StringNode; import org.kie.dmn.feel.lang.ast.TemporalConstantNode; @@ -253,6 +254,12 @@ public BlockStmt visit(RangeNode n) { return compilerHelper.add(n); } + @Override + public BlockStmt visit(RangeTypeNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + @Override public BlockStmt visit(SignedUnaryNode n) { LOGGER.trace("visit {}", n); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/DMNCodegenConstants.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/DMNCodegenConstants.java index 96520d8689c..f5db4e41509 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/DMNCodegenConstants.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/DMNCodegenConstants.java @@ -51,6 +51,7 @@ import org.kie.dmn.feel.lang.ast.QualifiedNameNode; import org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode; import org.kie.dmn.feel.lang.ast.RangeNode; +import org.kie.dmn.feel.lang.ast.RangeTypeNode; import org.kie.dmn.feel.lang.ast.SignedUnaryNode; import org.kie.dmn.feel.lang.ast.StringNode; import org.kie.dmn.feel.lang.ast.TemporalConstantNode; @@ -142,6 +143,8 @@ public class DMNCodegenConstants { public static final ClassOrInterfaceType LISTNODE_CT = parseClassOrInterfaceType(ListNode.class.getCanonicalName()); public static final ClassOrInterfaceType LISTTYPENODE_CT = parseClassOrInterfaceType(ListTypeNode.class.getCanonicalName()); + public static final ClassOrInterfaceType RANGETYPENODE_CT = + parseClassOrInterfaceType(RangeTypeNode.class.getCanonicalName()); public static final ClassOrInterfaceType NAMEDEFNODE_CT = parseClassOrInterfaceType(NameDefNode.class.getCanonicalName()); public static final ClassOrInterfaceType NAMEDPARAMETERNODE_CT = diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeTypeNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeTypeNode.java new file mode 100644 index 00000000000..21f4658c229 --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeTypeNode.java @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.kie.dmn.feel.lang.ast; + +import org.antlr.v4.runtime.ParserRuleContext; +import org.kie.dmn.feel.lang.EvaluationContext; +import org.kie.dmn.feel.lang.Type; +import org.kie.dmn.feel.lang.types.GenRangeType; + +public class RangeTypeNode extends TypeNode { + + private final TypeNode genTypeNode; + + public RangeTypeNode(ParserRuleContext ctx, TypeNode gen) { + super(ctx); + this.genTypeNode = gen; + } + + public RangeTypeNode(TypeNode genTypeNode, String text) { + this.genTypeNode = genTypeNode; + this.setText(text); + } + + @Override + public Type evaluate(EvaluationContext ctx) { + Type gen = genTypeNode.evaluate(ctx); + return new GenRangeType(gen); + } + + public TypeNode getGenTypeNode() { + return genTypeNode; + } + +} diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/Visitor.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/Visitor.java index 6904d03b2d5..82775356454 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/Visitor.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/Visitor.java @@ -50,6 +50,7 @@ public interface Visitor { T visit(QualifiedNameNode n); T visit(QuantifiedExpressionNode n); T visit(RangeNode n); + T visit(RangeTypeNode n); T visit(SignedUnaryNode n); T visit(StringNode n); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/visitor/DefaultedVisitor.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/visitor/DefaultedVisitor.java index 68d5baaa16a..6eb2d6b79d5 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/visitor/DefaultedVisitor.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/visitor/DefaultedVisitor.java @@ -49,6 +49,7 @@ import org.kie.dmn.feel.lang.ast.QualifiedNameNode; import org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode; import org.kie.dmn.feel.lang.ast.RangeNode; +import org.kie.dmn.feel.lang.ast.RangeTypeNode; import org.kie.dmn.feel.lang.ast.SignedUnaryNode; import org.kie.dmn.feel.lang.ast.StringNode; import org.kie.dmn.feel.lang.ast.UnaryTestListNode; @@ -194,6 +195,11 @@ public T visit(RangeNode n) { return defaultVisit(n); } + @Override + public T visit(RangeTypeNode n) { + return defaultVisit(n); + } + @Override public T visit(SignedUnaryNode n) { return defaultVisit(n); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/types/GenRangeType.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/types/GenRangeType.java new file mode 100644 index 00000000000..4386040ba0d --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/types/GenRangeType.java @@ -0,0 +1,64 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the + * License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and limitations under the License. + */ + +package org.kie.dmn.feel.lang.types; + +import org.kie.dmn.feel.lang.SimpleType; +import org.kie.dmn.feel.lang.Type; +import org.kie.dmn.feel.runtime.impl.RangeImpl; + +public class GenRangeType implements SimpleType { + + /** + * Represents the "generic" type of the current list + */ + private final Type gen; + + + public GenRangeType(Type gen) { + this.gen = gen; + } + + @Override + public boolean isInstanceOf(Object o) { + if (o instanceof RangeImpl rangeImpl) { + return gen.isInstanceOf(rangeImpl.getLowEndPoint()) && gen.isInstanceOf(rangeImpl.getHighEndPoint()); + } else { + return false; + } + } + + @Override + public boolean isAssignableValue(Object value) { + if ( value == null ) { + return true; // a null-value can be assigned to any type. + } + if (!(value instanceof RangeImpl)) { + return gen.isAssignableValue(value); + } + return isInstanceOf(value); + } + + @Override + public String getName() { + return "[anonymous]"; + } + + public Type getGen() { + return gen; + } + + @Override + public boolean conformsTo(Type t) { + return (t instanceof GenRangeType && this.gen.conformsTo(((GenRangeType) t).gen)) || t == BuiltInType.RANGE; + } + +} diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/parser/feel11/ASTBuilderVisitor.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/parser/feel11/ASTBuilderVisitor.java index 62ce7781a5a..295b9fe539f 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/parser/feel11/ASTBuilderVisitor.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/parser/feel11/ASTBuilderVisitor.java @@ -49,6 +49,7 @@ import org.kie.dmn.feel.lang.ast.QualifiedNameNode; import org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode; import org.kie.dmn.feel.lang.ast.RangeNode; +import org.kie.dmn.feel.lang.ast.RangeTypeNode; import org.kie.dmn.feel.lang.ast.StringNode; import org.kie.dmn.feel.lang.ast.TypeNode; import org.kie.dmn.feel.lang.ast.UnaryTestListNode; @@ -586,6 +587,12 @@ public BaseNode visitListType(FEEL_1_1Parser.ListTypeContext ctx) { return new ListTypeNode(ctx, type); } + @Override + public BaseNode visitRangeType(FEEL_1_1Parser.RangeTypeContext ctx) { + TypeNode type = (TypeNode) visit(ctx.type()); + return new RangeTypeNode(ctx, type); + } + @Override public BaseNode visitContextType(FEEL_1_1Parser.ContextTypeContext ctx) { List pNames = new ArrayList<>(); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/parser/feel11/ParserHelper.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/parser/feel11/ParserHelper.java index 3ac1ca33150..4308519335a 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/parser/feel11/ParserHelper.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/parser/feel11/ParserHelper.java @@ -42,6 +42,7 @@ import org.kie.dmn.feel.lang.types.DefaultBuiltinFEELTypeRegistry; import org.kie.dmn.feel.lang.types.FEELTypeRegistry; import org.kie.dmn.feel.lang.types.GenListType; +import org.kie.dmn.feel.lang.types.GenRangeType; import org.kie.dmn.feel.lang.types.ScopeImpl; import org.kie.dmn.feel.lang.types.SymbolTable; import org.kie.dmn.feel.lang.types.VariableSymbol; @@ -144,6 +145,10 @@ public void recoverScope( String name ) { scopeType = ((GenListType) scopeType).getGen(); } + if (scopeType instanceof GenRangeType) { + scopeType = ((GenRangeType) scopeType).getGen(); + } + if (resolved != null && scopeType instanceof CompositeType) { pushScope(scopeType); CompositeType type = (CompositeType) scopeType; diff --git a/kie-dmn/kie-dmn-tck/pom.xml b/kie-dmn/kie-dmn-tck/pom.xml index 8cd07ebced6..83b29b7e359 100644 --- a/kie-dmn/kie-dmn-tck/pom.xml +++ b/kie-dmn/kie-dmn-tck/pom.xml @@ -52,7 +52,6 @@ org.apache.maven.plugins maven-scm-plugin - 1.11.1 run-tck-suite From 93d10d5b479b676276dd0743dedf90b06fe4db25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20Zim=C3=A1nyi?= Date: Fri, 11 Oct 2024 14:51:39 +0200 Subject: [PATCH 2/5] Add RangeTypeNode tests. --- .../test/java/org/kie/dmn/feel/runtime/FEELOperatorsTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELOperatorsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELOperatorsTest.java index 92258af10bf..5d167665c70 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELOperatorsTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELOperatorsTest.java @@ -127,6 +127,8 @@ private static Collection data() { {"(function(a: context) {b: \"b\", c: \"c\"}) instance of function>->context", Boolean.TRUE , null}, {"(function(a: context) \"foo\") instance of function>->string", Boolean.FALSE , null}, {"(function(a: context, b: context) \"foo\") instance of function,context>->string", Boolean.TRUE , null}, + {"range(\"[1..3]\") instance of range", Boolean.TRUE , null}, + {"range(\"[1..3]\") instance of range", Boolean.FALSE , null} }; return addAdditionalParameters(cases, false); } From 0b7b528d5dd7beb1e5f63f89dc8ee93e77930b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20Zim=C3=A1nyi?= Date: Fri, 11 Oct 2024 15:00:27 +0200 Subject: [PATCH 3/5] Fix accept method in RangeTypeNode. --- .../main/java/org/kie/dmn/feel/lang/ast/RangeTypeNode.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeTypeNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeTypeNode.java index 21f4658c229..f6d86a94619 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeTypeNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeTypeNode.java @@ -36,6 +36,11 @@ public Type evaluate(EvaluationContext ctx) { return new GenRangeType(gen); } + @Override + public T accept(Visitor v) { + return v.visit(this); + } + public TypeNode getGenTypeNode() { return genTypeNode; } From de521ba2bb2917b4ebaffd194e8fce674fcc010b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20Zim=C3=A1nyi?= Date: Mon, 14 Oct 2024 12:27:28 +0200 Subject: [PATCH 4/5] Add RangeTypeNode Unit tests. --- .../org/kie/dmn/core/DMNCompilerTest.java | 2 +- .../codegen/feel11/ASTCompilerHelper.java | 2 +- .../kie/dmn/feel/lang/ast/RangeTypeNode.java | 14 +- .../feel11/CodegenFEELUnaryTestsTest.java | 3 +- .../codegen/feel11/DirectCompilerTest.java | 13 +- .../feel/lang/ast/ForExpressionNodeTest.java | 6 +- .../dmn/feel/lang/ast/RangeTypeNodeTest.java | 51 ++++ .../ForIterationUtilsTest.java | 2 +- .../dmn/feel/runtime/FEELCompilerTest.java | 14 +- .../functions/BaseFEELFunctionHelperTest.java | 4 +- .../functions/BaseFEELFunctionTest.java | 4 +- .../runtime/functions/ScorerHelperTest.java | 18 +- .../org/kie/dmn/feel/util/CompilerUtils.java | 3 +- .../EvaluationContextTestUtil.java} | 7 +- .../org/kie/dmn/feel/util/MockVisitor.java | 240 ++++++++++++++++++ 15 files changed, 337 insertions(+), 46 deletions(-) create mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/RangeTypeNodeTest.java rename kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/{codegen/feel11/CodegenTestUtil.java => util/EvaluationContextTestUtil.java} (91%) create mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/MockVisitor.java diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNCompilerTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNCompilerTest.java index 7e9874ef7da..18d96e5ef71 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNCompilerTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/DMNCompilerTest.java @@ -56,7 +56,7 @@ import static org.kie.dmn.core.util.DynamicTypeUtils.entry; import static org.kie.dmn.core.util.DynamicTypeUtils.mapOf; import static org.kie.dmn.core.util.DynamicTypeUtils.prototype; -import static org.kie.dmn.feel.codegen.feel11.CodegenTestUtil.newEmptyEvaluationContext; +import static org.kie.dmn.feel.util.EvaluationContextTestUtil.newEmptyEvaluationContext; public class DMNCompilerTest extends BaseVariantTest { diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ASTCompilerHelper.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ASTCompilerHelper.java index 4959c38f541..dc87cd9e5d7 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ASTCompilerHelper.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ASTCompilerHelper.java @@ -434,7 +434,7 @@ public BlockStmt add(RangeNode n) { } public BlockStmt add(RangeTypeNode n) { - Expression genTypeNodeExpression = getNodeExpression(n.getGenTypeNode()); + Expression genTypeNodeExpression = getNodeExpression(n.getGenericTypeNode()); return addVariableDeclaratorWithObjectCreation(RANGETYPENODE_CT, NodeList.nodeList(genTypeNodeExpression), n.getText()); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeTypeNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeTypeNode.java index f6d86a94619..87771e9ac0c 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeTypeNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeTypeNode.java @@ -18,21 +18,21 @@ public class RangeTypeNode extends TypeNode { - private final TypeNode genTypeNode; + private final TypeNode genericTypeNode; public RangeTypeNode(ParserRuleContext ctx, TypeNode gen) { super(ctx); - this.genTypeNode = gen; + this.genericTypeNode = gen; } - public RangeTypeNode(TypeNode genTypeNode, String text) { - this.genTypeNode = genTypeNode; + public RangeTypeNode(TypeNode genericTypeNode, String text) { + this.genericTypeNode = genericTypeNode; this.setText(text); } @Override public Type evaluate(EvaluationContext ctx) { - Type gen = genTypeNode.evaluate(ctx); + Type gen = genericTypeNode.evaluate(ctx); return new GenRangeType(gen); } @@ -41,8 +41,8 @@ public T accept(Visitor v) { return v.visit(this); } - public TypeNode getGenTypeNode() { - return genTypeNode; + public TypeNode getGenericTypeNode() { + return genericTypeNode; } } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/CodegenFEELUnaryTestsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/CodegenFEELUnaryTestsTest.java index ff42ea47a6d..c598d4f9df5 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/CodegenFEELUnaryTestsTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/CodegenFEELUnaryTestsTest.java @@ -34,6 +34,7 @@ import org.kie.dmn.feel.parser.feel11.ASTBuilderVisitor; import org.kie.dmn.feel.parser.feel11.FEELParser; import org.kie.dmn.feel.parser.feel11.FEEL_1_1Parser; +import org.kie.dmn.feel.util.EvaluationContextTestUtil; import org.kie.dmn.feel.util.NumberEvalHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -98,7 +99,7 @@ private List parseCompileEvaluate(String feelLiteralExpression, Object FEELEventListenersManager mgr = new FEELEventListenersManager(); SyntaxErrorListener listener = new SyntaxErrorListener(); mgr.addListener(listener); - EvaluationContext emptyContext = CodegenTestUtil.newEmptyEvaluationContext(mgr); + EvaluationContext emptyContext = EvaluationContextTestUtil.newEmptyEvaluationContext(mgr); CompiledFEELUnaryTests compiledUnaryTests = parse(feelLiteralExpression, mgr, listener); LOG.debug("{}", compiledUnaryTests); List result = compiledUnaryTests.getUnaryTests() diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/DirectCompilerTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/DirectCompilerTest.java index 9231a8b1d5d..5a8f00660d7 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/DirectCompilerTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/DirectCompilerTest.java @@ -36,6 +36,7 @@ import org.kie.dmn.feel.runtime.FEELTernaryLogicTest; import org.kie.dmn.feel.runtime.functions.CustomFEELFunction; import org.kie.dmn.feel.util.CompilerUtils; +import org.kie.dmn.feel.util.EvaluationContextTestUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -226,7 +227,7 @@ void filter_path_tricky1() { CompiledFEELExpression nameRef = CompilerUtils.parseCodegen("[ {x:1, y:2}, {x:2, y:3} ][x]"); LOG.debug("{}", nameRef); - EvaluationContext context = CodegenTestUtil.newEmptyEvaluationContext(); + EvaluationContext context = EvaluationContextTestUtil.newEmptyEvaluationContext(); context.setValue("x", 2); Object result = nameRef.apply(context); LOG.debug("{}", result); @@ -239,7 +240,7 @@ void filter_path_tricky2() { CompiledFEELExpression nameRef = CompilerUtils.parseCodegen("[ {x:1, y:2}, {x:2, y:3} ][x]"); LOG.debug("{}", nameRef); - EvaluationContext context = CodegenTestUtil.newEmptyEvaluationContext(); + EvaluationContext context = EvaluationContextTestUtil.newEmptyEvaluationContext(); context.setValue("x", false); Object result = nameRef.apply(context); LOG.debug("{}", result); @@ -410,7 +411,7 @@ void nameReference() { CompiledFEELExpression nameRef = parseCodegen(inputExpression, mapOf(entry("someSimpleName", BuiltInType.STRING) ) ); LOG.debug("{}", nameRef); - EvaluationContext context = CodegenTestUtil.newEmptyEvaluationContext(); + EvaluationContext context = EvaluationContextTestUtil.newEmptyEvaluationContext(); context.setValue("someSimpleName", 123L); Object result = nameRef.apply(context); LOG.debug("{}", result); @@ -425,7 +426,7 @@ void qualifiedName() { CompiledFEELExpression qualRef = parseCodegen(inputExpression, mapOf(entry("My Person", personType) ) ); LOG.debug("{}", qualRef); - EvaluationContext context = CodegenTestUtil.newEmptyEvaluationContext(); + EvaluationContext context = EvaluationContextTestUtil.newEmptyEvaluationContext(); context.setValue("My Person", mapOf( entry("Full Name", "John Doe"), entry("Age", 47) )); Object result = qualRef.apply(context); LOG.debug("{}", result); @@ -456,7 +457,7 @@ void qualifiedName2() { CompiledFEELExpression qualRef = parseCodegen(inputExpression, mapOf(entry("My Person", personType) ) ); LOG.debug("{}", qualRef); - EvaluationContext context = CodegenTestUtil.newEmptyEvaluationContext(); + EvaluationContext context = EvaluationContextTestUtil.newEmptyEvaluationContext(); context.setValue("My Person", new MyPerson()); Object result = qualRef.apply(context); LOG.debug("{}", result); @@ -471,7 +472,7 @@ void qualifiedName3() { CompiledFEELExpression qualRef = parseCodegen(inputExpression, mapOf(entry("a date", dateType))); LOG.debug("{}", qualRef); - EvaluationContext context = CodegenTestUtil.newEmptyEvaluationContext(); + EvaluationContext context = EvaluationContextTestUtil.newEmptyEvaluationContext(); context.setValue("a date", LocalDate.of(2016, 8, 2)); Object result = qualRef.apply(context); LOG.debug("{}", result); diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/ForExpressionNodeTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/ForExpressionNodeTest.java index 290abe5132f..f09f03caa66 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/ForExpressionNodeTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/ForExpressionNodeTest.java @@ -26,7 +26,7 @@ import java.util.Map; import org.junit.jupiter.api.Test; -import org.kie.dmn.feel.codegen.feel11.CodegenTestUtil; +import org.kie.dmn.feel.util.EvaluationContextTestUtil; import org.kie.dmn.feel.lang.Type; import org.kie.dmn.feel.lang.types.BuiltInType; @@ -39,7 +39,7 @@ void evaluateSimpleArray() { IterationContextNode x = getIterationContextNode("x", getListNode("[ 1, 2, 3, 4 ]", Arrays.asList("1", "2", "3", "4")), "x in [ 1, 2, 3, 4 ]"); IterationContextNode y = getIterationContextNode("y", getNameRefNode(BuiltInType.UNKNOWN, "x"), "y in x"); ForExpressionNode forExpressionNode = new ForExpressionNode(Arrays.asList(x, y), getNameRefNode(BuiltInType.UNKNOWN, "y"), "for x in [ 1, 2, 3, 4 ], y in x return y"); - Object retrieved = forExpressionNode.evaluate(CodegenTestUtil.newEmptyEvaluationContext()); + Object retrieved = forExpressionNode.evaluate(EvaluationContextTestUtil.newEmptyEvaluationContext()); assertThat(retrieved).isInstanceOf(List.class).asList(). containsExactly(BigDecimal.ONE, BigDecimal.valueOf(2), BigDecimal.valueOf(3), BigDecimal.valueOf(4)); } @@ -52,7 +52,7 @@ void evaluateNestedArray() { IterationContextNode x = getIterationContextNode("x", getNestedListNode("[ [1, 2], [3, 4] ]", firstIterationContext), "x in [ [1, 2], [3, 4] ]"); IterationContextNode y = getIterationContextNode("y", getNameRefNode(BuiltInType.UNKNOWN, "x"), "y in x"); ForExpressionNode forExpressionNode = new ForExpressionNode(Arrays.asList(x, y), getNameRefNode(BuiltInType.UNKNOWN, "y"), "for x in [ [1, 2], [3, 4] ], y in x return y"); - Object retrieved = forExpressionNode.evaluate(CodegenTestUtil.newEmptyEvaluationContext()); + Object retrieved = forExpressionNode.evaluate(EvaluationContextTestUtil.newEmptyEvaluationContext()); assertThat(retrieved).isInstanceOf(List.class).asList(). containsExactly(BigDecimal.ONE, BigDecimal.valueOf(2), BigDecimal.valueOf(3), BigDecimal.valueOf(4)); diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/RangeTypeNodeTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/RangeTypeNodeTest.java new file mode 100644 index 00000000000..5662f88a8cf --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/RangeTypeNodeTest.java @@ -0,0 +1,51 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.dmn.feel.lang.ast; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.kie.dmn.feel.lang.types.GenRangeType; +import org.kie.dmn.feel.util.EvaluationContextTestUtil; +import org.kie.dmn.feel.util.MockVisitor; +import org.kie.dmn.feel.lang.types.BuiltInType; + +class RangeTypeNodeTest { + + @Test + void evaluate() { + final CTypeNode typeNode = new CTypeNode(BuiltInType.BOOLEAN); + final RangeTypeNode rangeTypeNode = new RangeTypeNode(typeNode, "sometext"); + Assertions.assertThat(rangeTypeNode.evaluate(EvaluationContextTestUtil.newEmptyEvaluationContext())).isInstanceOf(GenRangeType.class); + } + + @Test + void accept() { + final MockVisitor visitor = new MockVisitor(); + final RangeTypeNode rangeTypeNode = new RangeTypeNode(null, "sometext"); + Assertions.assertThat(rangeTypeNode.accept(visitor)).isSameAs(rangeTypeNode); + } + + @Test + void getGenTypeNode() { + final CTypeNode typeNode = new CTypeNode(BuiltInType.BOOLEAN); + final RangeTypeNode rangeTypeNode = new RangeTypeNode(typeNode, "sometext"); + Assertions.assertThat(rangeTypeNode.getGenericTypeNode()).isSameAs(typeNode); + } +} \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationUtilsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationUtilsTest.java index 226d2e1797d..43547f15081 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationUtilsTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ForIterationUtilsTest.java @@ -32,7 +32,7 @@ import org.mockito.ArgumentCaptor; import static org.assertj.core.api.Assertions.assertThat; -import static org.kie.dmn.feel.codegen.feel11.CodegenTestUtil.newEmptyEvaluationContext; +import static org.kie.dmn.feel.util.EvaluationContextTestUtil.newEmptyEvaluationContext; import static org.kie.dmn.feel.lang.ast.forexpressioniterators.ForIterationUtils.getForIteration; import static org.kie.dmn.feel.lang.ast.forexpressioniterators.ForIterationUtils.validateValues; import static org.kie.dmn.feel.lang.ast.forexpressioniterators.ForIterationUtils.valueMustBeValid; diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELCompilerTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELCompilerTest.java index 80502839d79..f3b34fef4f9 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELCompilerTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELCompilerTest.java @@ -25,7 +25,7 @@ import java.util.List; import org.junit.jupiter.api.Test; -import org.kie.dmn.feel.codegen.feel11.CodegenTestUtil; +import org.kie.dmn.feel.util.EvaluationContextTestUtil; import org.kie.dmn.feel.codegen.feel11.CompiledFEELExpression; import org.kie.dmn.feel.lang.EvaluationContext; import org.kie.dmn.feel.lang.FEELProperty; @@ -226,7 +226,7 @@ void filter_path_tricky1() { CompiledFEELExpression nameRef = CompilerUtils.parseInterpreted("[ {x:1, y:2}, {x:2, y:3} ][x]"); LOG.debug("{}", nameRef); - EvaluationContext context = CodegenTestUtil.newEmptyEvaluationContext(); + EvaluationContext context = EvaluationContextTestUtil.newEmptyEvaluationContext(); context.setValue("x", 2); Object result = nameRef.apply(context); LOG.debug("{}", result); @@ -239,7 +239,7 @@ void filter_path_tricky2() { CompiledFEELExpression nameRef = CompilerUtils.parseInterpreted("[ {x:1, y:2}, {x:2, y:3} ][x]"); LOG.debug("{}", nameRef); - EvaluationContext context = CodegenTestUtil.newEmptyEvaluationContext(); + EvaluationContext context = EvaluationContextTestUtil.newEmptyEvaluationContext(); context.setValue("x", false); Object result = nameRef.apply(context); LOG.debug("{}", result); @@ -410,7 +410,7 @@ void nameReference() { CompiledFEELExpression nameRef = parseInterpreted(inputExpression, mapOf(entry("someSimpleName", BuiltInType.STRING) ) ); LOG.debug("{}", nameRef); - EvaluationContext context = CodegenTestUtil.newEmptyEvaluationContext(); + EvaluationContext context = EvaluationContextTestUtil.newEmptyEvaluationContext(); context.setValue("someSimpleName", 123L); Object result = nameRef.apply(context); LOG.debug("{}", result); @@ -425,7 +425,7 @@ void qualifiedName() { CompiledFEELExpression qualRef = parseInterpreted(inputExpression, mapOf(entry("My Person", personType) ) ); LOG.debug("{}", qualRef); - EvaluationContext context = CodegenTestUtil.newEmptyEvaluationContext(); + EvaluationContext context = EvaluationContextTestUtil.newEmptyEvaluationContext(); context.setValue("My Person", mapOf( entry("Full Name", "John Doe"), entry("Age", 47) )); Object result = qualRef.apply(context); LOG.debug("{}", result); @@ -456,7 +456,7 @@ void qualifiedName2() { CompiledFEELExpression qualRef = parseInterpreted(inputExpression, mapOf(entry("My Person", personType) ) ); LOG.debug("{}", qualRef); - EvaluationContext context = CodegenTestUtil.newEmptyEvaluationContext(); + EvaluationContext context = EvaluationContextTestUtil.newEmptyEvaluationContext(); context.setValue("My Person", new MyPerson()); Object result = qualRef.apply(context); LOG.debug("{}", result); @@ -471,7 +471,7 @@ void qualifiedName3() { CompiledFEELExpression qualRef = parseInterpreted(inputExpression, mapOf(entry("a date", dateType))); LOG.debug("{}", qualRef); - EvaluationContext context = CodegenTestUtil.newEmptyEvaluationContext(); + EvaluationContext context = EvaluationContextTestUtil.newEmptyEvaluationContext(); context.setValue("a date", LocalDate.of(2016, 8, 2)); Object result = qualRef.apply(context); LOG.debug("{}", result); diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionHelperTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionHelperTest.java index 9143712030a..b8d51268fa7 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionHelperTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionHelperTest.java @@ -30,7 +30,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.kie.dmn.feel.codegen.feel11.CodegenTestUtil; +import org.kie.dmn.feel.util.EvaluationContextTestUtil; import org.kie.dmn.feel.lang.EvaluationContext; import org.kie.dmn.feel.lang.impl.NamedParameter; import org.kie.dmn.feel.runtime.FEELFunction; @@ -44,7 +44,7 @@ class BaseFEELFunctionHelperTest { @BeforeEach public void setUp() { - ctx = CodegenTestUtil.newEmptyEvaluationContext(); + ctx = EvaluationContextTestUtil.newEmptyEvaluationContext(); } @Test diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionTest.java index f5deff2214d..af32bcc9c6a 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BaseFEELFunctionTest.java @@ -31,7 +31,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.kie.dmn.feel.codegen.feel11.CodegenTestUtil; +import org.kie.dmn.feel.util.EvaluationContextTestUtil; import org.kie.dmn.feel.lang.EvaluationContext; import org.kie.dmn.feel.lang.ast.BaseNode; import org.kie.dmn.feel.lang.ast.InfixOpNode; @@ -51,7 +51,7 @@ class BaseFEELFunctionTest { @BeforeEach public void setUp() { - ctx = CodegenTestUtil.newEmptyEvaluationContext(); + ctx = EvaluationContextTestUtil.newEmptyEvaluationContext(); } @Test diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ScorerHelperTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ScorerHelperTest.java index 71f4bf6934f..9cc4098d8cb 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ScorerHelperTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ScorerHelperTest.java @@ -24,7 +24,7 @@ import java.util.Random; import org.junit.jupiter.api.Test; -import org.kie.dmn.feel.codegen.feel11.CodegenTestUtil; +import org.kie.dmn.feel.util.EvaluationContextTestUtil; import org.kie.dmn.feel.lang.EvaluationContext; import org.kie.dmn.feel.lang.impl.NamedParameter; @@ -443,7 +443,7 @@ void typeIdentityOfParameters() { retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); assertThat(retrieved).isEqualTo(500); - originalInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), "String" }; + originalInput = new Object[] { EvaluationContextTestUtil.newEmptyEvaluationContext(), "String" }; adaptedInput = originalInput; parameterTypes = new Class[] { EvaluationContext.class, String.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); @@ -451,7 +451,7 @@ void typeIdentityOfParameters() { assertThat(retrieved).isEqualTo(1000); originalInput = new Object[] { "String" }; - adaptedInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), "String" }; + adaptedInput = new Object[] { EvaluationContextTestUtil.newEmptyEvaluationContext(), "String" }; parameterTypes = new Class[] { EvaluationContext.class, String.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); @@ -465,7 +465,7 @@ void typeIdentityOfParameters() { assertThat(retrieved).isEqualTo(0); originalInput = new Object[] { "String", 34 }; - adaptedInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), "String", 34 }; + adaptedInput = new Object[] { EvaluationContextTestUtil.newEmptyEvaluationContext(), "String", 34 }; parameterTypes = new Class[] { EvaluationContext.class, String.class, Integer.class }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); @@ -491,7 +491,7 @@ void typeIdentityOfParameters() { retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); assertThat(retrieved).isEqualTo(0); - originalInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), "String" }; + originalInput = new Object[] { EvaluationContextTestUtil.newEmptyEvaluationContext(), "String" }; parameterTypes = new Class[] { EvaluationContext.class, Integer.class }; compares = new ScoreHelper.Compares(originalInput, null, parameterTypes); retrieved = ScoreHelper.typeIdentityOfParameters.applyAsInt(compares); @@ -531,20 +531,20 @@ void coercedToVarargs() { retrieved = ScoreHelper.coercedToVarargs.applyAsInt(compares); assertThat(retrieved).isEqualTo(coercedToVarargsScore); - originalInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), "String", 34 }; + originalInput = new Object[] { EvaluationContextTestUtil.newEmptyEvaluationContext(), "String", 34 }; adaptedInput = new Object[] { new Object[] {"String", 34} }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, null); retrieved = ScoreHelper.coercedToVarargs.applyAsInt(compares); assertThat(retrieved).isEqualTo(coercedToVarargsScore); originalInput = new Object[] { "String", 34 }; - adaptedInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), new Object[] {"String", 34} }; + adaptedInput = new Object[] { EvaluationContextTestUtil.newEmptyEvaluationContext(), new Object[] {"String", 34} }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, null); retrieved = ScoreHelper.coercedToVarargs.applyAsInt(compares); assertThat(retrieved).isEqualTo(coercedToVarargsScore); - originalInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), "String", 34 }; - adaptedInput = new Object[] { CodegenTestUtil.newEmptyEvaluationContext(), new Object[] {"String", 34} }; + originalInput = new Object[] { EvaluationContextTestUtil.newEmptyEvaluationContext(), "String", 34 }; + adaptedInput = new Object[] { EvaluationContextTestUtil.newEmptyEvaluationContext(), new Object[] {"String", 34} }; compares = new ScoreHelper.Compares(originalInput, adaptedInput, null); retrieved = ScoreHelper.coercedToVarargs.applyAsInt(compares); assertThat(retrieved).isEqualTo(coercedToVarargsScore); diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/CompilerUtils.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/CompilerUtils.java index c201ec39ca3..3c645548ed0 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/CompilerUtils.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/CompilerUtils.java @@ -25,7 +25,6 @@ import com.github.javaparser.ast.stmt.BlockStmt; import org.antlr.v4.runtime.tree.ParseTree; import org.kie.dmn.feel.codegen.feel11.ASTCompilerVisitor; -import org.kie.dmn.feel.codegen.feel11.CodegenTestUtil; import org.kie.dmn.feel.codegen.feel11.CompiledFEELExpression; import org.kie.dmn.feel.codegen.feel11.CompilerBytecodeLoader; import org.kie.dmn.feel.lang.EvaluationContext; @@ -100,7 +99,7 @@ public static CompiledFEELExpression parseInterpreted(String input, Map { + @Override + public Object visit(ASTNode n) { + return null; + } + + @Override + public Object visit(AtLiteralNode n) { + return n; + } + + @Override + public Object visit(BetweenNode n) { + return n; + } + + @Override + public Object visit(BooleanNode n) { + return n; + } + + @Override + public Object visit(ContextNode n) { + return n; + } + + @Override + public Object visit(ContextEntryNode n) { + return n; + } + + @Override + public Object visit(ContextTypeNode n) { + return n; + } + + @Override + public Object visit(CTypeNode n) { + return n; + } + + @Override + public Object visit(DashNode n) { + return n; + } + + @Override + public Object visit(FilterExpressionNode n) { + return n; + } + + @Override + public Object visit(ForExpressionNode n) { + return n; + } + + @Override + public Object visit(FormalParameterNode n) { + return n; + } + + @Override + public Object visit(FunctionDefNode n) { + return n; + } + + @Override + public Object visit(FunctionTypeNode n) { + return n; + } + + @Override + public Object visit(FunctionInvocationNode n) { + return n; + } + + @Override + public Object visit(IfExpressionNode n) { + return n; + } + + @Override + public Object visit(InfixOpNode n) { + return n; + } + + @Override + public Object visit(InNode n) { + return n; + } + + @Override + public Object visit(InstanceOfNode n) { + return n; + } + + @Override + public Object visit(IterationContextNode n) { + return n; + } + + @Override + public Object visit(ListNode n) { + return n; + } + + @Override + public Object visit(ListTypeNode n) { + return n; + } + + @Override + public Object visit(NameDefNode n) { + return n; + } + + @Override + public Object visit(NamedParameterNode n) { + return n; + } + + @Override + public Object visit(NameRefNode n) { + return n; + } + + @Override + public Object visit(NullNode n) { + return n; + } + + @Override + public Object visit(NumberNode n) { + return n; + } + + @Override + public Object visit(PathExpressionNode n) { + return n; + } + + @Override + public Object visit(QualifiedNameNode n) { + return n; + } + + @Override + public Object visit(QuantifiedExpressionNode n) { + return n; + } + + @Override + public Object visit(RangeNode n) { + return n; + } + + @Override + public Object visit(RangeTypeNode n) { + return n; + } + + @Override + public Object visit(SignedUnaryNode n) { + return n; + } + + @Override + public Object visit(StringNode n) { + return n; + } + + @Override + public Object visit(UnaryTestListNode n) { + return n; + } + + @Override + public Object visit(UnaryTestNode n) { + return n; + } +} From e793f7eaea52c116c37ee7b9fa3de6a972cf2623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20Zim=C3=A1nyi?= Date: Mon, 14 Oct 2024 12:59:06 +0200 Subject: [PATCH 5/5] Change method of accept method test. --- .../dmn/feel/lang/ast/RangeTypeNodeTest.java | 7 +- .../org/kie/dmn/feel/util/MockVisitor.java | 240 ------------------ 2 files changed, 4 insertions(+), 243 deletions(-) delete mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/MockVisitor.java diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/RangeTypeNodeTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/RangeTypeNodeTest.java index 5662f88a8cf..aaa5a3caa02 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/RangeTypeNodeTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/RangeTypeNodeTest.java @@ -23,8 +23,8 @@ import org.junit.jupiter.api.Test; import org.kie.dmn.feel.lang.types.GenRangeType; import org.kie.dmn.feel.util.EvaluationContextTestUtil; -import org.kie.dmn.feel.util.MockVisitor; import org.kie.dmn.feel.lang.types.BuiltInType; +import org.mockito.Mockito; class RangeTypeNodeTest { @@ -37,9 +37,10 @@ void evaluate() { @Test void accept() { - final MockVisitor visitor = new MockVisitor(); + final Visitor visitor = Mockito.spy(Visitor.class); final RangeTypeNode rangeTypeNode = new RangeTypeNode(null, "sometext"); - Assertions.assertThat(rangeTypeNode.accept(visitor)).isSameAs(rangeTypeNode); + rangeTypeNode.accept(visitor); + Mockito.verify(visitor).visit(rangeTypeNode); } @Test diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/MockVisitor.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/MockVisitor.java deleted file mode 100644 index ddac3a66bb8..00000000000 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/MockVisitor.java +++ /dev/null @@ -1,240 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.kie.dmn.feel.util; - -import org.kie.dmn.feel.lang.ast.ASTNode; -import org.kie.dmn.feel.lang.ast.AtLiteralNode; -import org.kie.dmn.feel.lang.ast.BetweenNode; -import org.kie.dmn.feel.lang.ast.BooleanNode; -import org.kie.dmn.feel.lang.ast.CTypeNode; -import org.kie.dmn.feel.lang.ast.ContextEntryNode; -import org.kie.dmn.feel.lang.ast.ContextNode; -import org.kie.dmn.feel.lang.ast.ContextTypeNode; -import org.kie.dmn.feel.lang.ast.DashNode; -import org.kie.dmn.feel.lang.ast.FilterExpressionNode; -import org.kie.dmn.feel.lang.ast.ForExpressionNode; -import org.kie.dmn.feel.lang.ast.FormalParameterNode; -import org.kie.dmn.feel.lang.ast.FunctionDefNode; -import org.kie.dmn.feel.lang.ast.FunctionInvocationNode; -import org.kie.dmn.feel.lang.ast.FunctionTypeNode; -import org.kie.dmn.feel.lang.ast.IfExpressionNode; -import org.kie.dmn.feel.lang.ast.InNode; -import org.kie.dmn.feel.lang.ast.InfixOpNode; -import org.kie.dmn.feel.lang.ast.InstanceOfNode; -import org.kie.dmn.feel.lang.ast.IterationContextNode; -import org.kie.dmn.feel.lang.ast.ListNode; -import org.kie.dmn.feel.lang.ast.ListTypeNode; -import org.kie.dmn.feel.lang.ast.NameDefNode; -import org.kie.dmn.feel.lang.ast.NameRefNode; -import org.kie.dmn.feel.lang.ast.NamedParameterNode; -import org.kie.dmn.feel.lang.ast.NullNode; -import org.kie.dmn.feel.lang.ast.NumberNode; -import org.kie.dmn.feel.lang.ast.PathExpressionNode; -import org.kie.dmn.feel.lang.ast.QualifiedNameNode; -import org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode; -import org.kie.dmn.feel.lang.ast.RangeNode; -import org.kie.dmn.feel.lang.ast.RangeTypeNode; -import org.kie.dmn.feel.lang.ast.SignedUnaryNode; -import org.kie.dmn.feel.lang.ast.StringNode; -import org.kie.dmn.feel.lang.ast.UnaryTestListNode; -import org.kie.dmn.feel.lang.ast.UnaryTestNode; -import org.kie.dmn.feel.lang.ast.Visitor; - -public class MockVisitor implements Visitor { - @Override - public Object visit(ASTNode n) { - return null; - } - - @Override - public Object visit(AtLiteralNode n) { - return n; - } - - @Override - public Object visit(BetweenNode n) { - return n; - } - - @Override - public Object visit(BooleanNode n) { - return n; - } - - @Override - public Object visit(ContextNode n) { - return n; - } - - @Override - public Object visit(ContextEntryNode n) { - return n; - } - - @Override - public Object visit(ContextTypeNode n) { - return n; - } - - @Override - public Object visit(CTypeNode n) { - return n; - } - - @Override - public Object visit(DashNode n) { - return n; - } - - @Override - public Object visit(FilterExpressionNode n) { - return n; - } - - @Override - public Object visit(ForExpressionNode n) { - return n; - } - - @Override - public Object visit(FormalParameterNode n) { - return n; - } - - @Override - public Object visit(FunctionDefNode n) { - return n; - } - - @Override - public Object visit(FunctionTypeNode n) { - return n; - } - - @Override - public Object visit(FunctionInvocationNode n) { - return n; - } - - @Override - public Object visit(IfExpressionNode n) { - return n; - } - - @Override - public Object visit(InfixOpNode n) { - return n; - } - - @Override - public Object visit(InNode n) { - return n; - } - - @Override - public Object visit(InstanceOfNode n) { - return n; - } - - @Override - public Object visit(IterationContextNode n) { - return n; - } - - @Override - public Object visit(ListNode n) { - return n; - } - - @Override - public Object visit(ListTypeNode n) { - return n; - } - - @Override - public Object visit(NameDefNode n) { - return n; - } - - @Override - public Object visit(NamedParameterNode n) { - return n; - } - - @Override - public Object visit(NameRefNode n) { - return n; - } - - @Override - public Object visit(NullNode n) { - return n; - } - - @Override - public Object visit(NumberNode n) { - return n; - } - - @Override - public Object visit(PathExpressionNode n) { - return n; - } - - @Override - public Object visit(QualifiedNameNode n) { - return n; - } - - @Override - public Object visit(QuantifiedExpressionNode n) { - return n; - } - - @Override - public Object visit(RangeNode n) { - return n; - } - - @Override - public Object visit(RangeTypeNode n) { - return n; - } - - @Override - public Object visit(SignedUnaryNode n) { - return n; - } - - @Override - public Object visit(StringNode n) { - return n; - } - - @Override - public Object visit(UnaryTestListNode n) { - return n; - } - - @Override - public Object visit(UnaryTestNode n) { - return n; - } -}