From 0d89fa10b0accdb455b65ed20f4ee7acd1c61009 Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Fri, 21 Jun 2024 10:24:59 +0200 Subject: [PATCH 01/13] =?UTF-8?q?[incubator-kie-issues#1325]=20In=20functi?= =?UTF-8?q?ons=20with=20a=20`scale`=20parameter,=20that=20must=20be=20in?= =?UTF-8?q?=20the=20range=20[=E2=88=926111..6176]=20(#5993)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix Round functions scale parameter range. * Adding Ceiling, Decimal and Floor functions * Tests * Tests * Tests * Tests --- .../runtime/functions/CeilingFunction.java | 14 +++- .../runtime/functions/DecimalFunction.java | 4 + .../feel/runtime/functions/FloorFunction.java | 14 +++- .../functions/extended/RoundDownFunction.java | 4 + .../extended/RoundHalfDownFunction.java | 4 + .../extended/RoundHalfUpFunction.java | 4 + .../functions/extended/RoundUpFunction.java | 4 + .../dmn/feel/runtime/FEELFunctionsTest.java | 18 +++++ .../runtime/KieFEELExtendedFunctionsTest.java | 10 ++- .../functions/CeilingFunctionTest.java | 10 ++- .../functions/DecimalFunctionTest.java | 6 ++ .../runtime/functions/FloorFunctionTest.java | 8 ++ .../extended/RoundDownFunctionTest.java | 79 +++++++++++++++++++ .../extended/RoundHalfDownFunctionTest.java | 79 +++++++++++++++++++ .../extended/RoundHalfUpFunctionTest.java | 79 +++++++++++++++++++ .../extended/RoundUpFunctionTest.java | 79 +++++++++++++++++++ 16 files changed, 412 insertions(+), 4 deletions(-) create mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundDownFunctionTest.java create mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfDownFunctionTest.java create mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfUpFunctionTest.java create mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundUpFunctionTest.java diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CeilingFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CeilingFunction.java index c3e3a577ea0..6d632bf93db 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CeilingFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CeilingFunction.java @@ -35,9 +35,21 @@ public CeilingFunction() { } public FEELFnResult invoke(@ParameterName( "n" ) BigDecimal n) { + return invoke(n, BigDecimal.ZERO); + } + + public FEELFnResult invoke(@ParameterName( "n" ) BigDecimal n, @ParameterName( "scale" ) BigDecimal scale) { if ( n == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "n", "cannot be null")); } - return FEELFnResult.ofResult( n.setScale( 0, RoundingMode.CEILING ) ); + if ( scale == null ) { + return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "cannot be null")); + } + // Based on Table 76: Semantics of numeric functions, the scale is in range −6111 .. 6176 + if (scale.compareTo(BigDecimal.valueOf(-6111)) < 0 || scale.compareTo(BigDecimal.valueOf(6176)) > 0) { + return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "must be in range between -6111 to 6176.")); + } + + return FEELFnResult.ofResult( n.setScale( scale.intValue(), RoundingMode.CEILING ) ); } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DecimalFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DecimalFunction.java index 2e77aa3ceb9..b62266cda32 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DecimalFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DecimalFunction.java @@ -41,6 +41,10 @@ public FEELFnResult invoke(@ParameterName( "n" ) BigDecimal n, @Para if ( scale == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "cannot be null")); } + // Based on Table 76: Semantics of numeric functions, the scale is in range −6111 .. 6176 + if (scale.compareTo(BigDecimal.valueOf(-6111)) < 0 || scale.compareTo(BigDecimal.valueOf(6176)) > 0) { + return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "must be in range between -6111 to 6176.")); + } return FEELFnResult.ofResult( n.setScale( scale.intValue(), RoundingMode.HALF_EVEN ) ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/FloorFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/FloorFunction.java index e3c0cd906f8..f2b26d40ce6 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/FloorFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/FloorFunction.java @@ -34,9 +34,21 @@ public FloorFunction() { } public FEELFnResult invoke(@ParameterName( "n" ) BigDecimal n) { + return invoke(n, BigDecimal.ZERO); + } + + public FEELFnResult invoke(@ParameterName( "n" ) BigDecimal n, @ParameterName( "scale" ) BigDecimal scale) { if ( n == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "n", "cannot be null")); } - return FEELFnResult.ofResult( n.setScale( 0, RoundingMode.FLOOR ) ); + if ( scale == null ) { + return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "cannot be null")); + } + // Based on Table 76: Semantics of numeric functions, the scale is in range −6111 .. 6176 + if (scale.compareTo(BigDecimal.valueOf(-6111)) < 0 || scale.compareTo(BigDecimal.valueOf(6176)) > 0) { + return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "must be in range between -6111 to 6176.")); + } + + return FEELFnResult.ofResult( n.setScale( scale.intValue(), RoundingMode.FLOOR ) ); } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundDownFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundDownFunction.java index 9178dcb6b72..0a67a7d31f7 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundDownFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundDownFunction.java @@ -50,6 +50,10 @@ public FEELFnResult invoke(@ParameterName( "n" ) BigDecimal n, @Para if ( scale == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "cannot be null")); } + // Based on Table 76: Semantics of numeric functions, the scale is in range −6111 .. 6176 + if (scale.compareTo(BigDecimal.valueOf(-6111)) < 0 || scale.compareTo(BigDecimal.valueOf(6176)) > 0) { + return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "must be in range between -6111 to 6176.")); + } return FEELFnResult.ofResult( n.setScale( scale.intValue(), RoundingMode.DOWN ) ); } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfDownFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfDownFunction.java index 266ec0935fd..5d5648cc55d 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfDownFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfDownFunction.java @@ -50,6 +50,10 @@ public FEELFnResult invoke(@ParameterName( "n" ) BigDecimal n, @Para if ( scale == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "cannot be null")); } + // Based on Table 76: Semantics of numeric functions, the scale is in range −6111 .. 6176 + if (scale.compareTo(BigDecimal.valueOf(-6111)) < 0 || scale.compareTo(BigDecimal.valueOf(6176)) > 0) { + return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "must be in range between -6111 to 6176.")); + } return FEELFnResult.ofResult( n.setScale( scale.intValue(), RoundingMode.HALF_DOWN ) ); } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfUpFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfUpFunction.java index c18f71b35dc..990f19c5dd2 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfUpFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfUpFunction.java @@ -50,6 +50,10 @@ public FEELFnResult invoke(@ParameterName( "n" ) BigDecimal n, @Para if ( scale == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "cannot be null")); } + // Based on Table 76: Semantics of numeric functions, the scale is in range −6111 .. 6176 + if (scale.compareTo(BigDecimal.valueOf(-6111)) < 0 || scale.compareTo(BigDecimal.valueOf(6176)) > 0) { + return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "must be in range between -6111 to 6176.")); + } return FEELFnResult.ofResult( n.setScale( scale.intValue(), RoundingMode.HALF_UP ) ); } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundUpFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundUpFunction.java index 1a3388724e2..e17c90d57df 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundUpFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundUpFunction.java @@ -50,6 +50,10 @@ public FEELFnResult invoke(@ParameterName( "n" ) BigDecimal n, @Para if ( scale == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "cannot be null")); } + // Based on Table 76: Semantics of numeric functions, the scale is in range −6111 .. 6176 + if (scale.compareTo(BigDecimal.valueOf(-6111)) < 0 || scale.compareTo(BigDecimal.valueOf(6176)) > 0) { + return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "must be in range between -6111 to 6176.")); + } return FEELFnResult.ofResult( n.setScale( scale.intValue(), RoundingMode.UP ) ); } } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELFunctionsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELFunctionsTest.java index 9314eb357b0..4ec562e84f9 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELFunctionsTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELFunctionsTest.java @@ -156,13 +156,31 @@ private static Collection data() { { "decimal( 1.5, 0 )", new BigDecimal("2") , null}, { "decimal( 2.5, 0 )", new BigDecimal("2") , null}, { "decimal( null, 0 )", null , FEELEvent.Severity.ERROR}, + { "decimal( 1.555, 2 )", new BigDecimal("1.56") , null}, + { "decimal( -1.56, 1 )", new BigDecimal("-1.6") , null}, + { "decimal( 1.5, 6177 )", null , FEELEvent.Severity.ERROR}, + { "decimal( 1.5, -6122 )", null , FEELEvent.Severity.ERROR}, + { "decimal( 1.5, null )", null , FEELEvent.Severity.ERROR}, + { "decimal( null, null )", null , FEELEvent.Severity.ERROR}, { "floor( 1.5 )", new BigDecimal("1") , null}, { "floor( -1.5 )", new BigDecimal("-2") , null}, { "floor( null )", null , FEELEvent.Severity.ERROR}, + { "floor( 1.555, 2 )", new BigDecimal("1.55") , null}, + { "floor( -1.55, 1 )", new BigDecimal("-1.6") , null}, + { "floor( 1.5, 6177 )", null , FEELEvent.Severity.ERROR}, + { "floor( 1.5, -6122 )", null , FEELEvent.Severity.ERROR}, + { "floor( 1.5, null )", null , FEELEvent.Severity.ERROR}, + { "floor( null, null )", null , FEELEvent.Severity.ERROR}, { "ceiling( 1.5 )", new BigDecimal("2") , null}, { "ceiling( -1.5 )", new BigDecimal("-1") , null}, { "ceiling( null )", null , FEELEvent.Severity.ERROR}, { "ceiling( n : 1.5 )", new BigDecimal("2") , null}, + { "ceiling( 1.555, 2 )", new BigDecimal("1.56") , null}, + { "ceiling( -1.56, 1 )", new BigDecimal("-1.5") , null}, + { "ceiling( 1.5, 6177 )", null , FEELEvent.Severity.ERROR}, + { "ceiling( 1.5, -6122 )", null , FEELEvent.Severity.ERROR}, + { "ceiling( 1.5, null )", null , FEELEvent.Severity.ERROR}, + { "ceiling( null, null )", null , FEELEvent.Severity.ERROR}, { "abs( 10 )", new BigDecimal("10") , null}, { "abs( -10 )", new BigDecimal("10") , null}, { "abs( n: -10 )", new BigDecimal("10") , null}, diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/KieFEELExtendedFunctionsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/KieFEELExtendedFunctionsTest.java index 9997089de5d..050681eb83d 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/KieFEELExtendedFunctionsTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/KieFEELExtendedFunctionsTest.java @@ -73,18 +73,26 @@ private static Collection data() { { "round up(-5.5, 0) ", new BigDecimal("-6"), null }, { "round up(1.121, 2) ", new BigDecimal("1.13"), null }, { "round up(-1.126, 2) ", new BigDecimal("-1.13"), null }, + { "round up(1.126, 6177) ", null, FEELEvent.Severity.ERROR }, + { "round up(1.126, -6112) ", null, FEELEvent.Severity.ERROR }, { "round down(5.5, 0)", new BigDecimal("5"), null }, { "round down(-5.5, 0) ", new BigDecimal("-5"), null }, { "round down(1.121, 2) ", new BigDecimal("1.12"), null }, - { "round down (-1.126, 2) ", new BigDecimal("-1.12"), null }, + { "round down(-1.126, 2) ", new BigDecimal("-1.12"), null }, + { "round down(1.126, 6177) ", null, FEELEvent.Severity.ERROR }, + { "round down(1.126, -6112) ", null, FEELEvent.Severity.ERROR }, { "round half up(5.5, 0)", new BigDecimal("6"), null }, { "round half up(-5.5, 0) ", new BigDecimal("-6"), null }, { "round half up(1.121, 2) ", new BigDecimal("1.12"), null }, { "round half up(-1.126, 2) ", new BigDecimal("-1.13"), null }, + { "round half up(1.126, 6177) ", null, FEELEvent.Severity.ERROR }, + { "round half up(1.126, -6112) ", null, FEELEvent.Severity.ERROR }, { "round half down(5.5, 0)", new BigDecimal("5"), null }, { "round half down(-5.5, 0) ", new BigDecimal("-5"), null }, { "round half down(1.121, 2) ", new BigDecimal("1.12"), null }, { "round half down(-1.126, 2) ", new BigDecimal("-1.13"), null }, + { "round half down(1.126, 6177) ", null, FEELEvent.Severity.ERROR }, + { "round half down(1.126, -6112) ", null, FEELEvent.Severity.ERROR }, { "after( 1, 2 )", Boolean.FALSE, null }, { "after( date(\"2018-08-15\"), date(\"2018-07-25\") )", Boolean.TRUE, null }, { "after( date(\"2018-08-15\"), [date(\"2018-07-25\")..date(\"2018-08-10\")] )", Boolean.TRUE, null }, diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CeilingFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CeilingFunctionTest.java index e53d8ebcff6..386b053ddda 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CeilingFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CeilingFunctionTest.java @@ -36,7 +36,9 @@ void setUp() { @Test void invokeNull() { FunctionTestUtil.assertResultError(ceilingFunction.invoke(null), InvalidParametersEvent.class); - } + FunctionTestUtil.assertResultError(ceilingFunction.invoke((BigDecimal) null, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(ceilingFunction.invoke(BigDecimal.ONE, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(ceilingFunction.invoke(null, BigDecimal.ONE), InvalidParametersEvent.class); } @Test void invokeZero() { @@ -52,4 +54,10 @@ void invokePositive() { void invokeNegative() { FunctionTestUtil.assertResultBigDecimal(ceilingFunction.invoke(BigDecimal.valueOf(-10.2)), BigDecimal.valueOf(-10)); } + + @Test + void invokeOutRangeScale() { + FunctionTestUtil.assertResultError(ceilingFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(ceilingFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)), InvalidParametersEvent.class); + } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DecimalFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DecimalFunctionTest.java index 7078d6306cd..8e335cf1d1d 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DecimalFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DecimalFunctionTest.java @@ -64,4 +64,10 @@ void invokeRoundingOdd() { void invokeLargerScale() { FunctionTestUtil.assertResult(decimalFunction.invoke(BigDecimal.valueOf(10.123456789), BigDecimal.valueOf(6)), BigDecimal.valueOf(10.123457)); } + + @Test + void invokeOutRangeScale() { + FunctionTestUtil.assertResultError(decimalFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(decimalFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)), InvalidParametersEvent.class); + } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FloorFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FloorFunctionTest.java index 615b0aa0c75..bf84075681a 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FloorFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FloorFunctionTest.java @@ -36,6 +36,9 @@ void setUp() { @Test void invokeNull() { FunctionTestUtil.assertResultError(floorFunction.invoke(null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(floorFunction.invoke((BigDecimal) null, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(floorFunction.invoke(BigDecimal.ONE, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(floorFunction.invoke(null, BigDecimal.ONE), InvalidParametersEvent.class); } @Test @@ -53,4 +56,9 @@ void invokeNegative() { FunctionTestUtil.assertResultBigDecimal(floorFunction.invoke(BigDecimal.valueOf(-10.2)), BigDecimal.valueOf(-11)); } + @Test + void invokeOutRangeScale() { + FunctionTestUtil.assertResultError(floorFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(floorFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)), InvalidParametersEvent.class); + } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundDownFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundDownFunctionTest.java new file mode 100644 index 00000000000..37e4742f759 --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundDownFunctionTest.java @@ -0,0 +1,79 @@ +/** + * 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.runtime.functions.extended; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; +import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; + +import java.math.BigDecimal; + +class RoundDownFunctionTest { + + private RoundDownFunction roundDownFunction; + + @BeforeEach + void setUp() { + roundDownFunction = new RoundDownFunction(); + } + + @Test + void invokeNull() { + FunctionTestUtil.assertResultError(roundDownFunction.invoke(null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundDownFunction.invoke((BigDecimal) null, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundDownFunction.invoke(BigDecimal.ONE, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundDownFunction.invoke(null, BigDecimal.ONE), InvalidParametersEvent.class); + } + + @Test + void invokeRoundingUp() { + FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.27)), BigDecimal.valueOf(10)); + FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.27), BigDecimal.ONE), BigDecimal.valueOf(10.2)); + } + + @Test + void invokeRoundingDown() { + FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.24)), BigDecimal.valueOf(10)); + FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.24), BigDecimal.ONE), BigDecimal.valueOf(10.2)); + } + + @Test + void invokeRoundingEven() { + FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.25)), BigDecimal.valueOf(10)); + FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.25), BigDecimal.ONE), BigDecimal.valueOf(10.2)); + } + + @Test + void invokeRoundingOdd() { + FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.35)), BigDecimal.valueOf(10)); + FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.35), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + } + + @Test + void invokeLargerScale() { + FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.123456789), BigDecimal.valueOf(6)), BigDecimal.valueOf(10.123456)); + } + + @Test + void invokeOutRangeScale() { + FunctionTestUtil.assertResultError(roundDownFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundDownFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)), InvalidParametersEvent.class); + } +} \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfDownFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfDownFunctionTest.java new file mode 100644 index 00000000000..d91b548c14b --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfDownFunctionTest.java @@ -0,0 +1,79 @@ +/** + * 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.runtime.functions.extended; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; +import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; + +import java.math.BigDecimal; + +class RoundHalfDownFunctionTest { + + private RoundHalfDownFunction roundHalfDownFunction; + + @BeforeEach + void setUp() { + roundHalfDownFunction = new RoundHalfDownFunction(); + } + + @Test + void invokeNull() { + FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke(null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke((BigDecimal) null, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke(BigDecimal.ONE, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke(null, BigDecimal.ONE), InvalidParametersEvent.class); + } + + @Test + void invokeRoundingUp() { + FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.27)), BigDecimal.valueOf(10)); + FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.27), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + } + + @Test + void invokeRoundingDown() { + FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.24)), BigDecimal.valueOf(10)); + FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.24), BigDecimal.ONE), BigDecimal.valueOf(10.2)); + } + + @Test + void invokeRoundingEven() { + FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.25)), BigDecimal.valueOf(10)); + FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.25), BigDecimal.ONE), BigDecimal.valueOf(10.2)); + } + + @Test + void invokeRoundingOdd() { + FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.35)), BigDecimal.valueOf(10)); + FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.35), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + } + + @Test + void invokeLargerScale() { + FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.123456789), BigDecimal.valueOf(6)), BigDecimal.valueOf(10.123457)); + } + + @Test + void invokeOutRangeScale() { + FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)), InvalidParametersEvent.class); + } +} \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfUpFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfUpFunctionTest.java new file mode 100644 index 00000000000..a5afd7a5013 --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfUpFunctionTest.java @@ -0,0 +1,79 @@ +/** + * 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.runtime.functions.extended; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; +import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; + +import java.math.BigDecimal; + +class RoundHalfUpFunctionTest { + + private RoundHalfUpFunction roundHalfUpFunction; + + @BeforeEach + void setUp() { + roundHalfUpFunction = new RoundHalfUpFunction(); + } + + @Test + void invokeNull() { + FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke(null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke((BigDecimal) null, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke(BigDecimal.ONE, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke(null, BigDecimal.ONE), InvalidParametersEvent.class); + } + + @Test + void invokeRoundingUp() { + FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.27)), BigDecimal.valueOf(10)); + FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.27), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + } + + @Test + void invokeRoundingDown() { + FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.24)), BigDecimal.valueOf(10)); + FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.24), BigDecimal.ONE), BigDecimal.valueOf(10.2)); + } + + @Test + void invokeRoundingEven() { + FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.25)), BigDecimal.valueOf(10)); + FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.25), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + } + + @Test + void invokeRoundingOdd() { + FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.35)), BigDecimal.valueOf(10)); + FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.35), BigDecimal.ONE), BigDecimal.valueOf(10.4)); + } + + @Test + void invokeLargerScale() { + FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.123456789), BigDecimal.valueOf(6)), BigDecimal.valueOf(10.123457)); + } + + @Test + void invokeOutRangeScale() { + FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)), InvalidParametersEvent.class); + } +} \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundUpFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundUpFunctionTest.java new file mode 100644 index 00000000000..2175fe8f5c7 --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundUpFunctionTest.java @@ -0,0 +1,79 @@ +/** + * 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.runtime.functions.extended; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; +import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; + +import java.math.BigDecimal; + +class RoundUpFunctionTest { + + private RoundUpFunction roundUpFunction; + + @BeforeEach + void setUp() { + roundUpFunction = new RoundUpFunction(); + } + + @Test + void invokeNull() { + FunctionTestUtil.assertResultError(roundUpFunction.invoke(null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundUpFunction.invoke((BigDecimal) null, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundUpFunction.invoke(BigDecimal.ONE, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundUpFunction.invoke(null, BigDecimal.ONE), InvalidParametersEvent.class); + } + + @Test + void invokeRoundingUp() { + FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.27)), BigDecimal.valueOf(11)); + FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.27), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + } + + @Test + void invokeRoundingDown() { + FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.24)), BigDecimal.valueOf(11)); + FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.24), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + } + + @Test + void invokeRoundingEven() { + FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.25)), BigDecimal.valueOf(11)); + FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.25), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + } + + @Test + void invokeRoundingOdd() { + FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.35)), BigDecimal.valueOf(11)); + FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.35), BigDecimal.ONE), BigDecimal.valueOf(10.4)); + } + + @Test + void invokeLargerScale() { + FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.123456789), BigDecimal.valueOf(6)), BigDecimal.valueOf(10.123457)); + } + + @Test + void invokeOutRangeScale() { + FunctionTestUtil.assertResultError(roundUpFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundUpFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)), InvalidParametersEvent.class); + } +} \ No newline at end of file From e892d71dec3e5de790fee8b31f55f26668aa16f3 Mon Sep 17 00:00:00 2001 From: Mario Fusco Date: Fri, 21 Jun 2024 10:25:46 +0200 Subject: [PATCH 02/13] [KIE-1339] fix Drools reproducible build also when running the complete test-suite (#5999) --- .../drools/core/util/KeyStoreHelperTest.java | 12 ++++++++++++ .../DefaultKieSessionFromFileExample.java | 14 ++++++-------- ...aultKieSessionFromByteArrayExampleTest.java | 18 ++++++++---------- .../KieModuleFromMultipleFilesExample.java | 14 ++++++-------- .../kiemodulemodel/KieModuleModelExample.java | 14 ++++++-------- .../NamedKieSessionFromFileExample.java | 14 ++++++-------- 6 files changed, 44 insertions(+), 42 deletions(-) diff --git a/drools-core/src/test/java/org/drools/core/util/KeyStoreHelperTest.java b/drools-core/src/test/java/org/drools/core/util/KeyStoreHelperTest.java index aa8b95b33a7..50868fc9997 100755 --- a/drools-core/src/test/java/org/drools/core/util/KeyStoreHelperTest.java +++ b/drools-core/src/test/java/org/drools/core/util/KeyStoreHelperTest.java @@ -18,6 +18,7 @@ */ package org.drools.core.util; +import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -35,6 +36,7 @@ import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpec; +import org.junit.AfterClass; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -52,6 +54,16 @@ public class KeyStoreHelperTest { private static final String KEY_PASSWORD = "keypwd"; private static final String KEY_PHRASE = "secretkey"; + @AfterClass + public static void cleanup() { + try { + new File(KEYSTORE_JCEKS_FILENAME).delete(); + } catch (Exception e) { + // ignore + } + + } + @Test public void testSignDataWithPrivateKey() throws UnsupportedEncodingException, UnrecoverableKeyException, diff --git a/drools-examples-api/default-kiesession-from-file/src/main/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromFileExample.java b/drools-examples-api/default-kiesession-from-file/src/main/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromFileExample.java index 4022a96c58a..f2466e388dc 100644 --- a/drools-examples-api/default-kiesession-from-file/src/main/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromFileExample.java +++ b/drools-examples-api/default-kiesession-from-file/src/main/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromFileExample.java @@ -18,6 +18,9 @@ */ package org.drools.example.api.defaultkiesessionfromfile; +import java.io.File; +import java.io.PrintStream; + import org.kie.api.KieServices; import org.kie.api.builder.KieModule; import org.kie.api.builder.KieRepository; @@ -26,9 +29,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.PrintStream; - public class DefaultKieSessionFromFileExample { @@ -69,8 +69,7 @@ public static File getFile(String exampleName) { File folder = new File("drools-examples-api").getAbsoluteFile(); File exampleFolder = null; while (folder != null) { - exampleFolder = new File(folder, - exampleName); + exampleFolder = new File(folder, exampleName); if (exampleFolder.exists()) { break; } @@ -80,14 +79,13 @@ public static File getFile(String exampleName) { if (exampleFolder != null) { - File targetFolder = new File(exampleFolder, - "target"); + File targetFolder = new File(exampleFolder, "target"); if (!targetFolder.exists()) { throw new RuntimeException("The target folder does not exist, please build project " + exampleName + " first"); } for (String str : targetFolder.list()) { - if (str.startsWith(exampleName) && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { + if (str.startsWith(exampleName) && str.endsWith(".jar") && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { return new File(targetFolder, str); } } diff --git a/drools-examples-api/default-kiesession-from-file/src/test/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromByteArrayExampleTest.java b/drools-examples-api/default-kiesession-from-file/src/test/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromByteArrayExampleTest.java index 60c732e59a7..d43598a218a 100644 --- a/drools-examples-api/default-kiesession-from-file/src/test/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromByteArrayExampleTest.java +++ b/drools-examples-api/default-kiesession-from-file/src/test/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromByteArrayExampleTest.java @@ -18,6 +18,12 @@ */ package org.drools.example.api.defaultkiesessionfromfile; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.PrintStream; + import org.junit.Test; import org.kie.api.KieServices; import org.kie.api.builder.KieModule; @@ -25,12 +31,6 @@ import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieSession; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.io.PrintStream; - import static org.junit.Assert.assertEquals; public class DefaultKieSessionFromByteArrayExampleTest { @@ -105,8 +105,7 @@ public static File getFile(String exampleName) { File folder = new File("drools-examples-api").getAbsoluteFile(); File exampleFolder = null; while (folder != null) { - exampleFolder = new File(folder, - exampleName); + exampleFolder = new File(folder, exampleName); if (exampleFolder.exists()) { break; } @@ -116,8 +115,7 @@ public static File getFile(String exampleName) { if (exampleFolder != null) { - File targetFolder = new File(exampleFolder, - "target"); + File targetFolder = new File(exampleFolder, "target"); if (!targetFolder.exists()) { throw new RuntimeException("The target folder does not exist, please build project " + exampleName + " first"); } diff --git a/drools-examples-api/kie-module-from-multiple-files/src/main/java/org/drools/example/api/kiemodulefrommultiplefiles/KieModuleFromMultipleFilesExample.java b/drools-examples-api/kie-module-from-multiple-files/src/main/java/org/drools/example/api/kiemodulefrommultiplefiles/KieModuleFromMultipleFilesExample.java index c058e3a3842..19ac711b914 100644 --- a/drools-examples-api/kie-module-from-multiple-files/src/main/java/org/drools/example/api/kiemodulefrommultiplefiles/KieModuleFromMultipleFilesExample.java +++ b/drools-examples-api/kie-module-from-multiple-files/src/main/java/org/drools/example/api/kiemodulefrommultiplefiles/KieModuleFromMultipleFilesExample.java @@ -18,6 +18,9 @@ */ package org.drools.example.api.kiemodulefrommultiplefiles; +import java.io.File; +import java.io.PrintStream; + import org.kie.api.KieServices; import org.kie.api.builder.KieModule; import org.kie.api.builder.KieRepository; @@ -27,9 +30,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.PrintStream; - public class KieModuleFromMultipleFilesExample { @@ -76,8 +76,7 @@ public static File getFile(String exampleName) { File folder = new File( KieModuleFromMultipleFilesExample.class.getProtectionDomain().getCodeSource().getLocation().getPath() ); File exampleFolder = null; while (folder != null) { - exampleFolder = new File(folder, - exampleName); + exampleFolder = new File(folder, exampleName); if (exampleFolder.exists()) { break; } @@ -87,14 +86,13 @@ public static File getFile(String exampleName) { if (exampleFolder != null) { - File targetFolder = new File(exampleFolder, - "target"); + File targetFolder = new File(exampleFolder, "target"); if (!targetFolder.exists()) { throw new RuntimeException("The target folder does not exist, please build project " + exampleName + " first"); } for (String str : targetFolder.list()) { - if (str.startsWith(exampleName) && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { + if (str.startsWith(exampleName) && str.endsWith(".jar") && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { return new File(targetFolder, str); } } diff --git a/drools-examples-api/kiemodulemodel-example/src/main/java/org/drools/example/api/kiemodulemodel/KieModuleModelExample.java b/drools-examples-api/kiemodulemodel-example/src/main/java/org/drools/example/api/kiemodulemodel/KieModuleModelExample.java index fc6c1c158ed..363d426c9de 100644 --- a/drools-examples-api/kiemodulemodel-example/src/main/java/org/drools/example/api/kiemodulemodel/KieModuleModelExample.java +++ b/drools-examples-api/kiemodulemodel-example/src/main/java/org/drools/example/api/kiemodulemodel/KieModuleModelExample.java @@ -18,6 +18,9 @@ */ package org.drools.example.api.kiemodulemodel; +import java.io.File; +import java.io.PrintStream; + import org.drools.base.util.Drools; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; @@ -31,9 +34,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.PrintStream; - public class KieModuleModelExample { private static final Logger LOG = LoggerFactory.getLogger(KieModuleModelExample.class); @@ -115,8 +115,7 @@ public static File getFile(String exampleName) { File folder = new File("drools-examples-api").getAbsoluteFile(); File exampleFolder = null; while (folder != null) { - exampleFolder = new File(folder, - exampleName); + exampleFolder = new File(folder, exampleName); if (exampleFolder.exists()) { break; } @@ -126,14 +125,13 @@ public static File getFile(String exampleName) { if (exampleFolder != null) { - File targetFolder = new File(exampleFolder, - "target"); + File targetFolder = new File(exampleFolder, "target"); if (!targetFolder.exists()) { throw new RuntimeException("The target folder does not exist, please build project " + exampleName + " first"); } for (String str : targetFolder.list()) { - if (str.startsWith(exampleName) && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { + if (str.startsWith(exampleName) && str.endsWith(".jar") && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { return new File(targetFolder, str); } } diff --git a/drools-examples-api/named-kiesession-from-file/src/main/java/org/drools/example/api/namedkiesessionfromfile/NamedKieSessionFromFileExample.java b/drools-examples-api/named-kiesession-from-file/src/main/java/org/drools/example/api/namedkiesessionfromfile/NamedKieSessionFromFileExample.java index 330b4e4afd9..56784896361 100644 --- a/drools-examples-api/named-kiesession-from-file/src/main/java/org/drools/example/api/namedkiesessionfromfile/NamedKieSessionFromFileExample.java +++ b/drools-examples-api/named-kiesession-from-file/src/main/java/org/drools/example/api/namedkiesessionfromfile/NamedKieSessionFromFileExample.java @@ -18,6 +18,9 @@ */ package org.drools.example.api.namedkiesessionfromfile; +import java.io.File; +import java.io.PrintStream; + import org.kie.api.KieServices; import org.kie.api.builder.KieModule; import org.kie.api.builder.KieRepository; @@ -26,9 +29,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.PrintStream; - public class NamedKieSessionFromFileExample { @@ -69,8 +69,7 @@ public static File getFile(String exampleName) { File folder = new File("drools-examples-api").getAbsoluteFile(); File exampleFolder = null; while (folder != null) { - exampleFolder = new File(folder, - exampleName); + exampleFolder = new File(folder, exampleName); if (exampleFolder.exists()) { break; } @@ -80,14 +79,13 @@ public static File getFile(String exampleName) { if (exampleFolder != null) { - File targetFolder = new File(exampleFolder, - "target"); + File targetFolder = new File(exampleFolder, "target"); if (!targetFolder.exists()) { throw new RuntimeException("The target folder does not exist, please build project " + exampleName + " first"); } for (String str : targetFolder.list()) { - if (str.startsWith(exampleName) && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { + if (str.startsWith(exampleName) && str.endsWith(".jar") && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { return new File(targetFolder, str); } } From 041bc9dbcdc5a70d4d4dd6bb073ef5581200e9ad Mon Sep 17 00:00:00 2001 From: Gabriele Cardosi Date: Fri, 21 Jun 2024 10:36:55 +0200 Subject: [PATCH 03/13] [incubator-kie-issues#69] Time with a timezone is parsed into type Parsed (#5996) * [incubator-kie-issues#69] Creating ZonedOffsetTime decorator and related tests * [incubator-kie-issues#69] Fixing test to consider different offsets based on current date * [incubator-kie-issues#69] Fix as per pr suggestion * [incubator-kie-issues#69] Fix as per pr suggestion * [incubator-kie-issues#69] Fixing formatting on ZoneTime --------- Co-authored-by: Gabriele-Cardosi --- .../kie/dmn/feel/lang/types/BuiltInType.java | 3 +- .../kie/dmn/feel/runtime/custom/ZoneTime.java | 240 +++++++++++++++++ .../feel/runtime/functions/TimeFunction.java | 16 ++ .../functions/extended/TimeFunction.java | 9 + .../java/org/kie/dmn/feel/util/TypeUtil.java | 3 + .../runtime/FEELDateTimeDurationTest.java | 34 +++ .../dmn/feel/runtime/custom/ZoneTimeTest.java | 243 ++++++++++++++++++ .../ComposingDifferentFunctionsTest.java | 2 +- .../runtime/functions/TimeFunctionTest.java | 12 + 9 files changed, 560 insertions(+), 2 deletions(-) create mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/custom/ZoneTime.java create mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/types/BuiltInType.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/types/BuiltInType.java index cec0f953b78..fc28acc0011 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/types/BuiltInType.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/types/BuiltInType.java @@ -44,6 +44,7 @@ import org.kie.dmn.feel.runtime.FEELFunction; import org.kie.dmn.feel.runtime.Range; import org.kie.dmn.feel.runtime.UnaryTest; +import org.kie.dmn.feel.runtime.custom.ZoneTime; public enum BuiltInType implements SimpleType { @@ -124,7 +125,7 @@ public static Type determineTypeFromInstance( Object o ) { return STRING; } else if( o instanceof LocalDate ) { return DATE; - } else if( o instanceof LocalTime || o instanceof OffsetTime ) { + } else if( o instanceof LocalTime || o instanceof OffsetTime || o instanceof ZoneTime) { return TIME; } else if( o instanceof ZonedDateTime || o instanceof OffsetDateTime || o instanceof LocalDateTime ) { return DATE_TIME; diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/custom/ZoneTime.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/custom/ZoneTime.java new file mode 100644 index 00000000000..8cdbb64d337 --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/custom/ZoneTime.java @@ -0,0 +1,240 @@ +/** + * 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.runtime.custom; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetTime; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.ResolverStyle; +import java.time.temporal.Temporal; +import java.time.temporal.TemporalAdjuster; +import java.time.temporal.TemporalAmount; +import java.time.temporal.TemporalField; +import java.time.temporal.TemporalQueries; +import java.time.temporal.TemporalQuery; +import java.time.temporal.TemporalUnit; +import java.time.temporal.ValueRange; +import java.util.Objects; + +import static java.time.temporal.ChronoField.HOUR_OF_DAY; +import static java.time.temporal.ChronoField.MINUTE_OF_HOUR; +import static java.time.temporal.ChronoField.NANO_OF_SECOND; +import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; + +/** + * This class is meant as sort-of decorator over OffsetTime, that is a final class. + * It is used to provide both time and zoneid information, replacing the Parsed instance that would be + * returned otherwise by + * {@link org.kie.dmn.feel.runtime.functions.TimeFunction#invoke(String)} + */ +public final class ZoneTime + implements Temporal, + TemporalAdjuster, + Comparable, + Serializable { + + private final OffsetTime offsetTime; + private final ZoneId zoneId; + private final String stringRepresentation; + private final boolean hasSeconds; + + public static final DateTimeFormatter ZONED_OFFSET_WITH_SECONDS; + public static final DateTimeFormatter ZONED_OFFSET_WITHOUT_SECONDS; + + static { + ZONED_OFFSET_WITHOUT_SECONDS = new DateTimeFormatterBuilder() + .parseCaseInsensitive() + .appendValue(HOUR_OF_DAY, 2) + .appendLiteral(':') + .appendValue(MINUTE_OF_HOUR, 2) + .appendLiteral("@") + .appendZoneRegionId() + .toFormatter() + .withResolverStyle(ResolverStyle.STRICT); + + ZONED_OFFSET_WITH_SECONDS = new DateTimeFormatterBuilder() + .parseCaseInsensitive() + .appendValue(HOUR_OF_DAY, 2) + .appendLiteral(':') + .appendValue(MINUTE_OF_HOUR, 2) + .appendLiteral(':') + .appendValue(SECOND_OF_MINUTE, 2) + .optionalStart() + .appendFraction(NANO_OF_SECOND, 0, 9, true) + .optionalStart() + .appendLiteral("@") + .appendZoneRegionId() + .optionalEnd() + .toFormatter() + .withResolverStyle(ResolverStyle.STRICT); + } + + public static ZoneTime of(LocalTime localTime, ZoneId zoneId, boolean hasSeconds) { + return new ZoneTime(localTime, zoneId, hasSeconds); + } + + public ZoneId getZoneId() { + return zoneId; + } + + public String getTimezone() { + return zoneId.getId(); + } + + private ZoneTime(LocalTime localTime, ZoneId zoneId, boolean hasSeconds) { + ZoneOffset offset = zoneId.getRules().getOffset(LocalDateTime.now()); + this.offsetTime = OffsetTime.of(localTime, offset); + this.zoneId = zoneId; + this.hasSeconds = hasSeconds; + this.stringRepresentation = String.format("%s@%s", localTime, zoneId); + } + + // package default for testing purpose + ZoneTime(OffsetTime offsetTime, ZoneId zoneId, boolean hasSeconds) { + this.offsetTime = offsetTime; + this.zoneId = zoneId; + this.hasSeconds = hasSeconds; + String offsetString = offsetTime.toString().replace(offsetTime.getOffset().toString(), ""); + this.stringRepresentation = String.format("%s@%s", offsetString, zoneId); + } + + @Override + public int compareTo(ZoneTime o) { + return offsetTime.compareTo(o.offsetTime); + } + + @Override + public Temporal with(TemporalField field, long newValue) { + return getNewZoneOffset(offsetTime.with(field, newValue)); + } + + @Override + public Temporal with(TemporalAdjuster adjuster) { + return getNewZoneOffset(offsetTime.with(adjuster)); + } + + @Override + public Temporal plus(long amountToAdd, TemporalUnit unit) { + return getNewZoneOffset(offsetTime.plus(amountToAdd, unit)); + } + + @Override + public Temporal plus(TemporalAmount amount) { + return getNewZoneOffset(offsetTime.plus(amount)); + } + + @Override + public Temporal minus(long amountToSubtract, TemporalUnit unit) { + return + getNewZoneOffset(offsetTime.minus(amountToSubtract, unit)); + } + + @Override + public Temporal minus(TemporalAmount amount) { + return + getNewZoneOffset(offsetTime.minus(amount)); + } + + @Override + public long until(Temporal endExclusive, TemporalUnit unit) { + return offsetTime.until(endExclusive, unit); + } + + @Override + public boolean isSupported(TemporalUnit unit) { + return offsetTime.isSupported(unit); + } + + @Override + public boolean isSupported(TemporalField field) { + return offsetTime.isSupported(field); + } + + @Override + public long getLong(TemporalField field) { + return offsetTime.getLong(field); + } + + @Override + public Temporal adjustInto(Temporal temporal) { + return offsetTime.adjustInto(temporal); + } + + @Override + public R query(TemporalQuery query) { + if (query == TemporalQueries.zoneId() || query == TemporalQueries.zone()) { + return (R) zoneId; + } else if (query.toString().contains(DateTimeFormatterBuilder.class.getCanonicalName())) { + return (R) zoneId; + } else { + return offsetTime.query(query); + } + } + + @Override + public ValueRange range(TemporalField field) { + return offsetTime.range(field); + } + + @Override + public int get(TemporalField field) { + return offsetTime.get(field); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof ZoneTime that)) { + return false; + } + return Objects.equals(offsetTime, that.offsetTime) && Objects.equals(zoneId, that.zoneId); + } + + @Override + public int hashCode() { + return Objects.hash(offsetTime, zoneId); + } + + @Override + public String toString() { + return stringRepresentation; + } + + public String format() { + return hasSeconds ? ZONED_OFFSET_WITH_SECONDS.format(this) : ZONED_OFFSET_WITHOUT_SECONDS.format(this); + } + + // Package access for testing purpose + OffsetTime getOffsetTime() { + return offsetTime; + } + + // Package access for testing purpose + ZoneTime getNewZoneOffset(OffsetTime offset) { + return new ZoneTime(offset, zoneId, hasSeconds); + } + +} diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/TimeFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/TimeFunction.java index 93564f637d0..7bcd6e76d50 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/TimeFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/TimeFunction.java @@ -32,9 +32,11 @@ import java.time.temporal.ChronoField; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalQueries; +import java.util.regex.Pattern; import org.kie.dmn.api.feel.runtime.events.FEELEvent; import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; +import org.kie.dmn.feel.runtime.custom.ZoneTime; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; public class TimeFunction @@ -43,6 +45,10 @@ public class TimeFunction public static final TimeFunction INSTANCE = new TimeFunction(); public static final DateTimeFormatter FEEL_TIME; + + private static final String timePatternString = "[0-9]{2}[:]{1}[0-9]{2}[:]{1}[0-9]{2}"; + private static final Pattern timePattern = Pattern.compile(timePatternString); + static { FEEL_TIME = new DateTimeFormatterBuilder().parseCaseInsensitive() .append(DateTimeFormatter.ISO_LOCAL_TIME) @@ -77,6 +83,12 @@ public FEELFnResult invoke(@ParameterName("from") String val) // if it does not contain any zone information at all, then I know for certain is a local time. LocalTime asLocalTime = parsed.query(LocalTime::from); return FEELFnResult.ofResult(asLocalTime); + } else if (parsed.query(TemporalQueries.zone()) != null) { + boolean hasSeconds = timeStringWithSeconds(val); + LocalTime asLocalTime = parsed.query(LocalTime::from); + ZoneId zoneId = parsed.query(TemporalQueries.zone()); + ZoneTime zoneTime = ZoneTime.of(asLocalTime, zoneId, hasSeconds); + return FEELFnResult.ofResult(zoneTime); } return FEELFnResult.ofResult(parsed); @@ -85,6 +97,10 @@ public FEELFnResult invoke(@ParameterName("from") String val) } } + public static boolean timeStringWithSeconds(String val) { + return timePattern.matcher(val).find(); + } + private static final BigDecimal NANO_MULT = BigDecimal.valueOf( 1000000000 ); public FEELFnResult invoke( diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/TimeFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/TimeFunction.java index 6433dcdb836..744474dd615 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/TimeFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/TimeFunction.java @@ -34,6 +34,7 @@ import java.time.temporal.TemporalQueries; import org.kie.dmn.api.feel.runtime.events.FEELEvent; +import org.kie.dmn.feel.runtime.custom.ZoneTime; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; import org.kie.dmn.feel.runtime.functions.BuiltInFunctions; @@ -42,6 +43,8 @@ import org.kie.dmn.feel.runtime.functions.FEELFnResult; import org.kie.dmn.feel.runtime.functions.ParameterName; +import static org.kie.dmn.feel.runtime.functions.TimeFunction.timeStringWithSeconds; + public class TimeFunction extends BaseFEELFunction { public static final TimeFunction INSTANCE = new TimeFunction(); @@ -81,6 +84,12 @@ public FEELFnResult invoke(@ParameterName("from") String val) // if it does not contain any zone information at all, then I know for certain is a local time. LocalTime asLocalTime = parsed.query(LocalTime::from); return FEELFnResult.ofResult(asLocalTime); + } else if (parsed.query(TemporalQueries.zone()) != null) { + boolean hasZeroSeconds = timeStringWithSeconds(val); + LocalTime asLocalTime = parsed.query(LocalTime::from); + ZoneId zoneId = parsed.query(TemporalQueries.zone()); + ZoneTime zoneTime = ZoneTime.of(asLocalTime, zoneId, hasZeroSeconds); + return FEELFnResult.ofResult(zoneTime); } return FEELFnResult.ofResult(parsed); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/TypeUtil.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/TypeUtil.java index e53a4924574..7af8ad5d7af 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/TypeUtil.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/TypeUtil.java @@ -37,6 +37,7 @@ import org.kie.dmn.feel.lang.types.impl.ComparablePeriod; import org.kie.dmn.feel.runtime.Range; +import org.kie.dmn.feel.runtime.custom.ZoneTime; import org.kie.dmn.feel.runtime.functions.DateAndTimeFunction; import org.kie.dmn.feel.runtime.functions.DateFunction; import org.kie.dmn.feel.runtime.functions.TimeFunction; @@ -74,6 +75,8 @@ public static String formatValue(final Object val, final boolean wrapForCodeUsag return formatDate((LocalDate) val, wrapForCodeUsage); } else if (val instanceof LocalTime || val instanceof OffsetTime) { return formatTimeString(TimeFunction.FEEL_TIME.format((TemporalAccessor) val), wrapForCodeUsage); + } else if (val instanceof ZoneTime zoneTime) { + return formatTimeString(zoneTime.format(), wrapForCodeUsage); } else if (val instanceof LocalDateTime || val instanceof OffsetDateTime) { return formatDateTimeString(DateAndTimeFunction.FEEL_DATE_TIME.format((TemporalAccessor) val), wrapForCodeUsage); } else if (val instanceof ZonedDateTime) { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELDateTimeDurationTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELDateTimeDurationTest.java index 157e96149cb..c22d69e572a 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELDateTimeDurationTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELDateTimeDurationTest.java @@ -36,6 +36,9 @@ import org.kie.dmn.api.feel.runtime.events.FEELEvent; import org.kie.dmn.feel.lang.FEELDialect; import org.kie.dmn.feel.lang.types.impl.ComparablePeriod; +import org.kie.dmn.feel.runtime.custom.ZoneTime; + +import static org.kie.dmn.feel.runtime.functions.TimeFunction.timeStringWithSeconds; public class FEELDateTimeDurationTest extends BaseFEELTest { @@ -88,6 +91,9 @@ private static Collection data() { { "(@\"13:20:00@Etc/UTC\").timezone", "Etc/UTC" , null}, { "(@\"13:20:00@Etc/GMT\").timezone", "Etc/GMT" , null}, { "-duration( \"P2Y2M\" )", ComparablePeriod.parse( "-P2Y2M" ) , null}, + {"@\"2023-10-10T10:31:00@Australia/Melbourne\"", DateTimeFormatter.ISO_DATE_TIME.parse("2023-10-10T10" + + ":31+11:00[Australia/Melbourne]", ZonedDateTime::from), null}, + {"@\"10:15:00@Australia/Melbourne\"", ZoneTime.of(LocalTime.of(10, 15), ZoneId.of("Australia/Melbourne"), true), null}, // comparison operators { "duration( \"P1Y6M\" ) = duration( \"P1Y6M\" )", Boolean.TRUE , null}, @@ -184,6 +190,27 @@ private static Collection data() { { "time( 22, 57, 00, duration(\"PT5H\")) + duration( \"PT1H1M\" )", OffsetTime.of( 23, 58, 0, 0, ZoneOffset.ofHours( 5 ) ) , null}, { "duration( \"PT1H1M\" ) + time( 22, 57, 00, duration(\"PT5H\"))", OffsetTime.of( 23, 58, 0, 0, ZoneOffset.ofHours( 5 ) ) , null}, + { "@\"P1D\" + @\"2023-10-10T10:31:00@Australia/Melbourne\"", DateTimeFormatter.ISO_DATE_TIME.parse("2023-10-11T10" + + ":31+11:00[Australia/Melbourne]", ZonedDateTime::from), null}, + { "@\"-P1D\" + @\"2023-10-10T10:31:00@Australia/Melbourne\"", DateTimeFormatter.ISO_DATE_TIME.parse("2023-10-09T10" + + ":31+11:00[Australia/Melbourne]", ZonedDateTime::from), null}, + { "@\"P1D\" + @\"10:15:00@Australia/Melbourne\"", getCorrectZoneTime("10:15", "Australia/Melbourne"), null}, + { "@\"-P1D\" + @\"10:15:00@Australia/Melbourne\"", getCorrectZoneTime("10:15", "Australia/Melbourne"), null}, + { "@\"PT1H\" + @\"10:15:00@Australia/Melbourne\"", getCorrectZoneTime("11:15", "Australia/Melbourne"), null}, + { "@\"-PT1H\" + @\"10:15:00@Australia/Melbourne\"", getCorrectZoneTime("09:15", "Australia/Melbourne"), null}, + + + { "@\"10:15:00@Australia/Melbourne\" + @\"P1D\"", getCorrectZoneTime("10:15", "Australia/Melbourne"), null}, + { "@\"10:15:00@Australia/Melbourne\" - @\"P1D\"", getCorrectZoneTime("10:15", "Australia/Melbourne"), null}, + { "@\"10:15:00@Australia/Melbourne\" + @\"-P1D\"", getCorrectZoneTime("10:15", "Australia/Melbourne"), null}, + { "@\"10:15:00@Australia/Melbourne\" + @\"PT1H\"", getCorrectZoneTime("11:15", "Australia/Melbourne"), null}, + { "@\"10:15:00@Australia/Melbourne\" - @\"PT1H\"", getCorrectZoneTime("09:15", "Australia/Melbourne"), null}, + { "@\"10:15:00@Australia/Melbourne\" + @\"-PT1H\"", getCorrectZoneTime("09:15", "Australia/Melbourne"), null}, + + {"string(@\"10:10@Australia/Melbourne\" + @\"PT1H\")", "11:10@Australia/Melbourne", null}, + {"string(@\"10:10:00@Australia/Melbourne\" + @\"PT1H\")", "11:10:00@Australia/Melbourne", null}, + + // TODO support for zones - fix when timezones solved out (currently returns ZonedDateTime) // { "date and time(\"2016-07-29T05:48:23.765-05:00\") + duration( \"P1Y1M\" ) ", OffsetDateTime.of(2017, 8, 29, 5, 48, 23, 765000000, ZoneOffset.ofHours( -5 )), null}, // { "date and time(\"2016-07-29T05:48:23.765-05:00\") + duration( \"P1DT1H1M\" ) ", OffsetDateTime.of(2016, 7, 30, 6, 49, 23, 765000000, ZoneOffset.ofHours( -5 )), null}, @@ -305,4 +332,11 @@ private static Collection data() { }; return addAdditionalParameters(cases, false); } + + private static ZoneTime getCorrectZoneTime(String baseTime, String zone) { + LocalTime localTime = DateTimeFormatter.ISO_TIME.parse(baseTime, LocalTime::from ); + ZoneId zoneId = ZoneId.of(zone); + return ZoneTime.of(localTime, zoneId, timeStringWithSeconds(baseTime)); + } + } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java new file mode 100644 index 00000000000..81245b662e4 --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java @@ -0,0 +1,243 @@ +/** + * 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.runtime.custom; + +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetTime; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoField; +import java.time.temporal.ChronoUnit; +import java.time.temporal.TemporalAdjuster; +import java.time.temporal.TemporalAmount; +import java.time.temporal.TemporalQueries; +import java.util.Arrays; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; +import static org.kie.dmn.feel.runtime.custom.ZoneTime.ZONED_OFFSET_WITH_SECONDS; +import static org.kie.dmn.feel.runtime.custom.ZoneTime.ZONED_OFFSET_WITHOUT_SECONDS; + +class ZoneTimeTest { + + private static final String REFERENCED_TIME = "10:15:00"; + private static final String REFERENCED_ZONE = "Australia/Melbourne"; + private static LocalTime localTime ; + private static ZoneId zoneId; + private static OffsetTime offsetTime; + private static ZoneTime zoneTime; + + @BeforeAll + static void setUpClass() { + localTime = DateTimeFormatter.ISO_TIME.parse(REFERENCED_TIME, LocalTime::from ); + zoneId = ZoneId.of(REFERENCED_ZONE); + offsetTime = getCorrectOffsetTime(); + zoneTime = ZoneTime.of(localTime, zoneId, true); + } + + @Test + void of() { + ZoneTime retrieved = ZoneTime.of(localTime, zoneId, true); + assertNotNull(retrieved); + assertEquals(offsetTime, retrieved.getOffsetTime()); + assertEquals(zoneId, retrieved.getZoneId()); + } + + + @Test + void getTimezone() { + assertEquals(REFERENCED_ZONE, zoneTime.getTimezone()); + } + + @Test + void compareTo() { + ZoneTime toCompare = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse("09:34:31", LocalTime::from), zoneId, false); + OffsetTime comparison = toCompare.getOffsetTime(); + assertEquals(offsetTime.compareTo(comparison), zoneTime.compareTo(toCompare)); + + } + + @Test + void withTemporalField() { + ZoneTime expected = new ZoneTime(offsetTime.with(ChronoField.HOUR_OF_DAY, 3), zoneId, false); + assertEquals(expected, zoneTime.with(ChronoField.HOUR_OF_DAY, 3)); + } + + @Test + void withTemporalAdjuster() { + TemporalAdjuster adjuster = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse("09:34:31", LocalTime::from), zoneId + , false); + ZoneTime expected = new ZoneTime(offsetTime.with(adjuster), zoneId, false); + assertEquals(expected, zoneTime.with(adjuster)); + adjuster = DateTimeFormatter.ISO_TIME.parse("09:34:31", LocalTime::from ); + expected = new ZoneTime(offsetTime.with(adjuster), zoneId, false); + assertEquals(expected, zoneTime.with(adjuster)); + } + + + @Test + void plusLong() { + ZoneTime expected = new ZoneTime(offsetTime.plus(3, ChronoUnit.HOURS), zoneId, false); + assertEquals(expected, zoneTime.plus(3, ChronoUnit.HOURS)); + } + + @Test + void plusTemporalAmount() { + TemporalAmount amount = Duration.of(23, ChronoUnit.MINUTES); + ZoneTime expected = new ZoneTime(offsetTime.plus(amount), zoneId, false); + assertEquals(expected, zoneTime.plus(amount)); + } + + @Test + void minusLong() { + ZoneTime expected = new ZoneTime(offsetTime.minus(3, ChronoUnit.HOURS), zoneId, false); + assertEquals(expected, zoneTime.minus(3, ChronoUnit.HOURS)); + } + + @Test + void minusTemporalAmount() { + TemporalAmount amount = Duration.of(23, ChronoUnit.MINUTES); + ZoneTime expected = new ZoneTime(offsetTime.minus(amount), zoneId, false); + assertEquals(expected, zoneTime.minus(amount)); + } + + @Test + void until() { + ZoneTime endExclusive = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse("09:34:31", LocalTime::from), zoneId, + false); + long expected = offsetTime.until(endExclusive, ChronoUnit.SECONDS); + long retrieved = zoneTime.until(endExclusive, ChronoUnit.SECONDS); + assertEquals(expected, retrieved); + } + + @Test + void isSupportedTemporalUnit() { + for (ChronoUnit unit : ChronoUnit.values()) { + assertEquals(offsetTime.isSupported(unit), zoneTime.isSupported(unit)); + } + } + + @Test + void isSupportedTemporalField() { + for (ChronoField field : ChronoField.values()) { + assertEquals(offsetTime.isSupported(field), zoneTime.isSupported(field)); + } + } + + @Test + void getLong() { + Arrays.stream(ChronoField.values()).filter(offsetTime::isSupported) + .forEach(field -> assertEquals(offsetTime.getLong(field), zoneTime.getLong(field))); + } + + @Test + void adjustInto() { + ZoneTime temporal = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse("09:34:31", LocalTime::from), zoneId, false); + assertEquals(offsetTime.adjustInto(temporal), zoneTime.adjustInto(temporal)); + } + + @Test + void query() { + assertEquals(zoneId, zoneTime.query(TemporalQueries.zoneId())); + assertEquals(zoneId, zoneTime.query(TemporalQueries.zone())); + assertEquals(offsetTime.query(TemporalQueries.localTime()), zoneTime.query(TemporalQueries.localTime())); + assertEquals(offsetTime.query(TemporalQueries.offset()), zoneTime.query(TemporalQueries.offset())); + } + + @Test + void range() { + Arrays.stream(ChronoField.values()).filter(offsetTime::isSupported) + .forEach(field -> assertEquals(offsetTime.range(field), zoneTime.range(field))); + } + + @Test + void get() { + Arrays.stream(ChronoField.values()) + .filter(offsetTime::isSupported) + .filter(field -> field != ChronoField.NANO_OF_DAY && field != ChronoField.MICRO_OF_DAY) // Unsupported by offsettime.get() + .forEach(field -> assertEquals(offsetTime.get(field), zoneTime.get(field))); + } + + @Test + void testEquals() { + ZoneTime toCompare = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse("09:34:31", LocalTime::from), zoneId, false); + assertFalse(zoneTime.equals(toCompare)); + toCompare = ZoneTime.of(localTime, zoneId, false); + assertTrue(zoneTime.equals(toCompare)); + } + + @Test + void testZONED_OFFSET_WITHOUT_SECONDS() { + String timeString = "09:34"; + ZoneTime toFormat = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse(timeString, LocalTime::from), zoneId, false); + String expected = String.format("%s@%s", timeString, REFERENCED_ZONE); + assertEquals(expected, ZONED_OFFSET_WITHOUT_SECONDS.format(toFormat)); + } + + @Test + void testZONED_OFFSET_WITH_SECONDS() { + String timeString = "09:34:34"; + ZoneTime toFormat = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse(timeString, LocalTime::from), zoneId, true); + String expected = String.format("%s@%s", timeString, REFERENCED_ZONE); + assertEquals(expected, ZONED_OFFSET_WITH_SECONDS.format(toFormat)); + + timeString = "09:34:00"; + toFormat = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse(timeString, LocalTime::from), zoneId, true); + expected = String.format("%s@%s", timeString, REFERENCED_ZONE); + assertEquals(expected, ZONED_OFFSET_WITH_SECONDS.format(toFormat)); + } + + @Test + void testFormatWithoutSeconds() { + String timeString = "09:34"; + ZoneTime toFormat = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse(timeString, LocalTime::from), zoneId, false); + String expected = String.format("%s@%s", timeString, REFERENCED_ZONE); + assertEquals(expected, toFormat.format()); + } + + @Test + void testFormatWithSeconds() { + String timeString = "09:34:00"; + ZoneTime toFormat = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse(timeString, LocalTime::from), zoneId, true); + String expected = String.format("%s@%s", timeString, REFERENCED_ZONE); + assertEquals(expected, toFormat.format()); + + timeString = "09:34:34"; + toFormat = ZoneTime.of(DateTimeFormatter.ISO_TIME.parse(timeString, LocalTime::from), zoneId, true); + expected = String.format("%s@%s", timeString, REFERENCED_ZONE); + assertEquals(expected, toFormat.format()); + } + + private static OffsetTime getCorrectOffsetTime() { + String correctOffsetTimeString = getCorrectOffsetTimeString(REFERENCED_TIME, REFERENCED_ZONE); + return DateTimeFormatter.ISO_TIME.parse( correctOffsetTimeString, OffsetTime::from ); + } + + private static String getCorrectOffsetTimeString(String baseTime, String zone) { + ZoneId zoneId = ZoneId.of(zone); + ZoneOffset offset = zoneId.getRules().getOffset(LocalDateTime.now()); + String diffOffset = offset.getId(); + return String.format("%s%s",baseTime, diffOffset); + } +} \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ComposingDifferentFunctionsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ComposingDifferentFunctionsTest.java index 21821635e99..9da075adf9d 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ComposingDifferentFunctionsTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ComposingDifferentFunctionsTest.java @@ -101,6 +101,6 @@ void composite5() { assertThat(timeOnDateTime.query(TemporalQueries.localTime())).isEqualTo(LocalTime.of(10, 20, 0)); assertThat(timeOnDateTime.query(TemporalQueries.zone())).isEqualTo(ZoneId.of("Europe/Paris")); - FunctionTestUtil.assertResult(stringFunction.invoke(timeOnDateTime), "10:20:00@Europe/Paris"); + FunctionTestUtil.assertResult(stringFunction.invoke(timeOnDateTime), "10:20@Europe/Paris"); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java index 7f0ba0729b4..6e12e099172 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java @@ -35,6 +35,8 @@ import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; class TimeFunctionTest { @@ -173,4 +175,14 @@ void invokeTimeUnitsParamsWithOffsetWithNanoseconds() { timeFunction.invoke(10, 43, BigDecimal.valueOf(15.154), Duration.ofHours(-1)), OffsetTime.of(10, 43, 15, 154000000, ZoneOffset.ofHours(-1))); } + + @Test + void timeStringWithSeconds() { + assertTrue(TimeFunction.timeStringWithSeconds("10:10:00@Australia/Melbourne")); + assertTrue(TimeFunction.timeStringWithSeconds("10:10:00+10:00")); + assertTrue(TimeFunction.timeStringWithSeconds("10:10:00:123")); + + assertFalse(TimeFunction.timeStringWithSeconds("10:10@Australia/Melbourne")); + assertFalse(TimeFunction.timeStringWithSeconds("10:10+10:00")); + } } \ No newline at end of file From 805eadf1dc0fdc448b0e3de047dfad467af9c990 Mon Sep 17 00:00:00 2001 From: Gabriele Cardosi Date: Mon, 24 Jun 2024 13:49:29 +0200 Subject: [PATCH 04/13] [incubator-kie-issues#1206] DMN - Remove code path duplication for code gen execution (#5978) * [incubator-kie-issues#1206_reimplement_visitor] Refactored BaseNode and Visitor signatures * [incubator-kie-issues#1206_reimplement_visitor] Restored BaseNode and Visitor signatures. Reordered Visitor methods * [incubator-kie-issues#1206_reimplement_visitor] WIP - broken * [incubator-kie-issues#1206_reimplement_visitor_new_node_approach] WIP - All node implemented. Broken * [incubator-kie-issues#1206_reimplement_visitor_new_node_approach] WIP - All node implemented. Broken * [incubator-kie-issues#1206_reimplement_visitor_new_node_approach] WIP - fixing tests * [incubator-kie-issues#1206_reimplement_visitor_new_node_approach] WIP - fixed FEELDateTimeDurationTest * [incubator-kie-issues#1206_reimplement_visitor_new_node_approach] WIP - fixed FEELStringOperationsTest * [incubator-kie-issues#1206_reimplement_visitor_new_node_approach] WIP - fixed FEELStaticTypeTest * [incubator-kie-issues#1206_reimplement_visitor_new_node_approach] WIP - fixed feel tests * [incubator-kie-issues#1206_reimplement_visitor_new_node_approach] Fixed alphanetwork support. ALl tests works * [incubator-kie-issues#1206_reimplement_visitor_new_node_approach] Improved codegen - singleton BASENODE instantiation * [incubator-kie-issues#1206_reimplement_visitor_new_node_approach] Improved codegen - singleton UNARY_TESTS instantiation * [incubator-kie-issues#1206] Restore log config * [incubator-kie-issues#1206] Removing unused methods/classes * [incubator-kie-issues#1206] Further cleanup/reorganization * [incubator-kie-issues#1206] Managing AliasFEELType * [incubator-kie-issues#1206] Managing AliasFEELType * [incubator-kie-issues#1206] Removing duplication of same nodes in codegen * [incubator-kie-issues#1206] Cleanup * [incubator-kie-issues#1206] Removed unused class * [incubator-kie-issues#1206] Fix as per PR request * [incubator-kie-issues#1206] Small refactoring/improvement --------- Co-authored-by: Gabriele-Cardosi --- ...etworkSupportInLargeDecisionTableTest.java | 7 - kie-dmn/kie-dmn-feel/pom.xml | 4 + .../codegen/feel11/ASTCompilerHelper.java | 650 +++++++++++++++ .../codegen/feel11/ASTCompilerVisitor.java | 767 +++++------------- .../feel/codegen/feel11/CodegenConstants.java | 83 ++ .../feel11/CompilationErrorNotifier.java | 31 + .../feel11/CompiledFEELExpression.java | 6 +- .../feel11/CompiledFEELSemanticMappings.java | 494 ----------- .../codegen/feel11/CompiledFEELSupport.java | 566 ------------- .../feel11/CompiledFEELUnaryTests.java | 2 +- .../feel11/CompilerBytecodeLoader.java | 155 ++-- .../dmn/feel/codegen/feel11/Constants.java | 33 +- .../kie/dmn/feel/codegen/feel11/Contexts.java | 55 -- .../codegen/feel11/DMNCodegenConstants.java | 175 ++++ .../codegen/feel11/DirectCompilerResult.java | 93 --- .../dmn/feel/codegen/feel11/Expressions.java | 472 ----------- .../kie/dmn/feel/codegen/feel11/FeelCtx.java | 72 -- .../dmn/feel/codegen/feel11/Functions.java | 95 --- .../codegen/feel11/ProcessedExpression.java | 51 +- .../codegen/feel11/ProcessedFEELUnit.java | 52 +- .../codegen/feel11/ProcessedUnaryTest.java | 47 +- .../codegen/feel11/SyntaxErrorListener.java | 45 + .../org/kie/dmn/feel/lang/SimpleType.java | 24 +- .../kie/dmn/feel/lang/ast/AtLiteralNode.java | 5 + .../org/kie/dmn/feel/lang/ast/BaseNode.java | 17 + .../kie/dmn/feel/lang/ast/BetweenNode.java | 7 + .../kie/dmn/feel/lang/ast/BooleanNode.java | 5 + .../org/kie/dmn/feel/lang/ast/CTypeNode.java | 10 +- .../dmn/feel/lang/ast/ContextEntryNode.java | 6 + .../kie/dmn/feel/lang/ast/ContextNode.java | 21 +- .../dmn/feel/lang/ast/ContextTypeNode.java | 5 + .../org/kie/dmn/feel/lang/ast/DashNode.java | 4 + .../feel/lang/ast/FilterExpressionNode.java | 7 +- .../dmn/feel/lang/ast/ForExpressionNode.java | 6 + .../feel/lang/ast/FormalParameterNode.java | 6 + .../dmn/feel/lang/ast/FunctionDefNode.java | 11 +- .../feel/lang/ast/FunctionInvocationNode.java | 7 + .../dmn/feel/lang/ast/FunctionTypeNode.java | 6 + .../dmn/feel/lang/ast/IfExpressionNode.java | 7 + .../org/kie/dmn/feel/lang/ast/InNode.java | 6 + .../kie/dmn/feel/lang/ast/InfixOpNode.java | 7 + .../kie/dmn/feel/lang/ast/InstanceOfNode.java | 6 + .../feel/lang/ast/IterationContextNode.java | 7 + .../org/kie/dmn/feel/lang/ast/ListNode.java | 5 + .../kie/dmn/feel/lang/ast/ListTypeNode.java | 5 + .../kie/dmn/feel/lang/ast/NameDefNode.java | 6 + .../kie/dmn/feel/lang/ast/NameRefNode.java | 5 + .../dmn/feel/lang/ast/NamedParameterNode.java | 6 + .../org/kie/dmn/feel/lang/ast/NullNode.java | 4 + .../org/kie/dmn/feel/lang/ast/NumberNode.java | 5 + .../dmn/feel/lang/ast/PathExpressionNode.java | 6 + .../dmn/feel/lang/ast/QualifiedNameNode.java | 6 + .../lang/ast/QuantifiedExpressionNode.java | 9 +- .../org/kie/dmn/feel/lang/ast/RangeNode.java | 8 + .../dmn/feel/lang/ast/SignedUnaryNode.java | 8 +- .../org/kie/dmn/feel/lang/ast/StringNode.java | 5 + .../feel/lang/ast/TemporalConstantNode.java | 18 + .../dmn/feel/lang/ast/UnaryTestListNode.java | 33 +- .../kie/dmn/feel/lang/ast/UnaryTestNode.java | 16 +- .../org/kie/dmn/feel/lang/ast/Visitor.java | 45 +- .../org/kie/dmn/feel/lang/impl/FEELImpl.java | 3 +- .../feel/listeners/SyntaxErrorListener.java | 46 ++ .../kie/dmn/feel/runtime/FEELFunction.java | 2 +- .../runtime/functions/CustomFEELFunction.java | 17 + .../org/kie/dmn/feel/util/CodegenUtils.java | 249 ++++++ .../kie/dmn/feel/util/DateTimeEvalHelper.java | 10 + .../TemplateCompiledFEELExpression.java | 23 +- .../TemplateCompiledFEELUnaryTests.java | 35 +- ...st.java => CodegenFEELUnaryTestsTest.java} | 77 +- .../codegen/feel11/DirectCompilerTest.java | 5 +- .../ManualBasicFunctionInvocationTest.java | 63 -- .../codegen/feel11/ManualContextTest.java | 71 -- .../feel/codegen/feel11/ManualFilterTest.java | 71 -- .../feel/codegen/feel11/ManualForTest.java | 74 -- .../ManualNamedFunctionInvocationTest.java | 63 -- .../feel/codegen/feel11/ManualQuantTest.java | 68 -- .../codegen/feel11/ManualUnaryTestsTest.java | 68 -- .../feel/runtime/BaseFEELCompilerTest.java | 20 +- .../kie/dmn/feel/runtime/BaseFEELTest.java | 10 +- .../dmn/feel/runtime/FEELExpressionsTest.java | 2 +- .../org/kie/dmn/feel/util/CompilerUtils.java | 22 +- .../openapi/impl/BaseNodeSchemaMapper.java | 3 +- 82 files changed, 2115 insertions(+), 3212 deletions(-) create mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ASTCompilerHelper.java create mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CodegenConstants.java create mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompilationErrorNotifier.java delete mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELSemanticMappings.java delete mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELSupport.java delete mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Contexts.java create mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/DMNCodegenConstants.java delete mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/DirectCompilerResult.java delete mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Expressions.java delete mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/FeelCtx.java delete mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Functions.java create mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/SyntaxErrorListener.java create mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/listeners/SyntaxErrorListener.java create mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/CodegenUtils.java rename kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/{DirectCompilerUnaryTestsTest.java => CodegenFEELUnaryTestsTest.java} (79%) delete mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualBasicFunctionInvocationTest.java delete mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualContextTest.java delete mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualFilterTest.java delete mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualForTest.java delete mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualNamedFunctionInvocationTest.java delete mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualQuantTest.java delete mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualUnaryTestsTest.java diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/alphanetwork/AlphaNetworkSupportInLargeDecisionTableTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/alphanetwork/AlphaNetworkSupportInLargeDecisionTableTest.java index 7514d335e70..bc232eb7f3d 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/alphanetwork/AlphaNetworkSupportInLargeDecisionTableTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/alphanetwork/AlphaNetworkSupportInLargeDecisionTableTest.java @@ -47,16 +47,9 @@ public static Object[] params() { return new Object[]{true, false}; } - private boolean useAlphaNetwork; - - public void initAlphaNetworkSupportInLargeDecisionTableTest(final boolean useAlphaNetwork) { - this.useAlphaNetwork = useAlphaNetwork; - } - @MethodSource("params") @ParameterizedTest(name = "{0}") public void evaluateDecisionTable(final boolean useAlphaNetwork) { - initAlphaNetworkSupportInLargeDecisionTableTest(useAlphaNetwork); System.setProperty(AlphaNetworkOption.PROPERTY_NAME, Boolean.toString(useAlphaNetwork)); KieServices kieServices = KieServices.get(); diff --git a/kie-dmn/kie-dmn-feel/pom.xml b/kie-dmn/kie-dmn-feel/pom.xml index c0c9b9ecb92..933dd442952 100644 --- a/kie-dmn/kie-dmn-feel/pom.xml +++ b/kie-dmn/kie-dmn-feel/pom.xml @@ -131,6 +131,10 @@ asciidoctorj test + + com.fasterxml.jackson.core + jackson-databind + 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 new file mode 100644 index 00000000000..3e91a78d202 --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ASTCompilerHelper.java @@ -0,0 +1,650 @@ +/** + * 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.codegen.feel11; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; + +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.expr.BooleanLiteralExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.NullLiteralExpr; +import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.stmt.ThrowStmt; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import org.kie.dmn.feel.lang.Type; +import org.kie.dmn.feel.lang.ast.AtLiteralNode; +import org.kie.dmn.feel.lang.ast.BaseNode; +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.SignedUnaryNode; +import org.kie.dmn.feel.lang.ast.StringNode; +import org.kie.dmn.feel.lang.ast.TemporalConstantNode; +import org.kie.dmn.feel.lang.ast.TypeNode; +import org.kie.dmn.feel.lang.ast.UnaryTestListNode; +import org.kie.dmn.feel.lang.ast.UnaryTestNode; +import org.kie.dmn.feel.lang.impl.JavaBackedType; +import org.kie.dmn.feel.lang.impl.MapBackedType; +import org.kie.dmn.feel.lang.types.AliasFEELType; +import org.kie.dmn.feel.lang.types.BuiltInType; +import org.kie.dmn.feel.runtime.FEELFunction; +import org.kie.dmn.feel.util.CodegenUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType; +import static com.github.javaparser.StaticJavaParser.parseExpression; +import static com.github.javaparser.utils.StringEscapeUtils.escapeJava; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.ADDFIELD_S; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.HASHMAP_CT; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.ILLEGALSTATEEXCEPTION_CT; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.INSTANCE_S; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.MAP_CT; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.OF_S; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.PUT_S; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.VAR_S; +import static org.kie.dmn.feel.codegen.feel11.Constants.BUILTINTYPE_E; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.ALIASFEELTYPE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.ATLITERALNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.BETWEENNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.BOOLEANNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.CONTEXTENTRYNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.CONTEXTNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.CONTEXTTYPENODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.CTYPENODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.DASHNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.DETERMINEOPERATOR_S; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.FILTEREXPRESSIONNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.FOREXPRESSIONNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.FORMALPARAMETERNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.FUNCTIONDEFNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.FUNCTIONINVOCATIONNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.FUNCTIONTYPENODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.GETBIGDECIMALORNULL_S; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.IFEXPRESSIONNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.INFIXOPERATOR_N; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.INFIXOPNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.INNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.INSTANCEOFNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.ITERATIONCONTEXTNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.JAVABACKEDTYPE_N; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.LISTNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.LISTTYPENODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.MAPBACKEDTYPE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.NAMEDEFNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.NAMEDPARAMETERNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.NAMEREFNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.NULLNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.NUMBEREVALHELPER_N; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.NUMBERNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.PATHEXPRESSIONNODE_CT; +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.SIGNEDUNARYNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.STRINGNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.TEMPORALCONSTANTNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.TYPE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.UNARYTESTLISTNODE_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.UNARYTESTNODE_CT; +import static org.kie.dmn.feel.util.CodegenUtils.getEnumExpression; +import static org.kie.dmn.feel.util.CodegenUtils.getListExpression; +import static org.kie.dmn.feel.util.CodegenUtils.getStringLiteralExpr; +import static org.kie.dmn.feel.util.CodegenUtils.getVariableDeclaratorWithFieldAccessExpr; +import static org.kie.dmn.feel.util.CodegenUtils.getVariableDeclaratorWithObjectCreation; + +public class ASTCompilerHelper { + + private static final Logger LOGGER = LoggerFactory.getLogger(ASTCompilerVisitor.class); + private static final String EXTENDED_FUNCTION_PACKAGE = "org.kie.dmn.feel.runtime.functions.extended"; + private final ASTCompilerVisitor astCompilerVisitor; + private final BlockStmt toPopulate; + private final AtomicInteger variableCounter; + private final Map baseNodeCache; + private final Map typeCache; + private final Map objectCache; + private AtomicReference lastVariableName = new AtomicReference<>(); + + public ASTCompilerHelper(ASTCompilerVisitor astCompilerVisitor) { + this.astCompilerVisitor = astCompilerVisitor; + toPopulate = new BlockStmt(); + variableCounter = new AtomicInteger(0); + baseNodeCache = new ConcurrentHashMap<>(); + typeCache = new ConcurrentHashMap<>(); + objectCache = new ConcurrentHashMap<>(); + } + + public BlockStmt add(AtLiteralNode n) { + Expression stringLiteralExpression = getNodeExpression(n.getStringLiteral()); + return addVariableDeclaratorWithObjectCreation(ATLITERALNODE_CT, NodeList.nodeList(stringLiteralExpression), + n.getText()); + } + + public BlockStmt add(BetweenNode n) { + Expression valueExpression = getNodeExpression(n.getValue()); + Expression startExpression = getNodeExpression(n.getStart()); + Expression endExpression = getNodeExpression(n.getEnd()); + return addVariableDeclaratorWithObjectCreation(BETWEENNODE_CT, NodeList.nodeList(valueExpression, + startExpression, + endExpression), n.getText()); + } + + public BlockStmt add(BooleanNode n) { + Expression valueExpression = new BooleanLiteralExpr(n.getValue()); + return addVariableDeclaratorWithObjectCreation(BOOLEANNODE_CT, NodeList.nodeList(valueExpression), n.getText()); + } + + public BlockStmt add(ContextEntryNode n) { + Expression nameExpression = getNodeExpression(n.getName()); + Expression valueExpression = getNodeExpression(n.getValue()); + return addVariableDeclaratorWithObjectCreation(CONTEXTENTRYNODE_CT, NodeList.nodeList(nameExpression, + valueExpression), + n.getText()); + } + + public BlockStmt add(ContextNode n) { + List entryNodesExpressions = n.getEntries().stream().map(entryNode -> getNodeExpression(entryNode)) + .toList(); + return addVariableDeclaratorWithObjectCreation(CONTEXTNODE_CT, + NodeList.nodeList(getListExpression(entryNodesExpressions)), + n.getText()); + } + + public BlockStmt add(ContextTypeNode n) { + Map genExpressions = new HashMap<>(); // THe key is the StringLiteralExpr of the + // original key; the value is the NameExpr pointing at generated variable + for (Map.Entry kv : n.getGen().entrySet()) { + genExpressions.put(new StringLiteralExpr(kv.getKey()), getNodeExpression(kv.getValue())); + } + // Creating the map + String mapVariableName = getNextVariableName(); + final VariableDeclarator mapVariableDeclarator = + new VariableDeclarator(MAP_CT, mapVariableName); + final ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(null, HASHMAP_CT, NodeList.nodeList()); + mapVariableDeclarator.setInitializer(objectCreationExpr); + VariableDeclarationExpr mapVariableDeclarationExpr = new VariableDeclarationExpr(mapVariableDeclarator); + addExpression(mapVariableDeclarationExpr, mapVariableName); + // Populating the map + Expression mapVariableExpression = new NameExpr(mapVariableName); + genExpressions.forEach((key, value) -> { + MethodCallExpr putExpression = new MethodCallExpr(mapVariableExpression, PUT_S); + putExpression.addArgument(key); + putExpression.addArgument(value); + addExpression(putExpression); + }); + return addVariableDeclaratorWithObjectCreation(CONTEXTTYPENODE_CT, NodeList.nodeList(mapVariableExpression), + n.getText()); + } + + public BlockStmt add(CTypeNode n) { + if (!(n.getType() instanceof BuiltInType)) { + throw new UnsupportedOperationException(); + } + BuiltInType feelCType = (BuiltInType) n.getType(); + Expression typeExpression = new FieldAccessExpr(BUILTINTYPE_E, feelCType.name()); + return addVariableDeclaratorWithObjectCreation(CTYPENODE_CT, NodeList.nodeList(typeExpression), n.getText()); + } + + public BlockStmt add(DashNode n) { + return addVariableDeclaratorWithObjectCreation(DASHNODE_CT, NodeList.nodeList(), n.getText()); + } + + public BlockStmt add(ForExpressionNode n) { + List iterationContextsExpressions = + n.getIterationContexts().stream().map(elementNode -> getNodeExpression(elementNode)) + .toList(); + Expression expressionExpression = getNodeExpression(n.getExpression()); + return addVariableDeclaratorWithObjectCreation(FOREXPRESSIONNODE_CT, + NodeList.nodeList(getListExpression(iterationContextsExpressions), + expressionExpression), + n.getText()); + } + + public BlockStmt add(FilterExpressionNode n) { + Expression expressionExpression = getNodeExpression(n.getExpression()); + Expression filterExpression = getNodeExpression(n.getFilter()); + return addVariableDeclaratorWithObjectCreation(FILTEREXPRESSIONNODE_CT, NodeList.nodeList(expressionExpression, + filterExpression), + n.getText()); + } + + public BlockStmt add(FormalParameterNode n) { + Expression nameExpression = getNodeExpression(n.getName()); + Expression typeExpression = getNodeExpression(n.getType()); + return addVariableDeclaratorWithObjectCreation(FORMALPARAMETERNODE_CT, NodeList.nodeList(nameExpression, + typeExpression), + n.getText()); + } + + public BlockStmt add(FunctionDefNode n) { + List formalParametersExpressions = n.getFormalParameters().stream() + .map(elementNode -> getNodeExpression(elementNode)) + .toList(); + Expression bodyExpression = getNodeExpression(n.getBody()); + return addVariableDeclaratorWithObjectCreation(FUNCTIONDEFNODE_CT, + NodeList.nodeList(getListExpression(formalParametersExpressions), + new BooleanLiteralExpr(n.isExternal()), + bodyExpression), + n.getText()); + } + + public BlockStmt add(FunctionInvocationNode n) { + Expression nameExpression = getNodeExpression(n.getName()); + Expression paramsExpression = getNodeExpression(n.getParams()); + Expression tcFoldedExpression = getNodeExpression(n.getTcFolded()); + return addVariableDeclaratorWithObjectCreation(FUNCTIONINVOCATIONNODE_CT, NodeList.nodeList(nameExpression, + paramsExpression, + tcFoldedExpression), n.getText()); + } + + public BlockStmt add(FunctionTypeNode n) { + List argTypesExpressions = n.getArgTypes().stream().map(argTypeNode -> getNodeExpression(argTypeNode)) + .toList(); + Expression retTypeExpression = getNodeExpression(n.getRetType()); + return addVariableDeclaratorWithObjectCreation(FUNCTIONTYPENODE_CT, + NodeList.nodeList(getListExpression(argTypesExpressions), + retTypeExpression), + n.getText()); + } + + public BlockStmt add(IfExpressionNode n) { + Expression conditionExpression = getNodeExpression(n.getCondition()); + Expression thenExpression = getNodeExpression(n.getThenExpression()); + Expression elseExpression = getNodeExpression(n.getElseExpression()); + return addVariableDeclaratorWithObjectCreation(IFEXPRESSIONNODE_CT, NodeList.nodeList(conditionExpression, + thenExpression, + elseExpression), + n.getText()); + } + + public BlockStmt add(InfixOpNode n) { + Expression determineOperatorExpression = new MethodCallExpr(INFIXOPERATOR_N, DETERMINEOPERATOR_S, + new NodeList<>(new StringLiteralExpr(n.getOperator().getSymbol()))); + Expression leftExpression = getNodeExpression(n.getLeft()); + Expression rightExpression = getNodeExpression(n.getRight()); + return addVariableDeclaratorWithObjectCreation(INFIXOPNODE_CT, NodeList.nodeList(determineOperatorExpression, + leftExpression, + rightExpression), n.getText()); + } + + public BlockStmt add(InNode n) { + Expression valueExpression = getNodeExpression(n.getValue()); + Expression exprsExpression = getNodeExpression(n.getExprs()); + return addVariableDeclaratorWithObjectCreation(INNODE_CT, NodeList.nodeList(valueExpression, exprsExpression) + , n.getText()); + } + + public BlockStmt add(InstanceOfNode n) { + Expression expressionExpression = getNodeExpression(n.getExpression()); + Expression typeExpression = getNodeExpression(n.getType()); + return addVariableDeclaratorWithObjectCreation(INSTANCEOFNODE_CT, NodeList.nodeList(expressionExpression, + typeExpression), + n.getText()); + } + + public BlockStmt add(IterationContextNode n) { + Expression nameExpression = getNodeExpression(n.getName()); + Expression expressionExpression = getNodeExpression(n.getExpression()); + Expression rangeEndExprExpression = getNodeExpression(n.getRangeEndExpr()); + return addVariableDeclaratorWithObjectCreation(ITERATIONCONTEXTNODE_CT, NodeList.nodeList(nameExpression, + expressionExpression, rangeEndExprExpression), n.getText()); + } + + public BlockStmt add(ListNode n) { + List elements = n.getElements().stream().map(elementNode -> getNodeExpression(elementNode)) + .toList(); + return addVariableDeclaratorWithObjectCreation(LISTNODE_CT, NodeList.nodeList(getListExpression(elements)), + n.getText()); + } + + public BlockStmt add(ListTypeNode n) { + Expression genTypeNodeExpression = getNodeExpression(n.getGenTypeNode()); + return addVariableDeclaratorWithObjectCreation(LISTTYPENODE_CT, NodeList.nodeList(genTypeNodeExpression), + n.getText()); + } + + public BlockStmt add(NameDefNode n) { + List partsExpressions = n.getParts().stream().map(StringLiteralExpr::new) + .toList(); + Expression nameExpression = n.getName() != null ? new StringLiteralExpr(n.getName()) : new NullLiteralExpr(); + return addVariableDeclaratorWithObjectCreation(NAMEDEFNODE_CT, + NodeList.nodeList(getListExpression(partsExpressions), + nameExpression), n.getText()); + } + + public BlockStmt add(NamedParameterNode n) { + Expression nameExpression = getNodeExpression(n.getName()); + Expression expressionExpression = getNodeExpression(n.getExpression()); + return addVariableDeclaratorWithObjectCreation(NAMEDPARAMETERNODE_CT, NodeList.nodeList(nameExpression, + expressionExpression) + , n.getText()); + } + + public BlockStmt add(NameRefNode n) { + Expression typeExpression = getTypeExpression(n.getResultType()); + return addVariableDeclaratorWithObjectCreation(NAMEREFNODE_CT, NodeList.nodeList(typeExpression), n.getText()); + } + + public BlockStmt add(NullNode n) { + return addVariableDeclaratorWithObjectCreation(NULLNODE_CT, NodeList.nodeList(), n.getText()); + } + + public BlockStmt add(NumberNode n) { + MethodCallExpr valueExpression = new MethodCallExpr(NUMBEREVALHELPER_N, GETBIGDECIMALORNULL_S, + NodeList.nodeList(new StringLiteralExpr(n.getText()))); + return addVariableDeclaratorWithObjectCreation(NUMBERNODE_CT, NodeList.nodeList(valueExpression), n.getText()); + } + + public BlockStmt add(PathExpressionNode n) { + Expression expressionExpression = getNodeExpression(n.getExpression()); + Expression nameExpression = getNodeExpression(n.getName()); + return addVariableDeclaratorWithObjectCreation(PATHEXPRESSIONNODE_CT, NodeList.nodeList(expressionExpression, + nameExpression), + n.getText()); + } + + public BlockStmt add(QualifiedNameNode n) { + List partsExpressions = n.getParts().stream().map(partNode -> getNodeExpression(partNode)) + .toList(); + Expression typeExpression = getTypeExpression(n.getResultType()); + return addVariableDeclaratorWithObjectCreation(QUALIFIEDNAMENODE_CT, + NodeList.nodeList(getListExpression(partsExpressions), + typeExpression), + n.getText()); + } + + public BlockStmt add(QuantifiedExpressionNode n) { + Expression quantifierExpression = getEnumExpression(n.getQuantifier()); + List iterationContextsExpressions = + n.getIterationContexts().stream().map(iterationContextNode -> getNodeExpression(iterationContextNode)) + .toList(); + Expression expressionExpression = getNodeExpression(n.getExpression()); + return addVariableDeclaratorWithObjectCreation(QUANTIFIEDEXPRESSIONNODE_CT, + NodeList.nodeList(quantifierExpression, + getListExpression(iterationContextsExpressions), + expressionExpression), n.getText()); + } + + public BlockStmt add(RangeNode n) { + Expression lowerBoundExpression = getEnumExpression(n.getLowerBound()); + Expression upperBoundExpression = getEnumExpression(n.getUpperBound()); + Expression startExpression = getNodeExpression(n.getStart()); + Expression endExpression = getNodeExpression(n.getEnd()); + return addVariableDeclaratorWithObjectCreation(RANGENODE_CT, NodeList.nodeList(lowerBoundExpression, + upperBoundExpression, + startExpression, + endExpression), n.getText()); + } + + public BlockStmt add(SignedUnaryNode n) { + Expression signExpression = getEnumExpression(n.getSign()); + Expression expressionExpression = getNodeExpression(n.getExpression()); + return addVariableDeclaratorWithObjectCreation(SIGNEDUNARYNODE_CT, NodeList.nodeList(signExpression, + expressionExpression), + n.getText()); + } + + public BlockStmt add(StringNode n) { + return addVariableDeclaratorWithObjectCreation(STRINGNODE_CT, NodeList.nodeList(), + n.getText()); + } + + public BlockStmt add(TemporalConstantNode n) { + Expression valueExpression = getObjectExpression(n.getValue()); + FEELFunction fn = n.getFn(); + Expression fnVariableNameExpression; + if (fn != null) { + Class fnClass = fn.getClass(); + ClassOrInterfaceType fn_CT = parseClassOrInterfaceType(fnClass.getCanonicalName()); + Expression fn_N = new NameExpr(fnClass.getCanonicalName()); + if (fnClass.getPackageName().equals(EXTENDED_FUNCTION_PACKAGE)) { + addVariableDeclaratorWithWithFieldAccess(fn_CT, INSTANCE_S, fn_N); + } else { + addVariableDeclaratorWithObjectCreation(fn_CT, + NodeList.nodeList()); + } + fnVariableNameExpression = new NameExpr(lastVariableName.get()); + } else { + fnVariableNameExpression = new NullLiteralExpr(); + } + List paramsExpressions = n.getParams().stream().map(param -> getObjectExpression(param)).toList(); + return addVariableDeclaratorWithObjectCreation(TEMPORALCONSTANTNODE_CT, NodeList.nodeList(valueExpression, + fnVariableNameExpression, getListExpression(paramsExpressions)), n.getText()); + } + + public BlockStmt add(UnaryTestListNode n) { + List elementsExpressions = n.getElements().stream().map(elementNode -> getNodeExpression(elementNode)) + .toList(); + Expression stateExpression = getEnumExpression(n.getState()); + return addVariableDeclaratorWithObjectCreation(UNARYTESTLISTNODE_CT, + NodeList.nodeList(getListExpression(elementsExpressions), + stateExpression), + n.getText()); + } + + public BlockStmt add(UnaryTestNode n) { + Expression opExpression = getEnumExpression(n.getOperator()); + Expression valueExpression = getNodeExpression(n.getValue()); + return addVariableDeclaratorWithObjectCreation(UNARYTESTNODE_CT, NodeList.nodeList(opExpression, + valueExpression), + n.getText()); + } + + public String getLastVariableName() { + return lastVariableName.get(); + } + + public BlockStmt returnError(String errorMessage) { + ObjectCreationExpr illegalStateExceptionExpression = new ObjectCreationExpr(null, ILLEGALSTATEEXCEPTION_CT, + NodeList.nodeList(getStringLiteralExpr(errorMessage))); + ThrowStmt throwStmt = new ThrowStmt(); + throwStmt.setExpression(illegalStateExceptionExpression); + return addStatement(throwStmt); + } + + private String getNextVariableName() { + return String.format("%s_%d", VAR_S, variableCounter.getAndIncrement()); + } + + private BlockStmt addVariableDeclaratorWithObjectCreation(ClassOrInterfaceType variableType, + NodeList arguments, String text) { + Expression textExpression = text != null ? new StringLiteralExpr(escapeJava(text)) : new NullLiteralExpr(); + arguments.add(textExpression); + return addVariableDeclaratorWithObjectCreation(variableType, arguments); + } + + private BlockStmt addVariableDeclaratorWithObjectCreation(ClassOrInterfaceType variableType, + NodeList arguments) { + String variableName = getNextVariableName(); + final VariableDeclarationExpr toAdd = getVariableDeclaratorWithObjectCreation(variableName, variableType, + arguments); + return addExpression(toAdd, variableName); + } + + private BlockStmt addVariableDeclaratorWithWithFieldAccess(ClassOrInterfaceType variableType, + String name, + Expression scope) { + + String variableName = getNextVariableName(); + final VariableDeclarationExpr toAdd = getVariableDeclaratorWithFieldAccessExpr(variableName, + variableType, + name, + scope); + return addExpression(toAdd, variableName); + } + + private BlockStmt addExpression(Expression toAdd, String variableName) { + lastVariableName.set(variableName); + return addExpression(toAdd); + } + + private BlockStmt addExpression(Expression toAdd) { + toPopulate.addStatement(toAdd); + LOGGER.debug(toPopulate.toString()); + return toPopulate; + } + + private BlockStmt addStatement(Statement toAdd) { + toPopulate.addStatement(toAdd); + LOGGER.debug(toPopulate.toString()); + return toPopulate; + } + + private Expression getTypeExpression(Type type) { + if (!typeCache.containsKey(type)) { + Expression toPut; + if (type instanceof AliasFEELType aliasFEELType) { + toPut = getAliasFEELType(aliasFEELType); + } else if (type instanceof Enum typeEnum) { + toPut = getEnumExpression(typeEnum); + } else if (type instanceof JavaBackedType javaBackedType) { + toPut = getJavaBackedTypeExpression(javaBackedType); + } else if (type instanceof MapBackedType mapBackedType) { + toPut = getMapBackedTypeExpression(mapBackedType); + } else { + toPut = parseExpression(type.getClass().getCanonicalName()); + } + typeCache.put(type, toPut); + } + return typeCache.get(type); + } + + private Expression getAliasFEELType(AliasFEELType aliasFEELType) { + BuiltInType feelCType = aliasFEELType.getBuiltInType(); + Expression typeExpression = new FieldAccessExpr(BUILTINTYPE_E, feelCType.name()); + // Creating the AliasFEELType + String aliasFeelTypeVariableName = getNextVariableName(); + final VariableDeclarator aliasFeelTypeVariableDeclarator = + new VariableDeclarator(ALIASFEELTYPE_CT, aliasFeelTypeVariableName); + NodeList arguments = NodeList.nodeList(new StringLiteralExpr(aliasFEELType.getName()), + typeExpression); + final ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(null, ALIASFEELTYPE_CT, + arguments); + aliasFeelTypeVariableDeclarator.setInitializer(objectCreationExpr); + VariableDeclarationExpr mapVariableDeclarationExpr = + new VariableDeclarationExpr(aliasFeelTypeVariableDeclarator); + addExpression(mapVariableDeclarationExpr, aliasFeelTypeVariableName); + return new NameExpr(aliasFeelTypeVariableName); + } + + private Expression getJavaBackedTypeExpression(JavaBackedType javaBackedType) { + // Creating the JavaBackedType + String mapVariableName = getNextVariableName(); + final VariableDeclarator mapVariableDeclarator = + new VariableDeclarator(TYPE_CT, mapVariableName); + Expression classExpression = new NameExpr(javaBackedType.getWrapped().getCanonicalName() + ".class"); + final MethodCallExpr methodCallExpr = new MethodCallExpr(JAVABACKEDTYPE_N, OF_S, + NodeList.nodeList(classExpression)); + mapVariableDeclarator.setInitializer(methodCallExpr); + VariableDeclarationExpr mapVariableDeclarationExpr = new VariableDeclarationExpr(mapVariableDeclarator); + addExpression(mapVariableDeclarationExpr, mapVariableName); + return new NameExpr(mapVariableName); + } + + private Expression getMapBackedTypeExpression(MapBackedType mapBackedType) { + Map fieldsExpressions = new HashMap<>(); // The key is the StringLiteralExpr of the + // original key; the value is the Expression pointing at type + for (Map.Entry kv : mapBackedType.getFields().entrySet()) { + fieldsExpressions.put(new StringLiteralExpr(kv.getKey()), getTypeExpression(kv.getValue())); + } + + // Creating the MapBackedType + String mapVariableName = getNextVariableName(); + final VariableDeclarator mapVariableDeclarator = + new VariableDeclarator(MAPBACKEDTYPE_CT, mapVariableName); + final ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(null, MAPBACKEDTYPE_CT, + NodeList.nodeList(new StringLiteralExpr(mapBackedType.getName()))); + mapVariableDeclarator.setInitializer(objectCreationExpr); + VariableDeclarationExpr mapVariableDeclarationExpr = new VariableDeclarationExpr(mapVariableDeclarator); + addExpression(mapVariableDeclarationExpr, mapVariableName); + // Populating the map + Expression mapVariableExpression = new NameExpr(mapVariableName); + fieldsExpressions.forEach((key, value) -> { + MethodCallExpr putExpression = new MethodCallExpr(mapVariableExpression, ADDFIELD_S); + putExpression.addArgument(key); + putExpression.addArgument(value); + addExpression(putExpression); + }); + return new NameExpr(mapVariableName); + } + + private Expression getObjectExpression(Object object) { + if (object == null) { + return new NullLiteralExpr(); + } + if (!objectCache.containsKey(object)) { + String variableName = getNextVariableName(); + Expression objectExpression = CodegenUtils.getObjectExpression(object, variableName); + addExpression(objectExpression, variableName); + objectCache.put(object, new NameExpr(lastVariableName.get())); + } + return objectCache.get(object); + } + + private Expression getNodeExpression(BaseNode node) { + if (node != null) { + if (!baseNodeCache.containsKey(node)) { + node.accept(astCompilerVisitor); + baseNodeCache.put(node, new NameExpr(lastVariableName.get())); + } + return baseNodeCache.get(node); + } else { + return new NullLiteralExpr(); + } + } +} \ No newline at end of file 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 da960bd7990..0a509bca667 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 @@ -18,39 +18,9 @@ */ package org.kie.dmn.feel.codegen.feel11; -import java.time.Duration; -import java.time.chrono.ChronoPeriod; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.stream.Collectors; - -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.expr.BinaryExpr; -import com.github.javaparser.ast.expr.BooleanLiteralExpr; -import com.github.javaparser.ast.expr.ConditionalExpr; -import com.github.javaparser.ast.expr.EnclosedExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.FieldAccessExpr; -import com.github.javaparser.ast.expr.IntegerLiteralExpr; -import com.github.javaparser.ast.expr.LambdaExpr; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.NullLiteralExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; -import com.github.javaparser.ast.type.UnknownType; -import org.kie.dmn.feel.lang.CompositeType; -import org.kie.dmn.feel.lang.SimpleType; -import org.kie.dmn.feel.lang.Type; +import com.github.javaparser.ast.stmt.BlockStmt; import org.kie.dmn.feel.lang.ast.ASTNode; import org.kie.dmn.feel.lang.ast.AtLiteralNode; -import org.kie.dmn.feel.lang.ast.AtLiteralNode.TypeAndFn; -import org.kie.dmn.feel.lang.ast.BaseNode; import org.kie.dmn.feel.lang.ast.BetweenNode; import org.kie.dmn.feel.lang.ast.BooleanNode; import org.kie.dmn.feel.lang.ast.CTypeNode; @@ -83,603 +53,244 @@ import org.kie.dmn.feel.lang.ast.SignedUnaryNode; import org.kie.dmn.feel.lang.ast.StringNode; import org.kie.dmn.feel.lang.ast.TemporalConstantNode; -import org.kie.dmn.feel.lang.ast.TypeNode; import org.kie.dmn.feel.lang.ast.UnaryTestListNode; import org.kie.dmn.feel.lang.ast.UnaryTestNode; import org.kie.dmn.feel.lang.ast.Visitor; -import org.kie.dmn.feel.lang.impl.MapBackedType; -import org.kie.dmn.feel.lang.types.BuiltInType; -import org.kie.dmn.feel.parser.feel11.ScopeHelper; -import org.kie.dmn.feel.util.Msg; -import org.kie.dmn.feel.util.StringEvalHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import static org.kie.dmn.feel.codegen.feel11.DirectCompilerResult.mergeFDs; +public class ASTCompilerVisitor implements Visitor { -public class ASTCompilerVisitor implements Visitor { + private static final Logger LOGGER = LoggerFactory.getLogger(ASTCompilerVisitor.class); + private final ASTCompilerHelper compilerHelper; - ScopeHelper scopeHelper = new ScopeHelper<>(); + public ASTCompilerVisitor() { + compilerHelper = new ASTCompilerHelper(this); + } @Override - public DirectCompilerResult visit(ASTNode n) { + public BlockStmt visit(ASTNode n) { throw new UnsupportedOperationException("Not yet implemented"); } @Override - public DirectCompilerResult visit(DashNode n) { - return DirectCompilerResult.of(Expressions.dash(), BuiltInType.UNARY_TEST); + public BlockStmt visit(AtLiteralNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(BetweenNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(BooleanNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(ContextEntryNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); } @Override - public DirectCompilerResult visit(BooleanNode n) { - return DirectCompilerResult.of(new BooleanLiteralExpr(n.getValue()), BuiltInType.BOOLEAN); + public BlockStmt visit(ContextNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); } @Override - public DirectCompilerResult visit(NumberNode n) { - String originalText = n.getText(); - String constantName = Constants.numericName(originalText); - FieldDeclaration constant = Constants.numeric(constantName, originalText); - return DirectCompilerResult.of( - new NameExpr(constantName), - BuiltInType.NUMBER, - constant); + public BlockStmt visit(ContextTypeNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); } @Override - public DirectCompilerResult visit(StringNode n) { - return DirectCompilerResult.of( - Expressions.stringLiteral(n.getText()), // setString escapes the contents Java-style - BuiltInType.STRING); + public BlockStmt visit(CTypeNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); } @Override - public DirectCompilerResult visit(AtLiteralNode n) { - DirectCompilerResult stringLiteral = n.getStringLiteral().accept(this); - String value = ((StringLiteralExpr) stringLiteral.getExpression()).asString(); - TypeAndFn typeAndFn = AtLiteralNode.fromAtValue(value); - String functionName = typeAndFn.fnName; - Type resultType = typeAndFn.type; - if (resultType == BuiltInType.UNKNOWN) { - return DirectCompilerResult.of(CompiledFEELSupport.compiledErrorExpression(Msg.createMessage(Msg.MALFORMED_AT_LITERAL, n.getText())), - BuiltInType.UNKNOWN); - } - return DirectCompilerResult.of(Expressions.invoke(FeelCtx.getValue(functionName), - stringLiteral.getExpression()), - resultType) - .withFD(stringLiteral); + public BlockStmt visit(DashNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); } @Override - public DirectCompilerResult visit(UnaryTestListNode n) { - MethodCallExpr expr = Expressions.list(); - HashSet fds = new HashSet<>(); - for (BaseNode e : n.getElements()) { - DirectCompilerResult r = e.accept(this); - fds.addAll(r.getFieldDeclarations()); - expr.addArgument(r.getExpression()); - } + public BlockStmt visit(ForExpressionNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } - if (n.isNegated()) { - Expressions.NamedLambda negated = - Expressions.namedUnaryLambda( - Expressions.notExists(expr), n.getText()); + @Override + public BlockStmt visit(FilterExpressionNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } - fds.add(negated.field()); - return DirectCompilerResult.of( - Expressions.list(negated.name()), - BuiltInType.LIST, fds); - } else { - return DirectCompilerResult.of( - expr, BuiltInType.LIST, fds); - } + @Override + public BlockStmt visit(FormalParameterNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); } @Override - public DirectCompilerResult visit(NullNode n) { - return DirectCompilerResult.of(new NullLiteralExpr(), BuiltInType.UNKNOWN); + public BlockStmt visit(FunctionDefNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); } @Override - public DirectCompilerResult visit(NameDefNode n) { - StringLiteralExpr expr = Expressions.stringLiteral(StringEvalHelper.normalizeVariableName(n.getText())); - return DirectCompilerResult.of(expr, BuiltInType.STRING); + public BlockStmt visit(FunctionInvocationNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); } @Override - public DirectCompilerResult visit(NameRefNode n) { - String nameRef = StringEvalHelper.normalizeVariableName(n.getText()); - Type type = scopeHelper.resolve(nameRef).orElse(BuiltInType.UNKNOWN); - return DirectCompilerResult.of(FeelCtx.getValue(nameRef), type); + public BlockStmt visit(FunctionTypeNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); } @Override - public DirectCompilerResult visit(QualifiedNameNode n) { - List parts = n.getParts(); - DirectCompilerResult nameRef0 = parts.get(0).accept(this); - Type typeCursor = nameRef0.resultType; - Expression currentContext = nameRef0.getExpression(); - for (int i = 1; i < parts.size(); i++) { - NameRefNode acc = parts.get(i); - String key = acc.getText(); - if (typeCursor instanceof CompositeType) { - CompositeType currentContextType = (CompositeType) typeCursor; - currentContext = Contexts.getKey(currentContext, currentContextType, key); - typeCursor = currentContextType.getFields().get(key); - } else { - // degraded mode, or accessing fields of DATE etc. - currentContext = Expressions.path(currentContext, new StringLiteralExpr(key)); - typeCursor = BuiltInType.UNKNOWN; - } - } - // If it was a NameRef expression, the number coercion is directly performed by the EvaluationContext for the simple variable. - // Otherwise in case of QualifiedName expression, for a structured type like this case, it need to be coerced on the last accessor: - return DirectCompilerResult.of( - Expressions.coerceNumber(currentContext), - typeCursor); - } - - @Override - public DirectCompilerResult visit(InfixOpNode n) { - DirectCompilerResult left = n.getLeft().accept(this); - DirectCompilerResult right = n.getRight().accept(this); - MethodCallExpr expr = Expressions.binary( - n.getOperator(), - left.getExpression(), - right.getExpression()); - return DirectCompilerResult.of(expr, BuiltInType.UNKNOWN).withFD(left).withFD(right); - } - - @Override - public DirectCompilerResult visit(InstanceOfNode n) { - DirectCompilerResult expr = n.getExpression().accept(this); - DirectCompilerResult type = n.getType().accept(this); - switch (n.getType().getText()) { - case SimpleType.YEARS_AND_MONTHS_DURATION: - return DirectCompilerResult.of(Expressions.nativeInstanceOf(StaticJavaParser.parseClassOrInterfaceType(ChronoPeriod.class.getCanonicalName()), - expr.getExpression()), - BuiltInType.BOOLEAN, - mergeFDs(expr, type)); - case SimpleType.DAYS_AND_TIME_DURATION: - return DirectCompilerResult.of(Expressions.nativeInstanceOf(StaticJavaParser.parseClassOrInterfaceType(Duration.class.getCanonicalName()), - expr.getExpression()), - BuiltInType.BOOLEAN, - mergeFDs(expr, type)); - default: - return DirectCompilerResult.of(Expressions.isInstanceOf(expr.getExpression(), type.getExpression()), - BuiltInType.BOOLEAN, - mergeFDs(expr, type)); - } - - } - - @Override - public DirectCompilerResult visit(CTypeNode n) { - if (!(n.getType() instanceof BuiltInType)) { - throw new UnsupportedOperationException(); - } - BuiltInType feelCType = (BuiltInType) n.getType(); - return DirectCompilerResult.of(new FieldAccessExpr(Constants.BuiltInTypeT, feelCType.name()), - BuiltInType.UNKNOWN); + public BlockStmt visit(IfExpressionNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); } @Override - public DirectCompilerResult visit(ListTypeNode n) { - DirectCompilerResult expr = n.getGenTypeNode().accept(this); - return DirectCompilerResult.of(Expressions.genListType(expr.getExpression()), - BuiltInType.UNKNOWN, - mergeFDs(expr)); + public BlockStmt visit(InfixOpNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); } @Override - public DirectCompilerResult visit(ContextTypeNode n) { - Map fields = new HashMap<>(); - for (Entry kv : n.getGen().entrySet()) { - fields.put(kv.getKey(), kv.getValue().accept(this)); - } - return DirectCompilerResult.of(Expressions.genContextType(fields.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getExpression()))), - BuiltInType.UNKNOWN, - mergeFDs(fields.values().stream().collect(Collectors.toList()))); - } - - @Override - public DirectCompilerResult visit(FunctionTypeNode n) { - List args = new ArrayList<>(); - for (TypeNode arg : n.getArgTypes()) { - args.add(arg.accept(this)); - } - DirectCompilerResult ret = n.getRetType().accept(this); - return DirectCompilerResult.of(Expressions.genFnType(args.stream().map(DirectCompilerResult::getExpression).collect(Collectors.toList()), - ret.getExpression()), - BuiltInType.UNKNOWN, - mergeFDs(args)) - .withFD(ret); - } - - @Override - public DirectCompilerResult visit(IfExpressionNode n) { - DirectCompilerResult condition = n.getCondition().accept(this); - DirectCompilerResult thenExpr = n.getThenExpression().accept(this); - DirectCompilerResult elseExpr = n.getElseExpression().accept(this); - - return DirectCompilerResult.of( - new ConditionalExpr( - new BinaryExpr( - Expressions.nativeInstanceOf( - Constants.BooleanT, condition.getExpression()), - Expressions.reflectiveCastTo( - Constants.BooleanT, condition.getExpression()), - BinaryExpr.Operator.AND), - new EnclosedExpr(thenExpr.getExpression()), - new EnclosedExpr(elseExpr.getExpression())), - thenExpr.resultType // should find common type between then/else - ).withFD(condition).withFD(thenExpr).withFD(elseExpr); - } - - @Override - public DirectCompilerResult visit(ForExpressionNode n) { - DirectCompilerResult expr = n.getExpression().accept(this); - HashSet fds = new HashSet<>(); - - Expressions.NamedLambda namedLambda = - Expressions.namedLambda( - expr.getExpression(), - n.getExpression().getText()); - - fds.add(namedLambda.field()); - fds.addAll(expr.getFieldDeclarations()); - - List expressions = n.getIterationContexts() - .stream() - .map(iter -> iter.accept(this)) - .peek(r -> fds.addAll(r.getFieldDeclarations())) - .map(DirectCompilerResult::getExpression) - .collect(Collectors.toList()); - - // .satisfies(expr) - return DirectCompilerResult.of( - Expressions.ffor(expressions, namedLambda.name()), - expr.resultType, - fds); - } + public BlockStmt visit(InNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } @Override - public DirectCompilerResult visit(BetweenNode n) { - DirectCompilerResult value = n.getValue().accept(this); - DirectCompilerResult start = n.getStart().accept(this); - DirectCompilerResult end = n.getEnd().accept(this); - - return DirectCompilerResult.of( - Expressions.between( - value.getExpression(), - start.getExpression(), - end.getExpression()), - BuiltInType.BOOLEAN) - .withFD(value) - .withFD(start) - .withFD(end); - } - - @Override - public DirectCompilerResult visit(ContextNode n) { - if (n.getEntries().isEmpty()) { - return DirectCompilerResult.of( - FeelCtx.emptyContext(), BuiltInType.CONTEXT); - } - - scopeHelper.pushScope(); - - // openContext(feelCtx) - MapBackedType resultType = new MapBackedType(); - DirectCompilerResult openContext = - DirectCompilerResult.of(FeelCtx.openContext(), resultType); - - // .setEntry( k,v ) - // .setEntry( k,v ) - // ... - DirectCompilerResult entries = n.getEntries() - .stream() - .map(e -> { - DirectCompilerResult r = e.accept(this); - scopeHelper.addInScope(e.getName().getText(), r.resultType); - return r; - }) - .reduce(openContext, - (l, r) -> DirectCompilerResult.of( - r.getExpression().asMethodCallExpr().setScope(l.getExpression()), - r.resultType, - DirectCompilerResult.mergeFDs(l, r))); - - scopeHelper.popScope(); - - // .closeContext() - return DirectCompilerResult.of( - FeelCtx.closeContext(entries), - resultType, - entries.getFieldDeclarations()); - } - - @Override - public DirectCompilerResult visit(ContextEntryNode n) { - DirectCompilerResult key = n.getName().accept(this); - DirectCompilerResult value = n.getValue().accept(this); - if (key.resultType != BuiltInType.STRING) { - throw new IllegalArgumentException( - "a Context Entry Key must be a valid FEEL String type"); - } - String keyText = key.getExpression().asStringLiteralExpr().getValue(); - - // .setEntry(key, value) - MethodCallExpr setEntryContextCall = - FeelCtx.setEntry(keyText, value.getExpression()); - - return DirectCompilerResult.of( - setEntryContextCall, - value.resultType, - value.getFieldDeclarations()); - } - - @Override - public DirectCompilerResult visit(FilterExpressionNode n) { - DirectCompilerResult expr = n.getExpression().accept(this); - DirectCompilerResult filter = n.getFilter().accept(this); - - Expressions.NamedLambda lambda = Expressions.namedLambda(filter.getExpression(), n.getFilter().getText()); - DirectCompilerResult r = DirectCompilerResult.of( - Expressions.filter(expr.getExpression(), lambda.name()), - // here we could still try to infer the result type, but presently use ANY - BuiltInType.UNKNOWN).withFD(expr).withFD(filter); - r.addFieldDeclaration(lambda.field()); - return r; - } - - @Override - public DirectCompilerResult visit(FormalParameterNode n) { - DirectCompilerResult name = n.getName().accept(this); - DirectCompilerResult type = n.getType().accept(this); - return DirectCompilerResult.of(Expressions.formalParameter(name.getExpression(), type.getExpression()), - BuiltInType.UNKNOWN) - .withFD(name) - .withFD(type); - } - - @Override - public DirectCompilerResult visit(FunctionDefNode n) { - MethodCallExpr list = Expressions.list(); - n.getFormalParameters() - .stream() - .map(fp -> fp.accept(this)) - .map(DirectCompilerResult::getExpression) - .forEach(list::addArgument); - - if (n.isExternal()) { - List paramNames = - n.getFormalParameters().stream() - .map(FormalParameterNode::getName) - .map(BaseNode::getText) - .collect(Collectors.toList()); - - return Functions.declaration( - n, list, - Functions.external(paramNames, n.getBody())); - } else { - DirectCompilerResult body = n.getBody().accept(this); - return Functions.declaration(n, list, - body.getExpression()).withFD(body); - } - } - - @Override - public DirectCompilerResult visit(FunctionInvocationNode n) { - TemporalConstantNode tcFolded = n.getTcFolded(); - if (tcFolded != null) { - return replaceWithTemporalConstant(n, tcFolded); - } - DirectCompilerResult functionName = n.getName().accept(this); - DirectCompilerResult params = n.getParams().accept(this); - return DirectCompilerResult.of( - Expressions.invoke(functionName.getExpression(), params.getExpression()), - functionName.resultType) - .withFD(functionName) - .withFD(params); - } - - public DirectCompilerResult replaceWithTemporalConstant(FunctionInvocationNode n, TemporalConstantNode tcFolded) { - MethodCallExpr methodCallExpr = new MethodCallExpr(new FieldAccessExpr(new NameExpr(tcFolded.fn.getClass().getCanonicalName()), - "INSTANCE"), - "invoke"); - for (Object p : tcFolded.params) { - if (p instanceof String) { - methodCallExpr.addArgument(Expressions.stringLiteral((String) p)); - } else if (p instanceof Number) { - methodCallExpr.addArgument(new IntegerLiteralExpr(p.toString())); - } else { - throw new IllegalStateException("Unexpected Temporal Constant parameter found."); - } - } - methodCallExpr = new MethodCallExpr(methodCallExpr, "getOrElseThrow"); // since this AST Node exists, the Fn invocation returns result. - methodCallExpr.addArgument(new LambdaExpr(new Parameter(new UnknownType(), "e"), - Expressions.newIllegalState())); - String constantName = Constants.dtConstantName(n.getText()); - FieldDeclaration constant = Constants.dtConstant(constantName, methodCallExpr); - return DirectCompilerResult.of(new NameExpr(constantName), - BuiltInType.UNKNOWN, - constant); - } - - @Override - public DirectCompilerResult visit(NamedParameterNode n) { - DirectCompilerResult name = n.getName().accept(this); - DirectCompilerResult expr = n.getExpression().accept(this); - return DirectCompilerResult.of( - Expressions.namedParameter(name.getExpression(), expr.getExpression()), - BuiltInType.UNKNOWN).withFD(name).withFD(expr); - } - - @Override - public DirectCompilerResult visit(InNode n) { - DirectCompilerResult value = n.getValue().accept(this); - DirectCompilerResult exprs = n.getExprs().accept(this); - - if (exprs.resultType == BuiltInType.LIST) { - return DirectCompilerResult.of( - Expressions.exists(exprs.getExpression(), value.getExpression()), - BuiltInType.BOOLEAN).withFD(value).withFD(exprs); - } else if (exprs.resultType == BuiltInType.RANGE) { - return DirectCompilerResult.of( - Expressions.includes(exprs.getExpression(), value.getExpression()), - BuiltInType.BOOLEAN).withFD(value).withFD(exprs); - } else { - // this should be turned into a tree rewrite - return DirectCompilerResult.of( - Expressions.exists(exprs.getExpression(), value.getExpression()), - BuiltInType.BOOLEAN).withFD(value).withFD(exprs); - } - } - - @Override - public DirectCompilerResult visit(IterationContextNode n) { - DirectCompilerResult iterName = n.getName().accept(this); - DirectCompilerResult iterExpr = n.getExpression().accept(this); - - Expressions.NamedLambda nameLambda = - Expressions.namedLambda( - iterName.getExpression(), - n.getName().getText()); - Expressions.NamedLambda exprLambda = - Expressions.namedLambda( - iterExpr.getExpression(), - n.getExpression().getText()); - - MethodCallExpr with = - new MethodCallExpr(null, "with") - .addArgument(nameLambda.name()) - .addArgument(exprLambda.name()); - - DirectCompilerResult r = - DirectCompilerResult.of(with, BuiltInType.UNKNOWN); - r.addFieldDeclaration(nameLambda.field()); - r.addFieldDeclaration(exprLambda.field()); - r.withFD(iterName); - r.withFD(iterExpr); - - BaseNode rangeEndExpr = n.getRangeEndExpr(); - if (rangeEndExpr != null) { - DirectCompilerResult rangeEnd = rangeEndExpr.accept(this); - Expressions.NamedLambda rangeLambda = - Expressions.namedLambda( - rangeEnd.getExpression(), - rangeEndExpr.getText()); - with.addArgument(rangeLambda.name()); - r.addFieldDeclaration(rangeLambda.field()); - r.withFD(rangeEnd); - } - - return r; - } - - @Override - public DirectCompilerResult visit(ListNode n) { - MethodCallExpr list = Expressions.list(); - DirectCompilerResult result = DirectCompilerResult.of(list, BuiltInType.LIST); - - for (BaseNode e : n.getElements()) { - DirectCompilerResult r = e.accept(this); - result.withFD(r.getFieldDeclarations()); - list.addArgument(r.getExpression()); - } - - return result; - } - - @Override - public DirectCompilerResult visit(PathExpressionNode n) { - DirectCompilerResult expr = n.getExpression().accept(this); - BaseNode nameNode = n.getName(); - if (nameNode instanceof QualifiedNameNode) { - QualifiedNameNode qualifiedNameNode = (QualifiedNameNode) n.getName(); - List exprs = - qualifiedNameNode.getParts().stream() - .map(name -> new StringLiteralExpr(name.getText())) - .collect(Collectors.toList()); - - return DirectCompilerResult.of( - Expressions.path(expr.getExpression(), exprs), - // here we could still try to infer the result type, but presently use ANY - BuiltInType.UNKNOWN).withFD(expr); - } else { - return DirectCompilerResult.of( - Expressions.path(expr.getExpression(), new StringLiteralExpr(nameNode.getText())), - // here we could still try to infer the result type, but presently use ANY - BuiltInType.UNKNOWN).withFD(expr); - } - } - - @Override - public DirectCompilerResult visit(QuantifiedExpressionNode n) { - DirectCompilerResult expr = n.getExpression().accept(this); - HashSet fds = new HashSet<>(); - - Expressions.NamedLambda namedLambda = - Expressions.namedLambda( - expr.getExpression(), - n.getExpression().getText()); - - fds.add(namedLambda.field()); - fds.addAll(expr.getFieldDeclarations()); - - List expressions = n.getIterationContexts() - .stream() - .map(iter -> iter.accept(this)) - .peek(r -> fds.addAll(r.getFieldDeclarations())) - .map(DirectCompilerResult::getExpression) - .collect(Collectors.toList()); - - // .satisfies(expr) - return DirectCompilerResult.of( - Expressions.quantifier(n.getQuantifier(), namedLambda.name(), expressions), - expr.resultType, - fds); - } - - @Override - public DirectCompilerResult visit(RangeNode n) { - DirectCompilerResult start = n.getStart().accept(this); - DirectCompilerResult end = n.getEnd().accept(this); - return DirectCompilerResult.of( - Expressions.range( - n.getLowerBound(), - start.getExpression(), - end.getExpression(), - n.getUpperBound()), - BuiltInType.RANGE, - DirectCompilerResult.mergeFDs(start, end)); - } - - @Override - public DirectCompilerResult visit(SignedUnaryNode n) { - DirectCompilerResult result = n.getExpression().accept(this); - if (n.getSign() == SignedUnaryNode.Sign.NEGATIVE) { - return DirectCompilerResult.of( - Expressions.negate(result.getExpression()), - result.resultType, - result.getFieldDeclarations()); - } else { - return DirectCompilerResult.of( - Expressions.positive(result.getExpression()), - result.resultType, - result.getFieldDeclarations()); - } - } + public BlockStmt visit(InstanceOfNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } @Override - public DirectCompilerResult visit(UnaryTestNode n) { - DirectCompilerResult value = n.getValue().accept(this); - Expression expr = Expressions.unary(n.getOperator(), value.getExpression()); - Expressions.NamedLambda namedLambda = Expressions.namedUnaryLambda(expr, n.getText()); - DirectCompilerResult r = - DirectCompilerResult.of(namedLambda.name(), BuiltInType.UNARY_TEST) - .withFD(value); - r.addFieldDeclaration(namedLambda.field()); - return r; + public BlockStmt visit(IterationContextNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); } + + @Override + public BlockStmt visit(ListNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(ListTypeNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(NameDefNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(NamedParameterNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(NameRefNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(NullNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(NumberNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(PathExpressionNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(QualifiedNameNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(QuantifiedExpressionNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(RangeNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(SignedUnaryNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(StringNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(TemporalConstantNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(UnaryTestListNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + @Override + public BlockStmt visit(UnaryTestNode n) { + LOGGER.trace("visit {}", n); + return compilerHelper.add(n); + } + + public String getLastVariableName() { + LOGGER.trace("getLastVariableName"); + return compilerHelper.getLastVariableName(); + } + + public BlockStmt returnError(String errorMessage) { + LOGGER.trace("returnError {}", errorMessage); + return compilerHelper.returnError(errorMessage); + } + } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CodegenConstants.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CodegenConstants.java new file mode 100644 index 00000000000..120e9da37c4 --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CodegenConstants.java @@ -0,0 +1,83 @@ +/** + * 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.codegen.feel11; + +import java.math.BigDecimal; +import java.time.Duration; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetTime; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.temporal.TemporalAccessor; +import java.util.HashMap; +import java.util.Map; + +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.type.ClassOrInterfaceType; + +import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType; + +/** + * Class used to store constant values needed for codegen + */ +public class CodegenConstants { + + + // String + public static final String ADDFIELD_S = "addField"; + public static final String ASLIST_S = "asList"; + public static final String INSTANCE_S = "INSTANCE"; + public static final String OF_S = "of"; + public static final String PARSE_S = "parse"; + public static final String PUT_S = "put"; + public static final String VAR_S = "var"; + + // NameExpr + public static final NameExpr DURATION_N = new NameExpr(Duration.class.getCanonicalName()); + public static final NameExpr LOCAL_DATE_N = new NameExpr(LocalDate.class.getCanonicalName()); + public static final NameExpr LOCAL_DATE_TIME_N = new NameExpr(LocalDateTime.class.getCanonicalName()); + public static final NameExpr LOCAL_TIME_N = new NameExpr(LocalTime.class.getCanonicalName()); + public static final NameExpr OFFSETTIME_N = new NameExpr(OffsetTime.class.getCanonicalName()); + public static final NameExpr ZONED_DATE_TIME_N = new NameExpr(ZonedDateTime.class.getCanonicalName()); + public static final NameExpr ZONE_ID_N = new NameExpr(ZoneId.class.getCanonicalName()); + public static final NameExpr ZONE_OFFSET_N = new NameExpr(ZoneOffset.class.getCanonicalName()); + + + // ClassOrInterfaceType + public static final ClassOrInterfaceType BIGDECIMAL_CT = parseClassOrInterfaceType(BigDecimal.class.getCanonicalName()); + public static final ClassOrInterfaceType DURATION_CT = parseClassOrInterfaceType(Duration.class.getCanonicalName()); + public static final ClassOrInterfaceType HASHMAP_CT = parseClassOrInterfaceType(HashMap.class.getCanonicalName()); + public static final ClassOrInterfaceType ILLEGALSTATEEXCEPTION_CT = parseClassOrInterfaceType(IllegalStateException.class.getCanonicalName()); + public static final ClassOrInterfaceType INTEGER_CT = parseClassOrInterfaceType(Integer.class.getCanonicalName()); + public static final ClassOrInterfaceType LOCAL_DATE_CT = parseClassOrInterfaceType(LocalDate.class.getCanonicalName()); + public static final ClassOrInterfaceType LOCAL_DATE_TIME_CT = parseClassOrInterfaceType(LocalDateTime.class.getCanonicalName()); + public static final ClassOrInterfaceType LOCAL_TIME_CT = parseClassOrInterfaceType(LocalTime.class.getCanonicalName()); + public static final ClassOrInterfaceType OFFSETTIME_CT = parseClassOrInterfaceType(OffsetTime.class.getCanonicalName()); + public static final ClassOrInterfaceType MAP_CT = parseClassOrInterfaceType(Map.class.getCanonicalName()); + public static final ClassOrInterfaceType STRING_CT = parseClassOrInterfaceType(String.class.getCanonicalName()); + public static final ClassOrInterfaceType TEMPORALACCESSOR_CT = parseClassOrInterfaceType(TemporalAccessor.class.getCanonicalName()); + public static final ClassOrInterfaceType ZONED_DATE_TIME_CT = parseClassOrInterfaceType(ZonedDateTime.class.getCanonicalName()); + + + private CodegenConstants() { + } +} diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompilationErrorNotifier.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompilationErrorNotifier.java new file mode 100644 index 00000000000..7dbc77fb114 --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompilationErrorNotifier.java @@ -0,0 +1,31 @@ +/** + * 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.codegen.feel11; + +import org.kie.dmn.api.feel.runtime.events.FEELEvent; +import org.kie.dmn.feel.lang.EvaluationContext; +import org.kie.dmn.feel.runtime.events.ASTEventBase; + +public interface CompilationErrorNotifier { + + default Object notifyCompilationError(EvaluationContext feelExprCtx, String message) { + feelExprCtx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, message, null)); + return null; + } +} diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELExpression.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELExpression.java index 9e4cc60654b..02cc714c798 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELExpression.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELExpression.java @@ -23,6 +23,8 @@ import org.kie.dmn.feel.lang.CompiledExpression; import org.kie.dmn.feel.lang.EvaluationContext; -public interface CompiledFEELExpression extends CompiledExpression, Function { - +public interface CompiledFEELExpression extends CompiledExpression, + Function, + CompilationErrorNotifier { + } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELSemanticMappings.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELSemanticMappings.java deleted file mode 100644 index 21247c33311..00000000000 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELSemanticMappings.java +++ /dev/null @@ -1,494 +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.codegen.feel11; - -import java.time.Period; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.function.Supplier; - -import org.kie.dmn.api.feel.runtime.events.FEELEvent; -import org.kie.dmn.feel.lang.EvaluationContext; -import org.kie.dmn.feel.lang.ast.InfixOperator; -import org.kie.dmn.feel.lang.types.impl.ComparablePeriod; -import org.kie.dmn.feel.runtime.Range; -import org.kie.dmn.feel.runtime.UnaryTest; -import org.kie.dmn.feel.runtime.events.ASTEventBase; -import org.kie.dmn.feel.runtime.functions.ListContainsFunction; -import org.kie.dmn.feel.runtime.impl.RangeImpl; -import org.kie.dmn.feel.util.BooleanEvalHelper; -import org.kie.dmn.feel.util.EvalHelper; -import org.kie.dmn.feel.util.Msg; - -/** - * The purpose of this class is to offer import .* methods to compiled FEEL classes compiling expressions. - * Implementing DMN FEEL spec chapter 10.3.2.12 Semantic mappings - */ -public class CompiledFEELSemanticMappings { - - /** - * Represents a [n..m] construct - */ - public static RangeImpl range( - EvaluationContext ctx, - Range.RangeBoundary lowBoundary, - Object lowEndPoint, - Object highEndPoint, - Range.RangeBoundary highBoundary) { - - Comparable left = asComparable(lowEndPoint); - Comparable right = asComparable(highEndPoint); - if (left != null && right != null && !compatible(left, right)) { - ctx.notifyEvt(() -> new ASTEventBase( - FEELEvent.Severity.ERROR, - Msg.createMessage( - Msg.INCOMPATIBLE_TYPE_FOR_RANGE, - left.getClass().getSimpleName() - ), - null)); - return null; - } - return new RangeImpl( - lowBoundary, - left, - right, - highBoundary); - } - - public static Boolean includes( - EvaluationContext ctx, - Object range, - Object param) { - if (range instanceof Range) { - try { - return ((Range) range).includes(param); - } catch (Exception e) { - // e.g. java.base/java.time.Duration cannot be cast to java.base/java.time.Period - ctx.notifyEvt(() -> new ASTEventBase( - FEELEvent.Severity.ERROR, - Msg.createMessage( - Msg.INCOMPATIBLE_TYPE_FOR_RANGE, - param.getClass()), - null)); - return null; - } - } else if (range instanceof List) { - return ((List) range).contains(param); - } else if (range == null) { - ctx.notifyEvt(() -> new ASTEventBase( - FEELEvent.Severity.ERROR, - Msg.createMessage( - Msg.IS_NULL, - "range"), - null)); - return null; - } else { - return list(range).contains(param); - } - } - - /** - * Returns true when at least one of the elements of the list matches the target. - * The list may contain both objects (equals) and UnaryTests (apply) - */ - public static Boolean exists( - EvaluationContext ctx, - Object tests, - Object target) { - - if (!(tests instanceof List)) { - if (tests == null) { - ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.IS_NULL, "value"), null)); - return null; - } - return applyUnaryTest(ctx, tests, target); - } - - for (Object test : (List) tests) { - Boolean r = applyUnaryTest(ctx, test, target); - if (Boolean.TRUE.equals(r)) { - return true; - } - } - - return false; - } - - private static Boolean applyUnaryTest(EvaluationContext ctx, Object test, Object target) { - if (test instanceof UnaryTest) { - Boolean result = ((UnaryTest) test).apply(ctx, target); - return result != null && result; - } else if (test instanceof Range) { - Boolean result = ((Range) test).includes(target); - return result != null && result; - } else if (test == null) { - return target == null ? true : null; - } else { - return ListContainsFunction.itemEqualsSC(target, test); - } - } - - /** - * Implements a negated exists. - *

- * Returns false when at least one of the elements of the list - * matches the target. - * The list may contain both objects (equals) and UnaryTests (apply) - */ - public static Boolean notExists( - EvaluationContext ctx, - List tests, - Object target) { - - for (Object test : tests) { - Boolean r = applyUnaryTest(ctx, test, target); - if (r == null || r) { - return false; - } - } - - return true; - } - - public static Object getValue(EvaluationContext ctx, String varName) { - Object value = ctx.getValue(varName); - if (value == null && !ctx.isDefined(varName)) { - ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.UNKNOWN_VARIABLE_REFERENCE, varName), null)); - } - return value; - } - - private static boolean compatible(Comparable left, Comparable right) { - Class leftClass = left.getClass(); - Class rightClass = right.getClass(); - return leftClass.isAssignableFrom(rightClass) - || rightClass.isAssignableFrom(leftClass); - } - - private static Comparable asComparable(Object s) { - if (s == null) { - return null; - } else if (s instanceof Comparable) { - return (Comparable) s; - } else if (s instanceof Period) { - // period has special semantics - return new ComparablePeriod((Period) s); - } else { - throw new IllegalArgumentException("Unable to transform s " + s + " as Comparable"); - } - } - - public static Boolean coerceToBoolean(EvaluationContext ctx, Object value) { - if (value == null || value instanceof Boolean) { - return (Boolean) value; - } - - ctx.notifyEvt(() -> new ASTEventBase( - FEELEvent.Severity.ERROR, - Msg.createMessage( - Msg.X_TYPE_INCOMPATIBLE_WITH_Y_TYPE, - value == null ? "null" : value.getClass(), - "Boolean"), - null)); - - return null; - } - - public static T coerceTo(Class paramType, Object value) { - Object actual; - if (paramType.isAssignableFrom(value.getClass())) { - actual = value; - } else { - // try to coerce - if (value instanceof Number) { - if (paramType == byte.class || paramType == Byte.class) { - actual = ((Number) value).byteValue(); - } else if (paramType == short.class || paramType == Short.class) { - actual = ((Number) value).shortValue(); - } else if (paramType == int.class || paramType == Integer.class) { - actual = ((Number) value).intValue(); - } else if (paramType == long.class || paramType == Long.class) { - actual = ((Number) value).longValue(); - } else if (paramType == float.class || paramType == Float.class) { - actual = ((Number) value).floatValue(); - } else if (paramType == double.class || paramType == Double.class) { - actual = ((Number) value).doubleValue(); - } else if (paramType == Object[].class) { - actual = new Object[]{value}; - } else { - throw new IllegalArgumentException("Unable to coerce parameter " + value + ". Expected " + paramType + " but found " + value.getClass()); - } - } else if (value instanceof String - && ((String) value).length() == 1 - && (paramType == char.class || paramType == Character.class)) { - actual = ((String) value).charAt(0); - } else if (value instanceof Boolean && paramType == boolean.class) { - // Because Boolean can be also null, boolean.class is not assignable from Boolean.class. So we must coerce this. - actual = value; - } else { - throw new IllegalArgumentException("Unable to coerce parameter " + value + ". Expected " + paramType + " but found " + value.getClass()); - } - } - return (T) actual; - } - - /** - * Represent a [e1, e2, e3] construct. - */ - @SafeVarargs - @SuppressWarnings("varargs") - public static List list(T... a) { - if (a == null) { - return Collections.singletonList(null); - } - return Arrays.asList(a); - } - - /** - * FEEL spec Table 38 - * Delegates to {@link InfixOperator} except evaluationcontext - * - * @deprecated does not support short-circuit of the operator - */ - @Deprecated - public static Boolean and(Object left, Object right) { - return (Boolean) InfixOperator.AND.evaluate(left, right, null); - } - - public static Boolean and(Boolean left, Supplier right) { - if (left != null) { - if (left.booleanValue()) { - return right.get(); - } else { - return Boolean.FALSE; //left hand operand is false, we do not need to evaluate right side - } - } else { - Boolean rightAND = right.get(); - return Boolean.FALSE.equals(rightAND) ? Boolean.FALSE : null; - } - } - - public static Boolean and(boolean left, Object right) { - if (left == true) { - return BooleanEvalHelper.getBooleanOrNull(right); - } else { - return false; - } - } - - public static Boolean and(boolean left, boolean right) { - return left && right; - } - - /** - * FEEL spec Table 38 - * Delegates to {@link InfixOperator} except evaluationcontext - * - * @deprecated does not support short-circuit of the operator - */ - @Deprecated - public static Boolean or(Object left, Object right) { - return (Boolean) InfixOperator.OR.evaluate(left, right, null); - } - - public static Boolean or(Boolean left, Supplier right) { - if (left != null) { - if (!left.booleanValue()) { - return right.get(); - } else { - return Boolean.TRUE; //left hand operand is true, we do not need to evaluate right side - } - } else { - Boolean rightOR = right.get(); - return Boolean.TRUE.equals(rightOR) ? Boolean.TRUE : null; - } - } - - public static Boolean or(Object left, boolean right) { - if (right == true) { - return true; - } else { - return BooleanEvalHelper.getBooleanOrNull(left); - } - } - - public static Boolean or(boolean left, boolean right) { - return left || right; - } - - /** - * FEEL spec Table 45 - * Delegates to {@link InfixOperator} except evaluationcontext - */ - public static Object add(final Object left, final Object right, final EvaluationContext context) { - return InfixOperator.ADD.evaluate(left, right, context); - } - - /** - * FEEL spec Table 45 - * Delegates to {@link InfixOperator} except evaluationcontext - */ - public static Object sub(final Object left, final Object right, final EvaluationContext context) { - return InfixOperator.SUB.evaluate(left, right, context); - } - - /** - * FEEL spec Table 45 - * Delegates to {@link InfixOperator} except evaluationcontext - */ - public static Object mult(final Object left, final Object right, final EvaluationContext context) { - return InfixOperator.MULT.evaluate(left, right, context); - } - - /** - * FEEL spec Table 45 - * Delegates to {@link InfixOperator} except evaluationcontext - */ - public static Object div(final Object left, final Object right, final EvaluationContext context) { - return InfixOperator.DIV.evaluate(left, right, context); - } - - public static Object pow(final Object left, final Object right, final EvaluationContext context) { - return InfixOperator.POW.evaluate(left, right, context); - } - - /** - * FEEL spec Table 42 and derivations - * Delegates to {@link EvalHelper} except evaluationcontext - */ - public static Boolean lte(Object left, Object right) { - return or(lt(left, right), - eq(left, right)); // do not use Java || to avoid potential NPE due to FEEL 3vl. - } - - /** - * FEEL spec Table 42 and derivations - * Delegates to {@link EvalHelper} except evaluationcontext - */ - public static Boolean lt(Object left, Object right) { - return BooleanEvalHelper.compare(left, right, (l, r) -> l.compareTo(r) < 0); - } - - /** - * FEEL spec Table 42 and derivations - * Delegates to {@link EvalHelper} except evaluationcontext - */ - public static Boolean gte(Object left, Object right) { - return or(gt(left, right), - eq(left, right)); // do not use Java || to avoid potential NPE due to FEEL 3vl. - } - - /** - * FEEL spec Table 42 and derivations - * Delegates to {@link EvalHelper} except evaluationcontext - */ - public static Boolean gt(Object left, Object right) { - return BooleanEvalHelper.compare(left, right, (l, r) -> l.compareTo(r) > 0); - } - - /** - * FEEL spec Table 41: Specific semantics of equality - * Delegates to {@link EvalHelper} except evaluationcontext - */ - public static Boolean eq(Object left, Object right) { - return BooleanEvalHelper.isEqual(left, right); - } - - public static Boolean gracefulEq(EvaluationContext ctx, Object left, Object right) { - if (left instanceof List) { - return ((List) left).contains(right); - } else { - return eq(left, right); - } - } - - public static Boolean between(EvaluationContext ctx, - Object value, Object start, Object end) { - if (value == null) { - ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.IS_NULL, "value"), null)); - return null; - } - if (start == null) { - ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.IS_NULL, "start"), null)); - return null; - } - if (end == null) { - ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.IS_NULL, "end"), null)); - return null; - } - - Boolean gte = gte(value, start); - if (gte == null) { - ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.X_TYPE_INCOMPATIBLE_WITH_Y_TYPE, "value", "start"), null)); - } - Boolean lte = lte(value, end); - if (lte == null) { - ctx.notifyEvt(() -> new ASTEventBase(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.X_TYPE_INCOMPATIBLE_WITH_Y_TYPE, "value", "end"), null)); - } - return and(gte, lte); // do not use Java && to avoid potential NPE due to FEEL 3vl. - } - - /** - * FEEL spec Table 39 - */ - public static Boolean ne(Object left, Object right) { - return not(BooleanEvalHelper.isEqual(left, right)); - } - - public static Object negateTest(Object param) { - if (param instanceof Boolean) { - return param.equals(Boolean.FALSE); - } else if (param instanceof UnaryTest) { - UnaryTest orig = (UnaryTest) param; - UnaryTest t = negatedUnaryTest(orig); - return t; - } else if (param instanceof Range) { - UnaryTest t = (c, left) -> not(includes(c, param, left)); - return t; - } else { - UnaryTest t = (c, left) -> not(eq(left, param)); - return t; - } - } - - private static UnaryTest negatedUnaryTest(UnaryTest orig) { - return (c, left) -> { - Boolean r = orig.apply(c, left); - if (r == null) { - return null; - } - return r.equals(Boolean.FALSE); - }; - } - - public static Boolean not(Object arg, UnaryTest test) { - return not(test.apply(null, arg)); - } - - private static Boolean not(Object arg) { - if (Boolean.TRUE.equals(arg)) { - return Boolean.FALSE; - } - if (Boolean.FALSE.equals(arg)) { - return Boolean.TRUE; - } - return null; - } -} diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELSupport.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELSupport.java deleted file mode 100644 index aed762f5d36..00000000000 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELSupport.java +++ /dev/null @@ -1,566 +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.codegen.feel11; - -import java.math.BigDecimal; -import java.math.MathContext; -import java.time.Duration; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Function; - -import ch.obermuhlner.math.big.BigDecimalMath; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.expr.BooleanLiteralExpr; -import com.github.javaparser.ast.expr.LambdaExpr; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.stmt.ReturnStmt; -import com.github.javaparser.ast.stmt.Statement; -import com.github.javaparser.ast.type.UnknownType; -import org.kie.dmn.api.feel.runtime.events.FEELEvent; -import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; -import org.kie.dmn.api.feel.runtime.events.FEELEventListener; -import org.kie.dmn.feel.exceptions.EndpointOfRangeNotValidTypeException; -import org.kie.dmn.feel.exceptions.EndpointOfRangeOfDifferentTypeException; -import org.kie.dmn.feel.lang.EvaluationContext; -import org.kie.dmn.feel.lang.ast.ForExpressionNode; -import org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode; -import org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode.QEIteration; -import org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode.Quantifier; -import org.kie.dmn.feel.lang.ast.forexpressioniterators.ForIteration; -import org.kie.dmn.feel.lang.impl.SilentWrappingEvaluationContextImpl; -import org.kie.dmn.feel.lang.types.BuiltInType; -import org.kie.dmn.feel.lang.types.impl.ComparablePeriod; -import org.kie.dmn.feel.runtime.FEELFunction; -import org.kie.dmn.feel.runtime.Range; -import org.kie.dmn.feel.runtime.UnaryTest; -import org.kie.dmn.feel.runtime.events.ASTEventBase; -import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.events.SyntaxErrorEvent; -import org.kie.dmn.feel.util.EvalHelper; -import org.kie.dmn.feel.util.Msg; -import org.kie.dmn.feel.util.MsgUtil; -import org.kie.dmn.feel.util.NumberEvalHelper; - -import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType; -import static org.kie.dmn.feel.codegen.feel11.Expressions.compiledFeelSemanticMappingsFQN; -import static org.kie.dmn.feel.lang.ast.forexpressioniterators.ForIterationUtils.getForIteration; - -public class CompiledFEELSupport { - - public static ContextBuilder openContext(EvaluationContext ctx) { - return new ContextBuilder(ctx); - } - - public static class ContextBuilder { - private Map resultContext = new HashMap<>(); - private EvaluationContext evaluationContext; - - public ContextBuilder(EvaluationContext evaluationContext) { - this.evaluationContext = evaluationContext; - evaluationContext.enterFrame(); - } - - public ContextBuilder setEntry(String key, Object value) { - if (resultContext == null) { - return this; - } - if (resultContext.containsKey(key)) { - evaluationContext.notifyEvt(() -> new ASTEventBase(Severity.ERROR, Msg.createMessage(Msg.DUPLICATE_KEY_CTX, key), null)); - resultContext = null; - return this; - } - resultContext.put(key, value); - evaluationContext.setValue(key, value); - return this; - } - - public Map closeContext() { - evaluationContext.exitFrame(); - return resultContext; - } - } - - public static FilterBuilder filter(EvaluationContext ctx, Object value) { - return new FilterBuilder(ctx, value); - } - - public static class FilterBuilder { - - private EvaluationContext ctx; - private Object value; - - public FilterBuilder(EvaluationContext evaluationContext, Object value) { - this.ctx = evaluationContext; - this.value = value; - } - - public Object with(Function filterExpression) { - if (value == null) { - return null; - } - List list = value instanceof List ? (List) value : List.of(value); - - Object f = filterExpression.apply( - new SilentWrappingEvaluationContextImpl(ctx)); // I need to try evaluate filter first, ignoring errors; only if evaluation fails, or is not a Number, it delegates to try `evaluateExpressionsInContext` - - if (f instanceof Number) { - return withIndex(f); - } - - List results = new ArrayList(); - for (Object v : list) { - try { - ctx.enterFrame(); - // handle it as a predicate - // Have the "item" variable set first, so to respect the DMN spec: The expression in square brackets can reference a list - // element using the name item, unless the list element is a context that contains the key "item". - ctx.setValue("item", v); - - // using Root object logic to avoid having to eagerly inspect all attributes. - ctx.setRootObject(v); - - // Alignment to FilterExpressionNode: - // a filter would always return a list with all the elements for which the filter is true. - // In case any element fails in there or the filter expression returns null, it will only exclude the element, but will continue to process the list. - // In case all elements fail, the result will be an empty list. - Object r = filterExpression.apply(new SilentWrappingEvaluationContextImpl(ctx)); - if (r == Boolean.TRUE) { - results.add(v); - } - } catch (Exception e) { - ctx.notifyEvt(() -> new ASTEventBase(Severity.ERROR, Msg.createMessage(Msg.ERROR_EXECUTING_LIST_FILTER, filterExpression), null, e)); - return null; - } finally { - ctx.exitFrame(); - } - } - - return results; - } - - private Object withIndex(Object filterIndex) { - if (value == null) { - return null; - } - List list = value instanceof List ? (List) value : List.of(value); - - if (filterIndex instanceof Number) { - int i = ((Number) filterIndex).intValue(); - if (i > 0 && i <= list.size()) { - return list.get(i - 1); - } else if (i < 0 && Math.abs(i) <= list.size()) { - return list.get(list.size() + i); - } else { - ctx.notifyEvt(() -> new ASTEventBase(Severity.WARN, Msg.createMessage(Msg.INDEX_OUT_OF_BOUND, list.size(), i), null)); - return null; - } - } else if (filterIndex == null) { - return Collections.emptyList(); - } else { - ctx.notifyEvt(() -> new ASTEventBase(Severity.ERROR, Msg.createMessage(Msg.ERROR_EXECUTING_LIST_FILTER, filterIndex), null)); - return null; - } - } - } - - public static PathBuilder path(EvaluationContext ctx, Object value) { - return new PathBuilder(ctx, value); - } - - public static class PathBuilder { - - private EvaluationContext ctx; - private Object o; - - public PathBuilder(EvaluationContext evaluationContext, Object value) { - this.ctx = evaluationContext; - this.o = value; - } - - public Object with(final String... names) { - if (o instanceof List) { - List list = (List) o; - // list of contexts/elements as defined in the spec, page 114 - List results = new ArrayList(); - for (Object element : list) { - results.add(fetchValue(element, names)); - } - return results; - } else { - return fetchValue(o, names); - } - } - - private Object fetchValue(final Object o, final String... names) { - Object result = o; - for (String nr : names) { - result = EvalHelper.getDefinedValue(result, nr) - .getValueResult() - .cata(err -> { - // no need to report error here, eg: [ {x:1, y:2}, {x:2} ].y results in [2] with no errors. - return null; - }, Function.identity()); - } - return result; - } - } - - public static ForBuilder ffor(EvaluationContext ctx) { - return new ForBuilder(ctx); - } - - public static class ForBuilder { - - private EvaluationContext ctx; - private List iterationContexts = new ArrayList<>(); - - public ForBuilder(EvaluationContext evaluationContext) { - this.ctx = evaluationContext; - } - - public ForBuilder with(Function nameExpression, Function iterationExpression) { - iterationContexts.add(new IterationContextCompiled(nameExpression, iterationExpression)); - return this; - } - - public ForBuilder with(Function nameExpression, - Function iterationExpression, - Function rangeEndExpression) { - iterationContexts.add(new IterationContextCompiled(nameExpression, iterationExpression, rangeEndExpression)); - return this; - } - - public Object rreturn(Function expression) { - try { - ctx.enterFrame(); - List results = new ArrayList(); - ctx.setValue("partial", results); - ForIteration[] ictx = initializeContexts(ctx, iterationContexts); - - while (ForExpressionNode.nextIteration(ctx, ictx)) { - Object result = expression.apply(ctx); - results.add(result); - ctx.exitFrame(); // last i-th scope unrolled, see also ForExpressionNode.nextIteration(...) - } - return results; - } catch (EndpointOfRangeNotValidTypeException | EndpointOfRangeOfDifferentTypeException e) { - // ast error already reported - return null; - } finally { - ctx.exitFrame(); - } - } - - private ForIteration[] initializeContexts(EvaluationContext ctx, List iterationContexts) { - ForIteration[] ictx = new ForIteration[iterationContexts.size()]; - int i = 0; - for (IterationContextCompiled icn : iterationContexts) { - ictx[i] = createQuantifiedExpressionIterationContext(ctx, icn); - if (i < iterationContexts.size() - 1 && ictx[i].hasNextValue()) { - ctx.enterFrame(); // open loop scope frame, for every iter ctx, except last one as guarded by if clause above - ForExpressionNode.setValueIntoContext(ctx, ictx[i]); - } - i++; - } - return ictx; - } - - private ForIteration createQuantifiedExpressionIterationContext(EvaluationContext ctx, IterationContextCompiled icn) { - ForIteration fi; - String name = (String) icn.getName().apply(ctx); - Object result = icn.getExpression().apply(ctx); - Object rangeEnd = icn.getRangeEndExpr().apply(ctx); - if (rangeEnd == null) { - Iterable values = result instanceof Iterable ? (Iterable) result : Collections.singletonList(result); - fi = new ForIteration(name, values); - } else { - fi = getForIteration(ctx, name, result, rangeEnd); - } - return fi; - } - - } - - public static class IterationContextCompiled { - - private final Function name; - private final Function expression; - private final Function rangeEndExpr; - - public IterationContextCompiled(Function name, Function expression) { - this.name = name; - this.expression = expression; - this.rangeEndExpr = (ctx) -> null; - } - - public IterationContextCompiled(Function name, Function expression, Function rangeEndExpr) { - this.name = name; - this.expression = expression; - this.rangeEndExpr = rangeEndExpr; - } - - public Function getName() { - return name; - } - - public Function getExpression() { - return expression; - } - - public Function getRangeEndExpr() { - return rangeEndExpr; - } - - } - - public static QuantBuilder quant(Quantifier quantOp, EvaluationContext ctx) { - return new QuantBuilder(quantOp, ctx); - } - - public static class QuantBuilder { - - private Quantifier quantOp; - private EvaluationContext ctx; - private List iterationContexts = new ArrayList<>(); - - public QuantBuilder(Quantifier quantOp, EvaluationContext evaluationContext) { - this.quantOp = quantOp; - this.ctx = evaluationContext; - } - - public QuantBuilder with(Function nameExpression, Function iterationExpression) { - iterationContexts.add(new IterationContextCompiled(nameExpression, iterationExpression)); - return this; - } - - public Object satisfies(Function expression) { - if (quantOp == Quantifier.SOME || quantOp == Quantifier.EVERY) { - return iterateContexts(ctx, iterationContexts, expression, quantOp); - } - // can never happen, but anyway: - ctx.notifyEvt(() -> new ASTEventBase(Severity.ERROR, Msg.createMessage(Msg.IS_NULL, "Quantifier"), null)); - return null; - } - - private Boolean iterateContexts(EvaluationContext ctx, List iterationContexts, Function expression, Quantifier quantifier) { - try { - ctx.enterFrame(); - QEIteration[] ictx = initializeContexts(ctx, iterationContexts); - - while (QuantifiedExpressionNode.nextIteration(ctx, ictx)) { - Boolean result = (Boolean) expression.apply(ctx); - if (result != null && result.equals(quantifier.positiveTest())) { - return quantifier.positiveTest(); - } - } - return quantifier.defaultValue(); - } finally { - ctx.exitFrame(); - } - } - - private QEIteration[] initializeContexts(EvaluationContext ctx, List iterationContexts) { - QEIteration[] ictx = new QEIteration[iterationContexts.size()]; - int i = 0; - for (IterationContextCompiled icn : iterationContexts) { - ictx[i] = createQuantifiedExpressionIterationContext(ctx, icn); - if (i < ictx.length - 1) { - // initalize all contexts except the very last one, as it will be initialized in the nextIteration() method - QuantifiedExpressionNode.setValueIntoContext(ctx, ictx[i]); - } - i++; - } - return ictx; - } - - private QEIteration createQuantifiedExpressionIterationContext(EvaluationContext ctx, IterationContextCompiled icn) { - String name = (String) icn.getName().apply(ctx); - Object result = icn.getExpression().apply(ctx); - Iterable values = result instanceof Iterable ? (Iterable) result : Collections.singletonList(result); - QEIteration qei = new QEIteration(name, values); - return qei; - } - } - - public static Object invoke(EvaluationContext feelExprCtx, Object function, Object params) { - if (function == null) { - feelExprCtx.notifyEvt(() -> new ASTEventBase(Severity.ERROR, Msg.createMessage(Msg.FUNCTION_NOT_FOUND, function), null)); - return null; - } - if (function instanceof FEELFunction) { - Object[] invocationParams = toFunctionParams(params); - - FEELFunction f = (FEELFunction) function; - - if (function instanceof CompiledCustomFEELFunction) { - CompiledCustomFEELFunction ff = (CompiledCustomFEELFunction) function; - if (ff.isProperClosure()) { - return ff.invokeReflectively(ff.getEvaluationContext(), invocationParams); - } - } - - return f.invokeReflectively(feelExprCtx, invocationParams); - } else if (function instanceof UnaryTest) { - return ((UnaryTest) function).apply(feelExprCtx, ((List)params).get(0)); - } else if (function instanceof Range) { - // alignment to FunctionInvocationNode - List ps = (List) params; - if (ps.size() == 1) { - return ((Range) function).includes(ps.get(0)); - } else { - feelExprCtx.notifyEvt(() -> new ASTEventBase(Severity.ERROR, Msg.createMessage(Msg.CAN_T_INVOKE_AN_UNARY_TEST_WITH_S_PARAMETERS_UNARY_TESTS_REQUIRE_1_SINGLE_PARAMETER, ps.size()), null)); - } - } - feelExprCtx.notifyEvt(() -> new ASTEventBase(Severity.ERROR, Msg.createMessage(Msg.CANNOT_INVOKE, MsgUtil.clipToString(function, 50)), null)); - return null; - } - - private static Object[] toFunctionParams(Object params) { - Object[] invocationParams; - if (params instanceof List) { - invocationParams = ((List) params).toArray(new Object[]{}); - } else if (params instanceof Object[]) { - invocationParams = (Object[]) params; - } else { - invocationParams = new Object[]{params}; - } - return invocationParams; - } - - public static Object notifyCompilationError(EvaluationContext feelExprCtx, String message) { - feelExprCtx.notifyEvt(() -> new ASTEventBase(Severity.ERROR, message, null)); - return null; - } - - public static Object coerceNumber(Object value) { - return NumberEvalHelper.coerceNumber(value); - } - - - /** - * Generates a compilable class that reports a (compile-time) error at runtime - */ - public static CompiledFEELExpression compiledError(String expression, String msg) { - return new CompilerBytecodeLoader() - .makeFromJPExpression( - expression, - compiledErrorExpression(msg), - Collections.emptySet()); - } - - public static DirectCompilerResult compiledErrorUnaryTest(String msg) { - - LambdaExpr initializer = new LambdaExpr(); - initializer.setEnclosingParameters(true); - initializer.addParameter(new Parameter(new UnknownType(), "feelExprCtx")); - initializer.addParameter(new Parameter(new UnknownType(), "left")); - Statement lambdaBody = new BlockStmt(new NodeList<>( - new ExpressionStmt(compiledErrorExpression(msg)), - new ReturnStmt(new BooleanLiteralExpr(false)) - )); - initializer.setBody(lambdaBody); - String constantName = "UT_EMPTY"; - VariableDeclarator vd = new VariableDeclarator(parseClassOrInterfaceType(UnaryTest.class.getCanonicalName()), constantName); - vd.setInitializer(initializer); - FieldDeclaration fd = new FieldDeclaration(); - fd.setModifier(Modifier.publicModifier().getKeyword(), true); - fd.setModifier(Modifier.staticModifier().getKeyword(), true); - fd.setModifier(Modifier.finalModifier().getKeyword(), true); - fd.addVariable(vd); - - fd.setJavadocComment(" FEEL unary test: - "); - - MethodCallExpr list = new MethodCallExpr(compiledFeelSemanticMappingsFQN(), "list", new NodeList<>(new NameExpr(constantName))); - - DirectCompilerResult directCompilerResult = DirectCompilerResult.of(list, BuiltInType.LIST); - directCompilerResult.addFieldDeclaration(fd); - return directCompilerResult; - - } - - - public static MethodCallExpr compiledErrorExpression(String msg) { - return new MethodCallExpr( - new NameExpr("CompiledFEELSupport"), - "notifyCompilationError", - new NodeList<>( - new NameExpr("feelExprCtx"), - Expressions.stringLiteral(msg))); - } - - // thread-unsafe, but this is single-threaded so it's ok - public static class SyntaxErrorListener implements FEELEventListener { - private FEELEvent event = null; - @Override - public void onEvent(FEELEvent evt) { - if (evt instanceof SyntaxErrorEvent - || evt instanceof InvalidParametersEvent) { - this.event = evt; - } - } - public boolean isError() { return event != null; } - public FEELEvent event() { return event; } - } - - public static BigDecimal pow(BigDecimal l, BigDecimal r) { - return BigDecimalMath.pow( l, r, MathContext.DECIMAL128 ); - } - - public static Object negate(EvaluationContext feelExprCtx, Object value) { - if (isValidSignedType(feelExprCtx, value)) { - if (value instanceof ComparablePeriod comparablePeriod) { - return comparablePeriod.negated(); - } - if (value instanceof Duration duration) { - return duration.negated(); - } - return ((BigDecimal) value).negate(); - } else { - return null; - } - } - - public static BigDecimal positive(EvaluationContext feelExprCtx, Object value) { - if (isValidSignedType(feelExprCtx, value)) { - return (BigDecimal) value; - } else { - return null; - } - } - - private static boolean isValidSignedType(EvaluationContext feelExprCtx, Object value) { - if (value instanceof String) { - feelExprCtx.notifyEvt(() -> new ASTEventBase(Severity.ERROR, Msg.createMessage(Msg.CANNOT_BE_SIGNED), null)); - return false; - } else { - return true; - } - } -} diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELUnaryTests.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELUnaryTests.java index 33a09ebc27d..c60d10987ee 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELUnaryTests.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompiledFEELUnaryTests.java @@ -22,7 +22,7 @@ import org.kie.dmn.feel.runtime.UnaryTest; -public interface CompiledFEELUnaryTests { +public interface CompiledFEELUnaryTests extends CompilationErrorNotifier { List getUnaryTests(); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompilerBytecodeLoader.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompilerBytecodeLoader.java index 211388f3784..37150828de9 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompilerBytecodeLoader.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompilerBytecodeLoader.java @@ -19,10 +19,10 @@ package org.kie.dmn.feel.codegen.feel11; import java.util.Arrays; -import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map.Entry; +import java.util.Optional; import java.util.Set; import java.util.UUID; @@ -35,18 +35,24 @@ import com.github.javaparser.ast.expr.CastExpr; import com.github.javaparser.ast.expr.EnclosedExpr; import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.NullLiteralExpr; +import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.stmt.ThrowStmt; import org.drools.compiler.compiler.io.memory.MemoryFileSystem; +import org.drools.util.PortablePath; import org.kie.dmn.feel.util.ClassLoaderUtil; import org.kie.memorycompiler.CompilationResult; import org.kie.memorycompiler.JavaCompiler; -import org.drools.util.PortablePath; import org.kie.memorycompiler.resources.MemoryResourceReader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static com.github.javaparser.StaticJavaParser.parse; import static org.drools.compiler.compiler.JavaDialectConfiguration.createNativeCompiler; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.CREATEBASENODE_S; public class CompilerBytecodeLoader { @@ -88,27 +94,6 @@ public Class load(MemoryFileSystem pStore, String string) { } - public CompiledFEELExpression makeFromJPExpression(Expression theExpression) { - return makeFromJPExpression(null, theExpression, Collections.emptySet()); - } - - public CompiledFEELExpression makeFromJPExpression(String feelExpression, Expression theExpression, Set fieldDeclarations) { - return internal_makefromJP(CompiledFEELExpression.class, "/TemplateCompiledFEELExpression.java", generateRandomPackage(), "TemplateCompiledFEELExpression", feelExpression, theExpression, fieldDeclarations); - } - - public CompiledFEELUnaryTests makeFromJPUnaryTestsExpression(String feelExpression, Expression theExpression, Set fieldDeclarations) { - return internal_makefromJP(CompiledFEELUnaryTests.class, "/TemplateCompiledFEELUnaryTests.java", generateRandomPackage(), "TemplateCompiledFEELUnaryTests", feelExpression, theExpression, fieldDeclarations); - } - - public CompiledFEELUnaryTests makeFromJPUnaryTestsExpression(String packageName, String className, String feelExpression, Expression theExpression, Set fieldDeclarations) { - return internal_makefromJP(CompiledFEELUnaryTests.class, "/TemplateCompiledFEELUnaryTests.java", packageName, className, feelExpression, theExpression, fieldDeclarations); - } - - public T internal_makefromJP(Class clazz, String templateResourcePath, String cuPackage, String cuClass, String feelExpression, Expression theExpression, Set fieldDeclarations) { - CompilationUnit cu = getCompilationUnit(clazz, templateResourcePath, cuPackage, cuClass, feelExpression, theExpression, fieldDeclarations); - return compileUnit(cuPackage, cuClass, cu); - } - public T compileUnit(String cuPackage, String cuClass, CompilationUnit cu) { try { MemoryResourceReader pReader = new MemoryResourceReader(); @@ -118,13 +103,18 @@ public T compileUnit(String cuPackage, String cuClass, CompilationUnit cu) CompilationResult compilationResult = compiler.compile(new String[]{cuPackage.replaceAll("\\.", "/") + "/" + cuClass + ".java"}, pReader, pStore, - this.getClass().getClassLoader()); - LOG.debug("{}", Arrays.asList(compilationResult.getErrors())); - LOG.debug("{}", Arrays.asList(compilationResult.getWarnings())); + Thread.currentThread().getContextClassLoader()); + if (compilationResult.getErrors().length > 0) { + LOG.error("{}", Arrays.asList(compilationResult.getErrors())); + } + if (compilationResult.getWarnings().length > 0) { + LOG.warn("{}", Arrays.asList(compilationResult.getWarnings())); + } String fqnClassName = cuPackage + "." + cuClass; - Class loaded = (Class) new TemplateLoader(this.getClass().getClassLoader()).load(pStore, fqnClassName); - + Class loaded = + (Class) new TemplateLoader(Thread.currentThread().getContextClassLoader()).load(pStore, + fqnClassName); return loaded.newInstance(); } catch (Exception e) { LOG.error("Exception", e); @@ -132,68 +122,93 @@ public T compileUnit(String cuPackage, String cuClass, CompilationUnit cu) return null; } - public String getSourceForUnaryTest(String packageName, String className, String feelExpression, DirectCompilerResult directResult) { - return getSourceForUnaryTest(packageName, className, feelExpression, directResult.getExpression(), directResult.getFieldDeclarations()); - } + public CompilationUnit getCompilationUnit(String templateResourcePath, String cuPackage, + String cuClass, String feelExpression, + BlockStmt directCodegenResult, + String lastVariableName) { + CompilationUnit toReturn = getCompilationUnit(templateResourcePath, cuPackage, cuClass); + populateFirstMethodJavadoc(toReturn, feelExpression); + MethodDeclaration createBaseNodeMethodDeclaration = getCreateBaseNodeMethodDeclaration(toReturn); + ReturnStmt returnStmt = getReturnStmt(createBaseNodeMethodDeclaration, directCodegenResult); + Optional lastStatement = directCodegenResult.getStatements().getLast(); + if (lastStatement.isPresent() && lastStatement.get() instanceof ThrowStmt) { + directCodegenResult.remove(returnStmt); + createBaseNodeMethodDeclaration.remove(returnStmt); + } else { + Expression returnExpression = getReturnExpression(lastVariableName, lastStatement, + directCodegenResult); + returnStmt.setExpression(returnExpression); + directCodegenResult.addStatement(returnStmt); + } + List classDecls = toReturn.findAll(ClassOrInterfaceDeclaration.class); + if (classDecls.size() != 1) { + throw new RuntimeException("Something unexpected changed in the template."); + } - public String getSourceForUnaryTest(String packageName, String className, String feelExpression, Expression theExpression, Set fieldDeclarations) { - CompilationUnit cu = getCompilationUnit(CompiledFEELUnaryTests.class, "/TemplateCompiledFEELUnaryTests.java", packageName, className, feelExpression, theExpression, fieldDeclarations); - ClassOrInterfaceDeclaration classSource = cu.getClassByName( className ).orElseThrow(() -> new IllegalArgumentException("Cannot find class by name " + className)); - classSource.setStatic( true ); - return classSource.toString(); + if (generateClassListener != null) { + generateClassListener.generatedClass(toReturn); + } + + LOG.debug("{}", toReturn); + return toReturn; } - public CompilationUnit getCompilationUnit(Class clazz, String templateResourcePath, String cuPackage, String cuClass, String feelExpression, Expression theExpression, Set fieldDeclarations) { + private CompilationUnit getCompilationUnit(String templateResourcePath, String cuPackage, String cuClass) { CompilationUnit cu = parse(CompilerBytecodeLoader.class.getResourceAsStream(templateResourcePath)); cu.setPackageDeclaration(cuPackage); - final String className = templateResourcePath.substring( 1, templateResourcePath.length() - 5); - ClassOrInterfaceDeclaration classSource = cu.getClassByName(className).orElseThrow(() -> new IllegalArgumentException("Cannot find class by name " + className)); - classSource.setName( cuClass ); + final String className = templateResourcePath.substring(1, templateResourcePath.length() - 5); + ClassOrInterfaceDeclaration classSource = + cu.getClassByName(className).orElseThrow(() -> new IllegalArgumentException("Cannot find class by " + + "name " + className)); + classSource.setName(cuClass); + return cu; + } - MethodDeclaration lookupMethod = cu + private void populateFirstMethodJavadoc(CompilationUnit cu, String feelExpression) { + MethodDeclaration applyMethodDEclaration = cu .findFirst(MethodDeclaration.class) .orElseThrow(() -> new RuntimeException("Something unexpected changed in the template.")); + applyMethodDEclaration.setComment(new JavadocComment(" FEEL: " + feelExpression + " ")); + } - lookupMethod.setComment(new JavadocComment(" FEEL: " + feelExpression + " ")); + private MethodDeclaration getCreateBaseNodeMethodDeclaration(CompilationUnit cu) { + return cu + .findFirst(MethodDeclaration.class, + methodDeclaration -> methodDeclaration.getName().asString().equals(CREATEBASENODE_S)) + .orElseThrow(() -> new RuntimeException("Something unexpected changed in the template.")); + } - ReturnStmt returnStmt = + private ReturnStmt getReturnStmt(MethodDeclaration lookupMethod, BlockStmt directCodegenResult) { + ReturnStmt toReturn = lookupMethod.findFirst(ReturnStmt.class) - .orElseThrow(() -> new RuntimeException("Something unexpected changed in the template.")); + .orElseThrow(() -> new RuntimeException("Something unexpected changed in the template.")); + lookupMethod.setBody(directCodegenResult); + return toReturn; + } - Expression expr; - if (clazz.equals(CompiledFEELUnaryTests.class)) { - expr = new CastExpr(StaticJavaParser.parseType("java.util.List"), new EnclosedExpr(theExpression)); + private Expression getReturnExpression(String lastVariableName, + Optional lastStatement, + BlockStmt directCodegenResult) { + Expression toReturn; + if (lastVariableName != null) { + toReturn = new NameExpr(lastVariableName); } else { - expr = theExpression; - } - returnStmt.setExpression(expr); - - List classDecls = cu.findAll(ClassOrInterfaceDeclaration.class); - if (classDecls.size() != 1) { - throw new RuntimeException("Something unexpected changed in the template."); - } - ClassOrInterfaceDeclaration classDecl = classDecls.get(0); - - fieldDeclarations.stream() - .filter(fd -> !isUnaryTest(fd)) - .sorted(new SortFieldDeclarationStrategy()).forEach(classDecl::addMember); - fieldDeclarations.stream() - .filter(fd -> fd.getVariable(0).getName().asString().startsWith("UT")) - .sorted(new SortFieldDeclarationStrategy()).forEach(classDecl::addMember); - - if (generateClassListener != null) { - generateClassListener.generatedClass(cu); + if (lastStatement.isPresent()) { + Statement lastStmt = lastStatement.get(); + toReturn = lastStmt.asExpressionStmt().getExpression(); + directCodegenResult.remove(lastStmt); + } else { + toReturn = new NullLiteralExpr(); + } } - - LOG.debug("{}", cu); - return cu; + return toReturn; } private boolean isUnaryTest(FieldDeclaration fd) { return fd.getVariable(0).getName().asString().startsWith("UT"); } - private String generateRandomPackage() { + public String generateRandomPackage() { String uuid = UUID.randomUUID().toString().replaceAll("-", ""); return this.getClass().getPackage().getName() + ".gen" + uuid; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Constants.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Constants.java index b3319d8137f..3cf8efdb44d 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Constants.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Constants.java @@ -18,9 +18,6 @@ */ package org.kie.dmn.feel.codegen.feel11; -import java.math.BigDecimal; -import java.util.List; - import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.FieldDeclaration; @@ -31,26 +28,20 @@ import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.ast.expr.ObjectCreationExpr; import com.github.javaparser.ast.expr.StringLiteralExpr; -import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.ast.type.Type; import org.kie.dmn.feel.lang.ast.RangeNode; -import org.kie.dmn.feel.runtime.Range; -import org.kie.dmn.feel.runtime.UnaryTest; import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType; import static com.github.javaparser.StaticJavaParser.parseExpression; -import static com.github.javaparser.StaticJavaParser.parseType; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.BIGDECIMAL_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.FUNCTION_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.RANGEBOUNDARY_S; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.UNARYTEST_CT; public class Constants { - public static final Expression DECIMAL_128 = parseExpression("java.math.MathContext.DECIMAL128"); - public static final ClassOrInterfaceType BigDecimalT = parseClassOrInterfaceType(BigDecimal.class.getCanonicalName()); - public static final ClassOrInterfaceType BooleanT = parseClassOrInterfaceType(Boolean.class.getCanonicalName()); - private static final Type ListT = parseType(List.class.getCanonicalName()); - public static final ClassOrInterfaceType UnaryTestT = parseClassOrInterfaceType(UnaryTest.class.getCanonicalName()); - public static final String RangeBoundary = Range.RangeBoundary.class.getCanonicalName(); - public static final Expression BuiltInTypeT = parseExpression("org.kie.dmn.feel.lang.types.BuiltInType"); - public static final ClassOrInterfaceType FunctionT = parseClassOrInterfaceType("java.util.function.Function"); + public static final Expression DECIMAL_128_E = parseExpression("java.math.MathContext.DECIMAL128"); + public static final Expression BUILTINTYPE_E = parseExpression("org.kie.dmn.feel.lang.types.BuiltInType"); public static FieldDeclaration of(Type type, String name, Expression initializer) { return new FieldDeclaration( @@ -60,7 +51,7 @@ public static FieldDeclaration of(Type type, String name, Expression initializer public static FieldDeclaration numeric(String name, String numericValue) { ObjectCreationExpr initializer = new ObjectCreationExpr(); - initializer.setType(BigDecimalT); + initializer.setType(BIGDECIMAL_CT); String originalText = numericValue; try { Long.parseLong(originalText); @@ -68,8 +59,8 @@ public static FieldDeclaration numeric(String name, String numericValue) { } catch (Throwable t) { initializer.addArgument(new StringLiteralExpr(originalText)); } - initializer.addArgument(DECIMAL_128); - return of(BigDecimalT, name, initializer); + initializer.addArgument(DECIMAL_128_E); + return of(BIGDECIMAL_CT, name, initializer); } public static String numericName(String originalText) { @@ -77,7 +68,7 @@ public static String numericName(String originalText) { } public static FieldDeclaration unaryTest(String name, LambdaExpr value) { - return of(UnaryTestT, name, value); + return of(UNARYTEST_CT, name, value); } public static String unaryTestName(String originalText) { @@ -85,7 +76,7 @@ public static String unaryTestName(String originalText) { } public static FieldDeclaration function(String name, LambdaExpr value) { - return of(FunctionT, name, value); + return of(FUNCTION_CT, name, value); } public static String functionName(String originalText) { @@ -102,7 +93,7 @@ public static String dtConstantName(String originalText) { public static FieldAccessExpr rangeBoundary(RangeNode.IntervalBoundary boundary) { return new FieldAccessExpr( - new NameExpr(RangeBoundary), + new NameExpr(RANGEBOUNDARY_S), boundary == RangeNode.IntervalBoundary.OPEN ? "OPEN" : "CLOSED"); } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Contexts.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Contexts.java deleted file mode 100644 index 047b897b15f..00000000000 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Contexts.java +++ /dev/null @@ -1,55 +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.codegen.feel11; - -import java.lang.reflect.Method; -import java.util.Map; - -import com.github.javaparser.ast.expr.EnclosedExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; -import com.github.javaparser.ast.type.Type; -import org.kie.dmn.feel.lang.CompositeType; -import org.kie.dmn.feel.lang.impl.JavaBackedType; -import org.kie.dmn.feel.lang.impl.MapBackedType; -import org.kie.dmn.feel.util.EvalHelper; - -import static com.github.javaparser.StaticJavaParser.parseType; - -public class Contexts { - - public static final Type MapT = parseType(Map.class.getCanonicalName()); - - public static Expression getKey(Expression currentContext, CompositeType contextType, String key) { - if (contextType instanceof MapBackedType) { - EnclosedExpr enclosedExpr = Expressions.castTo(MapT, currentContext); - return new MethodCallExpr(enclosedExpr, "get") - .addArgument(new StringLiteralExpr(key)); - } else if (contextType instanceof JavaBackedType) { - JavaBackedType javaBackedType = (JavaBackedType) contextType; - Class wrappedType = javaBackedType.getWrapped(); - Method accessor = EvalHelper.getGenericAccessor(wrappedType, key); - Type type = parseType(wrappedType.getCanonicalName()); - return new MethodCallExpr(Expressions.castTo(type, currentContext), accessor.getName()); - } else { - throw new UnsupportedOperationException("A Composite type is either MapBacked or JavaBAcked"); - } - } -} 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 new file mode 100644 index 00000000000..59d96289d39 --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/DMNCodegenConstants.java @@ -0,0 +1,175 @@ +/** + * 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.codegen.feel11; + +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +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.InfixOperator; +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.SignedUnaryNode; +import org.kie.dmn.feel.lang.ast.StringNode; +import org.kie.dmn.feel.lang.ast.TemporalConstantNode; +import org.kie.dmn.feel.lang.ast.UnaryTestListNode; +import org.kie.dmn.feel.lang.ast.UnaryTestNode; +import org.kie.dmn.feel.lang.impl.JavaBackedType; +import org.kie.dmn.feel.lang.impl.MapBackedType; +import org.kie.dmn.feel.lang.types.AliasFEELType; +import org.kie.dmn.feel.lang.types.impl.ComparablePeriod; +import org.kie.dmn.feel.runtime.Range; +import org.kie.dmn.feel.runtime.UnaryTest; +import org.kie.dmn.feel.runtime.functions.TimeFunction; +import org.kie.dmn.feel.util.NumberEvalHelper; + +import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType; + +/** + * Class used to store constant values needed for codegen + */ +public class DMNCodegenConstants { + + // String + public static final String CREATEBASENODE_S = "createBaseNode"; + public static final String DETERMINEOPERATOR_S = "determineOperator"; + public static final String FEEL_TIME_S = "FEEL_TIME"; + public static final String GETBIGDECIMALORNULL_S = "getBigDecimalOrNull"; + public static final String RANGEBOUNDARY_S = Range.RangeBoundary.class.getCanonicalName(); + + // NameExpr + public static final NameExpr INFIXOPERATOR_N = new NameExpr(InfixOperator.class.getCanonicalName()); + public static final NameExpr COMPARABLEPERIOD_N = new NameExpr(ComparablePeriod.class.getCanonicalName()); + public static final NameExpr JAVABACKEDTYPE_N = new NameExpr(JavaBackedType.class.getCanonicalName()); + public static final NameExpr NUMBEREVALHELPER_N = new NameExpr(NumberEvalHelper.class.getCanonicalName()); + public static final NameExpr TIMEFUNCTION_N = new NameExpr(TimeFunction.class.getCanonicalName()); + + // ClassOrInterfaceType + public static final ClassOrInterfaceType COMPARABLEPERIOD_CT = + parseClassOrInterfaceType(ComparablePeriod.class.getCanonicalName()); + public static final ClassOrInterfaceType FUNCTION_CT = parseClassOrInterfaceType("java.util.function" + + ".Function" + + ""); + public static final ClassOrInterfaceType ALIASFEELTYPE_CT = + parseClassOrInterfaceType(AliasFEELType.class.getCanonicalName()); + public static final ClassOrInterfaceType MAPBACKEDTYPE_CT = + parseClassOrInterfaceType(MapBackedType.class.getCanonicalName()); + public static final ClassOrInterfaceType TYPE_CT = + parseClassOrInterfaceType(org.kie.dmn.feel.lang.Type.class.getCanonicalName()); + public static final ClassOrInterfaceType UNARYTEST_CT = + parseClassOrInterfaceType(UnaryTest.class.getCanonicalName()); + + // BaseNode + public static final ClassOrInterfaceType ATLITERALNODE_CT = + parseClassOrInterfaceType(AtLiteralNode.class.getCanonicalName()); + public static final ClassOrInterfaceType BETWEENNODE_CT = + parseClassOrInterfaceType(BetweenNode.class.getCanonicalName()); + public static final ClassOrInterfaceType BOOLEANNODE_CT = + parseClassOrInterfaceType(BooleanNode.class.getCanonicalName()); + public static final ClassOrInterfaceType CONTEXTNODE_CT = + parseClassOrInterfaceType(ContextNode.class.getCanonicalName()); + public static final ClassOrInterfaceType CONTEXTENTRYNODE_CT = + parseClassOrInterfaceType(ContextEntryNode.class.getCanonicalName()); + public static final ClassOrInterfaceType CONTEXTTYPENODE_CT = + parseClassOrInterfaceType(ContextTypeNode.class.getCanonicalName()); + public static final ClassOrInterfaceType CTYPENODE_CT = + parseClassOrInterfaceType(CTypeNode.class.getCanonicalName()); + public static final ClassOrInterfaceType DASHNODE_CT = parseClassOrInterfaceType(DashNode.class.getCanonicalName()); + public static final ClassOrInterfaceType FILTEREXPRESSIONNODE_CT = + parseClassOrInterfaceType(FilterExpressionNode.class.getCanonicalName()); + public static final ClassOrInterfaceType FOREXPRESSIONNODE_CT = + parseClassOrInterfaceType(ForExpressionNode.class.getCanonicalName()); + public static final ClassOrInterfaceType FORMALPARAMETERNODE_CT = + parseClassOrInterfaceType(FormalParameterNode.class.getCanonicalName()); + public static final ClassOrInterfaceType FUNCTIONDEFNODE_CT = + parseClassOrInterfaceType(FunctionDefNode.class.getCanonicalName()); + public static final ClassOrInterfaceType FUNCTIONTYPENODE_CT = + parseClassOrInterfaceType(FunctionTypeNode.class.getCanonicalName()); + public static final ClassOrInterfaceType FUNCTIONINVOCATIONNODE_CT = + parseClassOrInterfaceType(FunctionInvocationNode.class.getCanonicalName()); + public static final ClassOrInterfaceType IFEXPRESSIONNODE_CT = + parseClassOrInterfaceType(IfExpressionNode.class.getCanonicalName()); + public static final ClassOrInterfaceType INFIXOPNODE_CT = + parseClassOrInterfaceType(InfixOpNode.class.getCanonicalName()); + public static final ClassOrInterfaceType INNODE_CT = parseClassOrInterfaceType(InNode.class.getCanonicalName()); + public static final ClassOrInterfaceType INSTANCEOFNODE_CT = + parseClassOrInterfaceType(InstanceOfNode.class.getCanonicalName()); + public static final ClassOrInterfaceType ITERATIONCONTEXTNODE_CT = + parseClassOrInterfaceType(IterationContextNode.class.getCanonicalName()); + public static final ClassOrInterfaceType LISTNODE_CT = parseClassOrInterfaceType(ListNode.class.getCanonicalName()); + public static final ClassOrInterfaceType LISTTYPENODE_CT = + parseClassOrInterfaceType(ListTypeNode.class.getCanonicalName()); + public static final ClassOrInterfaceType NAMEDEFNODE_CT = + parseClassOrInterfaceType(NameDefNode.class.getCanonicalName()); + public static final ClassOrInterfaceType NAMEDPARAMETERNODE_CT = + parseClassOrInterfaceType(NamedParameterNode.class.getCanonicalName()); + public static final ClassOrInterfaceType NAMEREFNODE_CT = + parseClassOrInterfaceType(NameRefNode.class.getCanonicalName()); + public static final ClassOrInterfaceType NULLNODE_CT = parseClassOrInterfaceType(NullNode.class.getCanonicalName()); + public static final ClassOrInterfaceType NUMBERNODE_CT = + parseClassOrInterfaceType(NumberNode.class.getCanonicalName()); + public static final ClassOrInterfaceType PATHEXPRESSIONNODE_CT = + parseClassOrInterfaceType(PathExpressionNode.class.getCanonicalName()); + public static final ClassOrInterfaceType QUALIFIEDNAMENODE_CT = + parseClassOrInterfaceType(QualifiedNameNode.class.getCanonicalName()); + public static final ClassOrInterfaceType QUANTIFIEDEXPRESSIONNODE_CT = + parseClassOrInterfaceType(QuantifiedExpressionNode.class.getCanonicalName()); + public static final ClassOrInterfaceType RANGENODE_CT = + parseClassOrInterfaceType(RangeNode.class.getCanonicalName()); + public static final ClassOrInterfaceType SIGNEDUNARYNODE_CT = + parseClassOrInterfaceType(SignedUnaryNode.class.getCanonicalName()); + public static final ClassOrInterfaceType STRINGNODE_CT = + parseClassOrInterfaceType(StringNode.class.getCanonicalName()); + public static final ClassOrInterfaceType TEMPORALCONSTANTNODE_CT = + parseClassOrInterfaceType(TemporalConstantNode.class.getCanonicalName()); + public static final ClassOrInterfaceType UNARYTESTLISTNODE_CT = + parseClassOrInterfaceType(UnaryTestListNode.class.getCanonicalName()); + public static final ClassOrInterfaceType UNARYTESTNODE_CT = + parseClassOrInterfaceType(UnaryTestNode.class.getCanonicalName()); + + private DMNCodegenConstants() { + } +} diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/DirectCompilerResult.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/DirectCompilerResult.java deleted file mode 100644 index 1a957017fb3..00000000000 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/DirectCompilerResult.java +++ /dev/null @@ -1,93 +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.codegen.feel11; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.expr.Expression; -import org.kie.dmn.feel.lang.Type; - -public class DirectCompilerResult { - - private final Expression expression; - public final Type resultType; - - private final Set fieldDeclarations = new HashSet<>(); - - public DirectCompilerResult(Expression expression, - Type resultType, - Set fieldDeclarations) { - this.expression = expression; - this.resultType = resultType; - this.fieldDeclarations.addAll(fieldDeclarations); - } - - public static DirectCompilerResult of(Expression expression, Type resultType) { - return new DirectCompilerResult(expression, resultType, Collections.emptySet()); - } - - public static DirectCompilerResult of(Expression expression, Type resultType, Set fieldDeclarations) { - return new DirectCompilerResult(expression, resultType, fieldDeclarations); - } - - public static DirectCompilerResult of(Expression expression, Type resultType, FieldDeclaration fieldDeclaration) { - Set singleton = new HashSet<>(); - singleton.add(fieldDeclaration); - return new DirectCompilerResult(expression, resultType, singleton); - } - - public DirectCompilerResult withFD(DirectCompilerResult from) { - this.fieldDeclarations.addAll(from.getFieldDeclarations()); - return this; - } - - public DirectCompilerResult withFD(Set from) { - this.fieldDeclarations.addAll(from); - return this; - } - - public Set getFieldDeclarations() { - return Collections.unmodifiableSet(fieldDeclarations); - } - - public boolean addFieldDeclaration(FieldDeclaration d) { - return fieldDeclarations.add(d); - } - - public static Set mergeFDs( List sets ) { - Set result = new HashSet<>(); - for ( DirectCompilerResult fs : sets ) { - result.addAll(fs.getFieldDeclarations()); - } - return result; - } - - public static Set mergeFDs( DirectCompilerResult... sets ) { - return mergeFDs(Arrays.asList(sets)); - } - - public Expression getExpression() { - return expression; - } -} diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Expressions.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Expressions.java deleted file mode 100644 index 404db681118..00000000000 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Expressions.java +++ /dev/null @@ -1,472 +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.codegen.feel11; - -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.expr.CastExpr; -import com.github.javaparser.ast.expr.ClassExpr; -import com.github.javaparser.ast.expr.EnclosedExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.LambdaExpr; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.MethodReferenceExpr; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.ObjectCreationExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; -import com.github.javaparser.ast.stmt.ExpressionStmt; -import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.github.javaparser.ast.type.Type; -import com.github.javaparser.ast.type.UnknownType; -import org.kie.dmn.feel.lang.ast.InfixOperator; -import org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode; -import org.kie.dmn.feel.lang.ast.RangeNode; -import org.kie.dmn.feel.lang.ast.UnaryTestNode; -import org.kie.dmn.feel.lang.impl.MapBackedType; -import org.kie.dmn.feel.lang.impl.NamedParameter; -import org.kie.dmn.feel.lang.types.GenFnType; -import org.kie.dmn.feel.lang.types.GenListType; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; -import org.kie.dmn.feel.util.StringEvalHelper; - -import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType; -import static com.github.javaparser.StaticJavaParser.parseExpression; -import static org.kie.dmn.feel.codegen.feel11.Constants.BuiltInTypeT; - -public class Expressions { - - public static final ClassOrInterfaceType NamedParamterT = parseClassOrInterfaceType(NamedParameter.class.getCanonicalName()); - public static final ClassOrInterfaceType FormalParamterT = parseClassOrInterfaceType(BaseFEELFunction.Param.class.getCanonicalName()); - public static final ClassOrInterfaceType GenListTypeT = parseClassOrInterfaceType(GenListType.class.getCanonicalName()); - public static final ClassOrInterfaceType MapBackedTypeT = parseClassOrInterfaceType(MapBackedType.class.getCanonicalName()); - public static final ClassOrInterfaceType GenFnTypeT = parseClassOrInterfaceType(GenFnType.class.getCanonicalName()); - private static final Expression DASH_UNARY_TEST = parseExpression(org.kie.dmn.feel.lang.ast.DashNode.DashUnaryTest.class.getCanonicalName() + ".INSTANCE"); - - public static class NamedLambda { - - private final NameExpr name; - - private final LambdaExpr expr; - private final FieldDeclaration field; - - private NamedLambda(NameExpr name, LambdaExpr expr, FieldDeclaration field) { - this.name = name; - this.expr = expr; - this.field = field; - } - - public NameExpr name() { - return name; - } - - public LambdaExpr expr() { - return expr; - } - - public FieldDeclaration field() { - return field; - } - } - - private static final Expression QUANTIFIER_SOME = parseExpression("org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode.Quantifier.SOME"); - private static final Expression QUANTIFIER_EVERY = parseExpression("org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode.Quantifier.EVERY"); - - public static final String LEFT = "left"; - public static final NameExpr LEFT_EXPR = new NameExpr(LEFT); - public static final UnknownType UNKNOWN_TYPE = new UnknownType(); - public static final NameExpr STDLIB = new NameExpr(CompiledFEELSupport.class.getCanonicalName()); - - public static Expression dash() { - return DASH_UNARY_TEST; - } - - public static Expression negate(Expression expression) { - return new MethodCallExpr(STDLIB, "negate", NodeList.nodeList(FeelCtx.FEELCTX, expression)); - } - - public static Expression positive(Expression expression) { - return new MethodCallExpr(STDLIB, "positive", NodeList.nodeList(FeelCtx.FEELCTX, expression)); - } - - public static MethodCallExpr binary( - InfixOperator operator, - Expression l, - Expression r) { - switch (operator) { - case ADD: - return arithmetic("add", l, r); - case SUB: - return arithmetic("sub", l, r); - case MULT: - return arithmetic("mult", l, r); - case DIV: - return arithmetic("div", l, r); - case POW: - return arithmetic("pow", l, r); - - case LTE: - return comparison("lte", l, r); - case LT: - return comparison("lt", l, r); - case GT: - return comparison("gt", l, r); - case GTE: - return comparison("gte", l, r); - case EQ: - return equality("eq", l, r); - case NE: - return equality("ne", l, r); - case AND: - return booleans("and", l, r); - case OR: - return booleans("or", l, r); - default: - throw new UnsupportedOperationException(operator.toString()); - } - } - - private static MethodCallExpr arithmetic(String op, Expression left, Expression right) { - return new MethodCallExpr(compiledFeelSemanticMappingsFQN(), op) - .addArgument(left) - .addArgument(right) - .addArgument(FeelCtx.FEELCTX); - } - - private static MethodCallExpr equality(String op, Expression left, Expression right) { - return new MethodCallExpr(compiledFeelSemanticMappingsFQN(), op, new NodeList<>(left, right)); - } - - private static MethodCallExpr comparison(String op, Expression left, Expression right) { - return new MethodCallExpr(compiledFeelSemanticMappingsFQN(), op, new NodeList<>(left, right)); - } - - private static MethodCallExpr booleans(String op, Expression left, Expression right) { - Expression l = coerceToBoolean(left); - Expression r = supplierLambda(coerceToBoolean(right)); - - return new MethodCallExpr(compiledFeelSemanticMappingsFQN(), op, new NodeList<>(l, r)); - } - - public static Expression unary( - UnaryTestNode.UnaryOperator operator, - Expression right) { - switch (operator) { - case LTE: - return unaryComparison("lte", right); - case LT: - return unaryComparison("lt", right); - case GT: - return unaryComparison("gt", right); - case GTE: - return unaryComparison("gte", right); - case EQ: - return new MethodCallExpr(compiledFeelSemanticMappingsFQN(), "gracefulEq", new NodeList<>(FeelCtx.FEELCTX, right, LEFT_EXPR)); - case NE: - return unaryComparison("ne", right); - case IN: - // only used in decision tables: refactor? how? - return new MethodCallExpr(compiledFeelSemanticMappingsFQN(), "includes", new NodeList<>(FeelCtx.FEELCTX, right, LEFT_EXPR)); - case NOT: - return new MethodCallExpr(compiledFeelSemanticMappingsFQN(), "notExists", new NodeList<>(FeelCtx.FEELCTX, right, LEFT_EXPR)); - case TEST: - return coerceToBoolean(right); - default: - throw new UnsupportedOperationException(operator.toString()); - } - } - - public static MethodCallExpr unaryComparison(String operator, Expression right) { - return new MethodCallExpr(compiledFeelSemanticMappingsFQN(), operator, new NodeList<>(LEFT_EXPR, right)); - } - - public static MethodCallExpr lt(Expression left, Expression right) { - return new MethodCallExpr(null, "lt") - .addArgument(left) - .addArgument(right); - } - - public static MethodCallExpr gt(Expression left, Expression right) { - return new MethodCallExpr(null, "gt") - .addArgument(left) - .addArgument(right); - } - - public static MethodCallExpr between(Expression value, Expression start, Expression end) { - return new MethodCallExpr(null, "between") - .addArgument(FeelCtx.FEELCTX) - .addArgument(value) - .addArgument(start) - .addArgument(end); - } - - public static EnclosedExpr castTo(Type type, Expression expr) { - return new EnclosedExpr(new CastExpr(type, new EnclosedExpr(expr))); - } - - public static MethodCallExpr reflectiveCastTo(Type type, Expression expr) { - return new MethodCallExpr(new ClassExpr(type), "cast") - .addArgument(new EnclosedExpr(expr)); - } - - public static Expression quantifier( - QuantifiedExpressionNode.Quantifier quantifier, - Expression condition, - List iterationContexts) { - - // quant({SOME,EVERY}, FEELCTX) - MethodCallExpr quant = - new MethodCallExpr(Expressions.STDLIB, "quant") - .addArgument(quantifier == QuantifiedExpressionNode.Quantifier.SOME ? - QUANTIFIER_SOME : - QUANTIFIER_EVERY) - .addArgument(FeelCtx.FEELCTX); - - // .with(expr) - // .with(expr) - Expression chainedCalls = iterationContexts.stream() - .reduce(quant, (l, r) -> r.asMethodCallExpr().setScope(l)); - - return new MethodCallExpr(chainedCalls, "satisfies") - .addArgument(condition); - } - - public static MethodCallExpr ffor( - List iterationContexts, - Expression returnExpr) { - MethodCallExpr ffor = - new MethodCallExpr(Expressions.STDLIB, "ffor") - .addArgument(FeelCtx.FEELCTX); - - // .with(expr) - // .with(expr) - Expression chainedCalls = iterationContexts.stream() - .reduce(ffor, (l, r) -> r.asMethodCallExpr().setScope(l)); - - return new MethodCallExpr(chainedCalls, "rreturn") - .addArgument(returnExpr); - } - - public static NameExpr compiledFeelSemanticMappingsFQN() { - return new NameExpr("org.kie.dmn.feel.codegen.feel11.CompiledFEELSemanticMappings"); - } - - public static MethodCallExpr list(Expression... exprs) { - return new MethodCallExpr(compiledFeelSemanticMappingsFQN(), "list", NodeList.nodeList(exprs)); - } - - public static MethodCallExpr range(RangeNode.IntervalBoundary lowBoundary, - Expression lowEndPoint, - Expression highEndPoint, - RangeNode.IntervalBoundary highBoundary) { - - return new MethodCallExpr(compiledFeelSemanticMappingsFQN(), "range") - .addArgument(FeelCtx.FEELCTX) - .addArgument(Constants.rangeBoundary(lowBoundary)) - .addArgument(lowEndPoint) - .addArgument(highEndPoint) - .addArgument(Constants.rangeBoundary(highBoundary)); - } - - public static MethodCallExpr includes(Expression range, Expression target) { - return new MethodCallExpr(compiledFeelSemanticMappingsFQN(), "includes") - .addArgument(FeelCtx.FEELCTX) - .addArgument(range) - .addArgument(target); - } - - public static MethodCallExpr exists(Expression tests, Expression target) { - return new MethodCallExpr(compiledFeelSemanticMappingsFQN(), "exists") - .addArgument(FeelCtx.FEELCTX) - .addArgument(tests) - .addArgument(target); - } - - public static MethodCallExpr notExists(Expression expr) { - return new MethodCallExpr(compiledFeelSemanticMappingsFQN(), "notExists") - .addArgument(FeelCtx.FEELCTX) - .addArgument(expr) - .addArgument(LEFT_EXPR); - } - - public static NamedLambda namedLambda(Expression expr, String text) { - LambdaExpr lambda = Expressions.lambda(expr); - String name = Constants.functionName(text); - FieldDeclaration field = Constants.function(name, lambda); - return new NamedLambda(new NameExpr(name), lambda, field); - } - - public static LambdaExpr lambda(Expression expr) { - return new LambdaExpr( - new NodeList<>( - new Parameter(UNKNOWN_TYPE, FeelCtx.FEELCTX_N)), - new ExpressionStmt(expr), - true); - } - - public static LambdaExpr supplierLambda(Expression expr) { - return new LambdaExpr(new NodeList<>(), - new ExpressionStmt(expr), - true); - } - - public static NamedLambda namedUnaryLambda(Expression expr, String text) { - LambdaExpr lambda = Expressions.unaryLambda(expr); - String name = Constants.unaryTestName(text); - FieldDeclaration field = Constants.unaryTest(name, lambda); - return new NamedLambda(new NameExpr(name), lambda, field); - } - - - public static LambdaExpr unaryLambda(Expression expr) { - return new LambdaExpr( - new NodeList<>( - new Parameter(UNKNOWN_TYPE, FeelCtx.FEELCTX_N), - new Parameter(UNKNOWN_TYPE, "left")), - new ExpressionStmt(expr), - true); - } - - public static ObjectCreationExpr namedParameter(Expression name, Expression value) { - return new ObjectCreationExpr(null, NamedParamterT, new NodeList<>(name, value)); - } - - public static ObjectCreationExpr formalParameter(Expression name, Expression type) { - return new ObjectCreationExpr(null, FormalParamterT, new NodeList<>(name, type)); - } - - public static MethodCallExpr invoke(Expression functionName, Expression params) { - return new MethodCallExpr(STDLIB, "invoke") - .addArgument(FeelCtx.FEELCTX) - .addArgument(functionName) - .addArgument(params); - } - - public static MethodCallExpr filter(Expression expr, Expression filter) { - return new MethodCallExpr(new MethodCallExpr(STDLIB, "filter") - .addArgument(FeelCtx.FEELCTX) - .addArgument(expr), - "with") - .addArgument(filter); - } - - public static MethodCallExpr path(Expression expr, Expression filter) { - return new MethodCallExpr(new MethodCallExpr(STDLIB, "path") - .addArgument(FeelCtx.FEELCTX) - .addArgument(expr), - "with") - .addArgument(filter); - } - - public static MethodCallExpr path(Expression expr, List filters) { - MethodCallExpr methodCallExpr = new MethodCallExpr(new MethodCallExpr(STDLIB, "path") - .addArgument(FeelCtx.FEELCTX) - .addArgument(expr), - "with"); - filters.forEach(methodCallExpr::addArgument); - return methodCallExpr; - } - - public static MethodCallExpr isInstanceOf(Expression expr, Expression type) { - return new MethodCallExpr(type, "isInstanceOf") - .addArgument(expr); - } - - public static MethodCallExpr nativeInstanceOf(Type type, Expression condition) { - return new MethodCallExpr( - new ClassExpr(type), - "isInstance") - .addArgument(new EnclosedExpr(condition)); - } - - public static MethodCallExpr determineTypeFromName(String typeAsText) { - return new MethodCallExpr(BuiltInTypeT, "determineTypeFromName") - .addArgument(new StringLiteralExpr(typeAsText)); - } - - public static ObjectCreationExpr genListType(Expression gen) { - return new ObjectCreationExpr(null, GenListTypeT, new NodeList<>(gen)); - } - - public static Expression genContextType(Map fields) { - final ClassOrInterfaceType sie = parseClassOrInterfaceType(java.util.AbstractMap.SimpleImmutableEntry.class.getCanonicalName()); - sie.setTypeArguments(parseClassOrInterfaceType(String.class.getCanonicalName()), - parseClassOrInterfaceType(org.kie.dmn.feel.lang.Type.class.getCanonicalName())); - List entryParams = fields.entrySet().stream().map(e -> new ObjectCreationExpr(null, - sie, - new NodeList<>(stringLiteral(e.getKey()), - e.getValue()))) - .collect(Collectors.toList()); - MethodCallExpr mOf = new MethodCallExpr(new NameExpr(java.util.stream.Stream.class.getCanonicalName()), "of"); - entryParams.forEach(mOf::addArgument); - MethodCallExpr mCollect = new MethodCallExpr(mOf, "collect"); - mCollect.addArgument(new MethodCallExpr(new NameExpr(java.util.stream.Collectors.class.getCanonicalName()), - "toMap").addArgument(new MethodReferenceExpr(new NameExpr(java.util.Map.Entry.class.getCanonicalName()), new NodeList<>(), "getKey")) - .addArgument(new MethodReferenceExpr(new NameExpr(java.util.Map.Entry.class.getCanonicalName()), new NodeList<>(), "getValue"))); - return new ObjectCreationExpr(null, MapBackedTypeT, new NodeList<>(stringLiteral("[anonymous]"), mCollect)); - } - - public static ObjectCreationExpr genFnType(List args, Expression ret) { - return new ObjectCreationExpr(null, - GenFnTypeT, - new NodeList<>(new MethodCallExpr(new NameExpr(java.util.Arrays.class.getCanonicalName()), - "asList", - new NodeList<>(args)), - ret)); - } - - public static Expression contains(Expression expr, Expression value) { - return new MethodCallExpr(expr, "contains") - .addArgument(value); - } - - public static StringLiteralExpr stringLiteral(String text) { - if (text.startsWith("\"") && text.endsWith("\"")) { - String actualStringContent = text.substring(1, text.length() - 1); // remove start/end " from the FEEL text expression. - String unescaped = StringEvalHelper.unescapeString(actualStringContent); // unescapes String, FEEL-style - return new StringLiteralExpr().setString(unescaped); // setString escapes the contents Java-style - } else { - return new StringLiteralExpr().setString(text); - } - } - - public static Expression coerceToBoolean(Expression expression) { - return new MethodCallExpr(compiledFeelSemanticMappingsFQN(), "coerceToBoolean") - .addArgument(FeelCtx.FEELCTX) - .addArgument(expression); - } - - public static MethodCallExpr coerceNumber(Expression exprCursor) { - MethodCallExpr coerceNumberMethodCallExpr = new MethodCallExpr(new NameExpr(CompiledFEELSupport.class.getSimpleName()), "coerceNumber"); - coerceNumberMethodCallExpr.addArgument(exprCursor); - return coerceNumberMethodCallExpr; - } - - public static ObjectCreationExpr newIllegalState() { - return new ObjectCreationExpr(null, - parseClassOrInterfaceType(IllegalStateException.class.getCanonicalName()), - new NodeList<>()); - } -} - - diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/FeelCtx.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/FeelCtx.java deleted file mode 100644 index f37fdcc88db..00000000000 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/FeelCtx.java +++ /dev/null @@ -1,72 +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.codegen.feel11; - -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; - -import static com.github.javaparser.StaticJavaParser.parseExpression; -import static org.kie.dmn.feel.codegen.feel11.Expressions.compiledFeelSemanticMappingsFQN; - -public class FeelCtx { - - public static final String FEELCTX_N = "feelExprCtx"; - public static final NameExpr FEELCTX = new NameExpr(FEELCTX_N); - private static final String FEEL_SUPPORT = CompiledFEELSupport.class.getSimpleName(); - private static final Expression EMPTY_MAP = parseExpression("java.util.Collections.emptyMap()"); - - public static Expression emptyContext() { - return EMPTY_MAP; - } - - public static MethodCallExpr getValue(String nameRef) { - return new MethodCallExpr(compiledFeelSemanticMappingsFQN(), "getValue", new NodeList<>(FEELCTX, new StringLiteralExpr(nameRef))); - } - - public static MethodCallExpr current() { - return new MethodCallExpr(FeelCtx.FEELCTX, "current"); - } - - public static MethodCallExpr openContext() { - return new MethodCallExpr( - new NameExpr(FEEL_SUPPORT), - "openContext") - .addArgument(FEELCTX); - } - - - public static MethodCallExpr setEntry(String keyText, Expression expression) { - return new MethodCallExpr( - null, - "setEntry", - new NodeList<>( - new StringLiteralExpr(keyText), - expression)); - } - - public static MethodCallExpr closeContext(DirectCompilerResult contextEntriesMethodChain) { - return new MethodCallExpr( - contextEntriesMethodChain.getExpression(), - "closeContext"); - } - -} diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Functions.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Functions.java deleted file mode 100644 index e5ed7b6a609..00000000000 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/Functions.java +++ /dev/null @@ -1,95 +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.codegen.feel11; - -import java.util.List; -import java.util.Map; - -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.LambdaExpr; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.ObjectCreationExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; -import com.github.javaparser.ast.type.ClassOrInterfaceType; -import org.kie.dmn.feel.lang.FEELDialect; -import org.kie.dmn.feel.lang.ast.BaseNode; -import org.kie.dmn.feel.lang.ast.FunctionDefNode; -import org.kie.dmn.feel.lang.impl.EvaluationContextImpl; -import org.kie.dmn.feel.lang.impl.FEELEventListenersManager; -import org.kie.dmn.feel.lang.types.BuiltInType; -import org.kie.dmn.feel.util.Msg; - -import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType; -import static com.github.javaparser.StaticJavaParser.parseExpression; - -public class Functions { - public static final ClassOrInterfaceType TYPE_CUSTOM_FEEL_FUNCTION = - parseClassOrInterfaceType(CompiledCustomFEELFunction.class.getSimpleName()); - private static final Expression ANONYMOUS_STRING_LITERAL = new StringLiteralExpr(""); - private static final Expression EMPTY_LIST = parseExpression("java.util.Collections.emptyList()"); - - public static Expression external(List paramNames, BaseNode body) { - // Defaulting FEELDialect to FEEL - EvaluationContextImpl emptyEvalCtx = - new EvaluationContextImpl(Functions.class.getClassLoader(), new FEELEventListenersManager(), FEELDialect.FEEL); - - - Map conf = (Map) body.evaluate(emptyEvalCtx); - Map java = (Map) conf.get( "java" ); - - if (java != null) { - - String className = java.get("class"); - String methodSignature = java.get("method signature"); - if (className == null || methodSignature == null) { - throw new FEELCompilationError( - Msg.createMessage(Msg.UNABLE_TO_FIND_EXTERNAL_FUNCTION_AS_DEFINED_BY, methodSignature)); - } - - return FunctionDefs.asMethodCall(className, methodSignature, paramNames); - } else { - throw new FEELCompilationError(Msg.createMessage(Msg.UNABLE_TO_FIND_EXTERNAL_FUNCTION_AS_DEFINED_BY, null)); - } - } - - public static ObjectCreationExpr internal(Expression parameters, Expression body) { - ObjectCreationExpr functionDefExpr = new ObjectCreationExpr(); - functionDefExpr.setType(TYPE_CUSTOM_FEEL_FUNCTION); - functionDefExpr.addArgument(ANONYMOUS_STRING_LITERAL); - functionDefExpr.addArgument(parameters); - functionDefExpr.addArgument(body); - functionDefExpr.addArgument(new MethodCallExpr(new NameExpr("feelExprCtx"), "current")); - return functionDefExpr; - } - - public static DirectCompilerResult declaration(FunctionDefNode n, MethodCallExpr list, Expression fnBody) { - LambdaExpr lambda = Expressions.lambda(fnBody); - String fnName = Constants.functionName("FNBODY_" + n.getBody().getText()); - DirectCompilerResult r = DirectCompilerResult.of( - Functions.internal(list, new NameExpr(fnName)), - BuiltInType.FUNCTION); - r.addFieldDeclaration(Constants.function(fnName, lambda)); - return r; - } - - - - -} diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ProcessedExpression.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ProcessedExpression.java index a0ba1ddfd6d..c683af3bd0a 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ProcessedExpression.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ProcessedExpression.java @@ -20,20 +20,17 @@ import java.util.List; -import com.github.javaparser.ast.CompilationUnit; import org.antlr.v4.runtime.tree.ParseTree; import org.kie.dmn.api.feel.runtime.events.FEELEvent; import org.kie.dmn.api.feel.runtime.events.FEELEventListener; import org.kie.dmn.feel.lang.CompilerContext; import org.kie.dmn.feel.lang.EvaluationContext; import org.kie.dmn.feel.lang.FEELProfile; -import org.kie.dmn.feel.lang.ast.BaseNode; import org.kie.dmn.feel.lang.ast.visitor.ASTHeuristicCheckerVisitor; import org.kie.dmn.feel.lang.ast.visitor.ASTTemporalConstantVisitor; import org.kie.dmn.feel.lang.impl.CompiledExecutableExpression; import org.kie.dmn.feel.lang.impl.CompiledExpressionImpl; import org.kie.dmn.feel.lang.impl.InterpretedExecutableExpression; -import org.kie.dmn.feel.lang.types.BuiltInType; import org.kie.dmn.feel.parser.feel11.ASTBuilderVisitor; import static org.kie.dmn.feel.codegen.feel11.ProcessedFEELUnit.DefaultMode.Compiled; @@ -44,11 +41,8 @@ public class ProcessedExpression extends ProcessedFEELUnit { private static final String TEMPLATE_RESOURCE = "/TemplateCompiledFEELExpression.java"; private static final String TEMPLATE_CLASS = "TemplateCompiledFEELExpression"; - private final BaseNode ast; private final DefaultMode executionMode; - private DirectCompilerResult compilerResult; - private final CompilerBytecodeLoader compilerBytecodeLoader = new CompilerBytecodeLoader(); private CompiledFEELExpression executableFEELExpression; public ProcessedExpression( @@ -56,8 +50,7 @@ public ProcessedExpression( CompilerContext ctx, ProcessedFEELUnit.DefaultMode executionMode, List profiles) { - - super(expression, ctx, profiles); + super(expression, ctx, profiles, TEMPLATE_RESOURCE, TEMPLATE_CLASS); this.executionMode = executionMode; ParseTree tree = getFEELParser(expression, ctx, profiles).compilation_unit(); ASTBuilderVisitor astVisitor = new ASTBuilderVisitor(ctx.getInputVariableTypes(), ctx.getFEELFeelTypeRegistry()); @@ -90,55 +83,17 @@ public CompiledFEELExpression asCompiledFEELExpression() { return this; } - private DirectCompilerResult getCompilerResult() { - if (compilerResult == null) { - if (errorListener.isError()) { - compilerResult = - DirectCompilerResult.of( - CompiledFEELSupport.compiledErrorExpression( - errorListener.event().getMessage()), - BuiltInType.UNKNOWN); - } else { - try { - compilerResult = ast.accept(new ASTCompilerVisitor()); - } catch (FEELCompilationError e) { - compilerResult = DirectCompilerResult.of( - CompiledFEELSupport.compiledErrorExpression(e.getMessage()), - BuiltInType.UNKNOWN); - } - } - } - return compilerResult; - } - - public CompilationUnit getSourceCode() { - DirectCompilerResult directCompilerResult = getCompilerResult(); - return compilerBytecodeLoader.getCompilationUnit( - CompiledFEELExpression.class, - TEMPLATE_RESOURCE, - packageName, - TEMPLATE_CLASS, - expression, - directCompilerResult.getExpression(), - directCompilerResult.getFieldDeclarations() - ); - } - public InterpretedExecutableExpression getInterpreted() { return new InterpretedExecutableExpression(new CompiledExpressionImpl(ast)); } public CompiledExecutableExpression getCompiled() { - CompiledFEELExpression compiledFEELExpression = - compilerBytecodeLoader.compileUnit( - packageName, - TEMPLATE_CLASS, - getSourceCode()); - return new CompiledExecutableExpression(compiledFEELExpression); + return new CompiledExecutableExpression(getCommonCompiled()); } @Override public Object apply(EvaluationContext evaluationContext) { return executableFEELExpression.apply(evaluationContext); } + } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ProcessedFEELUnit.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ProcessedFEELUnit.java index ce3bf377830..7c90c364eea 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ProcessedFEELUnit.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ProcessedFEELUnit.java @@ -21,8 +21,12 @@ import java.util.List; import java.util.UUID; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.stmt.BlockStmt; import org.kie.dmn.feel.lang.CompilerContext; import org.kie.dmn.feel.lang.FEELProfile; +import org.kie.dmn.feel.lang.ast.BaseNode; +import org.kie.dmn.feel.lang.impl.CompiledExecutableExpression; import org.kie.dmn.feel.lang.impl.FEELEventListenersManager; import org.kie.dmn.feel.parser.feel11.FEELParser; import org.kie.dmn.feel.parser.feel11.FEEL_1_1Parser; @@ -41,17 +45,44 @@ public static DefaultMode of(boolean doCompile) { protected final String packageName; protected final String expression; - protected final CompiledFEELSupport.SyntaxErrorListener errorListener = - new CompiledFEELSupport.SyntaxErrorListener(); + protected final String templateResource; + protected final String templateClass; + + protected BaseNode ast; + protected BlockStmt codegenResult; + protected final SyntaxErrorListener errorListener = new SyntaxErrorListener(); protected final CompilerBytecodeLoader compiler = new CompilerBytecodeLoader(); ProcessedFEELUnit(String expression, CompilerContext ctx, - List profiles) { + List profiles, + String templateResource, + String templateClass) { this.expression = expression; this.packageName = generateRandomPackage(); + this.templateResource = templateResource; + this.templateClass = templateClass; + } + + public CompilationUnit getSourceCode() { + ASTCompilerVisitor astVisitor = new ASTCompilerVisitor(); + BlockStmt directCodegenResult = getCodegenResult(astVisitor); + return compiler.getCompilationUnit( + templateResource, + packageName, + templateClass, + expression, + directCodegenResult, + astVisitor.getLastVariableName()); + } + + public T getCommonCompiled() { + return compiler.compileUnit( + packageName, + templateClass, + getSourceCode()); } protected FEEL_1_1Parser getFEELParser(String expression, CompilerContext ctx, List profiles) { @@ -71,6 +102,21 @@ protected FEEL_1_1Parser getFEELParser(String expression, CompilerContext ctx, L ctx.getFEELFeelTypeRegistry()); } + protected BlockStmt getCodegenResult(ASTCompilerVisitor astVisitor) { + if (codegenResult == null) { + if (errorListener.isError()) { + return astVisitor.returnError(errorListener.event().getMessage()); + } else { + try { + codegenResult = ast.accept(astVisitor); + } catch (FEELCompilationError e) { + return astVisitor.returnError(e.getMessage()); + } + } + } + return codegenResult; + } + private String generateRandomPackage() { String uuid = UUID.randomUUID().toString().replaceAll("-", ""); return this.getClass().getPackage().getName() + ".gen" + uuid; diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ProcessedUnaryTest.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ProcessedUnaryTest.java index 9777748933f..26894de8b85 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ProcessedUnaryTest.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/ProcessedUnaryTest.java @@ -21,7 +21,6 @@ import java.util.Collections; import java.util.List; -import com.github.javaparser.ast.CompilationUnit; import org.antlr.v4.runtime.tree.ParseTree; import org.kie.dmn.feel.lang.CompilerContext; import org.kie.dmn.feel.lang.EvaluationContext; @@ -36,15 +35,12 @@ public class ProcessedUnaryTest extends ProcessedFEELUnit { - private static final String TEMPLATE_RESOURCE = "/TemplateCompiledFEELUnaryTests.java"; - private static final String TEMPLATE_CLASS = "TemplateCompiledFEELUnaryTests"; - - private final BaseNode ast; - private DirectCompilerResult compiledExpression; + public static final String TEMPLATE_RESOURCE = "/TemplateCompiledFEELUnaryTests.java"; + public static final String TEMPLATE_CLASS = "TemplateCompiledFEELUnaryTests"; public ProcessedUnaryTest(String expressions, CompilerContext ctx, List profiles) { - super(expressions, ctx, Collections.emptyList()); + super(expressions, ctx, Collections.emptyList(), TEMPLATE_RESOURCE, TEMPLATE_CLASS); ParseTree tree = getFEELParser(expression, ctx, profiles).unaryTestsRoot(); ASTBuilderVisitor astVisitor = new ASTBuilderVisitor(ctx.getInputVariableTypes(), ctx.getFEELFeelTypeRegistry()); BaseNode initialAst = tree.accept(astVisitor); @@ -54,34 +50,6 @@ public ProcessedUnaryTest(String expressions, } } - private DirectCompilerResult getCompilerResult() { - if (compiledExpression == null) { - if (errorListener.isError()) { - compiledExpression = CompiledFEELSupport.compiledErrorUnaryTest( - errorListener.event().getMessage()); - } else { - try { - compiledExpression = ast.accept(new ASTCompilerVisitor()); - } catch (FEELCompilationError e) { - compiledExpression = CompiledFEELSupport.compiledErrorUnaryTest(e.getMessage()); - } - } - } - return compiledExpression; - } - - public CompilationUnit getSourceCode() { - DirectCompilerResult compilerResult = getCompilerResult(); - return compiler.getCompilationUnit( - CompiledFEELUnaryTests.class, - TEMPLATE_RESOURCE, - packageName, - TEMPLATE_CLASS, - expression, - compilerResult.getExpression(), - compilerResult.getFieldDeclarations()); - } - public UnaryTestInterpretedExecutableExpression getInterpreted() { if (errorListener.isError()) { return UnaryTestInterpretedExecutableExpression.EMPTY; @@ -91,17 +59,12 @@ public UnaryTestInterpretedExecutableExpression getInterpreted() { } public UnaryTestCompiledExecutableExpression getCompiled() { - CompiledFEELUnaryTests compiledFEELExpression = - compiler.compileUnit( - packageName, - TEMPLATE_CLASS, - getSourceCode()); - - return new UnaryTestCompiledExecutableExpression(compiledFEELExpression); + return new UnaryTestCompiledExecutableExpression(getCommonCompiled()); } @Override public List apply(EvaluationContext evaluationContext) { return getInterpreted().apply(evaluationContext); } + } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/SyntaxErrorListener.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/SyntaxErrorListener.java new file mode 100644 index 00000000000..e2896dcac2e --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/SyntaxErrorListener.java @@ -0,0 +1,45 @@ +/** + * 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.codegen.feel11; + +import org.kie.dmn.api.feel.runtime.events.FEELEvent; +import org.kie.dmn.api.feel.runtime.events.FEELEventListener; +import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; +import org.kie.dmn.feel.runtime.events.SyntaxErrorEvent; + +public class SyntaxErrorListener implements FEELEventListener { + + private FEELEvent event = null; + + @Override + public void onEvent(FEELEvent evt) { + if (evt instanceof SyntaxErrorEvent + || evt instanceof InvalidParametersEvent) { + this.event = evt; + } + } + + public boolean isError() { + return event != null; + } + + public FEELEvent event() { + return event; + } +} \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/SimpleType.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/SimpleType.java index 7e3827dc32b..499b0db3b3a 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/SimpleType.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/SimpleType.java @@ -23,16 +23,16 @@ */ public interface SimpleType extends Type { - public static final String LIST = "list"; - public static final String CONTEXT = "context"; - public static final String FUNCTION = "function"; - public static final String BOOLEAN = "boolean"; - public static final String YEARS_AND_MONTHS_DURATION = "years and months duration"; - public static final String DAYS_AND_TIME_DURATION = "days and time duration"; - public static final String DATE_AND_TIME = "date and time"; - public static final String TIME = "time"; - public static final String DATE = "date"; - public static final String STRING = "string"; - public static final String NUMBER = "number"; - public static final String ANY = "Any"; + String LIST = "list"; + String CONTEXT = "context"; + String FUNCTION = "function"; + String BOOLEAN = "boolean"; + String YEARS_AND_MONTHS_DURATION = "years and months duration"; + String DAYS_AND_TIME_DURATION = "days and time duration"; + String DATE_AND_TIME = "date and time"; + String TIME = "time"; + String DATE = "date"; + String STRING = "string"; + String NUMBER = "number"; + String ANY = "Any"; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/AtLiteralNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/AtLiteralNode.java index 72c0874b9f6..eb10d7f7ec3 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/AtLiteralNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/AtLiteralNode.java @@ -36,6 +36,11 @@ public AtLiteralNode(ParserRuleContext ctx, StringNode stringLiteral) { this.stringLiteral = stringLiteral; } + public AtLiteralNode(StringNode stringLiteral, String text) { + this.stringLiteral = stringLiteral; + this.setText(text); + } + public StringNode getStringLiteral() { return stringLiteral; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/BaseNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/BaseNode.java index 05a116b26c4..9929e2b0281 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/BaseNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/BaseNode.java @@ -18,6 +18,7 @@ */ package org.kie.dmn.feel.lang.ast; +import java.util.Objects; import java.util.function.Supplier; import org.antlr.v4.runtime.ParserRuleContext; @@ -162,4 +163,20 @@ public ASTNode[] getChildrenNode() { public T accept(Visitor v) { return v.visit(this); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof BaseNode baseNode)) { + return false; + } + return Objects.equals(this.getClass(), o.getClass()) && Objects.equals(text, baseNode.text); + } + + @Override + public int hashCode() { + return Objects.hash(text); + } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/BetweenNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/BetweenNode.java index bc8d5c50bcf..3322a4c67e7 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/BetweenNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/BetweenNode.java @@ -41,6 +41,13 @@ public BetweenNode(ParserRuleContext ctx, BaseNode value, BaseNode start, BaseNo this.end = end; } + public BetweenNode(BaseNode value, BaseNode start, BaseNode end, String text) { + this.value = value; + this.start = start; + this.end = end; + this.setText(text); + } + public BaseNode getValue() { return value; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/BooleanNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/BooleanNode.java index 6d5c9471a8d..cd78f1875a1 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/BooleanNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/BooleanNode.java @@ -33,6 +33,11 @@ public BooleanNode(ParserRuleContext ctx) { value = Boolean.valueOf( ctx.getText() ); } + public BooleanNode(Boolean value, String text) { + this.value = value; + this.setText( text ); + } + public Boolean getValue() { return value; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/CTypeNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/CTypeNode.java index f321217dd8e..53fca437607 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/CTypeNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/CTypeNode.java @@ -26,14 +26,18 @@ public class CTypeNode extends TypeNode { private final Type type; + public CTypeNode(ParserRuleContext ctx, Type type) { + super( ctx ); + this.type = type; + } + public CTypeNode(Type type) { - super(); this.type = type; } - public CTypeNode(ParserRuleContext ctx, Type type) { - super( ctx ); + public CTypeNode(Type type, String text) { this.type = type; + this.setText(text); } @Override diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ContextEntryNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ContextEntryNode.java index ebf84267f69..a1276b36655 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ContextEntryNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ContextEntryNode.java @@ -39,6 +39,12 @@ public ContextEntryNode(ParserRuleContext ctx, BaseNode name, BaseNode value) { this.value = value; } + public ContextEntryNode(BaseNode name, BaseNode value, String text) { + this.name = name; + this.value = value; + this.setText(text); + } + public BaseNode getName() { return name; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ContextNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ContextNode.java index 898d0d705b8..01e43ddfa51 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ContextNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ContextNode.java @@ -46,11 +46,15 @@ public ContextNode(ParserRuleContext ctx) { public ContextNode(ParserRuleContext ctx, ListNode list) { super( ctx ); - for( BaseNode node : list.getElements() ) { - ContextEntryNode entry = (ContextEntryNode) node; - entries.add( entry ); - parsedResultType.addField(entry.getName().getText(), entry.getResultType()); - } + List entryNodes = list.getElements().stream() + .map(ContextEntryNode.class::cast) + .toList(); + setListNode(entryNodes); + } + + public ContextNode(List entryNodes, String text) { + setListNode(entryNodes); + this.setText(text); } public List getEntries() { @@ -105,4 +109,11 @@ public ASTNode[] getChildrenNode() { public T accept(Visitor v) { return v.visit(this); } + + private void setListNode(List entryNodes) { + for( ContextEntryNode entry : entryNodes ) { + entries.add( entry ); + parsedResultType.addField(entry.getName().getText(), entry.getResultType()); + } + } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ContextTypeNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ContextTypeNode.java index a4c3e277a4f..656e24fe935 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ContextTypeNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ContextTypeNode.java @@ -36,6 +36,11 @@ public ContextTypeNode(ParserRuleContext ctx, Map gen) { this.gen = new HashMap<>(gen); } + public ContextTypeNode(Map gen, String text) { + this.gen = gen; + this.setText(text); + } + @Override public Type evaluate(EvaluationContext ctx) { return new MapBackedType("[anonymous]", evalTypes(ctx, gen)); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/DashNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/DashNode.java index 7b567525a7b..a3562932a40 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/DashNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/DashNode.java @@ -31,6 +31,10 @@ public DashNode(ParserRuleContext ctx) { super( ctx ); } + public DashNode(String text) { + this.setText(text); + } + @Override public UnaryTest evaluate(EvaluationContext ctx) { // a dash is a unary test that always evaluates to true diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FilterExpressionNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FilterExpressionNode.java index 36f39c859c3..989e4d3e37a 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FilterExpressionNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FilterExpressionNode.java @@ -19,7 +19,6 @@ package org.kie.dmn.feel.lang.ast; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -42,6 +41,12 @@ public FilterExpressionNode(ParserRuleContext ctx, BaseNode expression, BaseNode this.filter = filter; } + public FilterExpressionNode(BaseNode expression, BaseNode filter, String text) { + this.expression = expression; + this.filter = filter; + this.setText(text); + } + public BaseNode getExpression() { return expression; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ForExpressionNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ForExpressionNode.java index 9b062179b1e..f25aa0ca569 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ForExpressionNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ForExpressionNode.java @@ -48,6 +48,12 @@ public ForExpressionNode(ParserRuleContext ctx, ListNode iterationContexts, Base } } + public ForExpressionNode(List iterationContexts, BaseNode expression, String text) { + this.iterationContexts = iterationContexts; + this.expression = expression; + this.setText(text); + } + public List getIterationContexts() { return iterationContexts; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FormalParameterNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FormalParameterNode.java index 9c835c9744c..3c0d053d5b9 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FormalParameterNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FormalParameterNode.java @@ -44,6 +44,12 @@ public FormalParameterNode(ParserRuleContext ctx, NameDefNode name, TypeNode typ } } + public FormalParameterNode(NameDefNode name, TypeNode type, String text) { + this.name = name; + this.type = type; + this.setText(text); + } + @Override public BaseFEELFunction.Param evaluate(EvaluationContext ctx) { return new Param(name.evaluate(ctx), type.evaluate(ctx)); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FunctionDefNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FunctionDefNode.java index c2cbc763ae4..b9d6d2962bc 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FunctionDefNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FunctionDefNode.java @@ -62,6 +62,13 @@ public FunctionDefNode(ParserRuleContext ctx, ListNode formalParameters, boolean } } + public FunctionDefNode(List formalParameters, boolean external, BaseNode body, String text) { + this.formalParameters = formalParameters; + this.external = external; + this.body = body; + this.setText(text); + } + public List getFormalParameters() { return formalParameters; } @@ -150,7 +157,7 @@ private Object locateMethodOrThrow(EvaluationContext ctx, List params, Cl throw e; } } - + private static String feelMethodSignature(Method method) { StringBuilder sb = new StringBuilder(method.getName()); sb.append("("); @@ -159,7 +166,7 @@ private static String feelMethodSignature(Method method) { sb.append(")"); return sb.toString(); } - + private Class getTypeInterceptinException(EvaluationContext ctx, String typeName, ClassLoader classLoader) { try { return getType(typeName, classLoader); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FunctionInvocationNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FunctionInvocationNode.java index af632d97d9b..b628795064c 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FunctionInvocationNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FunctionInvocationNode.java @@ -48,6 +48,13 @@ public FunctionInvocationNode(ParserRuleContext ctx, BaseNode name, ListNode par this.params = params; } + public FunctionInvocationNode(BaseNode name, ListNode params, TemporalConstantNode tcFolded, String text) { + this.name = name; + this.params = params; + this.tcFolded = tcFolded; + this.setText(text); + } + public BaseNode getName() { return name; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FunctionTypeNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FunctionTypeNode.java index b6f35624eb0..b74b26f049c 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FunctionTypeNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/FunctionTypeNode.java @@ -38,6 +38,12 @@ public FunctionTypeNode(ParserRuleContext ctx, List argTypes, TypeNode this.retType = gen; } + public FunctionTypeNode(List argTypes, TypeNode retType, String text) { + this.argTypes = new ArrayList<>(argTypes); + this.retType = retType; + this.setText(text); + } + @Override public Type evaluate(EvaluationContext ctx) { List args = argTypes.stream().map(t -> t.evaluate(ctx)).collect(Collectors.toList()); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/IfExpressionNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/IfExpressionNode.java index 82f171b5d83..953b7e71891 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/IfExpressionNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/IfExpressionNode.java @@ -37,6 +37,13 @@ public IfExpressionNode(ParserRuleContext ctx, BaseNode condition, BaseNode then this.elseExpression = elseExpression; } + public IfExpressionNode(BaseNode condition, BaseNode thenExpression, BaseNode elseExpression, String text) { + this.condition = condition; + this.thenExpression = thenExpression; + this.elseExpression = elseExpression; + this.setText(text); + } + public BaseNode getCondition() { return condition; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/InNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/InNode.java index f105463d582..f0225ee8064 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/InNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/InNode.java @@ -40,6 +40,12 @@ public InNode(ParserRuleContext ctx, BaseNode value, BaseNode exprs) { this.exprs = exprs; } + public InNode(BaseNode value, BaseNode exprs, String text) { + this.value = value; + this.exprs = exprs; + this.setText(text); + } + public BaseNode getValue() { return value; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/InfixOpNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/InfixOpNode.java index 69322892710..d4c56eb7aa2 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/InfixOpNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/InfixOpNode.java @@ -37,6 +37,13 @@ public InfixOpNode(ParserRuleContext ctx, BaseNode left, String op, BaseNode rig this.right = right; } + public InfixOpNode(InfixOperator operator, BaseNode left, BaseNode right, String text) { + this.operator = operator; + this.left = left; + this.right = right; + this.setText(text); + } + public InfixOperator getOperator() { return operator; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/InstanceOfNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/InstanceOfNode.java index 29cea47a2bc..9704d683b94 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/InstanceOfNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/InstanceOfNode.java @@ -39,6 +39,12 @@ public InstanceOfNode(ParserRuleContext ctx, BaseNode expression, TypeNode type) this.type = type; } + public InstanceOfNode(BaseNode expression, TypeNode type, String text) { + this.expression = expression; + this.type = type; + this.setText(text); + } + public BaseNode getExpression() { return expression; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/IterationContextNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/IterationContextNode.java index 2d14fb1301e..70cfa00c9fa 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/IterationContextNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/IterationContextNode.java @@ -41,6 +41,13 @@ public IterationContextNode(ParserRuleContext ctx, NameDefNode name, BaseNode ex this.rangeEndExpr = rangeEndExpr; } + public IterationContextNode(NameDefNode name, BaseNode expression, BaseNode rangeEndExpr, String text) { + this.name = name; + this.expression = expression; + this.rangeEndExpr = rangeEndExpr; + this.setText(text); + } + public NameDefNode getName() { return name; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ListNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ListNode.java index 808508cf0b5..1cba1c32c79 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ListNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ListNode.java @@ -46,6 +46,11 @@ public ListNode(List elements) { this.elements = elements; } + public ListNode(List elements, String text) { + this.elements = elements; + this.setText(text); + } + public List getElements() { return elements; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ListTypeNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ListTypeNode.java index 8a9c77f864a..ffc3a9d1235 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ListTypeNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/ListTypeNode.java @@ -32,6 +32,11 @@ public ListTypeNode(ParserRuleContext ctx, TypeNode gen) { this.genTypeNode = gen; } + public ListTypeNode(TypeNode genTypeNode, String text) { + this.genTypeNode = genTypeNode; + this.setText(text); + } + @Override public Type evaluate(EvaluationContext ctx) { Type gen = genTypeNode.evaluate(ctx); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NameDefNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NameDefNode.java index 7633981c136..ab558a2ca3d 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NameDefNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NameDefNode.java @@ -46,6 +46,12 @@ public NameDefNode(ParserRuleContext ctx, String name) { this.name = name; } + public NameDefNode(List parts, String name, String text) { + this.parts = parts; + this.name = name; + this.setText(text); + } + public List getParts() { return parts; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NameRefNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NameRefNode.java index cb4a5b20245..ec7a8c5b814 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NameRefNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NameRefNode.java @@ -40,6 +40,11 @@ public NameRefNode(ParserRuleContext ctx, String text, Type type) { this.setText(text); } + public NameRefNode(Type type, String text) { + this.resultType = type; + this.setText(text); + } + @Override public Object evaluate(EvaluationContext ctx) { Object result = ctx.getValue( getText() ); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NamedParameterNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NamedParameterNode.java index f68935e96dd..b279113da82 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NamedParameterNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NamedParameterNode.java @@ -35,6 +35,12 @@ public NamedParameterNode(ParserRuleContext ctx, NameDefNode name, BaseNode expr this.expression = expression; } + public NamedParameterNode(NameDefNode name, BaseNode expression, String text) { + this.name = name; + this.expression = expression; + this.setText(text); + } + public NameDefNode getName() { return name; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NullNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NullNode.java index 863ca724402..8c7eeb427e9 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NullNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NullNode.java @@ -28,6 +28,10 @@ public NullNode(ParserRuleContext ctx) { super( ctx ); } + public NullNode(String text) { + this.setText(text); + } + @Override public Object evaluate(EvaluationContext ctx) { return null; diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NumberNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NumberNode.java index c03f7f585c3..cf13e18a26d 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NumberNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/NumberNode.java @@ -36,6 +36,11 @@ public NumberNode(ParserRuleContext ctx) { value = NumberEvalHelper.getBigDecimalOrNull(ctx.getText() ); } + public NumberNode(BigDecimal value, String text) { + this.value = value; + this.setText(text); + } + public BigDecimal getValue() { return value; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/PathExpressionNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/PathExpressionNode.java index b16ce347580..3e572d2e838 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/PathExpressionNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/PathExpressionNode.java @@ -42,6 +42,12 @@ public PathExpressionNode(ParserRuleContext ctx, BaseNode expression, BaseNode n this.name = name; } + public PathExpressionNode(BaseNode expression, BaseNode name, String text) { + this.expression = expression; + this.name = name; + this.setText(text); + } + public BaseNode getExpression() { return expression; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/QualifiedNameNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/QualifiedNameNode.java index e36d821f5f7..5dced02c294 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/QualifiedNameNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/QualifiedNameNode.java @@ -42,6 +42,12 @@ public QualifiedNameNode(ParserRuleContext ctx, List parts, Type ty this.resultType = type; } + public QualifiedNameNode(List parts, Type resultType, String text) { + this.parts = parts; + this.resultType = resultType; + this.setText(text); + } + public List getParts() { return parts; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/QuantifiedExpressionNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/QuantifiedExpressionNode.java index cf411cb4fd1..8d93134578c 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/QuantifiedExpressionNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/QuantifiedExpressionNode.java @@ -33,7 +33,7 @@ public class QuantifiedExpressionNode extends BaseNode { - public static enum Quantifier { + public enum Quantifier { SOME, EVERY; public static Quantifier resolve(String text) { @@ -67,6 +67,13 @@ public QuantifiedExpressionNode(ParserRuleContext ctx, Quantifier quantifier, Li } } + public QuantifiedExpressionNode(Quantifier quantifier, List iterationContexts, BaseNode expression, String text) { + this.quantifier = quantifier; + this.iterationContexts = iterationContexts; + this.expression = expression; + this.setText(text); + } + public Quantifier getQuantifier() { return quantifier; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeNode.java index bf4eea94740..c64317ad43d 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/RangeNode.java @@ -66,6 +66,14 @@ public RangeNode(ParserRuleContext ctx, IntervalBoundary lowerBound, BaseNode st this.end = end; } + public RangeNode(IntervalBoundary lowerBound, IntervalBoundary upperBound, BaseNode start, BaseNode end, String text) { + this.lowerBound = lowerBound; + this.upperBound = upperBound; + this.start = start; + this.end = end; + this.setText(text); + } + public IntervalBoundary getLowerBound() { return lowerBound; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/SignedUnaryNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/SignedUnaryNode.java index e0d64f2c48b..c5ab99685e3 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/SignedUnaryNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/SignedUnaryNode.java @@ -32,7 +32,7 @@ public class SignedUnaryNode extends BaseNode { - public static enum Sign { + public enum Sign { POSITIVE, NEGATIVE; public static Sign determineSign(String str) { @@ -54,6 +54,12 @@ public SignedUnaryNode(ParserRuleContext ctx, BaseNode expr) { expression = expr; } + public SignedUnaryNode(Sign sign, BaseNode expression, String text) { + this.sign = sign; + this.expression = expression; + this.setText(text); + } + public Sign getSign() { return sign; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/StringNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/StringNode.java index 627f8c6c840..994193888c9 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/StringNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/StringNode.java @@ -32,6 +32,11 @@ public StringNode(ParserRuleContext ctx) { this.value = StringEvalHelper.unescapeString(getText()); } + public StringNode(String text) { + this.value = StringEvalHelper.unescapeString(text); + this.setText(text); + } + @Override public Object evaluate(EvaluationContext ctx) { return getValue(); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/TemporalConstantNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/TemporalConstantNode.java index 6a9af22c6bf..3c394086eb7 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/TemporalConstantNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/TemporalConstantNode.java @@ -39,6 +39,13 @@ public TemporalConstantNode(FunctionInvocationNode orig, Object value, FEELFunct this.params = Collections.unmodifiableList(params); } + public TemporalConstantNode(Object value, FEELFunction fn, List params, String text) { + this.value = value; + this.fn = fn; + this.params = params; + this.setText(text); + } + @Override public Object evaluate(EvaluationContext ctx) { return value; @@ -54,4 +61,15 @@ public T accept(Visitor v) { return v.visit(this); } + public Object getValue() { + return value; + } + + public FEELFunction getFn() { + return fn; + } + + public List getParams() { + return params; + } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/UnaryTestListNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/UnaryTestListNode.java index 5bf6c392ded..d20a8a4be05 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/UnaryTestListNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/UnaryTestListNode.java @@ -21,12 +21,15 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.function.Function; +import java.util.function.Predicate; import java.util.stream.Collectors; 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.BuiltInType; +import org.kie.dmn.feel.runtime.UnaryTest; public class UnaryTestListNode extends BaseNode { @@ -38,7 +41,7 @@ public enum State { private List elements; private State state; - private BaseNode notNode; + private UnaryTestNode notNode; public UnaryTestListNode(ParserRuleContext ctx) { this(ctx, new ArrayList<>(), State.Positive); @@ -63,6 +66,11 @@ public UnaryTestListNode(List elements, State state) { } } + public UnaryTestListNode(List elements, State state, String text) { + this(elements, state); + this.setText(text); + } + public boolean isNegated() { return state == State.Negated; } @@ -75,10 +83,11 @@ public List getElements() { return elements; } - public void setElements(List elements) { - this.elements = elements; + public void setElements(List elements) { + this.elements = elements.stream().map(UnaryTestNode.class::cast).collect(Collectors.toList()); } + @Override public List evaluate(EvaluationContext ctx) { if (notNode != null) { @@ -102,4 +111,22 @@ public ASTNode[] getChildrenNode() { public T accept(Visitor v) { return v.visit(this); } + + public List getCompiledUnaryTests() { + return notNode != null ? Collections.singletonList(getUnaryTest(notNode)) : + elements.stream() + .filter(baseNode -> baseNode instanceof UnaryTestNode || baseNode instanceof DashNode) + .map(this::getUnaryTest).toList(); + } + + private UnaryTest getUnaryTest(BaseNode baseNode) { + if (baseNode instanceof UnaryTestNode) { + return ((UnaryTestNode) baseNode).getUnaryTest(); + } else if (baseNode instanceof DashNode) { + return DashNode.DashUnaryTest.INSTANCE; + } else { + throw new RuntimeException("Unexpected node type: " + baseNode.getClass().getSimpleName()); + } + } + } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/UnaryTestNode.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/UnaryTestNode.java index a3dafdd8818..cd5d31d916b 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/UnaryTestNode.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/UnaryTestNode.java @@ -29,7 +29,6 @@ import org.kie.dmn.feel.runtime.UnaryTest; import org.kie.dmn.feel.runtime.UnaryTestImpl; import org.kie.dmn.feel.util.BooleanEvalHelper; -import org.kie.dmn.feel.util.EvalHelper; import org.kie.dmn.feel.util.Msg; public class UnaryTestNode @@ -85,6 +84,12 @@ public UnaryTestNode(ParserRuleContext ctx, String op, BaseNode value) { this.value = value; } + public UnaryTestNode( UnaryOperator op, BaseNode value, String text ) { + this.operator = op; + this.value = value; + this.setText( text); + } + public UnaryOperator getOperator() { return operator; } @@ -103,6 +108,14 @@ public void setValue(BaseNode value) { @Override public UnaryTest evaluate(EvaluationContext ctx) { + UnaryTest toReturn = getUnaryTest(); + if (toReturn == null) { + ctx.notifyEvt(astEvent(Severity.ERROR, Msg.createMessage(Msg.NULL_OR_UNKNOWN_OPERATOR))); + } + return toReturn; + } + + public UnaryTest getUnaryTest() { switch ( operator ) { case LTE: return new UnaryTestImpl( createCompareUnaryTest( (l, r) -> l.compareTo( r ) <= 0 ) , value.getText() ); @@ -123,7 +136,6 @@ public UnaryTest evaluate(EvaluationContext ctx) { case TEST: return new UnaryTestImpl( createBooleanUnaryTest(), value.getText() ); } - ctx.notifyEvt( astEvent(Severity.ERROR, Msg.createMessage(Msg.NULL_OR_UNKNOWN_OPERATOR))); return null; } 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 09ab2fc3cc1..6904d03b2d5 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 @@ -20,38 +20,43 @@ public interface Visitor { T visit(ASTNode n); - T visit(DashNode n); - T visit(BooleanNode n); - T visit(NumberNode n); - T visit(StringNode n); - T visit(NullNode n); - T visit(CTypeNode n); - T visit(NameDefNode n); - T visit(NameRefNode n); - T visit(QualifiedNameNode n); - T visit(InfixOpNode n); - T visit(InstanceOfNode n); - T visit(IfExpressionNode n); - T visit(ForExpressionNode n); + T visit(AtLiteralNode n); T visit(BetweenNode n); + T visit(BooleanNode n); T visit(ContextNode n); T visit(ContextEntryNode n); + T visit(ContextTypeNode n); + T visit(CTypeNode n); + T visit(DashNode n); T visit(FilterExpressionNode n); + T visit(ForExpressionNode n); + T visit(FormalParameterNode n); T visit(FunctionDefNode n); + T visit(FunctionTypeNode n); T visit(FunctionInvocationNode n); - T visit(NamedParameterNode n); + T visit(IfExpressionNode n); + T visit(InfixOpNode n); T visit(InNode n); + T visit(InstanceOfNode n); T visit(IterationContextNode n); T visit(ListNode n); + T visit(ListTypeNode n); + T visit(NameDefNode n); + T visit(NamedParameterNode n); + T visit(NameRefNode n); + T visit(NullNode n); + T visit(NumberNode n); T visit(PathExpressionNode n); + T visit(QualifiedNameNode n); T visit(QuantifiedExpressionNode n); T visit(RangeNode n); T visit(SignedUnaryNode n); - T visit(UnaryTestNode n); + T visit(StringNode n); + + default T visit(TemporalConstantNode n) { + return null; + } + T visit(UnaryTestListNode n); - T visit(FormalParameterNode n); - T visit(AtLiteralNode n); - T visit(ListTypeNode n); - T visit(ContextTypeNode n); - T visit(FunctionTypeNode n); + T visit(UnaryTestNode n); } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/impl/FEELImpl.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/impl/FEELImpl.java index 80024a15564..a5fdc51152e 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/impl/FEELImpl.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/impl/FEELImpl.java @@ -152,7 +152,8 @@ public Object evaluate(String expression, Map inputVariables) { @Override public Object evaluate(CompiledExpression expr, Map inputVariables) { CompiledFEELExpression e = (CompiledFEELExpression) expr; - return e.apply(newEvaluationContext(Collections.EMPTY_SET, inputVariables)); + EvaluationContextImpl evaluationContext = newEvaluationContext(Collections.EMPTY_SET, inputVariables); // split to simplify debug + return e.apply(evaluationContext); } @Override diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/listeners/SyntaxErrorListener.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/listeners/SyntaxErrorListener.java new file mode 100644 index 00000000000..267c259c12e --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/listeners/SyntaxErrorListener.java @@ -0,0 +1,46 @@ +/** + * 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.listeners; + +import org.kie.dmn.api.feel.runtime.events.FEELEvent; +import org.kie.dmn.api.feel.runtime.events.FEELEventListener; +import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; +import org.kie.dmn.feel.runtime.events.SyntaxErrorEvent; + +// thread-unsafe +public class SyntaxErrorListener implements FEELEventListener { + + private FEELEvent event = null; + + @Override + public void onEvent(FEELEvent evt) { + if (evt instanceof SyntaxErrorEvent + || evt instanceof InvalidParametersEvent) { + this.event = evt; + } + } + + public boolean isError() { + return event != null; + } + + public FEELEvent event() { + return event; + } +} \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/FEELFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/FEELFunction.java index 15941675c02..435654b91d3 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/FEELFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/FEELFunction.java @@ -70,7 +70,7 @@ public interface FEELFunction { */ Object invokeReflectively(EvaluationContext ctx, Object[] params); - public static class Param { + class Param { public final String name; public final Type type; diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CustomFEELFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CustomFEELFunction.java index 8ca827e93be..a18b9813987 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CustomFEELFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CustomFEELFunction.java @@ -19,6 +19,7 @@ package org.kie.dmn.feel.runtime.functions; import java.util.List; +import java.util.Objects; import org.kie.dmn.feel.lang.EvaluationContext; import org.kie.dmn.feel.lang.ast.BaseNode; @@ -34,4 +35,20 @@ protected Object internalInvoke(EvaluationContext ctx) { return this.body.evaluate(ctx); } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + CustomFEELFunction that = (CustomFEELFunction) o; + return Objects.equals(toString(), that.toString()); + } + + @Override + public int hashCode() { + return Objects.hashCode(toString()); + } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/CodegenUtils.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/CodegenUtils.java new file mode 100644 index 00000000000..9eaddf4df80 --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/CodegenUtils.java @@ -0,0 +1,249 @@ +/** + * 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 java.time.Duration; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetTime; +import java.time.ZonedDateTime; +import java.time.temporal.TemporalAccessor; +import java.util.Arrays; +import java.util.List; + +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.ast.expr.IntegerLiteralExpr; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.stmt.ExpressionStmt; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import org.kie.dmn.feel.lang.types.impl.ComparablePeriod; + +import static com.github.javaparser.StaticJavaParser.parseExpression; +import static com.github.javaparser.utils.StringEscapeUtils.escapeJava; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.ASLIST_S; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.DURATION_CT; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.DURATION_N; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.FEEL_TIME_S; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.INTEGER_CT; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.LOCAL_DATE_CT; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.LOCAL_DATE_N; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.LOCAL_DATE_TIME_CT; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.LOCAL_DATE_TIME_N; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.LOCAL_TIME_CT; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.LOCAL_TIME_N; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.OFFSETTIME_CT; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.OFFSETTIME_N; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.OF_S; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.PARSE_S; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.STRING_CT; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.TEMPORALACCESSOR_CT; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.ZONED_DATE_TIME_CT; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.ZONED_DATE_TIME_N; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.ZONE_ID_N; +import static org.kie.dmn.feel.codegen.feel11.CodegenConstants.ZONE_OFFSET_N; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.COMPARABLEPERIOD_CT; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.COMPARABLEPERIOD_N; +import static org.kie.dmn.feel.codegen.feel11.DMNCodegenConstants.TIMEFUNCTION_N; + +/** + * Class meant to provide commons utility methods for codegen. + * This class should not have any reference to dmn-specific classes/methods. + */ +public class CodegenUtils { + + private CodegenUtils() { + } + + public static Expression getEnumExpression(Enum enumType) { + Expression scopeExpression = parseExpression(enumType.getClass().getCanonicalName()); + return new FieldAccessExpr(scopeExpression, enumType.name()); + } + + public static VariableDeclarationExpr getObjectExpression(Object object, String variableName) { + if (object instanceof ComparablePeriod comparablePeriod) { + NodeList arguments = NodeList.nodeList(new StringLiteralExpr(comparablePeriod.asPeriod().toString())); + + return getVariableDeclaratorWithMethodCall(variableName, + COMPARABLEPERIOD_CT, + PARSE_S, + COMPARABLEPERIOD_N, arguments); + } else if (object instanceof Duration duration) { + NodeList arguments = NodeList.nodeList(new StringLiteralExpr(duration.toString())); + return getVariableDeclaratorWithMethodCall(variableName, + DURATION_CT, + PARSE_S, + DURATION_N, + arguments); + } else if (object instanceof LocalDate localDate) { + NodeList arguments = NodeList.nodeList(new IntegerLiteralExpr(localDate.getYear()), + new IntegerLiteralExpr(localDate.getMonthValue()), + new IntegerLiteralExpr(localDate.getDayOfMonth())); + + return getVariableDeclaratorWithMethodCall(variableName, + LOCAL_DATE_CT, + OF_S, + LOCAL_DATE_N, + arguments); + } else if (object instanceof LocalDateTime localDateTime) { + NodeList arguments = NodeList.nodeList(new IntegerLiteralExpr(localDateTime.getYear()), + new IntegerLiteralExpr(localDateTime.getMonthValue()), + new IntegerLiteralExpr(localDateTime.getDayOfMonth()), + new IntegerLiteralExpr(localDateTime.getHour()), + new IntegerLiteralExpr(localDateTime.getMinute()), + new IntegerLiteralExpr(localDateTime.getSecond())); + return getVariableDeclaratorWithMethodCall(variableName, + LOCAL_DATE_TIME_CT, + OF_S, + LOCAL_DATE_TIME_N, + arguments); + } else if (object instanceof LocalTime localTime) { + NodeList arguments = NodeList.nodeList(new IntegerLiteralExpr(localTime.getHour()), + new IntegerLiteralExpr(localTime.getMinute()), + new IntegerLiteralExpr(localTime.getSecond()), + new IntegerLiteralExpr(localTime.getNano())); + return getVariableDeclaratorWithMethodCall(variableName, + LOCAL_TIME_CT, + OF_S, + LOCAL_TIME_N, + arguments); + } else if (object instanceof Number number) { + return getVariableDeclaratorWithInitializerExpression(variableName, INTEGER_CT, + new IntegerLiteralExpr(number.toString())); + } else if (object instanceof OffsetTime offsetTime) { + Expression zoneOffsetExpression = new MethodCallExpr(ZONE_OFFSET_N, + OF_S, + NodeList.nodeList(new StringLiteralExpr(offsetTime.getOffset().getId()))); + NodeList arguments = NodeList.nodeList(new IntegerLiteralExpr(offsetTime.getHour()), + new IntegerLiteralExpr(offsetTime.getMinute()), + new IntegerLiteralExpr(offsetTime.getSecond()), + new IntegerLiteralExpr(offsetTime.getNano()), + zoneOffsetExpression); + return getVariableDeclaratorWithMethodCall(variableName, + OFFSETTIME_CT, + OF_S, + OFFSETTIME_N, + arguments); + } else if (object instanceof String string) { + return getVariableDeclaratorWithInitializerExpression(variableName, STRING_CT, + new StringLiteralExpr(escapeJava(string))); + } else if (object instanceof ZonedDateTime zonedDateTime) { + Expression zoneIdExpression = new MethodCallExpr(ZONE_ID_N, OF_S, + NodeList.nodeList(new StringLiteralExpr(zonedDateTime.getZone().getId()))); + NodeList arguments = NodeList.nodeList(new IntegerLiteralExpr(zonedDateTime.getYear()), + new IntegerLiteralExpr(zonedDateTime.getMonthValue()), + new IntegerLiteralExpr(zonedDateTime.getDayOfMonth()), + new IntegerLiteralExpr(zonedDateTime.getHour()), + new IntegerLiteralExpr(zonedDateTime.getMinute()), + new IntegerLiteralExpr(zonedDateTime.getSecond()), + new IntegerLiteralExpr(zonedDateTime.getNano()), + zoneIdExpression); + return getVariableDeclaratorWithMethodCall(variableName, + ZONED_DATE_TIME_CT, + OF_S, + ZONED_DATE_TIME_N, + arguments); + } else if (object instanceof TemporalAccessor temporalAccessor) { + // FallBack in case of Parse or other unmanaged classes - keep at the end + String parsedString = DateTimeEvalHelper.toParsableString(temporalAccessor); + Expression feelTimeExpression = new FieldAccessExpr(TIMEFUNCTION_N, FEEL_TIME_S); + return getVariableDeclaratorWithMethodCall(variableName, + TEMPORALACCESSOR_CT, + PARSE_S, + feelTimeExpression, + NodeList.nodeList(new StringLiteralExpr(parsedString))); + } else { + throw new UnsupportedOperationException("Unexpected Object: " + object + " " + object.getClass()); + } + } + + public static StringLiteralExpr getStringLiteralExpr(String text) { + if (text.startsWith("\"") && text.endsWith("\"")) { + String actualStringContent = text.substring(1, text.length() - 1); // remove start/end " from the FEEL text expression. + String unescaped = StringEvalHelper.unescapeString(actualStringContent); // unescapes String, FEEL-style + return new StringLiteralExpr().setString(unescaped); // setString escapes the contents Java-style + } else { + return new StringLiteralExpr().setString(text); + } + } + + public static Expression getListExpression(List expressions) { + ExpressionStmt asListExpression = new ExpressionStmt(); + MethodCallExpr arraysCallExpression = new MethodCallExpr(); + SimpleName arraysName = new SimpleName(Arrays.class.getName()); + arraysCallExpression.setScope(new NameExpr(arraysName)); + arraysCallExpression.setName(new SimpleName(ASLIST_S)); + asListExpression.setExpression(arraysCallExpression); + NodeList arguments = new NodeList<>(); + arguments.addAll(expressions); + arraysCallExpression.setArguments(arguments); + asListExpression.setExpression(arraysCallExpression); + return asListExpression.getExpression(); + } + + public static VariableDeclarationExpr getVariableDeclaratorWithObjectCreation(String variableName, + ClassOrInterfaceType variableType, + NodeList arguments) { + final VariableDeclarator variableDeclarator = + new VariableDeclarator(variableType, variableName); + final ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(null, variableType, arguments); + variableDeclarator.setInitializer(objectCreationExpr); + return new VariableDeclarationExpr(variableDeclarator); + } + + public static VariableDeclarationExpr getVariableDeclaratorWithMethodCall(String variableName, + ClassOrInterfaceType variableType, + String name, + Expression scope, + NodeList arguments) { + final VariableDeclarator variableDeclarator = + new VariableDeclarator(variableType, variableName); + final MethodCallExpr methodCallExpr = new MethodCallExpr(scope, name, arguments); + variableDeclarator.setInitializer(methodCallExpr); + return new VariableDeclarationExpr(variableDeclarator); + } + + public static VariableDeclarationExpr getVariableDeclaratorWithFieldAccessExpr(String variableName, + ClassOrInterfaceType variableType, + String name, + Expression scope) { + final VariableDeclarator variableDeclarator = + new VariableDeclarator(variableType, variableName); + final FieldAccessExpr methodCallExpr = new FieldAccessExpr(scope, name); + variableDeclarator.setInitializer(methodCallExpr); + return new VariableDeclarationExpr(variableDeclarator); + } + + public static VariableDeclarationExpr getVariableDeclaratorWithInitializerExpression(String variableName, + ClassOrInterfaceType variableType, + Expression initializer) { + final VariableDeclarator variableDeclarator = + new VariableDeclarator(variableType, variableName); + variableDeclarator.setInitializer(initializer); + return new VariableDeclarationExpr(variableDeclarator); + } +} \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/DateTimeEvalHelper.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/DateTimeEvalHelper.java index 3ba39f9a883..c36ba7905f3 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/DateTimeEvalHelper.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/DateTimeEvalHelper.java @@ -27,6 +27,8 @@ import java.time.ZonedDateTime; import java.time.temporal.ChronoField; import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalQueries; +import java.time.temporal.TemporalQuery; import java.util.Optional; import java.util.function.BiPredicate; @@ -40,6 +42,14 @@ public class DateTimeEvalHelper { public static ZonedDateTime coerceDateTime(final LocalDate value) { return ZonedDateTime.of(value, LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC); } + + public static String toParsableString(TemporalAccessor temporalAccessor) { + int hour = temporalAccessor.get(ChronoField.HOUR_OF_DAY); + int minute = temporalAccessor.get(ChronoField.MINUTE_OF_HOUR); + int second = temporalAccessor.get(ChronoField.SECOND_OF_MINUTE); + ZoneId query = temporalAccessor.query(TemporalQueries.zoneId()); + return String.format("%02d:%02d:%02d@%s", hour, minute, second, query.getId()); + } /** * DMNv1.2 10.3.2.3.6 date-time, valuedt(date and time), for use in this {@link BooleanEvalHelper#compare(Object, Object, EvaluationContext, BiPredicate)} diff --git a/kie-dmn/kie-dmn-feel/src/main/resources/TemplateCompiledFEELExpression.java b/kie-dmn/kie-dmn-feel/src/main/resources/TemplateCompiledFEELExpression.java index 07d1bc45435..2810df47394 100644 --- a/kie-dmn/kie-dmn-feel/src/main/resources/TemplateCompiledFEELExpression.java +++ b/kie-dmn/kie-dmn-feel/src/main/resources/TemplateCompiledFEELExpression.java @@ -18,18 +18,22 @@ */ package org.kie.dmn.feel.codegen.feel11; -import static org.kie.dmn.feel.codegen.feel11.CompiledFEELSemanticMappings.*; - import org.kie.dmn.feel.codegen.feel11.CompiledCustomFEELFunction; import org.kie.dmn.feel.codegen.feel11.CompiledFEELExpression; -import org.kie.dmn.feel.codegen.feel11.CompiledFEELSupport; +import org.kie.dmn.feel.lang.ast.BaseNode; import org.kie.dmn.feel.lang.EvaluationContext; public class TemplateCompiledFEELExpression implements org.kie.dmn.feel.codegen.feel11.CompiledFEELExpression { + private BaseNode BASE_NODE; + @Override public Object apply(EvaluationContext feelExprCtx) { - return null; + try { + return getBaseNode().evaluate(feelExprCtx); + } catch (IllegalStateException e) { + return notifyCompilationError(feelExprCtx, e.getMessage()); + } } private static TemplateCompiledFEELExpression INSTANCE; @@ -41,4 +45,15 @@ public static TemplateCompiledFEELExpression getInstance() { return INSTANCE; } + private BaseNode getBaseNode() { + if (BASE_NODE == null) { + BASE_NODE = createBaseNode(); + } + return BASE_NODE; + } + + private BaseNode createBaseNode() { + return null; + } + } diff --git a/kie-dmn/kie-dmn-feel/src/main/resources/TemplateCompiledFEELUnaryTests.java b/kie-dmn/kie-dmn-feel/src/main/resources/TemplateCompiledFEELUnaryTests.java index 8e3c90b2aef..0bc582db7c2 100644 --- a/kie-dmn/kie-dmn-feel/src/main/resources/TemplateCompiledFEELUnaryTests.java +++ b/kie-dmn/kie-dmn-feel/src/main/resources/TemplateCompiledFEELUnaryTests.java @@ -20,21 +20,32 @@ import org.kie.dmn.feel.codegen.feel11.CompiledCustomFEELFunction; import org.kie.dmn.feel.codegen.feel11.CompiledFEELExpression; -import org.kie.dmn.feel.codegen.feel11.CompiledFEELSupport; import org.kie.dmn.feel.lang.EvaluationContext; - +import java.util.Collections; import java.util.List; import java.util.function.BiFunction; +import org.kie.dmn.feel.lang.ast.UnaryTestListNode; import org.kie.dmn.feel.runtime.UnaryTest; public class TemplateCompiledFEELUnaryTests implements org.kie.dmn.feel.codegen.feel11.CompiledFEELUnaryTests { + private org.kie.dmn.feel.lang.ast.UnaryTestListNode BASE_NODE; + private java.util.List UNARY_TESTS; + @Override public java.util.List getUnaryTests() { - return null; + try { + return getCompiledUnaryTests(); + } catch (IllegalStateException e) { + org.kie.dmn.feel.runtime.UnaryTest unaryTest = (feelExprCtx, left) -> { + notifyCompilationError(feelExprCtx, e.getMessage()); + return false; + }; + return java.util.Collections.singletonList(unaryTest); + } } private static TemplateCompiledFEELUnaryTests INSTANCE; @@ -45,4 +56,22 @@ public static TemplateCompiledFEELUnaryTests getInstance() { } return INSTANCE; } + + private java.util.List getCompiledUnaryTests() { + if (UNARY_TESTS == null) { + UNARY_TESTS = getBaseNode().getCompiledUnaryTests(); + } + return UNARY_TESTS; + } + + private org.kie.dmn.feel.lang.ast.UnaryTestListNode getBaseNode() { + if (BASE_NODE == null) { + BASE_NODE = createBaseNode(); + } + return BASE_NODE; + } + + private org.kie.dmn.feel.lang.ast.UnaryTestListNode createBaseNode() { + return null; + } } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/DirectCompilerUnaryTestsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/CodegenFEELUnaryTestsTest.java similarity index 79% rename from kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/DirectCompilerUnaryTestsTest.java rename to kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/CodegenFEELUnaryTestsTest.java index 13f61615b31..ff42ea47a6d 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/DirectCompilerUnaryTestsTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/CodegenFEELUnaryTestsTest.java @@ -23,7 +23,8 @@ import java.util.Map; import java.util.stream.Collectors; -import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.stmt.BlockStmt; import org.antlr.v4.runtime.tree.ParseTree; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.lang.EvaluationContext; @@ -38,30 +39,12 @@ import org.slf4j.LoggerFactory; import static org.assertj.core.api.Assertions.assertThat; +import static org.kie.dmn.feel.codegen.feel11.ProcessedUnaryTest.TEMPLATE_CLASS; +import static org.kie.dmn.feel.codegen.feel11.ProcessedUnaryTest.TEMPLATE_RESOURCE; -public class DirectCompilerUnaryTestsTest { +public class CodegenFEELUnaryTestsTest { - public static final Logger LOG = LoggerFactory.getLogger(DirectCompilerUnaryTestsTest.class); - - private List parseCompileEvaluate(String feelLiteralExpression, Object l) { - Object left = NumberEvalHelper.coerceNumber(l); - FEELEventListenersManager mgr = new FEELEventListenersManager(); - CompiledFEELSupport.SyntaxErrorListener listener = new CompiledFEELSupport.SyntaxErrorListener(); - mgr.addListener(listener); - EvaluationContext emptyContext = CodegenTestUtil.newEmptyEvaluationContext(mgr); - CompiledFEELUnaryTests compiledUnaryTests = parse(feelLiteralExpression, mgr, listener); - LOG.debug("{}", compiledUnaryTests); - List result = compiledUnaryTests.getUnaryTests() - .stream() - .map(ut -> ut.apply(emptyContext, left)) - .collect(Collectors.toList()); - if (listener.isError()) { - LOG.debug("{}", listener.event()); - return Collections.emptyList(); - } - LOG.debug("{}", result); - return result; - } + public static final Logger LOG = LoggerFactory.getLogger(CodegenFEELUnaryTestsTest.class); @Test void dash() { @@ -109,27 +92,59 @@ void t2() { assertThat(parseCompileEvaluate("\"asd\"", "asd")).containsExactly(Boolean.TRUE); } - private CompiledFEELUnaryTests parse(String input, FEELEventListenersManager mgr, CompiledFEELSupport.SyntaxErrorListener listener) { + + private List parseCompileEvaluate(String feelLiteralExpression, Object l) { + Object left = NumberEvalHelper.coerceNumber(l); + FEELEventListenersManager mgr = new FEELEventListenersManager(); + SyntaxErrorListener listener = new SyntaxErrorListener(); + mgr.addListener(listener); + EvaluationContext emptyContext = CodegenTestUtil.newEmptyEvaluationContext(mgr); + CompiledFEELUnaryTests compiledUnaryTests = parse(feelLiteralExpression, mgr, listener); + LOG.debug("{}", compiledUnaryTests); + List result = compiledUnaryTests.getUnaryTests() + .stream() + .map(ut -> ut.apply(emptyContext, left)) + .collect(Collectors.toList()); + if (listener.isError()) { + LOG.debug("{}", listener.event()); + return Collections.emptyList(); + } + LOG.debug("{}", result); + return result; + } + + private CompiledFEELUnaryTests parse(String input, FEELEventListenersManager mgr, SyntaxErrorListener listener) { return parse( input, Collections.emptyMap(), mgr, listener ); } - private CompiledFEELUnaryTests parse(String input, Map inputTypes, FEELEventListenersManager mgr, CompiledFEELSupport.SyntaxErrorListener listener) { + private CompiledFEELUnaryTests parse(String input, Map inputTypes, FEELEventListenersManager mgr, SyntaxErrorListener listener) { FEEL_1_1Parser parser = FEELParser.parse(mgr, input, inputTypes, Collections.emptyMap(), Collections.emptyList(), Collections.emptyList(), null); ParseTree tree = parser.unaryTestsRoot(); - DirectCompilerResult directResult; + ASTCompilerVisitor compilerVisitor = new ASTCompilerVisitor(); + BlockStmt directCodegenResult; + if (listener.isError()) { - directResult = CompiledFEELSupport.compiledErrorUnaryTest(listener.event().getMessage()); + directCodegenResult = compilerVisitor.returnError(listener.event().getMessage()); } else { ASTBuilderVisitor v = new ASTBuilderVisitor(inputTypes, null); BaseNode node = v.visit(tree); BaseNode transformed = node.accept(new ASTUnaryTestTransform()).node(); - directResult = transformed.accept(new ASTCompilerVisitor()); + directCodegenResult = transformed.accept(compilerVisitor); } - Expression expr = directResult.getExpression(); - CompiledFEELUnaryTests cu = new CompilerBytecodeLoader().makeFromJPUnaryTestsExpression(input, expr, directResult.getFieldDeclarations()); - return cu; + CompilerBytecodeLoader compilerBytecodeLoader = new CompilerBytecodeLoader(); + String packageName = compilerBytecodeLoader.generateRandomPackage(); + CompilationUnit cu = new CompilerBytecodeLoader() + .getCompilationUnit( + TEMPLATE_RESOURCE, + packageName, + TEMPLATE_CLASS, + input, + directCodegenResult, + compilerVisitor.getLastVariableName()); + + return compilerBytecodeLoader.compileUnit(packageName, TEMPLATE_CLASS, cu); } 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 137a3c50db1..8cb00e16551 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 @@ -32,6 +32,7 @@ import org.kie.dmn.feel.parser.feel11.FEELParserTest; import org.kie.dmn.feel.runtime.FEELConditionsAndLoopsTest; import org.kie.dmn.feel.runtime.FEELTernaryLogicTest; +import org.kie.dmn.feel.runtime.functions.CustomFEELFunction; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -284,7 +285,7 @@ void basic_function_invocation() { @Test void basic_function_definition() { - assertThat(parseCompileEvaluate("function (a, b) a + b")).isInstanceOf(CompiledCustomFEELFunction.class); + assertThat(parseCompileEvaluate("function (a, b) a + b")).isInstanceOf(CustomFEELFunction.class); assertThat(parseCompileEvaluate("{ s : function (a, b) a + b, x : 1, y : 2, r : s(x,y) }.r")).isEqualTo(new BigDecimal(3)); } @@ -320,7 +321,7 @@ void context_expression() { assertThat(parseCompileEvaluate("{ }")).isEqualTo(Collections.emptyMap()); assertThat(parseCompileEvaluate("{ a : 1 }")).isEqualTo(mapOf(entry("a", new BigDecimal(1)))); assertThat(parseCompileEvaluate("{ \"a\" : 1 }")).isEqualTo(mapOf(entry("a", new BigDecimal(1)))); - assertThat(parseCompileEvaluate("{ \" a\" : 1 }")).isEqualTo(mapOf(entry(" a", new BigDecimal(1)))); // Demonstrating a bad practice. + assertThat(parseCompileEvaluate("{ \" a\" : 1 }")).isEqualTo(mapOf(entry("a", new BigDecimal(1)))); // Demonstrating a bad practice. assertThat(parseCompileEvaluate("{ a : 1, b : 2, c : 3 }")).isEqualTo(mapOf(entry("a", new BigDecimal(1)), entry("b", new BigDecimal(2)), entry("c", new BigDecimal(3)))); assertThat(parseCompileEvaluate("{ a : 1, a name : \"John Doe\" }")).isEqualTo(mapOf(entry("a", new BigDecimal(1)), entry("a name", "John Doe"))); diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualBasicFunctionInvocationTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualBasicFunctionInvocationTest.java deleted file mode 100644 index 5d2e34086ca..00000000000 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualBasicFunctionInvocationTest.java +++ /dev/null @@ -1,63 +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.codegen.feel11; - -import java.math.BigDecimal; -import java.util.Arrays; - -import org.junit.jupiter.api.Test; -import org.kie.dmn.feel.lang.EvaluationContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ManualBasicFunctionInvocationTest { - - public static final Logger LOG = LoggerFactory.getLogger(ManualBasicFunctionInvocationTest.class); - - public static class ManualFilterExpression implements CompiledFEELExpression { - - public static final java.math.BigDecimal K_1 = new java.math.BigDecimal(1, java.math.MathContext.DECIMAL128); - - public static final java.math.BigDecimal K_2 = new java.math.BigDecimal(2, java.math.MathContext.DECIMAL128); - - public static final java.math.BigDecimal K_3 = new java.math.BigDecimal(3, java.math.MathContext.DECIMAL128); - - /** FEEL: max( 1, 2, 3 ) */ - @Override - public Object apply(EvaluationContext feelExprCtx) { - return CompiledFEELSupport.invoke(feelExprCtx, feelExprCtx.getValue("max"), Arrays.asList(K_1, K_2, K_3)); - } - - } - - @Test - void manualContext() { - CompiledFEELExpression compiledExpression = new ManualFilterExpression(); - LOG.debug("{}", compiledExpression); - - EvaluationContext emptyContext = CodegenTestUtil.newEmptyEvaluationContext(); - Object result = compiledExpression.apply(emptyContext); - LOG.debug("{}", result); - - assertThat(result).isEqualTo(BigDecimal.valueOf(3)); - } - -} diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualContextTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualContextTest.java deleted file mode 100644 index 1b79c12a6b1..00000000000 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualContextTest.java +++ /dev/null @@ -1,71 +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.codegen.feel11; - -import java.util.Map; - -import org.junit.jupiter.api.Test; -import org.kie.dmn.feel.lang.EvaluationContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ManualContextTest { - - public static final Logger LOG = LoggerFactory.getLogger(ManualContextTest.class); - - public class ManualContext implements CompiledFEELExpression { - - // { an applicant : { - // home address : { - // street name: \"broadway st\", - // city : \"New York\" - // } - // }, - // street : an applicant.home address.street name - // } - @Override - public Map apply(EvaluationContext feelExprCtx) { - return CompiledFEELSupport.openContext(feelExprCtx) - .setEntry("an applicant", CompiledFEELSupport.openContext(feelExprCtx) - .setEntry("home address", CompiledFEELSupport.openContext(feelExprCtx) - .setEntry("street name", "broadway st") - .setEntry("city", "New York") - .closeContext()) - .closeContext()) - .setEntry("street", ((java.util.Map) ((java.util.Map) feelExprCtx.getValue("an applicant")).get("home address")).get("street name")) - .closeContext(); - } - } - - @Test - void manualContext() { - CompiledFEELExpression compiledExpression = new ManualContext(); - LOG.debug("{}", compiledExpression); - - EvaluationContext emptyContext = CodegenTestUtil.newEmptyEvaluationContext(); - Object result = compiledExpression.apply(emptyContext); - LOG.debug("{}", result); - - assertThat(result).isInstanceOf(Map.class); - assertThat(((Map) result)).containsEntry("street", "broadway st"); - } - -} diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualFilterTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualFilterTest.java deleted file mode 100644 index f081a65da67..00000000000 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualFilterTest.java +++ /dev/null @@ -1,71 +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.codegen.feel11; - -import java.math.BigDecimal; - -import org.junit.jupiter.api.Test; -import org.kie.dmn.feel.lang.EvaluationContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.kie.dmn.feel.codegen.feel11.CompiledFEELSemanticMappings.gt; - -public class ManualFilterTest { - - public static final Logger LOG = LoggerFactory.getLogger(ManualFilterTest.class); - - public static class ManualFilterExpression implements CompiledFEELExpression { - - public static final java.math.BigDecimal K_1 = new java.math.BigDecimal(1, java.math.MathContext.DECIMAL128); - - public static final java.math.BigDecimal K_2 = new java.math.BigDecimal(2, java.math.MathContext.DECIMAL128); - - public static final java.math.BigDecimal K_3 = new java.math.BigDecimal(3, java.math.MathContext.DECIMAL128); - - public static final java.math.BigDecimal K_4 = new java.math.BigDecimal(4, java.math.MathContext.DECIMAL128); - - /** FEEL: [1, 2, 3, 4][item > 2] */ - @Override - public Object apply(EvaluationContext feelExprCtx) { - return CompiledFEELSupport.filter(feelExprCtx, java.util.Arrays.asList(K_1, K_2, K_3, K_4)).with(new java.util.function.Function() { - - @Override - public Object apply(EvaluationContext feelExprCtx) { - return gt(feelExprCtx.getValue("item"), K_2); - } - }); - } - - } - - @Test - void manualContext() { - CompiledFEELExpression compiledExpression = new ManualFilterExpression(); - LOG.debug("{}", compiledExpression); - - EvaluationContext emptyContext = CodegenTestUtil.newEmptyEvaluationContext(); - Object result = compiledExpression.apply(emptyContext); - LOG.debug("{}", result); - - assertThat(result).asList().containsExactly(BigDecimal.valueOf(3), BigDecimal.valueOf(4)); - } - -} diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualForTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualForTest.java deleted file mode 100644 index d7ec805b62f..00000000000 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualForTest.java +++ /dev/null @@ -1,74 +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.codegen.feel11; - -import java.math.BigDecimal; -import java.util.Arrays; - -import org.junit.jupiter.api.Test; -import org.kie.dmn.feel.lang.EvaluationContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ManualForTest { - - public static final Logger LOG = LoggerFactory.getLogger(ManualForTest.class); - - public static class ManualFilterExpression implements CompiledFEELExpression { - - public static final java.math.BigDecimal K_1 = new java.math.BigDecimal(1, java.math.MathContext.DECIMAL128); - - public static final java.math.BigDecimal K_2 = new java.math.BigDecimal(2, java.math.MathContext.DECIMAL128); - - public static final java.math.BigDecimal K_3 = new java.math.BigDecimal(3, java.math.MathContext.DECIMAL128); - - public static final java.math.BigDecimal K_10 = new java.math.BigDecimal(10, java.math.MathContext.DECIMAL128); - - public static final java.math.BigDecimal K_20 = new java.math.BigDecimal(20, java.math.MathContext.DECIMAL128); - - public static final java.math.BigDecimal K_30 = new java.math.BigDecimal(30, java.math.MathContext.DECIMAL128); - - /** FEEL: for x in [ 10, 20, 30 ], y in [ 1, 2, 3 ] return x * y */ - @Override - public Object apply(EvaluationContext feelExprCtx) { - return CompiledFEELSupport.ffor(feelExprCtx) - .with(c -> "x", c -> Arrays.asList(K_10, K_20, K_30)) - .with(c -> "y", c -> Arrays.asList(K_1, K_2, K_3)) - .rreturn(c -> ((BigDecimal) feelExprCtx.getValue("x")).multiply((BigDecimal) feelExprCtx.getValue("y"))); - } - - } - - @Test - void manualContext() { - CompiledFEELExpression compiledExpression = new ManualFilterExpression(); - LOG.debug("{}", compiledExpression); - - EvaluationContext emptyContext = CodegenTestUtil.newEmptyEvaluationContext(); - Object result = compiledExpression.apply(emptyContext); - LOG.debug("{}", result); - - assertThat(result).asList().containsExactly(BigDecimal.valueOf(10), BigDecimal.valueOf(20), BigDecimal.valueOf(30), - BigDecimal.valueOf(20), BigDecimal.valueOf(40), BigDecimal.valueOf(60), - BigDecimal.valueOf(30), BigDecimal.valueOf(60), BigDecimal.valueOf(90)); - } - -} diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualNamedFunctionInvocationTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualNamedFunctionInvocationTest.java deleted file mode 100644 index d2d254e8f79..00000000000 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualNamedFunctionInvocationTest.java +++ /dev/null @@ -1,63 +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.codegen.feel11; - -import java.util.Arrays; - -import org.junit.jupiter.api.Test; -import org.kie.dmn.feel.lang.EvaluationContext; -import org.kie.dmn.feel.lang.impl.NamedParameter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ManualNamedFunctionInvocationTest { - - public static final Logger LOG = LoggerFactory.getLogger(ManualNamedFunctionInvocationTest.class); - - static class NamedFunctionExample implements CompiledFEELExpression { - static final java.math.BigDecimal K_1 = new java.math.BigDecimal(2, java.math.MathContext.DECIMAL128); - static final String K_s = "FOOBAR"; - - /** FEEL: substring( start position: 2, string: "FOOBAR" ) */ - @Override - public Object apply(EvaluationContext feelExprCtx) { - return CompiledFEELSupport.invoke( - feelExprCtx, - feelExprCtx.getValue("substring"), - Arrays.asList(new NamedParameter("start position", K_1), - new NamedParameter("string", K_s))); - } - - } - - @Test - void manualContext() { - CompiledFEELExpression compiledExpression = new NamedFunctionExample(); - LOG.debug("{}", compiledExpression); - - EvaluationContext emptyContext = CodegenTestUtil.newEmptyEvaluationContext(); - Object result = compiledExpression.apply(emptyContext); - LOG.debug("{}", result); - - assertThat(result).isEqualTo("OOBAR"); - } - -} diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualQuantTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualQuantTest.java deleted file mode 100644 index 7204f3e6417..00000000000 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualQuantTest.java +++ /dev/null @@ -1,68 +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.codegen.feel11; - -import java.util.Arrays; - -import org.junit.jupiter.api.Test; -import org.kie.dmn.feel.lang.EvaluationContext; -import org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode.Quantifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.kie.dmn.feel.codegen.feel11.CompiledFEELSemanticMappings.gt; - -public class ManualQuantTest { - - public static final Logger LOG = LoggerFactory.getLogger(ManualQuantTest.class); - - public static class ManualFilterExpression implements CompiledFEELExpression { - - public static final java.math.BigDecimal K_80 = new java.math.BigDecimal(80, java.math.MathContext.DECIMAL128); - - public static final java.math.BigDecimal K_11 = new java.math.BigDecimal(11, java.math.MathContext.DECIMAL128); - - public static final java.math.BigDecimal K_100 = new java.math.BigDecimal(100, java.math.MathContext.DECIMAL128); - - public static final java.math.BigDecimal K_110 = new java.math.BigDecimal(110, java.math.MathContext.DECIMAL128); - - /** FEEL: some price in [ 80, 11, 110 ] satisfies price > 100 */ - @Override - public Object apply(EvaluationContext feelExprCtx) { - return CompiledFEELSupport.quant(Quantifier.SOME, feelExprCtx) - .with(c -> "price", c -> Arrays.asList(K_80, K_11, K_110)) - .satisfies(c -> gt(feelExprCtx.getValue("price"), K_100)); - } - - } - - @Test - void manualContext() { - CompiledFEELExpression compiledExpression = new ManualFilterExpression(); - LOG.debug("{}", compiledExpression); - - EvaluationContext emptyContext = CodegenTestUtil.newEmptyEvaluationContext(); - Object result = compiledExpression.apply(emptyContext); - LOG.debug("{}", result); - - assertThat(result).isEqualTo(Boolean.TRUE); - } - -} diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualUnaryTestsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualUnaryTestsTest.java deleted file mode 100644 index 5d6165f6536..00000000000 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/codegen/feel11/ManualUnaryTestsTest.java +++ /dev/null @@ -1,68 +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.codegen.feel11; - -import java.math.BigDecimal; -import java.math.MathContext; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import org.junit.jupiter.api.Test; -import org.kie.dmn.feel.lang.EvaluationContext; -import org.kie.dmn.feel.runtime.UnaryTest; -import org.kie.dmn.feel.util.NumberEvalHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.kie.dmn.feel.codegen.feel11.CompiledFEELSemanticMappings.lt; - -public class ManualUnaryTestsTest { - - public static final Logger LOG = LoggerFactory.getLogger(ManualUnaryTestsTest.class); - - public static class ManualImpl1 implements CompiledFEELUnaryTests { - - private static final UnaryTest UT_a = (feelExprCtx, left) -> lt(left, new BigDecimal(47, MathContext.DECIMAL128)); - - private static final UnaryTest UT_b = (feelExprCtx, left) -> lt(left, new BigDecimal(1, MathContext.DECIMAL128)); - - @Override - public List getUnaryTests() { - return Arrays.asList(UT_a, UT_b); - } - - } - - @Test - void manualUnaryTests() { - Object left = NumberEvalHelper.coerceNumber(7); - - CompiledFEELUnaryTests compiledUnaryTests = new ManualImpl1(); - LOG.debug("{}", compiledUnaryTests); - - EvaluationContext emptyContext = CodegenTestUtil.newEmptyEvaluationContext(); - List result = compiledUnaryTests.getUnaryTests().stream().map(ut -> ut.apply(emptyContext, left)).collect(Collectors.toList()); - LOG.debug("{}", result); - - assertThat(result).asList().containsExactly(true, false); - } - -} diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/BaseFEELCompilerTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/BaseFEELCompilerTest.java index a9a2d51b36b..0d2d83e4791 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/BaseFEELCompilerTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/BaseFEELCompilerTest.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; +import org.assertj.core.api.ObjectAssert; import org.kie.dmn.feel.FEEL; import org.kie.dmn.feel.lang.CompiledExpression; import org.kie.dmn.feel.lang.CompilerContext; @@ -60,18 +61,21 @@ public void expression(String expression, Map inputTypes, Map inputTypes, Map inputValues, Object result, FEEL_TARGET testFEELTarget); - - protected void assertResult(final String expression, final Map inputTypes, final Map inputValues, final Object result) { + protected void assertResult(final String expression, final Map inputTypes, final Map inputValues, final Object expected) { final CompilerContext ctx = feel.newCompilerContext(); inputTypes.forEach(ctx::addInputVariableType); final CompiledExpression compiledExpression = feel.compile(expression, ctx ); - if( result == null ) { - assertThat(feel.evaluate( compiledExpression, inputValues)).as("Evaluating: '" + expression + "'").isNull(); - } else if( result instanceof Class ) { - assertThat(feel.evaluate( compiledExpression, inputValues)).as("Evaluating: '" + expression + "'").isInstanceOf((Class) result); + Object retrieved = feel.evaluate(compiledExpression, inputValues); + String description = String.format("Evaluating: '%s'", expression); + ObjectAssert assertion = assertThat(retrieved).as(description); + if (expected == null) { + assertion.isNull(); + } else if (expected instanceof Class) { + assertion.isInstanceOf((Class) expected); } else { - assertThat(feel.evaluate( compiledExpression, inputValues)).as("Evaluating: '" + expression + "'").isEqualTo(result); + assertion.isEqualTo(expected); } } @@ -79,8 +83,6 @@ protected static List enrichWith5thParameter(final Object[][] cases) { final List results = new ArrayList<>(); for (final Object[] c : cases) { results.add(new Object[]{c[0], c[1], c[2], c[3], FEEL_TARGET.AST_INTERPRETED}); - } - for (final Object[] c : cases) { results.add(new Object[]{c[0], c[1], c[2], c[3], FEEL_TARGET.JAVA_TRANSLATED}); } return results; diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/BaseFEELTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/BaseFEELTest.java index c1a44019e7f..6b2c62f30fb 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/BaseFEELTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/BaseFEELTest.java @@ -85,16 +85,16 @@ public void expression(String expression, Object result, FEELEvent.Severity seve protected abstract void instanceTest(String expression, Object result, FEELEvent.Severity severity, FEEL_TARGET testFEELTarget, Boolean useExtendedProfile, FEELDialect dialect); - protected void assertResult(final String expression, final Object result ) { + protected void assertResult(final String expression, final Object expected ) { Object retrieved = feel.evaluate( expression ); String description = String.format("Evaluating: '%s'", expression); ObjectAssert assertion = assertThat(retrieved).as(description); - if( result == null ) { + if( expected == null ) { assertion.isNull(); - } else if( result instanceof Class ) { - assertion.isInstanceOf((Class) result); + } else if( expected instanceof Class ) { + assertion.isInstanceOf((Class) expected); } else { - assertion.isEqualTo(result); + assertion.isEqualTo(expected); } } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELExpressionsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELExpressionsTest.java index 686b5e98122..fece3027f3d 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELExpressionsTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELExpressionsTest.java @@ -91,7 +91,7 @@ private static Collection data() { {"{ x : 10, test : > x, y : 20, result : y in ( test ) }.result", Boolean.TRUE , null}, {"{ x : 10, test : > x, y : 20, result : test( y ) }.result", Boolean.TRUE , null}, {"{ test : in x, y : 20, x : [10, 20, 30], result : test( y ) }.result", null, FEELEvent.Severity.ERROR}, - + {"2 in 2", Boolean.TRUE , null}, {"{ x : 2, result : x in 2 }.result", Boolean.TRUE , null}, {"{ someList : [1, 2, 3], result : 2 in someList }.result", Boolean.TRUE , null}, 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 df1b63559d0..b56bd81798c 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 @@ -21,13 +21,13 @@ import java.util.Collections; import java.util.Map; -import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.CompilationUnit; +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.codegen.feel11.DirectCompilerResult; import org.kie.dmn.feel.lang.EvaluationContext; import org.kie.dmn.feel.lang.Type; import org.kie.dmn.feel.lang.ast.BaseNode; @@ -40,6 +40,8 @@ public class CompilerUtils { public static final Logger LOG = LoggerFactory.getLogger(CompilerUtils.class); + private static final String TEMPLATE_RESOURCE = "/TemplateCompiledFEELExpression.java"; + private static final String TEMPLATE_CLASS = "TemplateCompiledFEELExpression"; public static Object parseCompileEvaluate(String feelLiteralExpression) { CompiledFEELExpression compiledExpression = parse( feelLiteralExpression ); @@ -62,12 +64,20 @@ public static CompiledFEELExpression parse(String input, Map input ASTBuilderVisitor v = new ASTBuilderVisitor(inputTypes, null); BaseNode node = v.visit(tree); - DirectCompilerResult directResult = node.accept(new ASTCompilerVisitor()); + ASTCompilerVisitor astVisitor = new ASTCompilerVisitor(); - Expression expr = directResult.getExpression(); - CompiledFEELExpression cu = new CompilerBytecodeLoader().makeFromJPExpression(input, expr, directResult.getFieldDeclarations()); + BlockStmt directCodegenResult = node.accept(astVisitor); - return cu; + CompilerBytecodeLoader compilerBytecodeLoader = new CompilerBytecodeLoader(); + String packageName = compilerBytecodeLoader.generateRandomPackage(); + CompilationUnit cu = compilerBytecodeLoader.getCompilationUnit( + TEMPLATE_RESOURCE, + packageName, + TEMPLATE_CLASS, + input, + directCodegenResult, + astVisitor.getLastVariableName()); + return compilerBytecodeLoader.compileUnit(packageName, TEMPLATE_CLASS, cu); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/BaseNodeSchemaMapper.java b/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/BaseNodeSchemaMapper.java index e6c9814124a..3922a7381da 100644 --- a/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/BaseNodeSchemaMapper.java +++ b/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/BaseNodeSchemaMapper.java @@ -26,7 +26,6 @@ import java.util.function.BiConsumer; import org.eclipse.microprofile.openapi.models.media.Schema; -import org.kie.dmn.feel.codegen.feel11.Functions; import org.kie.dmn.feel.lang.FEELDialect; import org.kie.dmn.feel.lang.ast.AtLiteralNode; import org.kie.dmn.feel.lang.ast.BaseNode; @@ -52,7 +51,7 @@ public class BaseNodeSchemaMapper { private static BiConsumer ATLITERALNODE_CONSUMER = (node, schema) -> { // Defaulting FEELDialect to FEEL EvaluationContextImpl emptyEvalCtx = - new EvaluationContextImpl(Functions.class.getClassLoader(), new FEELEventListenersManager(), FEELDialect.FEEL); + new EvaluationContextImpl(BaseNodeSchemaMapper.class.getClassLoader(), new FEELEventListenersManager(), FEELDialect.FEEL); Object evaluated = node.evaluate(emptyEvalCtx); Object toStore = evaluated != null ? evaluated : ((AtLiteralNode) node).getStringLiteral().toString(); populateEnumSchema(schema, toStore); From 307f1a73be00e9b0b315f31ff6bda59ca5381805 Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Mon, 24 Jun 2024 13:53:09 +0200 Subject: [PATCH 05/13] [incubator-kie-issues#1326] `Filter`, `Some` and `Every` expression should fail when the matching function doesn't return a Boolean (#6000) * Fix + Tests * Fix tests * Minor changes --- .../kie/dmn/core/ast/DMNFilterEvaluator.java | 49 +++++++------------ .../dmn/core/ast/DMNIteratorEvaluator.java | 36 +++++++++++--- .../main/java/org/kie/dmn/core/util/Msg.java | 2 + .../dmn/core/v1_4/DMN14ExpressionsTest.java | 8 +-- .../kie/dmn/core/v1_4/dmn14expressions.dmn | 2 +- 5 files changed, 55 insertions(+), 42 deletions(-) diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/ast/DMNFilterEvaluator.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/ast/DMNFilterEvaluator.java index 750c671e0c2..ccaddaac570 100644 --- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/ast/DMNFilterEvaluator.java +++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/ast/DMNFilterEvaluator.java @@ -19,7 +19,6 @@ package org.kie.dmn.core.ast; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -70,8 +69,8 @@ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult d } Object inObj = inResult.getResult(); - if (inObj instanceof Range) { - inObj = new IterableRange((Range) inObj); + if (inObj instanceof Range range) { + inObj = new IterableRange(range); } else if (!(inObj instanceof Iterable)) { if (inObj == null) { MsgUtil.reportMessage(logger, @@ -85,7 +84,7 @@ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult d return new EvaluatorResultImpl(null, ResultType.FAILURE); } - // 10.3.2.9.4 Type conversions "to singleton list" + // 10.3.2.9.4 Type conversions "to singleton list" inObj = Collections.singletonList(inObj); } @@ -96,45 +95,33 @@ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult d try { result.setContext(dmnContext); - boolean first = true; - for (Object item : (Iterable) inObj) { + for (Object item : (Iterable) inObj) { dmnContext.set("item", item); if (item instanceof Map) { Map complexItem = (Map) item; - complexItem.forEach((k, v) -> dmnContext.set(k, v)); + complexItem.forEach(dmnContext::set); } EvaluatorResult evaluate = filterEvaluator.evaluate(eventManager, dmnr); Object evalReturn = evaluate.getResult(); //If the evaluation is a boolean result, we add the item based on a return of true - if (evalReturn instanceof Boolean && ((Boolean) evalReturn).booleanValue() == true) { - returnList.add(item); - } - - //If on the first evaluation, a number is returned, we are using an index instead of a boolean filter - if (first && evalReturn instanceof Number) { - List list = inObj instanceof List ? (List) inObj : List.of(inObj); - int i = ((Number) evalReturn).intValue(); - if (i > 0 && i <= list.size()) { - return new EvaluatorResultImpl(list.get(i - 1), ResultType.SUCCESS); - } else if (i < 0 && Math.abs(i) <= list.size()) { - return new EvaluatorResultImpl(list.get(list.size() + i), ResultType.SUCCESS); - } else { - MsgUtil.reportMessage(logger, - DMNMessage.Severity.ERROR, - node, - result, - null, - null, - Msg.INDEX_OUT_OF_BOUND, - list.size(), - i); - return new EvaluatorResultImpl(null, ResultType.FAILURE); + if (evalReturn instanceof Boolean booleanResult) { + if (Boolean.TRUE.equals(booleanResult)) { + returnList.add(item); } + } else { + MsgUtil.reportMessage(logger, + DMNMessage.Severity.ERROR, + node, + result, + null, + null, + Msg.FILTER_EXPRESSION_RESULT_NOT_BOOLEAN, + name); + return new EvaluatorResultImpl(null, ResultType.FAILURE); } - first = false; } } finally { diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/ast/DMNIteratorEvaluator.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/ast/DMNIteratorEvaluator.java index 63a8f05b3f6..1abbe18e518 100644 --- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/ast/DMNIteratorEvaluator.java +++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/ast/DMNIteratorEvaluator.java @@ -72,8 +72,8 @@ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult d } Object inObj = inResult.getResult(); - if (inObj instanceof Range) { - inObj = new IterableRange((Range) inObj); + if (inObj instanceof Range range) { + inObj = new IterableRange(range); } else if (!(inObj instanceof Iterable)) { if (inObj == null) { MsgUtil.reportMessage(logger, @@ -112,16 +112,40 @@ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult d if (type instanceof Every) { for (Object satisfies : returnList) { - if (!(satisfies instanceof Boolean) || ((Boolean) satisfies).booleanValue() == false) { - return new EvaluatorResultImpl(Boolean.FALSE, ResultType.SUCCESS); + if (satisfies instanceof Boolean satifiesBoolean) { + if (Boolean.FALSE.equals(satifiesBoolean)) { + return new EvaluatorResultImpl(Boolean.FALSE, ResultType.SUCCESS); + } + } else { + MsgUtil.reportMessage(logger, + DMNMessage.Severity.ERROR, + node, + result, + null, + null, + Msg.ITERATOR_EXPRESSION_RESULT_NOT_BOOLEAN, + name); + return new EvaluatorResultImpl(null, ResultType.FAILURE); } } return new EvaluatorResultImpl(Boolean.TRUE, ResultType.SUCCESS); } if (type instanceof Some) { for (Object satisfies : returnList) { - if (satisfies instanceof Boolean && ((Boolean) satisfies).booleanValue() == true) { - return new EvaluatorResultImpl(Boolean.TRUE, ResultType.SUCCESS); + if (satisfies instanceof Boolean satifiesBoolean) { + if (Boolean.TRUE.equals(satifiesBoolean)) { + return new EvaluatorResultImpl(Boolean.TRUE, ResultType.SUCCESS); + } + } else { + MsgUtil.reportMessage(logger, + DMNMessage.Severity.ERROR, + node, + result, + null, + null, + Msg.ITERATOR_EXPRESSION_RESULT_NOT_BOOLEAN, + name); + return new EvaluatorResultImpl(null, ResultType.FAILURE); } } return new EvaluatorResultImpl(Boolean.FALSE, ResultType.SUCCESS); diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/util/Msg.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/util/Msg.java index 310b936f57d..2f65e3e2639 100644 --- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/util/Msg.java +++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/util/Msg.java @@ -172,6 +172,8 @@ public final class Msg { public static final Message2 MISSING_EXPRESSION_FOR_FILTER = new Message2( DMNMessageType.MISSING_EXPRESSION, "Missing %s expression for Filter node '%s'" ); public static final Message2 CONDITION_RESULT_NOT_BOOLEAN = new Message2( DMNMessageType.ERROR_EVAL_NODE, "The if condition on node %s returned a non boolean result: '%s'" ); public static final Message1 IN_RESULT_NULL = new Message1( DMNMessageType.ERROR_EVAL_NODE, "The in condition on node %s returned null."); + public static final Message1 FILTER_EXPRESSION_RESULT_NOT_BOOLEAN = new Message1( DMNMessageType.ERROR_EVAL_NODE, "The filter expression on node %s returned a non boolean result"); + public static final Message1 ITERATOR_EXPRESSION_RESULT_NOT_BOOLEAN = new Message1( DMNMessageType.ERROR_EVAL_NODE, "The satisfy expression on node %s returned a non boolean result"); public static final Message2 INDEX_OUT_OF_BOUND = new Message2( DMNMessageType.ERROR_EVAL_NODE, "Index out of bound: list of %s elements, index %s; will evaluate as FEEL null"); diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/v1_4/DMN14ExpressionsTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/v1_4/DMN14ExpressionsTest.java index b684c947a0e..1fd9851f69e 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/v1_4/DMN14ExpressionsTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/v1_4/DMN14ExpressionsTest.java @@ -170,14 +170,14 @@ public void filterIndex(final BaseVariantTest.VariantTestConf conf) throws Throw testConfig = conf; setup(); DMNResult results = runtime.evaluateByName(model, new DMNContextImpl(Collections.singletonMap("Number Input", 5)), "Match by index"); - assertThat(results.getDecisionResultByName("Match by index").getResult()).isEqualTo(new BigDecimal(5)); + assertThat(results.getDecisionResultByName("Match by index").getResult()).asList().hasSize(1); + assertThat(results.getDecisionResultByName("Match by index").getResult()).asList().contains(new BigDecimal(5)); results = runtime.evaluateByName(model, new DMNContextImpl(Collections.singletonMap("Number Input", -2)), "Match by index"); - assertThat(results.getDecisionResultByName("Match by index").getResult()).isEqualTo(new BigDecimal(9)); + assertThat(results.getDecisionResultByName("Match by index").getResult()).asList().isEmpty(); results = runtime.evaluateByName(model, new DMNContextImpl(Collections.singletonMap("Number Input", 0)), "Match by index"); - assertThat(results.getMessages()).hasSizeGreaterThan(0); - + assertThat(results.getDecisionResultByName("Match by index").getResult()).asList().isEmpty(); } @MethodSource("params") diff --git a/kie-dmn/kie-dmn-core/src/test/resources/org/kie/dmn/core/v1_4/dmn14expressions.dmn b/kie-dmn/kie-dmn-core/src/test/resources/org/kie/dmn/core/v1_4/dmn14expressions.dmn index 9168bd2473c..ef6068630be 100644 --- a/kie-dmn/kie-dmn-core/src/test/resources/org/kie/dmn/core/v1_4/dmn14expressions.dmn +++ b/kie-dmn/kie-dmn-core/src/test/resources/org/kie/dmn/core/v1_4/dmn14expressions.dmn @@ -245,7 +245,7 @@ - Number Input + item = Number Input From e9eb000703bf02641c9da2b8b48be98192ff43fa Mon Sep 17 00:00:00 2001 From: Roberto Oliveira Date: Mon, 8 Jul 2024 07:34:19 -0400 Subject: [PATCH 06/13] [incubator-kie-issues#1347] Enforce reproducible build (#6001) * [incubator-kie-issues#1347] Enforce reproducible build * [incubator-kie-issues#1347] Enforce reproducible build - using custom property * [incubator-kie-issues#1347] Enforce reproducible build - fix broken test on reproducible build --------- Co-authored-by: Gabriele-Cardosi # Conflicts: # .github/workflows/pr-drools.yml --- ...ultKieSessionFromByteArrayExampleTest.java | 18 +++++++--- pom.xml | 36 +++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/drools-examples-api/default-kiesession-from-file/src/test/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromByteArrayExampleTest.java b/drools-examples-api/default-kiesession-from-file/src/test/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromByteArrayExampleTest.java index d43598a218a..76093b9989c 100644 --- a/drools-examples-api/default-kiesession-from-file/src/test/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromByteArrayExampleTest.java +++ b/drools-examples-api/default-kiesession-from-file/src/test/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromByteArrayExampleTest.java @@ -21,8 +21,10 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FilenameFilter; import java.io.InputStream; import java.io.PrintStream; +import java.util.Arrays; import org.junit.Test; import org.kie.api.KieServices; @@ -120,11 +122,19 @@ public static File getFile(String exampleName) { throw new RuntimeException("The target folder does not exist, please build project " + exampleName + " first"); } - for (String str : targetFolder.list()) { - if (str.startsWith(exampleName) && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { - return new File(targetFolder, str); - } + FilenameFilter expectedJArFilter = (d, str ) -> str.startsWith(exampleName) && + str.endsWith(".jar") && + !str.endsWith("-sources.jar") && + !str.endsWith("-tests.jar") && + !str.endsWith("-javadoc.jar"); + String[] foundFile = targetFolder.list(expectedJArFilter); + if (foundFile == null || foundFile.length == 0) { + throw new RuntimeException("The target jar does not exist, please build project " + exampleName + " first"); + } else if (foundFile.length > 1) { + String errorFiles = Arrays.toString(foundFile); + throw new RuntimeException("Multiple matching files exists: " + errorFiles + "; please check!"); } + return new File(targetFolder, foundFile[0]); } throw new RuntimeException("The target jar does not exist, please build project " + exampleName + " first"); diff --git a/pom.xml b/pom.xml index fcab554d20f..c23c483f355 100644 --- a/pom.xml +++ b/pom.xml @@ -239,6 +239,42 @@ drools-distribution + + reproducible-build + + + reproducible + + + + + + org.apache.maven.plugins + maven-artifact-plugin + + + check-buildplan + + check-buildplan + + + validate + + + compare + + compare + + + install + + + + + + rewrite From 95aad635cb657a230f0b0198fcd8308989f9ce0a Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Fri, 28 Jun 2024 09:33:31 +0200 Subject: [PATCH 07/13] [incubator-kie-issues#1367] The `context` function should throw an error when providing objects with the same keys (#6003) * context function * context function test * oops * Tests --- .../functions/extended/ContextFunction.java | 3 + .../runtime/KieFEELExtendedFunctionsTest.java | 1 + .../extended/ContextFunctionTest.java | 61 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/ContextFunctionTest.java diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/ContextFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/ContextFunction.java index 21a01a1bf62..08ffd5e3020 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/ContextFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/ContextFunction.java @@ -63,6 +63,9 @@ public FEELFnResult> invoke(@ParameterName("entries") List data() { { "context([{key: \"name\", value: \"John Doe\"},{\"key\":\"age\", \"value\":47}])", mapOf(entry("name", "John Doe"),entry("age", new BigDecimal(47))), null }, { "context([{key: \"name\", value: \"John Doe\"},{\"key\":\"age\", \"value\":47, \"something\":\"else\"}])", mapOf(entry("name", "John Doe"),entry("age", new BigDecimal(47))), null }, { "context([{key: \"name\", value: \"John Doe\"},{\"key\":\"age\"}])", null, FEELEvent.Severity.ERROR }, + { "context([{key: \"name\", value: \"John Doe\"},{key: \"name\", value: \"Doe John\"}])", null, FEELEvent.Severity.ERROR }, { "time(10, 20, 30)", LocalTime.of(10, 20, 30), null }, { "date( 2020, 2, 31 )", null, FEELEvent.Severity.ERROR}, { "date( \"2020-02-31\" )", null, FEELEvent.Severity.ERROR}, diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/ContextFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/ContextFunctionTest.java new file mode 100644 index 00000000000..e4909074e77 --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/ContextFunctionTest.java @@ -0,0 +1,61 @@ +/** + * 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.runtime.functions.extended; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; +import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; + +import java.util.List; +import java.util.Map; + +class ContextFunctionTest { + + private ContextFunction contextFunction; + private record ContextEntry(String key, Object value) {} + + @BeforeEach + void setUp() { + contextFunction = new ContextFunction(); + } + + @Test + void invokeListNull() { + FunctionTestUtil.assertResultError(contextFunction.invoke(null), InvalidParametersEvent.class); + } + + @Test + void invokeContainsNoKeyAndValue() { + FunctionTestUtil.assertResultError(contextFunction.invoke(List.of( + Map.of("test", "name", "value", "John Doe"), + Map.of("key", "name", "test", "John Doe"))), InvalidParametersEvent.class); +} + + @Test + void invokeDuplicateKey() { + FunctionTestUtil.assertResultError(contextFunction.invoke(List.of( + Map.of("key", "name", "value", "John Doe"), + Map.of("key", "name", "value", "John Doe"))), InvalidParametersEvent.class); + FunctionTestUtil.assertResultNotError(contextFunction.invoke(List.of( + Map.of("key", "name", "value", "John Doe"), + Map.of("key", "age", "value", 12)))); + } +} \ No newline at end of file From 611cde2c0f14b934985a7f2ee8c66747e2082386 Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Fri, 28 Jun 2024 21:09:45 +0900 Subject: [PATCH 08/13] [incubator-kie-drools-5995] kie-maven-plugin mixes multiple Maven versions: [3.8.6, 3.8.4] (#6004) --- kie-maven-plugin/pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/kie-maven-plugin/pom.xml b/kie-maven-plugin/pom.xml index 84c2fb42225..cfb5f49f9e9 100644 --- a/kie-maven-plugin/pom.xml +++ b/kie-maven-plugin/pom.xml @@ -40,7 +40,6 @@ org.kie.maven.plugin 3.3.0 3.6.4 - 3.8.4 1.4.2 1.7.3 @@ -108,11 +107,6 @@ pom import - - org.apache.maven - maven-plugin-api - ${maven.version} - org.apache.maven.plugin-testing maven-plugin-testing-harness From d3b43d38dc8457d3923f0bf533bce74e8aa1efa3 Mon Sep 17 00:00:00 2001 From: Gabriele Cardosi Date: Mon, 1 Jul 2024 09:34:56 +0200 Subject: [PATCH 09/13] [incubator-kie-issues#1344] Refactoring/reorganizing Functions (#6005) * [incubator-kie-issues#1344] Rrefactoring/reorganizing Functions * [incubator-kie-issues#1344] Fixed as per PR suggestion * [incubator-kie-issues#1344] Hiding constructors from functions, that are singleton by design * [incubator-kie-issues#1344] Fixing tests --------- Co-authored-by: Gabriele-Cardosi --- .../DMNFeelExpressionEvaluator.java | 2 +- .../utils/DynamicDMNContextBuilder.java | 8 +- .../src/main/java/org/kie/dmn/feel/FEEL.java | 2 +- .../codegen/feel11/ASTCompilerHelper.java | 7 +- .../visitor/ASTTemporalConstantVisitor.java | 7 +- .../java/org/kie/dmn/feel/runtime/Range.java | 2 +- .../feel/runtime/functions/AbsFunction.java | 2 +- .../feel/runtime/functions/AllFunction.java | 3 +- .../feel/runtime/functions/AnyFunction.java | 3 +- .../runtime/functions/AppendFunction.java | 3 +- .../runtime/functions/BuiltInFunctions.java | 15 +- .../runtime/functions/CeilingFunction.java | 3 +- .../functions/ConcatenateFunction.java | 3 +- .../runtime/functions/ContainsFunction.java | 2 +- .../{extended => }/ContextFunction.java | 13 +- .../{extended => }/ContextMergeFunction.java | 12 +- .../{extended => }/ContextPutFunction.java | 13 +- .../feel/runtime/functions/CountFunction.java | 3 +- .../functions/DateAndTimeFunction.java | 2 +- .../feel/runtime/functions/DateFunction.java | 8 +- .../runtime/functions/DayOfWeekFunction.java | 2 +- .../runtime/functions/DayOfYearFunction.java | 2 +- .../runtime/functions/DecimalFunction.java | 3 +- .../functions/DecisionTableFunction.java | 2 +- .../functions/DistinctValuesFunction.java | 3 +- .../runtime/functions/DurationFunction.java | 6 +- .../runtime/functions/EndsWithFunction.java | 2 +- .../feel/runtime/functions/EvenFunction.java | 6 +- .../feel/runtime/functions/ExpFunction.java | 2 +- .../runtime/functions/FlattenFunction.java | 3 +- .../feel/runtime/functions/FloorFunction.java | 2 +- .../runtime/functions/GetEntriesFunction.java | 3 +- .../runtime/functions/GetValueFunction.java | 2 +- .../runtime/functions/IndexOfFunction.java | 3 +- .../functions/InsertBeforeFunction.java | 3 +- .../feel/runtime/functions/IsFunction.java | 3 +- .../functions/ListContainsFunction.java | 2 +- .../feel/runtime/functions/LogFunction.java | 2 +- .../runtime/functions/MatchesFunction.java | 8 +- .../feel/runtime/functions/MaxFunction.java | 2 +- .../feel/runtime/functions/MeanFunction.java | 2 +- .../runtime/functions/MedianFunction.java | 2 +- .../feel/runtime/functions/MinFunction.java | 2 +- .../feel/runtime/functions/ModeFunction.java | 2 +- .../runtime/functions/ModuloFunction.java | 2 +- .../functions/MonthOfYearFunction.java | 2 +- .../feel/runtime/functions/NotFunction.java | 2 +- .../functions/{extended => }/NowFunction.java | 9 +- .../runtime/functions/NumberFunction.java | 2 +- .../feel/runtime/functions/OddFunction.java | 6 +- .../runtime/functions/ProductFunction.java | 2 +- .../{extended => }/RangeFunction.java | 54 +- .../runtime/functions/RemoveFunction.java | 3 +- .../runtime/functions/ReplaceFunction.java | 2 +- .../runtime/functions/ReverseFunction.java | 3 +- .../{extended => }/RoundDownFunction.java | 10 +- .../{extended => }/RoundHalfDownFunction.java | 10 +- .../{extended => }/RoundHalfUpFunction.java | 10 +- .../{extended => }/RoundUpFunction.java | 10 +- .../feel/runtime/functions/SortFunction.java | 3 +- .../feel/runtime/functions/SplitFunction.java | 2 +- .../feel/runtime/functions/SqrtFunction.java | 2 +- .../runtime/functions/StartsWithFunction.java | 2 +- .../runtime/functions/StddevFunction.java | 3 +- .../runtime/functions/StringFunction.java | 2 +- .../{extended => }/StringJoinFunction.java | 7 +- .../functions/StringLengthFunction.java | 2 +- .../functions/StringLowerCaseFunction.java | 2 +- .../functions/StringUpperCaseFunction.java | 2 +- .../runtime/functions/SublistFunction.java | 3 +- .../functions/SubstringAfterFunction.java | 2 +- .../functions/SubstringBeforeFunction.java | 2 +- .../runtime/functions/SubstringFunction.java | 2 +- .../feel/runtime/functions/SumFunction.java | 3 +- .../feel/runtime/functions/TimeFunction.java | 23 +- .../{extended => }/TodayFunction.java | 9 +- .../feel/runtime/functions/UnionFunction.java | 3 +- .../runtime/functions/WeekOfYearFunction.java | 3 +- .../functions/YearsAndMonthsFunction.java | 2 +- .../functions/extended/CeilingFunction.java | 55 - .../functions/extended/CodeFunction.java | 4 +- .../functions/extended/DateFunction.java | 94 +- .../functions/extended/DurationFunction.java | 70 - .../functions/extended/FloorFunction.java | 55 - .../functions/extended/InvokeFunction.java | 4 +- .../extended/KieExtendedDMNFunctions.java | 20 +- .../functions/extended/TimeFunction.java | 146 +- .../functions/interval/AfterFunction.java | 2 +- .../functions/interval/BeforeFunction.java | 2 +- .../functions/interval/CoincidesFunction.java | 2 +- .../functions/interval/DuringFunction.java | 2 +- .../interval/FinishedByFunction.java | 2 +- .../functions/interval/FinishesFunction.java | 2 +- .../functions/interval/IncludesFunction.java | 2 +- .../functions/interval/MeetsFunction.java | 2 +- .../functions/interval/MetByFunction.java | 2 +- .../interval/OverlapsAfterFunction.java | 2 +- .../interval/OverlapsBeforeFunction.java | 2 +- .../functions/interval/OverlapsFunction.java | 2 +- .../functions/interval/StartedByFunction.java | 2 +- .../functions/interval/StartsFunction.java | 2 +- .../twovaluelogic/NNAllFunction.java | 47 +- .../twovaluelogic/NNAnyFunction.java | 45 +- .../twovaluelogic/NNCountFunction.java | 36 +- .../twovaluelogic/NNMaxFunction.java | 44 +- .../twovaluelogic/NNMeanFunction.java | 2 +- .../twovaluelogic/NNMedianFunction.java | 2 +- .../twovaluelogic/NNMinFunction.java | 8 +- .../twovaluelogic/NNModeFunction.java | 2 +- .../twovaluelogic/NNStddevFunction.java | 2 +- .../twovaluelogic/NNSumFunction.java | 2 +- .../kie/dmn/feel/util/BooleanEvalHelper.java | 2 - .../org.kie/kie-dmn-feel/reflect-config.json | 1980 ++++++++--------- .../runtime/functions/AllFunctionTest.java | 32 +- .../runtime/functions/AnyFunctionTest.java | 32 +- .../runtime/functions/AppendFunctionTest.java | 35 +- .../functions/CeilingFunctionTest.java | 32 +- .../runtime/functions/CodeFunctionTest.java | 38 +- .../ComposingDifferentFunctionsTest.java | 17 +- .../functions/ConcatenateFunctionTest.java | 27 +- .../functions/ContainsFunctionTest.java | 14 +- .../{extended => }/ContextFunctionTest.java | 26 +- .../runtime/functions/CountFunctionTest.java | 15 +- .../functions/DateTimeFunctionTest.java | 54 +- .../functions/DecimalFunctionTest.java | 38 +- .../functions/DistinctValuesFunctionTest.java | 17 +- .../functions/DurationFunctionTest.java | 8 +- .../functions/EndsWithFunctionTest.java | 14 +- .../functions/FlattenFunctionTest.java | 28 +- .../runtime/functions/FloorFunctionTest.java | 8 +- .../functions/IndexOfFunctionTest.java | 28 +- .../functions/InsertBeforeFunctionTest.java | 58 +- .../functions/ListContainsFunctionTest.java | 23 +- .../functions/MatchesFunctionTest.java | 14 +- .../runtime/functions/MaxFunctionTest.java | 56 +- .../runtime/functions/MeanFunctionTest.java | 17 +- .../runtime/functions/MinFunctionTest.java | 56 +- .../runtime/functions/MonthOfYearTest.java | 20 +- .../runtime/functions/NotFunctionTest.java | 14 +- .../runtime/functions/NowFunctionTest.java | 19 +- .../runtime/functions/NumberFunctionTest.java | 20 +- .../{extended => }/RangeFunctionTest.java | 286 +-- .../runtime/functions/RemoveFunctionTest.java | 40 +- .../functions/ReplaceFunctionTest.java | 53 +- .../functions/ReverseFunctionTest.java | 14 +- .../{extended => }/RoundDownFunctionTest.java | 53 +- .../RoundHalfDownFunctionTest.java | 54 +- .../RoundHalfUpFunctionTest.java | 53 +- .../{extended => }/RoundUpFunctionTest.java | 45 +- .../runtime/functions/SortFunctionTest.java | 8 +- .../functions/StartsWithFunctionTest.java | 17 +- .../runtime/functions/StringFunctionTest.java | 32 +- .../functions/StringLengthFunctionTest.java | 14 +- .../StringLowerCaseFunctionTest.java | 14 +- .../StringUpperCaseFunctionTest.java | 14 +- .../functions/SublistFunctionTest.java | 54 +- .../functions/SubstringAfterFunctionTest.java | 17 +- .../SubstringBeforeFunctionTest.java | 17 +- .../functions/SubstringFunctionTest.java | 14 +- .../runtime/functions/SumFunctionTest.java | 32 +- .../runtime/functions/TimeFunctionTest.java | 61 +- .../runtime/functions/TodayFunctionTest.java | 16 +- .../runtime/functions/UnionFunctionTest.java | 32 +- .../runtime/functions/WeekOfYearTest.java | 20 +- .../functions/YearsAndMonthsFunctionTest.java | 20 +- .../twovaluelogic/CountFunctionTest.java | 8 +- .../twovaluelogic/MaxFunctionTest.java | 20 +- .../twovaluelogic/MeanFunctionTest.java | 21 +- .../twovaluelogic/MinFunctionTest.java | 22 +- .../twovaluelogic/NNAllFunctionTest.java | 49 +- .../twovaluelogic/NNAnyFunctionTest.java | 7 +- .../twovaluelogic/SumFunctionTest.java | 38 +- .../signavio/MultiInstanceDecisionLogic.java | 12 +- 173 files changed, 2265 insertions(+), 2688 deletions(-) rename kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/{extended => }/ContextFunction.java (88%) rename kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/{extended => }/ContextMergeFunction.java (85%) rename kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/{extended => }/ContextPutFunction.java (92%) rename kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/{extended => }/NowFunction.java (84%) rename kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/{extended => }/RangeFunction.java (87%) rename kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/{extended => }/RoundDownFunction.java (87%) rename kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/{extended => }/RoundHalfDownFunction.java (87%) rename kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/{extended => }/RoundHalfUpFunction.java (87%) rename kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/{extended => }/RoundUpFunction.java (87%) rename kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/{extended => }/StringJoinFunction.java (90%) rename kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/{extended => }/TodayFunction.java (84%) delete mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/CeilingFunction.java delete mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/DurationFunction.java delete mode 100644 kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/FloorFunction.java rename kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/{extended => }/ContextFunctionTest.java (82%) rename kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/{extended => }/RangeFunctionTest.java (66%) rename kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/{extended => }/RoundDownFunctionTest.java (62%) rename kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/{extended => }/RoundHalfDownFunctionTest.java (61%) rename kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/{extended => }/RoundHalfUpFunctionTest.java (62%) rename kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/{extended => }/RoundUpFunctionTest.java (70%) diff --git a/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/expression/DMNFeelExpressionEvaluator.java b/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/expression/DMNFeelExpressionEvaluator.java index 776f5b7c462..41f59a0d512 100644 --- a/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/expression/DMNFeelExpressionEvaluator.java +++ b/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/expression/DMNFeelExpressionEvaluator.java @@ -51,7 +51,7 @@ public class DMNFeelExpressionEvaluator extends AbstractExpressionEvaluator { private final ClassLoader classLoader; - private final CodeFunction codeFunction = new CodeFunction(); + private final CodeFunction codeFunction = CodeFunction.INSTANCE; public DMNFeelExpressionEvaluator(ClassLoader classLoader) { this.classLoader = classLoader; diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/internal/utils/DynamicDMNContextBuilder.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/internal/utils/DynamicDMNContextBuilder.java index f225180cbf1..9ecb89a0e6a 100644 --- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/internal/utils/DynamicDMNContextBuilder.java +++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/internal/utils/DynamicDMNContextBuilder.java @@ -182,11 +182,11 @@ private Object getAsFEELBuiltinType(Object value, DMNType resultType) { case UNKNOWN: return value; case DATE: - return new DateFunction().invoke((String) value).getOrElseThrow(FailedConversionException::new); + return DateFunction.INSTANCE.invoke((String) value).getOrElseThrow(FailedConversionException::new); case TIME: - return new TimeFunction().invoke((String) value).getOrElseThrow(FailedConversionException::new); + return TimeFunction.INSTANCE.invoke((String) value).getOrElseThrow(FailedConversionException::new); case DATE_TIME: - return new DateAndTimeFunction().invoke((String) value).getOrElseThrow(FailedConversionException::new); + return DateAndTimeFunction.INSTANCE.invoke((String) value).getOrElseThrow(FailedConversionException::new); case BOOLEAN: return value; case NUMBER: @@ -194,7 +194,7 @@ private Object getAsFEELBuiltinType(Object value, DMNType resultType) { case STRING: return value; case DURATION: - return new DurationFunction().invoke((String) value).getOrElseThrow(FailedConversionException::new); + return DurationFunction.INSTANCE.invoke((String) value).getOrElseThrow(FailedConversionException::new); default: throw new IllegalArgumentException(); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/FEEL.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/FEEL.java index 1dd0f2306de..280ed3e6a0e 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/FEEL.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/FEEL.java @@ -148,7 +148,7 @@ static FEEL newInstance(ClassLoader cl, List profiles) { * Evaluates the given compiled FEEL expression using the * given EvaluationContext, and returns the result * - * @param expression a FEEL expression + * @param expr a FEEL expression * @param ctx the EvaluationContext to be used for defining * input variables and additional feel event listeners * contextual to this method call 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 3e91a78d202..72b2013fcb9 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 @@ -452,12 +452,7 @@ public BlockStmt add(TemporalConstantNode n) { Class fnClass = fn.getClass(); ClassOrInterfaceType fn_CT = parseClassOrInterfaceType(fnClass.getCanonicalName()); Expression fn_N = new NameExpr(fnClass.getCanonicalName()); - if (fnClass.getPackageName().equals(EXTENDED_FUNCTION_PACKAGE)) { - addVariableDeclaratorWithWithFieldAccess(fn_CT, INSTANCE_S, fn_N); - } else { - addVariableDeclaratorWithObjectCreation(fn_CT, - NodeList.nodeList()); - } + addVariableDeclaratorWithWithFieldAccess(fn_CT, INSTANCE_S, fn_N); fnVariableNameExpression = new NameExpr(lastVariableName.get()); } else { fnVariableNameExpression = new NullLiteralExpr(); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/visitor/ASTTemporalConstantVisitor.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/visitor/ASTTemporalConstantVisitor.java index 631101b68fc..c6e4aafafaf 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/visitor/ASTTemporalConstantVisitor.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/visitor/ASTTemporalConstantVisitor.java @@ -70,8 +70,7 @@ public class ASTTemporalConstantVisitor extends DefaultedVisitor { DateAndTimeFunction.INSTANCE, DurationFunction.INSTANCE, org.kie.dmn.feel.runtime.functions.extended.TimeFunction.INSTANCE, - org.kie.dmn.feel.runtime.functions.extended.DateFunction.INSTANCE, - org.kie.dmn.feel.runtime.functions.extended.DurationFunction.INSTANCE); + org.kie.dmn.feel.runtime.functions.extended.DateFunction.INSTANCE); public static final Set TEMPORAL_FNS_NAMES = TEMPORAL_FNS.stream().map(FEELFunction::getName).collect(Collectors.toSet()); public ASTTemporalConstantVisitor(CompilerContext ctx) { @@ -200,10 +199,6 @@ private TemporalConstantNode buildTCNodeForDuration(FunctionInvocationNode n, FE FEELFnResult invoke = DurationFunction.INSTANCE.invoke(p0); return invoke.cata(e -> null, v -> new TemporalConstantNode(n, v, DurationFunction.INSTANCE, Collections.singletonList(p0))); - } else if (fn == org.kie.dmn.feel.runtime.functions.extended.DurationFunction.INSTANCE) { - FEELFnResult invoke = org.kie.dmn.feel.runtime.functions.extended.DurationFunction.INSTANCE.invoke(p0); - return invoke.cata(e -> null, - v -> new TemporalConstantNode(n, v, org.kie.dmn.feel.runtime.functions.extended.DurationFunction.INSTANCE, Collections.singletonList(p0))); } } return null; diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/Range.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/Range.java index a334beaeb9e..39666b6c858 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/Range.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/Range.java @@ -20,7 +20,7 @@ public interface Range { - static enum RangeBoundary { + enum RangeBoundary { OPEN, CLOSED; } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AbsFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AbsFunction.java index a26dca7d032..e56db41af71 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AbsFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AbsFunction.java @@ -30,7 +30,7 @@ public class AbsFunction extends BaseFEELFunction { public static final AbsFunction INSTANCE = new AbsFunction(); - AbsFunction() { + private AbsFunction() { super( "abs" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AllFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AllFunction.java index 08520f44fff..fb6bc4cdda4 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AllFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AllFunction.java @@ -20,6 +20,7 @@ import java.util.Arrays; import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; @@ -28,7 +29,7 @@ public class AllFunction public static final AllFunction INSTANCE = new AllFunction(); - public AllFunction() { + private AllFunction() { super( "all" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AnyFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AnyFunction.java index a8d3abff969..17e8d330634 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AnyFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AnyFunction.java @@ -20,6 +20,7 @@ import java.util.Arrays; import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; @@ -28,7 +29,7 @@ public class AnyFunction public static final AnyFunction INSTANCE = new AnyFunction(); - public AnyFunction() { + private AnyFunction() { super( "any" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AppendFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AppendFunction.java index ef5554da227..7d47e8ac0c5 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AppendFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AppendFunction.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; @@ -30,7 +31,7 @@ public class AppendFunction public static final AppendFunction INSTANCE = new AppendFunction(); - public AppendFunction() { + private AppendFunction() { super( "append" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/BuiltInFunctions.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/BuiltInFunctions.java index 6b90492713a..07f1728f6eb 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/BuiltInFunctions.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/BuiltInFunctions.java @@ -119,7 +119,20 @@ public class BuiltInFunctions { OverlapsAfterFunction.INSTANCE, MeetsFunction.INSTANCE, MetByFunction.INSTANCE, - ListReplaceFunction.INSTANCE + ListReplaceFunction.INSTANCE, + StringJoinFunction.INSTANCE, + + NowFunction.INSTANCE, + TodayFunction.INSTANCE, + ContextPutFunction.INSTANCE, + ContextMergeFunction.INSTANCE, + ContextFunction.INSTANCE, + RoundUpFunction.INSTANCE, + RoundDownFunction.INSTANCE, + RoundHalfUpFunction.INSTANCE, + RoundHalfDownFunction.INSTANCE, + + RangeFunction.INSTANCE, }; public static FEELFunction[] getFunctions() { diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CeilingFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CeilingFunction.java index 6d632bf93db..1fc173edbd2 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CeilingFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CeilingFunction.java @@ -23,14 +23,13 @@ import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; public class CeilingFunction extends BaseFEELFunction { public static final CeilingFunction INSTANCE = new CeilingFunction(); - public CeilingFunction() { + private CeilingFunction() { super( "ceiling" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ConcatenateFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ConcatenateFunction.java index d6a295f4ff2..0d579f6c46c 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ConcatenateFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ConcatenateFunction.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; @@ -29,7 +30,7 @@ public class ConcatenateFunction public static final ConcatenateFunction INSTANCE = new ConcatenateFunction(); - public ConcatenateFunction() { + private ConcatenateFunction() { super( "concatenate" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ContainsFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ContainsFunction.java index 883d8367d0b..452a201d033 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ContainsFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ContainsFunction.java @@ -26,7 +26,7 @@ public class ContainsFunction public static final ContainsFunction INSTANCE = new ContainsFunction(); - public ContainsFunction() { + private ContainsFunction() { super( "contains" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/ContextFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ContextFunction.java similarity index 88% rename from kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/ContextFunction.java rename to kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ContextFunction.java index 08ffd5e3020..5b5f5e7bb16 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/ContextFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ContextFunction.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; import java.util.HashMap; import java.util.List; @@ -24,20 +24,13 @@ import org.kie.dmn.api.feel.runtime.events.FEELEvent; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; -import org.kie.dmn.feel.runtime.functions.ParameterName; -/** - * Proposal DMN14-187 - * Experimental for DMN14-183, an inverse of `get entries()` - * See also: DMN14-181, DMN14-182 - */ + public class ContextFunction extends BaseFEELFunction { public static final ContextFunction INSTANCE = new ContextFunction(); - public ContextFunction() { + private ContextFunction() { super("context"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/ContextMergeFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ContextMergeFunction.java similarity index 85% rename from kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/ContextMergeFunction.java rename to kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ContextMergeFunction.java index 5571b75efdf..05442f357e0 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/ContextMergeFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ContextMergeFunction.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; import java.util.Collections; import java.util.HashMap; @@ -25,20 +25,12 @@ import org.kie.dmn.api.feel.runtime.events.FEELEvent; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; -import org.kie.dmn.feel.runtime.functions.ParameterName; -/** - * Proposal DMN14-187 - * Experimental for DMN14-182 - * See also: DMN14-181, DMN14-183 - */ public class ContextMergeFunction extends BaseFEELFunction { public static final ContextMergeFunction INSTANCE = new ContextMergeFunction(); - public ContextMergeFunction() { + private ContextMergeFunction() { super("context merge"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/ContextPutFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ContextPutFunction.java similarity index 92% rename from kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/ContextPutFunction.java rename to kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ContextPutFunction.java index 3c7a7216126..57d8173b325 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/ContextPutFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ContextPutFunction.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; import java.util.HashMap; import java.util.List; @@ -27,20 +27,13 @@ import org.kie.dmn.feel.lang.types.BuiltInType; import org.kie.dmn.feel.lang.types.impl.ImmutableFPAWrappingPOJO; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; -import org.kie.dmn.feel.runtime.functions.ParameterName; -/** - * Proposal DMN14-187 - * Experimental for DMN14-181 - * See also: DMN14-182, DMN14-183 - */ + public class ContextPutFunction extends BaseFEELFunction { public static final ContextPutFunction INSTANCE = new ContextPutFunction(); - public ContextPutFunction() { + private ContextPutFunction() { super("context put"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CountFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CountFunction.java index 32d20f455f9..dc3033c6be4 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CountFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/CountFunction.java @@ -24,14 +24,13 @@ import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; public class CountFunction extends BaseFEELFunction { public static final CountFunction INSTANCE = new CountFunction(); - public CountFunction() { + private CountFunction() { super( "count" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DateAndTimeFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DateAndTimeFunction.java index 28de9b41c91..90f47217d92 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DateAndTimeFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DateAndTimeFunction.java @@ -57,7 +57,7 @@ public class DateAndTimeFunction .toFormatter(); } - public DateAndTimeFunction() { + private DateAndTimeFunction() { super(FEELConversionFunctionNames.DATE_AND_TIME); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DateFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DateFunction.java index 05f28b8bfde..1c2e07780e8 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DateFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DateFunction.java @@ -51,7 +51,7 @@ public class DateFunction .withResolverStyle(ResolverStyle.STRICT); } - public DateFunction() { + protected DateFunction() { super(FEELConversionFunctionNames.DATE); } @@ -66,7 +66,7 @@ public FEELFnResult invoke(@ParameterName( "from" ) String val try { return FEELFnResult.ofResult(LocalDate.from(FEEL_DATE.parse(val))); } catch (DateTimeException e) { - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "date", e)); + return manageDateTimeException(e, val); } } @@ -99,4 +99,8 @@ public FEELFnResult invoke(@ParameterName( "from" ) TemporalAc return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "from", "date-parsing exception", e)); } } + + protected FEELFnResult manageDateTimeException(DateTimeException e, String val) { + return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "date", e)); + } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DayOfWeekFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DayOfWeekFunction.java index becac394fe5..ff2ac9a53f8 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DayOfWeekFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DayOfWeekFunction.java @@ -29,7 +29,7 @@ public class DayOfWeekFunction extends BaseFEELFunction { public static final DayOfWeekFunction INSTANCE = new DayOfWeekFunction(); - DayOfWeekFunction() { + private DayOfWeekFunction() { super("day of week"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DayOfYearFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DayOfYearFunction.java index 9a218dcbefd..5354d2efc1b 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DayOfYearFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DayOfYearFunction.java @@ -29,7 +29,7 @@ public class DayOfYearFunction extends BaseFEELFunction { public static final DayOfYearFunction INSTANCE = new DayOfYearFunction(); - DayOfYearFunction() { + private DayOfYearFunction() { super("day of year"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DecimalFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DecimalFunction.java index b62266cda32..e1dce2f1cfc 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DecimalFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DecimalFunction.java @@ -23,14 +23,13 @@ import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; public class DecimalFunction extends BaseFEELFunction { public static final DecimalFunction INSTANCE = new DecimalFunction(); - public DecimalFunction() { + private DecimalFunction() { super( "decimal" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DecisionTableFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DecisionTableFunction.java index 5643ee5922d..80437477ada 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DecisionTableFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DecisionTableFunction.java @@ -50,7 +50,7 @@ public class DecisionTableFunction private static final Logger LOG = LoggerFactory.getLogger( DecisionTableFunction.class ); - public DecisionTableFunction() { + private DecisionTableFunction() { super( "decision table" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DistinctValuesFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DistinctValuesFunction.java index 3de0a290ac9..65a43ab3bc8 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DistinctValuesFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DistinctValuesFunction.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; @@ -29,7 +30,7 @@ public class DistinctValuesFunction public static final DistinctValuesFunction INSTANCE = new DistinctValuesFunction(); - public DistinctValuesFunction() { + private DistinctValuesFunction() { super( "distinct values" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DurationFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DurationFunction.java index acf5d8ab587..b6ddaccd0a3 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DurationFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DurationFunction.java @@ -33,7 +33,7 @@ public class DurationFunction public static final DurationFunction INSTANCE = new DurationFunction(); - public DurationFunction() { + private DurationFunction() { super(FEELConversionFunctionNames.DURATION); } @@ -42,10 +42,6 @@ public FEELFnResult invoke(@ParameterName( "from" ) String val) return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "from", "cannot be null")); } - if ( val.indexOf("-") > 0) { - return FEELFnResult.ofError( new InvalidParametersEvent(Severity.ERROR, "from", "negative values for units are not allowed.") ); - } - try { // try to parse as days/hours/minute/seconds return FEELFnResult.ofResult( Duration.parse( val ) ); diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/EndsWithFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/EndsWithFunction.java index bbf0b64d037..04b4e4bf6e2 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/EndsWithFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/EndsWithFunction.java @@ -26,7 +26,7 @@ public class EndsWithFunction public static final EndsWithFunction INSTANCE = new EndsWithFunction(); - public EndsWithFunction() { + private EndsWithFunction() { super( "ends with" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/EvenFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/EvenFunction.java index 259455ebe0e..5bf86b2ed21 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/EvenFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/EvenFunction.java @@ -18,18 +18,18 @@ */ package org.kie.dmn.feel.runtime.functions; +import java.math.BigDecimal; + import org.kie.dmn.api.feel.runtime.events.FEELEvent; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import java.math.BigDecimal; - public class EvenFunction extends BaseFEELFunction { public static final EvenFunction INSTANCE = new EvenFunction(); private static final BigDecimal TWO = BigDecimal.valueOf(2); - EvenFunction() { + private EvenFunction() { super("even"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ExpFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ExpFunction.java index 4b17ef39a27..9fc25f9b8ba 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ExpFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ExpFunction.java @@ -29,7 +29,7 @@ public class ExpFunction extends BaseFEELFunction { public static final ExpFunction INSTANCE = new ExpFunction(); - ExpFunction() { + private ExpFunction() { super("exp"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/FlattenFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/FlattenFunction.java index 9194eb9da4e..314b5829b0c 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/FlattenFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/FlattenFunction.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; @@ -29,7 +30,7 @@ public class FlattenFunction public static final FlattenFunction INSTANCE = new FlattenFunction(); - public FlattenFunction() { + private FlattenFunction() { super( "flatten" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/FloorFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/FloorFunction.java index f2b26d40ce6..9e05a16a739 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/FloorFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/FloorFunction.java @@ -29,7 +29,7 @@ public class FloorFunction public static final FloorFunction INSTANCE = new FloorFunction(); - public FloorFunction() { + private FloorFunction() { super( "floor" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/GetEntriesFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/GetEntriesFunction.java index aba3972368e..69c2d4d7f45 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/GetEntriesFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/GetEntriesFunction.java @@ -25,13 +25,12 @@ import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.extended.ContextPutFunction; public class GetEntriesFunction extends BaseFEELFunction { public static final GetEntriesFunction INSTANCE = new GetEntriesFunction(); - public GetEntriesFunction() { + private GetEntriesFunction() { super("get entries"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/GetValueFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/GetValueFunction.java index 1dee390bcdc..89fc3a3e09c 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/GetValueFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/GetValueFunction.java @@ -29,7 +29,7 @@ public class GetValueFunction extends BaseFEELFunction { public static final GetValueFunction INSTANCE = new GetValueFunction(); - public GetValueFunction() { + private GetValueFunction() { super("get value"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/IndexOfFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/IndexOfFunction.java index 529901d8b00..7bca208b845 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/IndexOfFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/IndexOfFunction.java @@ -21,6 +21,7 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; @@ -29,7 +30,7 @@ public class IndexOfFunction public static final IndexOfFunction INSTANCE = new IndexOfFunction(); - public IndexOfFunction() { + private IndexOfFunction() { super( "index of" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/InsertBeforeFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/InsertBeforeFunction.java index ba2a587958d..78e7c151ad0 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/InsertBeforeFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/InsertBeforeFunction.java @@ -21,6 +21,7 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; @@ -29,7 +30,7 @@ public class InsertBeforeFunction public static final InsertBeforeFunction INSTANCE = new InsertBeforeFunction(); - public InsertBeforeFunction() { + private InsertBeforeFunction() { super( "insert before" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/IsFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/IsFunction.java index b45d128ae43..36a225d3567 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/IsFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/IsFunction.java @@ -23,12 +23,11 @@ import org.kie.dmn.feel.lang.types.BuiltInType; import org.kie.dmn.feel.util.BooleanEvalHelper; -import org.kie.dmn.feel.util.EvalHelper; public class IsFunction extends BaseFEELFunction { public static final IsFunction INSTANCE = new IsFunction(); - IsFunction() { + private IsFunction() { super("is"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ListContainsFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ListContainsFunction.java index d4e92df21ee..c14853f0a96 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ListContainsFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ListContainsFunction.java @@ -31,7 +31,7 @@ public class ListContainsFunction public static final ListContainsFunction INSTANCE = new ListContainsFunction(); - public ListContainsFunction() { + private ListContainsFunction() { super( "list contains" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/LogFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/LogFunction.java index 7c98cc99542..6d8925c2ef1 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/LogFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/LogFunction.java @@ -29,7 +29,7 @@ public class LogFunction extends BaseFEELFunction { public static final LogFunction INSTANCE = new LogFunction(); - LogFunction() { + private LogFunction() { super("log"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MatchesFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MatchesFunction.java index e13beaa0fc3..f6b1806ca20 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MatchesFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MatchesFunction.java @@ -18,19 +18,19 @@ */ package org.kie.dmn.feel.runtime.functions; -import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; -import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; - import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; +import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; + public class MatchesFunction extends BaseFEELFunction { public static final MatchesFunction INSTANCE = new MatchesFunction(); - public MatchesFunction() { + private MatchesFunction() { super( "matches" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MaxFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MaxFunction.java index 2310dfc4652..bb4a5f9665d 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MaxFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MaxFunction.java @@ -31,7 +31,7 @@ public class MaxFunction public static final MaxFunction INSTANCE = new MaxFunction(); - public MaxFunction() { + private MaxFunction() { super( "max" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MeanFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MeanFunction.java index c53dc339952..0d940380ba7 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MeanFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MeanFunction.java @@ -36,7 +36,7 @@ public class MeanFunction private SumFunction sum = SumFunction.INSTANCE; - public MeanFunction() { + private MeanFunction() { super( "mean" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MedianFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MedianFunction.java index e2a6a6c7092..1340e3a42d8 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MedianFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MedianFunction.java @@ -31,7 +31,7 @@ public class MedianFunction extends BaseFEELFunction { public static final MedianFunction INSTANCE = new MedianFunction(); - MedianFunction() { + private MedianFunction() { super("median"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MinFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MinFunction.java index 81a44c0e96f..c7cc8509e97 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MinFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MinFunction.java @@ -31,7 +31,7 @@ public class MinFunction public static final MinFunction INSTANCE = new MinFunction(); - public MinFunction() { + private MinFunction() { super( "min" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ModeFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ModeFunction.java index 09224dcc621..e5807c9ff06 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ModeFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ModeFunction.java @@ -35,7 +35,7 @@ public class ModeFunction extends BaseFEELFunction { public static final ModeFunction INSTANCE = new ModeFunction(); - ModeFunction() { + private ModeFunction() { super("mode"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ModuloFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ModuloFunction.java index ad0aa35b170..d9f78893cb9 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ModuloFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ModuloFunction.java @@ -28,7 +28,7 @@ public class ModuloFunction extends BaseFEELFunction { public static final ModuloFunction INSTANCE = new ModuloFunction(); - ModuloFunction() { + private ModuloFunction() { super( "modulo" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MonthOfYearFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MonthOfYearFunction.java index 8aa7c197fc3..76a231c55d1 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MonthOfYearFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MonthOfYearFunction.java @@ -29,7 +29,7 @@ public class MonthOfYearFunction extends BaseFEELFunction { public static final MonthOfYearFunction INSTANCE = new MonthOfYearFunction(); - MonthOfYearFunction() { + private MonthOfYearFunction() { super("month of year"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/NotFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/NotFunction.java index 287c63331e3..c099876dbf5 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/NotFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/NotFunction.java @@ -31,7 +31,7 @@ public class NotFunction public static final NotFunction INSTANCE = new NotFunction(); - public NotFunction() { + private NotFunction() { super( "not" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/NowFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/NowFunction.java similarity index 84% rename from kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/NowFunction.java rename to kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/NowFunction.java index c9a2bd61a9d..73c5a1ce455 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/NowFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/NowFunction.java @@ -16,18 +16,17 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; import java.time.ZonedDateTime; import java.time.temporal.TemporalAccessor; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; - public class NowFunction extends BaseFEELFunction { - public NowFunction() { + public static final NowFunction INSTANCE = new NowFunction(); + + private NowFunction() { super( "now" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/NumberFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/NumberFunction.java index 822b592ba7c..54759f5f2d9 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/NumberFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/NumberFunction.java @@ -29,7 +29,7 @@ public class NumberFunction public static final NumberFunction INSTANCE = new NumberFunction(); - public NumberFunction() { + private NumberFunction() { super(FEELConversionFunctionNames.NUMBER); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/OddFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/OddFunction.java index e4eec63f036..c32176d594a 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/OddFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/OddFunction.java @@ -18,18 +18,18 @@ */ package org.kie.dmn.feel.runtime.functions; +import java.math.BigDecimal; + import org.kie.dmn.api.feel.runtime.events.FEELEvent; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import java.math.BigDecimal; - public class OddFunction extends BaseFEELFunction { public static final OddFunction INSTANCE = new OddFunction(); private static final BigDecimal TWO = BigDecimal.valueOf(2); - OddFunction() { + private OddFunction() { super("odd"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ProductFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ProductFunction.java index 689dfafe3af..11462667c87 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ProductFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ProductFunction.java @@ -30,7 +30,7 @@ public class ProductFunction extends BaseFEELFunction { public static final ProductFunction INSTANCE = new ProductFunction(); - ProductFunction() { + private ProductFunction() { super( "product" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RangeFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RangeFunction.java similarity index 87% rename from kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RangeFunction.java rename to kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RangeFunction.java index 1eac4c6dfe6..9dab904aca7 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RangeFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RangeFunction.java @@ -16,13 +16,32 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; + +import java.time.Duration; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.ZonedDateTime; +import java.time.chrono.ChronoPeriod; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.function.Predicate; import org.antlr.v4.runtime.tree.ParseTree; import org.kie.dmn.api.feel.runtime.events.FEELEvent; import org.kie.dmn.feel.lang.EvaluationContext; import org.kie.dmn.feel.lang.FEELDialect; -import org.kie.dmn.feel.lang.ast.*; +import org.kie.dmn.feel.lang.ast.AtLiteralNode; +import org.kie.dmn.feel.lang.ast.BaseNode; +import org.kie.dmn.feel.lang.ast.FunctionInvocationNode; +import org.kie.dmn.feel.lang.ast.NullNode; +import org.kie.dmn.feel.lang.ast.NumberNode; +import org.kie.dmn.feel.lang.ast.StringNode; import org.kie.dmn.feel.lang.impl.EvaluationContextImpl; import org.kie.dmn.feel.lang.impl.FEELEventListenersManager; import org.kie.dmn.feel.parser.feel11.ASTBuilderVisitor; @@ -31,24 +50,14 @@ import org.kie.dmn.feel.runtime.Range; import org.kie.dmn.feel.runtime.Range.RangeBoundary; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; -import org.kie.dmn.feel.runtime.functions.ParameterName; import org.kie.dmn.feel.runtime.impl.RangeImpl; -import java.time.*; -import java.time.chrono.ChronoPeriod; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.function.Predicate; - public class RangeFunction extends BaseFEELFunction { public static final RangeFunction INSTANCE = new RangeFunction(); - // Defaulting FEELDialect to FEEL - private static final EvaluationContext STUBBED = new EvaluationContextImpl(Thread.currentThread().getContextClassLoader(), new FEELEventListenersManager(), 0, FEELDialect.FEEL); + + private static EvaluationContext STUBBED; + private static final List> ALLOWED_NODES = Arrays.asList(baseNode -> baseNode instanceof NullNode, baseNode -> baseNode instanceof NumberNode, @@ -69,7 +78,7 @@ public class RangeFunction extends BaseFEELFunction { object -> object instanceof LocalTime); - public RangeFunction() { + private RangeFunction() { super("range"); } @@ -111,12 +120,12 @@ public FEELFnResult invoke(@ParameterName("from") String from) { if (!nodeIsAllowed(rightNode)) { return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "right endpoint is not a recognised valid literal")); } - Object left = leftNode.evaluate(STUBBED); + Object left = leftNode.evaluate(getStubbed()); if (!nodeValueIsAllowed(left)) { return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "left endpoint is not a valid value " + left.getClass())); } - Object right = rightNode.evaluate(STUBBED); + Object right = rightNode.evaluate(getStubbed()); if (!nodeValueIsAllowed(right)) { return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "right endpoint is not a valid value " + right.getClass())); } @@ -169,4 +178,13 @@ protected BaseNode parseNotEmptyInput(String input) { return expr; } + private EvaluationContext getStubbed() { + if (STUBBED == null) { + // Defaulting FEELDialect to FEEL + STUBBED = new EvaluationContextImpl(Thread.currentThread().getContextClassLoader(), + new FEELEventListenersManager(), 0, FEELDialect.FEEL); + } + return STUBBED; + } + } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RemoveFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RemoveFunction.java index f4ee82a787e..9a7734a60a6 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RemoveFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RemoveFunction.java @@ -21,6 +21,7 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; @@ -29,7 +30,7 @@ public class RemoveFunction public static final RemoveFunction INSTANCE = new RemoveFunction(); - public RemoveFunction() { + private RemoveFunction() { super( "remove" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ReplaceFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ReplaceFunction.java index 11a041d4ae4..723efcbdd36 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ReplaceFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ReplaceFunction.java @@ -26,7 +26,7 @@ public class ReplaceFunction public static final ReplaceFunction INSTANCE = new ReplaceFunction(); - public ReplaceFunction() { + private ReplaceFunction() { super( "replace" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ReverseFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ReverseFunction.java index 6b588868e78..233f7c70938 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ReverseFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ReverseFunction.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; @@ -29,7 +30,7 @@ public class ReverseFunction public static final ReverseFunction INSTANCE = new ReverseFunction(); - public ReverseFunction() { + private ReverseFunction() { super( "reverse" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundDownFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RoundDownFunction.java similarity index 87% rename from kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundDownFunction.java rename to kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RoundDownFunction.java index 0a67a7d31f7..eb645198613 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundDownFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RoundDownFunction.java @@ -16,26 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; import java.math.BigDecimal; import java.math.RoundingMode; import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; -import org.kie.dmn.feel.runtime.functions.ParameterName; -/** - * provisional access for DMN14-126 - */ public class RoundDownFunction extends BaseFEELFunction { public static final RoundDownFunction INSTANCE = new RoundDownFunction(); - public RoundDownFunction() { + private RoundDownFunction() { super( "round down" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfDownFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RoundHalfDownFunction.java similarity index 87% rename from kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfDownFunction.java rename to kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RoundHalfDownFunction.java index 5d5648cc55d..08829325c58 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfDownFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RoundHalfDownFunction.java @@ -16,26 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; import java.math.BigDecimal; import java.math.RoundingMode; import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; -import org.kie.dmn.feel.runtime.functions.ParameterName; -/** - * provisional access for DMN14-126 - */ public class RoundHalfDownFunction extends BaseFEELFunction { public static final RoundHalfDownFunction INSTANCE = new RoundHalfDownFunction(); - public RoundHalfDownFunction() { + private RoundHalfDownFunction() { super( "round half down" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfUpFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RoundHalfUpFunction.java similarity index 87% rename from kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfUpFunction.java rename to kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RoundHalfUpFunction.java index 990f19c5dd2..da9b000e4e9 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfUpFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RoundHalfUpFunction.java @@ -16,26 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; import java.math.BigDecimal; import java.math.RoundingMode; import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; -import org.kie.dmn.feel.runtime.functions.ParameterName; -/** - * provisional access for DMN14-126 - */ public class RoundHalfUpFunction extends BaseFEELFunction { public static final RoundHalfUpFunction INSTANCE = new RoundHalfUpFunction(); - public RoundHalfUpFunction() { + private RoundHalfUpFunction() { super( "round half up" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundUpFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RoundUpFunction.java similarity index 87% rename from kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundUpFunction.java rename to kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RoundUpFunction.java index e17c90d57df..d840526bbed 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/RoundUpFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/RoundUpFunction.java @@ -16,26 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; import java.math.BigDecimal; import java.math.RoundingMode; import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; -import org.kie.dmn.feel.runtime.functions.ParameterName; -/** - * provisional access for DMN14-126 - */ public class RoundUpFunction extends BaseFEELFunction { public static final RoundUpFunction INSTANCE = new RoundUpFunction(); - public RoundUpFunction() { + private RoundUpFunction() { super( "round up" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SortFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SortFunction.java index 8d091ec684b..48450eabcb1 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SortFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SortFunction.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.lang.EvaluationContext; import org.kie.dmn.feel.runtime.FEELFunction; @@ -31,7 +32,7 @@ public class SortFunction public static final SortFunction INSTANCE = new SortFunction(); - public SortFunction() { + private SortFunction() { super( "sort" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SplitFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SplitFunction.java index ba633d17eee..d7c31332ffa 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SplitFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SplitFunction.java @@ -29,7 +29,7 @@ public class SplitFunction extends BaseFEELFunction { public static final SplitFunction INSTANCE = new SplitFunction(); - SplitFunction() { + private SplitFunction() { super( "split" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SqrtFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SqrtFunction.java index 90e0521157e..e2ec2d7a597 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SqrtFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SqrtFunction.java @@ -30,7 +30,7 @@ public class SqrtFunction extends BaseFEELFunction { public static final SqrtFunction INSTANCE = new SqrtFunction(); - SqrtFunction() { + private SqrtFunction() { super("sqrt"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StartsWithFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StartsWithFunction.java index 6fac9e2708c..c5029643fb0 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StartsWithFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StartsWithFunction.java @@ -26,7 +26,7 @@ public class StartsWithFunction public static final StartsWithFunction INSTANCE = new StartsWithFunction(); - public StartsWithFunction() { + private StartsWithFunction() { super( "starts with" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StddevFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StddevFunction.java index 88a3484e9a6..de7451bb13f 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StddevFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StddevFunction.java @@ -25,7 +25,6 @@ import org.kie.dmn.api.feel.runtime.events.FEELEvent; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.util.EvalHelper; import org.kie.dmn.feel.util.NumberEvalHelper; // based on the examples of calculations, stddev is supposed to return sample standard deviation, not population standard deviation @@ -33,7 +32,7 @@ public class StddevFunction extends BaseFEELFunction { public static final StddevFunction INSTANCE = new StddevFunction(); - StddevFunction() { + private StddevFunction() { super("stddev"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringFunction.java index a5b5629360b..a95dbbb80e9 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringFunction.java @@ -27,7 +27,7 @@ public class StringFunction public static final StringFunction INSTANCE = new StringFunction(); - public StringFunction() { + private StringFunction() { super(FEELConversionFunctionNames.STRING); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/StringJoinFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringJoinFunction.java similarity index 90% rename from kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/StringJoinFunction.java rename to kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringJoinFunction.java index 3ee399fc18e..532da277c54 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/StringJoinFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringJoinFunction.java @@ -16,22 +16,19 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; import java.util.List; import java.util.StringJoiner; import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; -import org.kie.dmn.feel.runtime.functions.ParameterName; public class StringJoinFunction extends BaseFEELFunction { public static final StringJoinFunction INSTANCE = new StringJoinFunction(); - public StringJoinFunction() { + private StringJoinFunction() { super("string join"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringLengthFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringLengthFunction.java index e1c673102a7..630a2bfd150 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringLengthFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringLengthFunction.java @@ -29,7 +29,7 @@ public class StringLengthFunction public static final StringLengthFunction INSTANCE = new StringLengthFunction(); - public StringLengthFunction() { + private StringLengthFunction() { super( "string length" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringLowerCaseFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringLowerCaseFunction.java index c3ee83c4994..bc238d6a035 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringLowerCaseFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringLowerCaseFunction.java @@ -26,7 +26,7 @@ public class StringLowerCaseFunction public static final StringLowerCaseFunction INSTANCE = new StringLowerCaseFunction(); - public StringLowerCaseFunction() { + private StringLowerCaseFunction() { super( "lower case" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringUpperCaseFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringUpperCaseFunction.java index 4bffb14476d..481301fd4d7 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringUpperCaseFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StringUpperCaseFunction.java @@ -26,7 +26,7 @@ public class StringUpperCaseFunction public static final StringUpperCaseFunction INSTANCE = new StringUpperCaseFunction(); - public StringUpperCaseFunction() { + private StringUpperCaseFunction() { super( "upper case" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SublistFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SublistFunction.java index 261b75e942b..068b2445da5 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SublistFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SublistFunction.java @@ -20,6 +20,7 @@ import java.math.BigDecimal; import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; @@ -28,7 +29,7 @@ public class SublistFunction public static final SublistFunction INSTANCE = new SublistFunction(); - public SublistFunction() { + private SublistFunction() { super( "sublist" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SubstringAfterFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SubstringAfterFunction.java index c0e036d9df0..d7c060f6fe1 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SubstringAfterFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SubstringAfterFunction.java @@ -26,7 +26,7 @@ public class SubstringAfterFunction public static final SubstringAfterFunction INSTANCE = new SubstringAfterFunction(); - public SubstringAfterFunction() { + private SubstringAfterFunction() { super( "substring after" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SubstringBeforeFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SubstringBeforeFunction.java index 689bab3ca60..32c8a3082e6 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SubstringBeforeFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SubstringBeforeFunction.java @@ -26,7 +26,7 @@ public class SubstringBeforeFunction public static final SubstringBeforeFunction INSTANCE = new SubstringBeforeFunction(); - public SubstringBeforeFunction() { + private SubstringBeforeFunction() { super( "substring before" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SubstringFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SubstringFunction.java index cd5f1939aeb..87d01b2ce5b 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SubstringFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SubstringFunction.java @@ -28,7 +28,7 @@ public class SubstringFunction public static final SubstringFunction INSTANCE = new SubstringFunction(); - public SubstringFunction() { + private SubstringFunction() { super( "substring" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SumFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SumFunction.java index aa2e30013c7..86d3a0310c2 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SumFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SumFunction.java @@ -24,7 +24,6 @@ import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.util.EvalHelper; import org.kie.dmn.feel.util.NumberEvalHelper; public class SumFunction @@ -32,7 +31,7 @@ public class SumFunction public static final SumFunction INSTANCE = new SumFunction(); - public SumFunction() { + private SumFunction() { super( "sum" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/TimeFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/TimeFunction.java index 7bcd6e76d50..8150480613b 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/TimeFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/TimeFunction.java @@ -63,7 +63,14 @@ public class TimeFunction .withResolverStyle(ResolverStyle.STRICT); } - public TimeFunction() { + public static boolean timeStringWithSeconds(String val) { + return timePattern.matcher(val).find(); + } + + private static final BigDecimal NANO_MULT = BigDecimal.valueOf( 1000000000 ); + + + protected TimeFunction() { super(FEELConversionFunctionNames.TIME); } @@ -71,7 +78,6 @@ public FEELFnResult invoke(@ParameterName("from") String val) if ( val == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "from", "cannot be null")); } - try { TemporalAccessor parsed = FEEL_TIME.parse(val); @@ -90,19 +96,12 @@ public FEELFnResult invoke(@ParameterName("from") String val) ZoneTime zoneTime = ZoneTime.of(asLocalTime, zoneId, hasSeconds); return FEELFnResult.ofResult(zoneTime); } - return FEELFnResult.ofResult(parsed); } catch (DateTimeException e) { - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "from", e)); + return manageDateTimeException(e, val); } } - public static boolean timeStringWithSeconds(String val) { - return timePattern.matcher(val).find(); - } - - private static final BigDecimal NANO_MULT = BigDecimal.valueOf( 1000000000 ); - public FEELFnResult invoke( @ParameterName("hour") Number hour, @ParameterName("minute") Number minute, @ParameterName("second") Number seconds) { @@ -171,4 +170,8 @@ public FEELFnResult invoke(@ParameterName("from") TemporalAcce } } + protected FEELFnResult manageDateTimeException(DateTimeException e, String val) { + return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "from", e)); + } + } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/TodayFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/TodayFunction.java similarity index 84% rename from kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/TodayFunction.java rename to kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/TodayFunction.java index d392ec6803e..d0ff403ef64 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/TodayFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/TodayFunction.java @@ -16,18 +16,17 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; import java.time.LocalDate; import java.time.temporal.TemporalAccessor; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; - public class TodayFunction extends BaseFEELFunction { - public TodayFunction() { + public static final TodayFunction INSTANCE = new TodayFunction(); + + private TodayFunction() { super( "today" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/UnionFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/UnionFunction.java index 926627a26ed..81926dd3a66 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/UnionFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/UnionFunction.java @@ -23,6 +23,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; @@ -31,7 +32,7 @@ public class UnionFunction public static final UnionFunction INSTANCE = new UnionFunction(); - public UnionFunction() { + private UnionFunction() { super( "union" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/WeekOfYearFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/WeekOfYearFunction.java index a01aeeae339..eb272d0e183 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/WeekOfYearFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/WeekOfYearFunction.java @@ -24,13 +24,12 @@ import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.util.EvalHelper; import org.kie.dmn.feel.util.NumberEvalHelper; public class WeekOfYearFunction extends BaseFEELFunction { public static final WeekOfYearFunction INSTANCE = new WeekOfYearFunction(); - WeekOfYearFunction() { + private WeekOfYearFunction() { super("week of year"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/YearsAndMonthsFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/YearsAndMonthsFunction.java index fad88161e98..4e53a238937 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/YearsAndMonthsFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/YearsAndMonthsFunction.java @@ -35,7 +35,7 @@ public class YearsAndMonthsFunction public static final YearsAndMonthsFunction INSTANCE = new YearsAndMonthsFunction(); - public YearsAndMonthsFunction() { + private YearsAndMonthsFunction() { super(FEELConversionFunctionNames.YEARS_AND_MONTHS_DURATION); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/CeilingFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/CeilingFunction.java deleted file mode 100644 index a406a26bc1e..00000000000 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/CeilingFunction.java +++ /dev/null @@ -1,55 +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.runtime.functions.extended; - -import java.math.BigDecimal; -import java.math.RoundingMode; - -import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; -import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; -import org.kie.dmn.feel.runtime.functions.ParameterName; - -/** - * provisional access for DMN14-126 - */ -public class CeilingFunction - extends BaseFEELFunction { - - public static final CeilingFunction INSTANCE = new CeilingFunction(); - - public CeilingFunction() { - super( "ceiling" ); - } - - public FEELFnResult invoke(@ParameterName( "n" ) BigDecimal n) { - return invoke(n, BigDecimal.ZERO); - } - - public FEELFnResult invoke(@ParameterName( "n" ) BigDecimal n, @ParameterName( "scale" ) BigDecimal scale) { - if ( n == null ) { - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "n", "cannot be null")); - } - if ( scale == null ) { - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "cannot be null")); - } - return FEELFnResult.ofResult( n.setScale( scale.intValue(), RoundingMode.CEILING ) ); - } -} diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/CodeFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/CodeFunction.java index d353251de84..a844b5e823c 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/CodeFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/CodeFunction.java @@ -26,7 +26,9 @@ public class CodeFunction extends BaseFEELFunction { - public CodeFunction() { + public static final CodeFunction INSTANCE = new CodeFunction(); + + private CodeFunction() { super( "code" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/DateFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/DateFunction.java index e40fd3a77b4..addf07c0166 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/DateFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/DateFunction.java @@ -19,94 +19,48 @@ package org.kie.dmn.feel.runtime.functions.extended; import java.time.DateTimeException; -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeFormatterBuilder; -import java.time.format.ResolverStyle; -import java.time.format.SignStyle; import java.time.temporal.TemporalAccessor; -import java.util.regex.Pattern; import org.kie.dmn.api.feel.runtime.events.FEELEvent; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; import org.kie.dmn.feel.runtime.functions.BuiltInFunctions; import org.kie.dmn.feel.runtime.functions.DateAndTimeFunction; -import org.kie.dmn.feel.runtime.functions.FEELConversionFunctionNames; import org.kie.dmn.feel.runtime.functions.FEELFnResult; import org.kie.dmn.feel.runtime.functions.ParameterName; -import static java.time.temporal.ChronoField.DAY_OF_MONTH; -import static java.time.temporal.ChronoField.MONTH_OF_YEAR; -import static java.time.temporal.ChronoField.YEAR; - -public class DateFunction extends BaseFEELFunction { +/** + * This class overrides parent methods due to BaseFEELFunction#getCandidateMethod implementation + */ +public class DateFunction extends org.kie.dmn.feel.runtime.functions.DateFunction { public static final DateFunction INSTANCE = new DateFunction(); - private static final Pattern BEGIN_YEAR = Pattern.compile("^-?(([1-9]\\d\\d\\d+)|(0\\d\\d\\d))-"); // FEEL spec, "specified by XML Schema Part 2 Datatypes", hence: yearFrag ::= '-'? (([1-9] digit digit digit+)) | ('0' digit digit digit)) - private static final DateTimeFormatter FEEL_DATE; - - static { - FEEL_DATE = new DateTimeFormatterBuilder().appendValue(YEAR, 4, 9, SignStyle.NORMAL) - .appendLiteral('-') - .appendValue(MONTH_OF_YEAR, 2) - .appendLiteral('-') - .appendValue(DAY_OF_MONTH, 2) - .toFormatter() - .withResolverStyle(ResolverStyle.STRICT); - } - - DateFunction() { - super(FEELConversionFunctionNames.DATE); + private DateFunction() { } + @Override public FEELFnResult invoke(@ParameterName("from") String val) { - if (val == null) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "cannot be null")); - } - if (!BEGIN_YEAR.matcher(val).find()) { // please notice the regex strictly requires the beginning, so we can use find. - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "year not compliant with XML Schema Part 2 Datatypes")); - } - - try { - return FEELFnResult.ofResult(LocalDate.from(FEEL_DATE.parse(val))); - } catch (DateTimeException e) { - // try to parse it as a date time and extract the date component - // NOTE: this is an extension to the standard - return BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(val) - .cata(overrideLeft -> FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "date-parsing exception", e)), - this::invoke - ); - } + return super.invoke(val); } - public FEELFnResult invoke(@ParameterName("year") Number year, @ParameterName("month") Number month, @ParameterName("day") Number day) { - if (year == null) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "year", "cannot be null")); - } - if (month == null) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "month", "cannot be null")); - } - if (day == null) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "day", "cannot be null")); - } - - try { - return FEELFnResult.ofResult(LocalDate.of(year.intValue(), month.intValue(), day.intValue())); - } catch (DateTimeException e) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "input parameters date-parsing exception", e)); - } + @Override + public FEELFnResult invoke(@ParameterName( "year" ) Number year, @ParameterName( "month" ) Number month, @ParameterName( "day" ) Number day) { + return super.invoke(year, month, day); } - public FEELFnResult invoke(@ParameterName("from") TemporalAccessor date) { - if (date == null) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "cannot be null")); - } + @Override + public FEELFnResult invoke(@ParameterName( "from" ) TemporalAccessor date) { + return super.invoke(date); + } - try { - return FEELFnResult.ofResult(LocalDate.from(date)); - } catch (DateTimeException e) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "date-parsing exception", e)); - } + @Override + protected FEELFnResult manageDateTimeException(DateTimeException e, String val) { + // try to parse it as a date time and extract the date component + // NOTE: this is an extension to the standard + return BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(val) + .cata(overrideLeft -> FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from" + , "date-parsing exception", e)), + this::invoke + ); } + } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/DurationFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/DurationFunction.java deleted file mode 100644 index 869efea0035..00000000000 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/DurationFunction.java +++ /dev/null @@ -1,70 +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.runtime.functions.extended; - -import java.time.Duration; -import java.time.format.DateTimeParseException; -import java.time.temporal.TemporalAmount; -import java.util.Arrays; -import java.util.List; - -import org.kie.dmn.api.feel.runtime.events.FEELEvent; -import org.kie.dmn.feel.lang.types.impl.ComparablePeriod; -import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; -import org.kie.dmn.feel.runtime.functions.FEELConversionFunctionNames; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; -import org.kie.dmn.feel.runtime.functions.ParameterName; - -public class DurationFunction extends BaseFEELFunction { - public static final DurationFunction INSTANCE = new DurationFunction(); - - DurationFunction() { - super(FEELConversionFunctionNames.DURATION); - } - - public FEELFnResult invoke(@ParameterName( "from" ) String val) { - if ( val == null ) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "cannot be null")); - } - - try { - // try to parse as days/hours/minute/seconds - return FEELFnResult.ofResult( Duration.parse( val ) ); - } catch( DateTimeParseException e ) { - // if it failed, try to parse as years/months - try { - return FEELFnResult.ofResult(ComparablePeriod.parse(val).normalized()); - } catch( DateTimeParseException e2 ) { - // failed to parse, so return null according to the spec - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "date-parsing exception", - new RuntimeException(new Throwable() { public final List causes = Arrays.asList( new Throwable[]{e, e2} ); } ))); - } - } - - } - - public FEELFnResult invoke(@ParameterName( "from" ) TemporalAmount val) { - if ( val == null ) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "cannot be null")); - } - return FEELFnResult.ofResult( val ); - } - -} diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/FloorFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/FloorFunction.java deleted file mode 100644 index 3fefcca6788..00000000000 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/FloorFunction.java +++ /dev/null @@ -1,55 +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.runtime.functions.extended; - -import java.math.BigDecimal; -import java.math.RoundingMode; - -import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; -import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; -import org.kie.dmn.feel.runtime.functions.ParameterName; - -/** - * provisional access for DMN14-126 - */ -public class FloorFunction - extends BaseFEELFunction { - - public static final FloorFunction INSTANCE = new FloorFunction(); - - public FloorFunction() { - super( "floor" ); - } - - public FEELFnResult invoke(@ParameterName( "n" ) BigDecimal n) { - return invoke(n, BigDecimal.ZERO); - } - - public FEELFnResult invoke(@ParameterName( "n" ) BigDecimal n, @ParameterName( "scale" ) BigDecimal scale) { - if ( n == null ) { - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "n", "cannot be null")); - } - if ( scale == null ) { - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "scale", "cannot be null")); - } - return FEELFnResult.ofResult( n.setScale( scale.intValue(), RoundingMode.FLOOR ) ); - } -} diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/InvokeFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/InvokeFunction.java index f6c005ae5c7..3a1ac7cdbd2 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/InvokeFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/InvokeFunction.java @@ -39,7 +39,9 @@ @Deprecated public class InvokeFunction extends BaseFEELFunction { - public InvokeFunction() { + public static final InvokeFunction INSTANCE = new InvokeFunction(); + + private InvokeFunction() { super("invoke"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/KieExtendedDMNFunctions.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/KieExtendedDMNFunctions.java index e6ab02e2993..6a4d89ef648 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/KieExtendedDMNFunctions.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/KieExtendedDMNFunctions.java @@ -40,23 +40,10 @@ public class KieExtendedDMNFunctions { protected static final FEELFunction[] FUNCTIONS = new FEELFunction[]{ TimeFunction.INSTANCE, DateFunction.INSTANCE, - DurationFunction.INSTANCE, // additional functions not part of the spec version 1.1 - new NowFunction(), - new TodayFunction(), - new CodeFunction(), - new InvokeFunction(), - - ContextPutFunction.INSTANCE, - ContextMergeFunction.INSTANCE, - ContextFunction.INSTANCE, - FloorFunction.INSTANCE, - CeilingFunction.INSTANCE, - RoundUpFunction.INSTANCE, - RoundDownFunction.INSTANCE, - RoundHalfUpFunction.INSTANCE, - RoundHalfDownFunction.INSTANCE, + CodeFunction.INSTANCE, + InvokeFunction.INSTANCE, // CQL based, two value logic functions NNAnyFunction.INSTANCE, @@ -70,9 +57,6 @@ public class KieExtendedDMNFunctions { NNStddevFunction.INSTANCE, NNSumFunction.INSTANCE, - StringJoinFunction.INSTANCE, - RangeFunction.INSTANCE, - }; public static FEELFunction[] getFunctions() { diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/TimeFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/TimeFunction.java index 744474dd615..3c7aa4593e6 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/TimeFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/extended/TimeFunction.java @@ -18,158 +18,58 @@ */ package org.kie.dmn.feel.runtime.functions.extended; -import java.math.BigDecimal; -import java.math.RoundingMode; import java.time.DateTimeException; import java.time.Duration; -import java.time.LocalTime; -import java.time.OffsetTime; -import java.time.ZoneId; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeFormatterBuilder; -import java.time.format.ResolverStyle; -import java.time.temporal.ChronoField; import java.time.temporal.TemporalAccessor; -import java.time.temporal.TemporalQueries; import org.kie.dmn.api.feel.runtime.events.FEELEvent; -import org.kie.dmn.feel.runtime.custom.ZoneTime; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; import org.kie.dmn.feel.runtime.functions.BuiltInFunctions; import org.kie.dmn.feel.runtime.functions.DateAndTimeFunction; -import org.kie.dmn.feel.runtime.functions.FEELConversionFunctionNames; import org.kie.dmn.feel.runtime.functions.FEELFnResult; import org.kie.dmn.feel.runtime.functions.ParameterName; -import static org.kie.dmn.feel.runtime.functions.TimeFunction.timeStringWithSeconds; - -public class TimeFunction extends BaseFEELFunction { +/** + * This class overrides parent methods due to BaseFEELFunction#getCandidateMethod implementation + */ +public class TimeFunction extends org.kie.dmn.feel.runtime.functions.TimeFunction { public static final TimeFunction INSTANCE = new TimeFunction(); - private static final DateTimeFormatter FEEL_TIME; - - static { - FEEL_TIME = new DateTimeFormatterBuilder().parseCaseInsensitive() - .append(DateTimeFormatter.ISO_LOCAL_TIME) - .optionalStart() - .appendLiteral("@") - .appendZoneRegionId() - .optionalEnd() - .optionalStart() - .appendOffsetId() - .optionalEnd() - .toFormatter() - .withResolverStyle(ResolverStyle.STRICT); - } - - TimeFunction() { - super(FEELConversionFunctionNames.TIME); + private TimeFunction() { } + @Override public FEELFnResult invoke(@ParameterName("from") String val) { - if (val == null) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "cannot be null")); - } - - try { - TemporalAccessor parsed = FEEL_TIME.parse(val); - - if (parsed.query(TemporalQueries.offset()) != null) { - // it is an offset-zoned time, so I can know for certain an OffsetTime - OffsetTime asOffSetTime = parsed.query(OffsetTime::from); - return FEELFnResult.ofResult(asOffSetTime); - } else if (parsed.query(TemporalQueries.zone()) == null) { - // if it does not contain any zone information at all, then I know for certain is a local time. - LocalTime asLocalTime = parsed.query(LocalTime::from); - return FEELFnResult.ofResult(asLocalTime); - } else if (parsed.query(TemporalQueries.zone()) != null) { - boolean hasZeroSeconds = timeStringWithSeconds(val); - LocalTime asLocalTime = parsed.query(LocalTime::from); - ZoneId zoneId = parsed.query(TemporalQueries.zone()); - ZoneTime zoneTime = ZoneTime.of(asLocalTime, zoneId, hasZeroSeconds); - return FEELFnResult.ofResult(zoneTime); - } - - return FEELFnResult.ofResult(parsed); - } catch (DateTimeException e) { - // try to parse it as a date time and extract the date component - // NOTE: this is an extension to the standard - return BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(val) - .cata(overrideLeft -> FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "time-parsing exception", e)), - this::invoke - ); - } + return super.invoke(val); } - private static final BigDecimal NANO_MULT = BigDecimal.valueOf(1000000000); - + @Override public FEELFnResult invoke( @ParameterName("hour") Number hour, @ParameterName("minute") Number minute, @ParameterName("second") Number seconds) { - return invoke(hour, minute, seconds, null); + return super.invoke(hour, minute, seconds); } + @Override public FEELFnResult invoke( @ParameterName("hour") Number hour, @ParameterName("minute") Number minute, @ParameterName("second") Number seconds, @ParameterName("offset") Duration offset) { - if (hour == null) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "hour", "cannot be null")); - } - if (minute == null) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "minute", "cannot be null")); - } - if (seconds == null) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "seconds", "cannot be null")); - } - - try { - int nanosecs = 0; - if (seconds instanceof BigDecimal) { - BigDecimal secs = (BigDecimal) seconds; - nanosecs = secs.subtract(secs.setScale(0, RoundingMode.DOWN)).multiply(NANO_MULT).intValue(); - } - - if (offset == null) { - return FEELFnResult.ofResult(LocalTime.of(hour.intValue(), minute.intValue(), seconds.intValue(), - nanosecs)); - } else { - return FEELFnResult.ofResult(OffsetTime.of(hour.intValue(), minute.intValue(), seconds.intValue(), - nanosecs, - ZoneOffset.ofTotalSeconds((int) offset.getSeconds()))); - } - } catch (DateTimeException e) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "time-parsing exception", e)); - } + return super.invoke(hour, minute, seconds, offset); } + @Override public FEELFnResult invoke(@ParameterName("from") TemporalAccessor date) { - if (date == null) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "cannot be null")); - } + return super.invoke(date); + } - try { - // If the temporal accessor type doesn't support time, try to parse it as a date with UTC midnight. - if (!date.isSupported(ChronoField.HOUR_OF_DAY)) { - return BuiltInFunctions.getFunction( DateAndTimeFunction.class ).invoke( date, OffsetTime.of(0, 0, 0, 0, ZoneOffset.UTC) ) - .cata( overrideLeft -> FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "time-parsing exception")), - this::invoke - ); - } else if( date.query( TemporalQueries.offset() ) == null ) { - return FEELFnResult.ofResult(LocalTime.from(date)); - } else { - ZoneId zone = date.query(TemporalQueries.zoneId()); - if (!(zone instanceof ZoneOffset)) { - // TZ is a ZoneRegion, so do NOT normalize (although the result will be unreversible, but will keep what was supplied originally). - // Unfortunately java.time.Parsed is a package-private class, hence will need to re-parse in order to have it instantiated. - return invoke(date.query(TemporalQueries.localTime()) + "@" + zone); - } else { - return FEELFnResult.ofResult(OffsetTime.from(date)); - } - } - } catch (DateTimeException e) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "time-parsing exception", e)); - } + @Override + protected FEELFnResult manageDateTimeException(DateTimeException e, String val) { + // try to parse it as a date time and extract the date component + // NOTE: this is an extension to the standard + return BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(val) + .cata(overrideLeft -> FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from" + , "time-parsing exception", e)), + this::invoke + ); } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/AfterFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/AfterFunction.java index 007250f1687..fafe3a4a939 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/AfterFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/AfterFunction.java @@ -31,7 +31,7 @@ public class AfterFunction public static final AfterFunction INSTANCE = new AfterFunction(); - public AfterFunction() { + private AfterFunction() { super( "after" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/BeforeFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/BeforeFunction.java index 4ae46d43ad1..f6b22e421ce 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/BeforeFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/BeforeFunction.java @@ -30,7 +30,7 @@ public class BeforeFunction public static final BeforeFunction INSTANCE = new BeforeFunction(); - public BeforeFunction() { + private BeforeFunction() { super( "before" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/CoincidesFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/CoincidesFunction.java index 9247aa69fec..6f15d0a87fe 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/CoincidesFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/CoincidesFunction.java @@ -30,7 +30,7 @@ public class CoincidesFunction public static final CoincidesFunction INSTANCE = new CoincidesFunction(); - public CoincidesFunction() { + private CoincidesFunction() { super( "coincides" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/DuringFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/DuringFunction.java index 9adf8a3a936..14ca0aef43b 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/DuringFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/DuringFunction.java @@ -31,7 +31,7 @@ public class DuringFunction public static final DuringFunction INSTANCE = new DuringFunction(); - public DuringFunction() { + private DuringFunction() { super( "during" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/FinishedByFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/FinishedByFunction.java index c64b697a9d4..b17066eaed5 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/FinishedByFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/FinishedByFunction.java @@ -31,7 +31,7 @@ public class FinishedByFunction public static final FinishedByFunction INSTANCE = new FinishedByFunction(); - public FinishedByFunction() { + private FinishedByFunction() { super( "finished by" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/FinishesFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/FinishesFunction.java index bc03b1ef1ba..ab6fd59f7ab 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/FinishesFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/FinishesFunction.java @@ -31,7 +31,7 @@ public class FinishesFunction public static final FinishesFunction INSTANCE = new FinishesFunction(); - public FinishesFunction() { + private FinishesFunction() { super( "finishes" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/IncludesFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/IncludesFunction.java index 1445053d516..8ef61b23ecc 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/IncludesFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/IncludesFunction.java @@ -31,7 +31,7 @@ public class IncludesFunction public static final IncludesFunction INSTANCE = new IncludesFunction(); - public IncludesFunction() { + private IncludesFunction() { super( "includes" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/MeetsFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/MeetsFunction.java index 7c33d183022..747eef9ee06 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/MeetsFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/MeetsFunction.java @@ -29,7 +29,7 @@ public class MeetsFunction extends BaseFEELFunction { public static final MeetsFunction INSTANCE = new MeetsFunction(); - public MeetsFunction() { + private MeetsFunction() { super( "meets" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/MetByFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/MetByFunction.java index 125867ebc3e..4f2ea578b72 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/MetByFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/MetByFunction.java @@ -29,7 +29,7 @@ public class MetByFunction extends BaseFEELFunction { public static final MetByFunction INSTANCE = new MetByFunction(); - public MetByFunction() { + private MetByFunction() { super("met by"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/OverlapsAfterFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/OverlapsAfterFunction.java index 7924bd1c026..af10abd3007 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/OverlapsAfterFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/OverlapsAfterFunction.java @@ -28,7 +28,7 @@ public class OverlapsAfterFunction public static final OverlapsAfterFunction INSTANCE = new OverlapsAfterFunction(); - public OverlapsAfterFunction() { + private OverlapsAfterFunction() { super("overlaps after"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/OverlapsBeforeFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/OverlapsBeforeFunction.java index c20a7643646..16ebbb89836 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/OverlapsBeforeFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/OverlapsBeforeFunction.java @@ -31,7 +31,7 @@ public class OverlapsBeforeFunction public static final OverlapsBeforeFunction INSTANCE = new OverlapsBeforeFunction(); - public OverlapsBeforeFunction() { + private OverlapsBeforeFunction() { super("overlaps before"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/OverlapsFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/OverlapsFunction.java index 49afd62753e..51208ef9df6 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/OverlapsFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/OverlapsFunction.java @@ -30,7 +30,7 @@ public class OverlapsFunction extends BaseFEELFunction { public static final OverlapsFunction INSTANCE = new OverlapsFunction(); - public OverlapsFunction() { + private OverlapsFunction() { super("overlaps"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/StartedByFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/StartedByFunction.java index 54aaa2ac7b2..611d4f2c35b 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/StartedByFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/StartedByFunction.java @@ -31,7 +31,7 @@ public class StartedByFunction public static final StartedByFunction INSTANCE = new StartedByFunction(); - public StartedByFunction() { + private StartedByFunction() { super( "started by" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/StartsFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/StartsFunction.java index 900bfb4852a..1026798486e 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/StartsFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/interval/StartsFunction.java @@ -31,7 +31,7 @@ public class StartsFunction public static final StartsFunction INSTANCE = new StartsFunction(); - public StartsFunction() { + private StartsFunction() { super( "starts" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAllFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAllFunction.java index 40384f66b30..203b48287e7 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAllFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAllFunction.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -18,15 +18,15 @@ */ package org.kie.dmn.feel.runtime.functions.twovaluelogic; +import java.util.Arrays; +import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; import org.kie.dmn.feel.runtime.functions.FEELFnResult; import org.kie.dmn.feel.runtime.functions.ParameterName; -import java.util.Arrays; -import java.util.List; - /** * An implementation of the all() function that ignores nulls */ @@ -35,39 +35,40 @@ public class NNAllFunction public static final NNAllFunction INSTANCE = new NNAllFunction(); - public NNAllFunction() { - super( "nn all" ); + private NNAllFunction() { + super("nn all"); } - public FEELFnResult invoke(@ParameterName( "list" ) List list) { - if ( list == null ) { - return FEELFnResult.ofResult( true ); + public FEELFnResult invoke(@ParameterName("list") List list) { + if (list == null) { + return FEELFnResult.ofResult(true); } boolean result = true; - for ( final Object element : list ) { + for (final Object element : list) { if (element != null && !(element instanceof Boolean)) { - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "an element in the list is not a Boolean")); + return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "an element in the list is not" + + " a Boolean")); } else { if (element != null) { result &= (Boolean) element; } } } - return FEELFnResult.ofResult( result ); + return FEELFnResult.ofResult(result); } - public FEELFnResult invoke(@ParameterName( "list" ) Boolean single) { - if( single == null ) { - return FEELFnResult.ofResult( true ); + public FEELFnResult invoke(@ParameterName("list") Boolean single) { + if (single == null) { + return FEELFnResult.ofResult(true); } - return FEELFnResult.ofResult( Boolean.TRUE.equals( single ) ); + return FEELFnResult.ofResult(Boolean.TRUE.equals(single)); } - public FEELFnResult invoke(@ParameterName( "b" ) Object[] list) { - if ( list == null ) { - return FEELFnResult.ofResult( true ); + public FEELFnResult invoke(@ParameterName("b") Object[] list) { + if (list == null) { + return FEELFnResult.ofResult(true); } - - return invoke( Arrays.asList( list ) ); + + return invoke(Arrays.asList(list)); } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAnyFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAnyFunction.java index fd826ddbabd..f149cc0f201 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAnyFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAnyFunction.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -18,15 +18,15 @@ */ package org.kie.dmn.feel.runtime.functions.twovaluelogic; +import java.util.Arrays; +import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; import org.kie.dmn.feel.runtime.functions.FEELFnResult; import org.kie.dmn.feel.runtime.functions.ParameterName; -import java.util.Arrays; -import java.util.List; - /** * An implementation of the any() function that ignores nulls */ @@ -35,39 +35,40 @@ public class NNAnyFunction public static final NNAnyFunction INSTANCE = new NNAnyFunction(); - public NNAnyFunction() { - super( "nn any" ); + private NNAnyFunction() { + super("nn any"); } - public FEELFnResult invoke(@ParameterName( "list" ) List list) { - if ( list == null ) { - return FEELFnResult.ofResult( false ); + public FEELFnResult invoke(@ParameterName("list") List list) { + if (list == null) { + return FEELFnResult.ofResult(false); } boolean result = false; - for ( final Object element : list ) { + for (final Object element : list) { if (element != null && !(element instanceof Boolean)) { - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "an element in the list is not a Boolean")); + return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "an element in the list is not" + + " a Boolean")); } else { if (element != null) { result |= (Boolean) element; } } } - return FEELFnResult.ofResult( result ); + return FEELFnResult.ofResult(result); } - public FEELFnResult invoke(@ParameterName( "list" ) Boolean single) { - if( single == null ) { + public FEELFnResult invoke(@ParameterName("list") Boolean single) { + if (single == null) { single = Boolean.FALSE; } - return FEELFnResult.ofResult( single ); + return FEELFnResult.ofResult(single); } - public FEELFnResult invoke(@ParameterName( "b" ) Object[] list) { - if ( list == null ) { - return FEELFnResult.ofResult( false ); + public FEELFnResult invoke(@ParameterName("b") Object[] list) { + if (list == null) { + return FEELFnResult.ofResult(false); } - - return invoke( Arrays.asList( list ) ); + + return invoke(Arrays.asList(list)); } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNCountFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNCountFunction.java index 14ee16efd35..cfbd32f31ac 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNCountFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNCountFunction.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -18,47 +18,47 @@ */ package org.kie.dmn.feel.runtime.functions.twovaluelogic; +import java.math.BigDecimal; +import java.util.List; + import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; import org.kie.dmn.feel.runtime.functions.FEELFnResult; import org.kie.dmn.feel.runtime.functions.ParameterName; -import java.math.BigDecimal; -import java.util.List; - public class NNCountFunction extends BaseFEELFunction { public static final NNCountFunction INSTANCE = new NNCountFunction(); - public NNCountFunction() { - super( "nn count" ); + private NNCountFunction() { + super("nn count"); } - public FEELFnResult invoke(@ParameterName( "list" ) List list) { - if ( list == null ) { + public FEELFnResult invoke(@ParameterName("list") List list) { + if (list == null) { return FEELFnResult.ofResult(BigDecimal.ZERO); } // using raw loop instead of streams for performance int count = 0; - for( int i = 0; i < list.size(); i++ ) { - if( list.get( i ) != null ) { + for (int i = 0; i < list.size(); i++) { + if (list.get(i) != null) { count++; } } - return FEELFnResult.ofResult( BigDecimal.valueOf( count ) ); + return FEELFnResult.ofResult(BigDecimal.valueOf(count)); } - public FEELFnResult invoke(@ParameterName( "c" ) Object[] list) { - if ( list == null ) { + public FEELFnResult invoke(@ParameterName("c") Object[] list) { + if (list == null) { return FEELFnResult.ofResult(BigDecimal.ZERO); } // using raw loop instead of streams for performance int count = 0; - for( int i = 0; i < list.length; i++ ) { - if( list[ i ] != null ) { + for (int i = 0; i < list.length; i++) { + if (list[i] != null) { count++; } } - return FEELFnResult.ofResult( BigDecimal.valueOf( count ) ); + return FEELFnResult.ofResult(BigDecimal.valueOf(count)); } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMaxFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMaxFunction.java index 57af28511df..788e22954b7 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMaxFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMaxFunction.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -18,53 +18,53 @@ */ package org.kie.dmn.feel.runtime.functions.twovaluelogic; +import java.util.Arrays; +import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; import org.kie.dmn.feel.runtime.functions.FEELFnResult; import org.kie.dmn.feel.runtime.functions.ParameterName; -import java.util.Arrays; -import java.util.List; - public class NNMaxFunction extends BaseFEELFunction { public static final NNMaxFunction INSTANCE = new NNMaxFunction(); - public NNMaxFunction() { - super( "nn max" ); + private NNMaxFunction() { + super("nn max"); } public FEELFnResult invoke(@ParameterName("list") List list) { - if ( list == null || list.isEmpty() ) { - return FEELFnResult.ofResult( null ); + if (list == null || list.isEmpty()) { + return FEELFnResult.ofResult(null); } else { try { Comparable max = null; - for( int i = 0; i < list.size(); i++ ) { - Comparable candidate = (Comparable) list.get( i ); - if( candidate == null ) { + for (int i = 0; i < list.size(); i++) { + Comparable candidate = (Comparable) list.get(i); + if (candidate == null) { continue; - } else if( max == null ) { + } else if (max == null) { max = candidate; - } else if( max.compareTo( candidate ) < 0 ) { + } else if (max.compareTo(candidate) < 0) { max = candidate; } } - return FEELFnResult.ofResult( max ); + return FEELFnResult.ofResult(max); } catch (ClassCastException e) { - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "contains items that are not comparable")); + return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "contains items that " + + "are not comparable")); } } } public FEELFnResult invoke(@ParameterName("c") Object[] list) { - if ( list == null || list.length == 0 ) { - return FEELFnResult.ofResult( null ); + if (list == null || list.length == 0) { + return FEELFnResult.ofResult(null); } - - return invoke( Arrays.asList( list ) ); - } + return invoke(Arrays.asList(list)); + } } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMeanFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMeanFunction.java index e84c767c8c8..d0cee07fcfa 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMeanFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMeanFunction.java @@ -35,7 +35,7 @@ public class NNMeanFunction public static final NNMeanFunction INSTANCE = new NNMeanFunction(); - public NNMeanFunction() { + private NNMeanFunction() { super( "nn mean" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMedianFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMedianFunction.java index c6af85b7ab9..f3ddbbbeff8 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMedianFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMedianFunction.java @@ -37,7 +37,7 @@ public class NNMedianFunction public static final NNMedianFunction INSTANCE = new NNMedianFunction(); - NNMedianFunction() { + private NNMedianFunction() { super("nn median"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMinFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMinFunction.java index e50ced74450..3f54cb86742 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMinFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMinFunction.java @@ -18,21 +18,21 @@ */ package org.kie.dmn.feel.runtime.functions.twovaluelogic; +import java.util.Arrays; +import java.util.List; + import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; import org.kie.dmn.feel.runtime.functions.BaseFEELFunction; import org.kie.dmn.feel.runtime.functions.FEELFnResult; import org.kie.dmn.feel.runtime.functions.ParameterName; -import java.util.Arrays; -import java.util.List; - public class NNMinFunction extends BaseFEELFunction { public static final NNMinFunction INSTANCE = new NNMinFunction(); - public NNMinFunction() { + private NNMinFunction() { super( "nn min" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNModeFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNModeFunction.java index f4e30e5c8e2..4bca232125d 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNModeFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNModeFunction.java @@ -36,7 +36,7 @@ public class NNModeFunction extends BaseFEELFunction { public static final NNModeFunction INSTANCE = new NNModeFunction(); - NNModeFunction() { + private NNModeFunction() { super("nn mode"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNStddevFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNStddevFunction.java index c07410ec4fa..36178e0ee45 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNStddevFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNStddevFunction.java @@ -37,7 +37,7 @@ public class NNStddevFunction extends BaseFEELFunction { public static final NNStddevFunction INSTANCE = new NNStddevFunction(); - NNStddevFunction() { + private NNStddevFunction() { super("nn stddev"); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNSumFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNSumFunction.java index 0ed8d289c75..e4dfa336a58 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNSumFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNSumFunction.java @@ -34,7 +34,7 @@ public class NNSumFunction public static final NNSumFunction INSTANCE = new NNSumFunction(); - public NNSumFunction() { + private NNSumFunction() { super( "nn sum" ); } diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/BooleanEvalHelper.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/BooleanEvalHelper.java index f6049372c7f..39f9707923d 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/BooleanEvalHelper.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/BooleanEvalHelper.java @@ -30,8 +30,6 @@ import java.util.Optional; import java.util.function.BiPredicate; -import org.kie.dmn.feel.lang.EvaluationContext; -import org.kie.dmn.feel.lang.FEELDialect; import org.kie.dmn.feel.lang.types.BuiltInType; import org.kie.dmn.feel.lang.types.impl.ComparablePeriod; import org.kie.dmn.feel.runtime.Range; diff --git a/kie-dmn/kie-dmn-feel/src/main/resources/META-INF/native-image/org.kie/kie-dmn-feel/reflect-config.json b/kie-dmn/kie-dmn-feel/src/main/resources/META-INF/native-image/org.kie/kie-dmn-feel/reflect-config.json index c6b830b456f..a80edd19086 100644 --- a/kie-dmn/kie-dmn-feel/src/main/resources/META-INF/native-image/org.kie/kie-dmn-feel/reflect-config.json +++ b/kie-dmn/kie-dmn-feel/src/main/resources/META-INF/native-image/org.kie/kie-dmn-feel/reflect-config.json @@ -1,992 +1,992 @@ [ - { - "name": "org.kie.dmn.feel.codegen.feel11.CompiledCustomFEELFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.AbsFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.AbstractCustomFEELFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.AllFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.AnyFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.AppendFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.BaseFEELFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.CeilingFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.ConcatenateFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.ContainsFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.CountFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.CustomFEELFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.DTInvokerFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.DateAndTimeFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.DateFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.DayOfWeekFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.DayOfYearFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.DecimalFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.DecisionTableFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.DistinctValuesFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.DurationFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.EndsWithFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.EvenFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.ExpFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.FlattenFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.FloorFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.GetEntriesFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.GetValueFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.IndexOfFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.InsertBeforeFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.IsFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.JavaFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.ListContainsFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.ListReplaceFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.LogFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.MatchesFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.MaxFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.MeanFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.MedianFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.MinFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.ModeFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.ModuloFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.MonthOfYearFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.NotFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.NumberFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.OddFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.ProductFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.RemoveFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.ReplaceFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.ReverseFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.SortFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.SplitFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.SqrtFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.StartsWithFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.StddevFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.StringFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.StringLengthFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.StringLowerCaseFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.StringUpperCaseFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.SublistFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.SubstringAfterFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.SubstringBeforeFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.SubstringFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.SumFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.TimeFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.UnionFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.WeekOfYearFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.YearsAndMonthsFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.CeilingFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.CodeFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.ContextFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.ContextMergeFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.ContextPutFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.DateFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.DurationFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.FloorFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.InvokeFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.NowFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.RangeFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.RoundDownFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.RoundHalfDownFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.RoundHalfUpFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.RoundUpFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.StringJoinFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.TimeFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.extended.TodayFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.interval.AfterFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.interval.BeforeFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.interval.CoincidesFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.interval.DuringFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.interval.FinishedByFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.interval.FinishesFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.interval.IncludesFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.interval.MeetsFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.interval.MetByFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.interval.OverlapsAfterFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.interval.OverlapsBeforeFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.interval.OverlapsFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.interval.StartedByFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.interval.StartsFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNAllFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNAnyFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNCountFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNMaxFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNMeanFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNMedianFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNMinFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNModeFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNStddevFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - }, - { - "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNSumFunction", - "allDeclaredConstructors": true, - "allPublicConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredClasses": true, - "allPublicClasses": true - } + { + "name": "org.kie.dmn.feel.codegen.feel11.CompiledCustomFEELFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.AbsFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.AbstractCustomFEELFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.AllFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.AnyFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.AppendFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.BaseFEELFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.CeilingFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.ConcatenateFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.ContainsFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.CountFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.CustomFEELFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.DTInvokerFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.DateAndTimeFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.DateFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.DayOfWeekFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.DayOfYearFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.DecimalFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.DecisionTableFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.DistinctValuesFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.DurationFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.EndsWithFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.EvenFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.ExpFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.FlattenFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.FloorFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.GetEntriesFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.GetValueFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.IndexOfFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.InsertBeforeFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.IsFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.JavaFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.ListContainsFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.ListReplaceFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.LogFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.MatchesFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.MaxFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.MeanFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.MedianFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.MinFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.ModeFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.ModuloFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.MonthOfYearFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.NotFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.NumberFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.OddFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.ProductFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.RemoveFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.ReplaceFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.ReverseFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.SortFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.SplitFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.SqrtFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.StartsWithFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.StddevFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.StringFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.StringLengthFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.StringLowerCaseFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.StringUpperCaseFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.SublistFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.SubstringAfterFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.SubstringBeforeFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.SubstringFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.SumFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.TimeFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.UnionFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.WeekOfYearFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.YearsAndMonthsFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.CeilingFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.ContextFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.ContextMergeFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.ContextPutFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.DurationFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.FloorFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.NowFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.RangeFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.RoundDownFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.RoundHalfDownFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.RoundHalfUpFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.RoundUpFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.StringJoinFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.TodayFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.extended.CodeFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.extended.DateFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.extended.InvokeFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.extended.TimeFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.interval.AfterFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.interval.BeforeFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.interval.CoincidesFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.interval.DuringFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.interval.FinishedByFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.interval.FinishesFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.interval.IncludesFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.interval.MeetsFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.interval.MetByFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.interval.OverlapsAfterFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.interval.OverlapsBeforeFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.interval.OverlapsFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.interval.StartedByFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.interval.StartsFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNAllFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNAnyFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNCountFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNMaxFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNMeanFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNMedianFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNMinFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNModeFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNStddevFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "org.kie.dmn.feel.runtime.functions.twovaluelogic.NNSumFunction", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + } ] diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AllFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AllFunctionTest.java index 721d7ac405e..06e35405ee0 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AllFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AllFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -22,18 +22,12 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class AllFunctionTest { - private AllFunction allFunction; - - @BeforeEach - void setUp() { - allFunction = new AllFunction(); - } + private static final AllFunction allFunction = AllFunction.INSTANCE; @Test void invokeBooleanParamNull() { @@ -78,9 +72,12 @@ void invokeArrayParamReturnNull() { @Test void invokeArrayParamTypeHeterogenousArray() { - FunctionTestUtil.assertResultError(allFunction.invoke(new Object[]{Boolean.TRUE, 1}), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(allFunction.invoke(new Object[]{Boolean.FALSE, 1}), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(allFunction.invoke(new Object[]{Boolean.TRUE, null, 1}), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(allFunction.invoke(new Object[]{Boolean.TRUE, 1}), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(allFunction.invoke(new Object[]{Boolean.FALSE, 1}), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(allFunction.invoke(new Object[]{Boolean.TRUE, null, 1}), + InvalidParametersEvent.class); } @Test @@ -111,8 +108,11 @@ void invokeListParamReturnNull() { @Test void invokeListParamTypeHeterogenousArray() { - FunctionTestUtil.assertResultError(allFunction.invoke(Arrays.asList(Boolean.TRUE, 1)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(allFunction.invoke(Arrays.asList(Boolean.FALSE, 1)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(allFunction.invoke(Arrays.asList(Boolean.TRUE, null, 1)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(allFunction.invoke(Arrays.asList(Boolean.TRUE, 1)), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(allFunction.invoke(Arrays.asList(Boolean.FALSE, 1)), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(allFunction.invoke(Arrays.asList(Boolean.TRUE, null, 1)), + InvalidParametersEvent.class); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AnyFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AnyFunctionTest.java index 216b5c7fa83..aa322fb38f0 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AnyFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AnyFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -22,18 +22,12 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class AnyFunctionTest { - private AnyFunction anyFunction; - - @BeforeEach - void setUp() { - anyFunction = new AnyFunction(); - } + private static final AnyFunction anyFunction = AnyFunction.INSTANCE; @Test void invokeBooleanParamNull() { @@ -80,9 +74,12 @@ void invokeArrayParamReturnNull() { @Test void invokeArrayParamTypeHeterogenousArray() { - FunctionTestUtil.assertResultError(anyFunction.invoke(new Object[]{Boolean.FALSE, 1}), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(anyFunction.invoke(new Object[]{Boolean.TRUE, 1}), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(anyFunction.invoke(new Object[]{Boolean.TRUE, null, 1}), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(anyFunction.invoke(new Object[]{Boolean.FALSE, 1}), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(anyFunction.invoke(new Object[]{Boolean.TRUE, 1}), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(anyFunction.invoke(new Object[]{Boolean.TRUE, null, 1}), + InvalidParametersEvent.class); } @Test @@ -115,8 +112,11 @@ void invokeListParamReturnNull() { @Test void invokeListParamTypeHeterogenousArray() { - FunctionTestUtil.assertResultError(anyFunction.invoke(Arrays.asList(Boolean.FALSE, 1)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(anyFunction.invoke(Arrays.asList(Boolean.TRUE, 1)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(anyFunction.invoke(Arrays.asList(Boolean.TRUE, null, 1)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(anyFunction.invoke(Arrays.asList(Boolean.FALSE, 1)), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(anyFunction.invoke(Arrays.asList(Boolean.TRUE, 1)), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(anyFunction.invoke(Arrays.asList(Boolean.TRUE, null, 1)), + InvalidParametersEvent.class); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AppendFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AppendFunctionTest.java index 2a94891f4fa..5298f0be4bc 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AppendFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AppendFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -22,41 +22,42 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class AppendFunctionTest { - private AppendFunction appendFunction; - - @BeforeEach - void setUp() { - appendFunction = new AppendFunction(); - } + private static final AppendFunction appendFunction = AppendFunction.INSTANCE; @Test void invokeInvalidParams() { FunctionTestUtil.assertResultError(appendFunction.invoke((List) null, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(appendFunction.invoke((List) null, new Object[]{}), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(appendFunction.invoke(Collections.emptyList(), null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(appendFunction.invoke((List) null, new Object[]{}), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(appendFunction.invoke(Collections.emptyList(), null), + InvalidParametersEvent.class); } @Test void invokeEmptyParams() { - FunctionTestUtil.assertResultList(appendFunction.invoke(Collections.emptyList(), new Object[]{}), Collections.emptyList()); + FunctionTestUtil.assertResultList(appendFunction.invoke(Collections.emptyList(), new Object[]{}), + Collections.emptyList()); } @Test void invokeAppendNothing() { FunctionTestUtil.assertResultList(appendFunction.invoke(List.of("test"), new Object[]{}), List.of("test")); - FunctionTestUtil.assertResultList(appendFunction.invoke(Arrays.asList("test", "test2"), new Object[]{}), Arrays.asList("test", "test2")); + FunctionTestUtil.assertResultList(appendFunction.invoke(Arrays.asList("test", "test2"), new Object[]{}), + Arrays.asList("test", "test2")); } @Test void invokeAppendSomething() { - FunctionTestUtil.assertResultList(appendFunction.invoke(Collections.emptyList(), new Object[]{"test"}), List.of("test")); - FunctionTestUtil.assertResultList(appendFunction.invoke(List.of("test"), new Object[]{"test2"}), Arrays.asList("test", "test2")); - FunctionTestUtil.assertResultList(appendFunction.invoke(List.of("test"), new Object[]{"test2", "test3"}), Arrays.asList("test", "test2", "test3")); + FunctionTestUtil.assertResultList(appendFunction.invoke(Collections.emptyList(), new Object[]{"test"}), + List.of("test")); + FunctionTestUtil.assertResultList(appendFunction.invoke(List.of("test"), new Object[]{"test2"}), + Arrays.asList("test", "test2")); + FunctionTestUtil.assertResultList(appendFunction.invoke(List.of("test"), new Object[]{"test2", "test3"}), + Arrays.asList("test", "test2", "test3")); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CeilingFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CeilingFunctionTest.java index 386b053ddda..b7eaea5785e 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CeilingFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CeilingFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -20,25 +20,21 @@ import java.math.BigDecimal; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class CeilingFunctionTest { - private CeilingFunction ceilingFunction; - - @BeforeEach - void setUp() { - ceilingFunction = new CeilingFunction(); - } + private static final CeilingFunction ceilingFunction = CeilingFunction.INSTANCE; @Test void invokeNull() { FunctionTestUtil.assertResultError(ceilingFunction.invoke(null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(ceilingFunction.invoke((BigDecimal) null, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(ceilingFunction.invoke((BigDecimal) null, null), + InvalidParametersEvent.class); FunctionTestUtil.assertResultError(ceilingFunction.invoke(BigDecimal.ONE, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(ceilingFunction.invoke(null, BigDecimal.ONE), InvalidParametersEvent.class); } + FunctionTestUtil.assertResultError(ceilingFunction.invoke(null, BigDecimal.ONE), InvalidParametersEvent.class); + } @Test void invokeZero() { @@ -47,17 +43,21 @@ void invokeZero() { @Test void invokePositive() { - FunctionTestUtil.assertResultBigDecimal(ceilingFunction.invoke(BigDecimal.valueOf(10.2)), BigDecimal.valueOf(11)); + FunctionTestUtil.assertResultBigDecimal(ceilingFunction.invoke(BigDecimal.valueOf(10.2)), + BigDecimal.valueOf(11)); } @Test void invokeNegative() { - FunctionTestUtil.assertResultBigDecimal(ceilingFunction.invoke(BigDecimal.valueOf(-10.2)), BigDecimal.valueOf(-10)); + FunctionTestUtil.assertResultBigDecimal(ceilingFunction.invoke(BigDecimal.valueOf(-10.2)), + BigDecimal.valueOf(-10)); } @Test void invokeOutRangeScale() { - FunctionTestUtil.assertResultError(ceilingFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(ceilingFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(ceilingFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(ceilingFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)) + , InvalidParametersEvent.class); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CodeFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CodeFunctionTest.java index acafaed37eb..0bdbd97ba21 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CodeFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CodeFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -33,7 +33,6 @@ import java.util.List; import java.util.Map; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.Range; import org.kie.dmn.feel.runtime.functions.extended.CodeFunction; @@ -41,12 +40,7 @@ class CodeFunctionTest { - private CodeFunction codeFunction; - - @BeforeEach - void setUp() { - codeFunction = new CodeFunction(); - } + private static final CodeFunction codeFunction = CodeFunction.INSTANCE; @Test void invokeNull() { @@ -72,31 +66,36 @@ void invokeLocalDate() { @Test void invokeLocalTime() { final LocalTime localTime = LocalTime.now(); - FunctionTestUtil.assertResult(codeFunction.invoke(localTime), "time( \"" + TimeFunction.FEEL_TIME.format(localTime) + "\" )"); + FunctionTestUtil.assertResult(codeFunction.invoke(localTime), + "time( \"" + TimeFunction.FEEL_TIME.format(localTime) + "\" )"); } @Test void invokeOffsetTime() { final OffsetTime offsetTime = OffsetTime.now(); - FunctionTestUtil.assertResult(codeFunction.invoke(offsetTime), "time( \"" + TimeFunction.FEEL_TIME.format(offsetTime) + "\" )"); + FunctionTestUtil.assertResult(codeFunction.invoke(offsetTime), + "time( \"" + TimeFunction.FEEL_TIME.format(offsetTime) + "\" )"); } @Test void invokeLocalDateTime() { final LocalDateTime localDateTime = LocalDateTime.now(); - FunctionTestUtil.assertResult(codeFunction.invoke(localDateTime), "date and time( \"" + DateAndTimeFunction.FEEL_DATE_TIME.format(localDateTime) + "\" )"); + FunctionTestUtil.assertResult(codeFunction.invoke(localDateTime), + "date and time( \"" + DateAndTimeFunction.FEEL_DATE_TIME.format(localDateTime) + "\" )"); } @Test void invokeOffsetDateTime() { final OffsetDateTime offsetDateTime = OffsetDateTime.now(); - FunctionTestUtil.assertResult(codeFunction.invoke(offsetDateTime), "date and time( \"" + DateAndTimeFunction.FEEL_DATE_TIME.format(offsetDateTime) + "\" )"); + FunctionTestUtil.assertResult(codeFunction.invoke(offsetDateTime), + "date and time( \"" + DateAndTimeFunction.FEEL_DATE_TIME.format(offsetDateTime) + "\" )"); } @Test void invokeZonedDateTime() { final ZonedDateTime zonedDateTime = ZonedDateTime.now(); - FunctionTestUtil.assertResult(codeFunction.invoke(zonedDateTime), "date and time( \"" + DateAndTimeFunction.REGION_DATETIME_FORMATTER.format(zonedDateTime) + "\" )"); + FunctionTestUtil.assertResult(codeFunction.invoke(zonedDateTime), + "date and time( \"" + DateAndTimeFunction.REGION_DATETIME_FORMATTER.format(zonedDateTime) + "\" )"); } @Test @@ -140,8 +139,10 @@ void invokeDurationNanosMillis() { FunctionTestUtil.assertResult(codeFunction.invoke(Duration.ofNanos(10000)), "duration( \"PT0.00001S\" )"); FunctionTestUtil.assertResult(codeFunction.invoke(Duration.ofNanos(10025)), "duration( \"PT0.000010025S\" )"); FunctionTestUtil.assertResult(codeFunction.invoke(Duration.ofMillis(1500)), "duration( \"PT1.5S\" )"); - FunctionTestUtil.assertResult(codeFunction.invoke(Duration.ofMillis(90061025)), "duration( \"P1DT1H1M1.025S\" )"); - FunctionTestUtil.assertResult(codeFunction.invoke(Duration.ofMillis(-90061025)), "duration( \"-P1DT1H1M1.025S\" )"); + FunctionTestUtil.assertResult(codeFunction.invoke(Duration.ofMillis(90061025)), "duration( \"P1DT1H1M1.025S\"" + + " )"); + FunctionTestUtil.assertResult(codeFunction.invoke(Duration.ofMillis(-90061025)), "duration( \"-P1DT1H1M1" + + ".025S\" )"); } @Test @@ -218,6 +219,7 @@ void invokeContextNonEmpty() { contextMap.put("key1", "value1"); contextMap.put("key2", childContextMap); - FunctionTestUtil.assertResult(codeFunction.invoke(contextMap), "{ key1 : \"value1\", key2 : { childKey1 : \"childValue1\" } }"); + FunctionTestUtil.assertResult(codeFunction.invoke(contextMap), "{ key1 : \"value1\", key2 : { childKey1 : " + + "\"childValue1\" } }"); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ComposingDifferentFunctionsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ComposingDifferentFunctionsTest.java index 9da075adf9d..4914f64143d 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ComposingDifferentFunctionsTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ComposingDifferentFunctionsTest.java @@ -27,25 +27,16 @@ import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalQueries; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; class ComposingDifferentFunctionsTest { - private DateAndTimeFunction dateTimeFunction; - private DateFunction dateFunction; - private TimeFunction timeFunction; - private StringFunction stringFunction; - - @BeforeEach - void setUp() { - dateTimeFunction = new DateAndTimeFunction(); - dateFunction = new DateFunction(); - timeFunction = new TimeFunction(); - stringFunction = new StringFunction(); - } + private static final DateAndTimeFunction dateTimeFunction = DateAndTimeFunction.INSTANCE; + private static final DateFunction dateFunction = DateFunction.INSTANCE; + private static final TimeFunction timeFunction = TimeFunction.INSTANCE; + private static final StringFunction stringFunction = StringFunction.INSTANCE; @Test void composite1() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ConcatenateFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ConcatenateFunctionTest.java index 9687ba46580..e7b9e39d74f 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ConcatenateFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ConcatenateFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -22,18 +22,12 @@ import java.util.Arrays; import java.util.Collections; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class ConcatenateFunctionTest { - private ConcatenateFunction concatenateFunction; - - @BeforeEach - void setUp() { - concatenateFunction = new ConcatenateFunction(); - } + private static final ConcatenateFunction concatenateFunction = ConcatenateFunction.INSTANCE; @Test void invokeNull() { @@ -47,18 +41,21 @@ void invokeEmptyArray() { @Test void invokeArrayWithNull() { - FunctionTestUtil.assertResultError(concatenateFunction.invoke(new Object[]{null}), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(concatenateFunction.invoke(new Object[]{1, null}), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(concatenateFunction.invoke(new Object[]{null}), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(concatenateFunction.invoke(new Object[]{1, null}), + InvalidParametersEvent.class); } @Test void invokeArrayWithList() { - FunctionTestUtil.assertResultList(concatenateFunction.invoke(new Object[]{"test", 2, Arrays.asList(2, 3)}), Arrays.asList("test", 2, 2, 3)); + FunctionTestUtil.assertResultList(concatenateFunction.invoke(new Object[]{"test", 2, Arrays.asList(2, 3)}), + Arrays.asList("test", 2, 2, 3)); } @Test void invokeArrayWithoutList() { - FunctionTestUtil.assertResultList(concatenateFunction.invoke(new Object[]{"test", 2, BigDecimal.valueOf(25.3)}), Arrays.asList("test", 2, BigDecimal.valueOf(25.3))); + FunctionTestUtil.assertResultList(concatenateFunction.invoke(new Object[]{"test", 2, + BigDecimal.valueOf(25.3)}), Arrays.asList("test", 2, BigDecimal.valueOf(25.3))); } - } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ContainsFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ContainsFunctionTest.java index 23c0e182475..31349953d4a 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ContainsFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ContainsFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -18,18 +18,12 @@ */ package org.kie.dmn.feel.runtime.functions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class ContainsFunctionTest { - private ContainsFunction containsFunction; - - @BeforeEach - void setUp() { - containsFunction = new ContainsFunction(); - } + private static final ContainsFunction containsFunction = ContainsFunction.INSTANCE; @Test void invokeParamsNull() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/ContextFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ContextFunctionTest.java similarity index 82% rename from kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/ContextFunctionTest.java rename to kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ContextFunctionTest.java index e4909074e77..7078e33b65c 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/ContextFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ContextFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -16,26 +16,18 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; +package org.kie.dmn.feel.runtime.functions; import java.util.List; import java.util.Map; +import org.junit.jupiter.api.Test; +import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; + class ContextFunctionTest { - private ContextFunction contextFunction; - private record ContextEntry(String key, Object value) {} + private static final ContextFunction contextFunction = ContextFunction.INSTANCE; - @BeforeEach - void setUp() { - contextFunction = new ContextFunction(); - } @Test void invokeListNull() { @@ -47,7 +39,7 @@ void invokeContainsNoKeyAndValue() { FunctionTestUtil.assertResultError(contextFunction.invoke(List.of( Map.of("test", "name", "value", "John Doe"), Map.of("key", "name", "test", "John Doe"))), InvalidParametersEvent.class); -} + } @Test void invokeDuplicateKey() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CountFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CountFunctionTest.java index b743b549e42..aa9591e5b6f 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CountFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CountFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -23,18 +23,12 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class CountFunctionTest { - private CountFunction countFunction; - - @BeforeEach - void setUp() { - countFunction = new CountFunction(); - } + private static final CountFunction countFunction = CountFunction.INSTANCE; @Test void invokeParamListNull() { @@ -65,5 +59,4 @@ void invokeParamArrayEmpty() { void invokeParamArrayNonEmpty() { FunctionTestUtil.assertResult(countFunction.invoke(new Object[]{1, 2, "test"}), BigDecimal.valueOf(3)); } - } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DateTimeFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DateTimeFunctionTest.java index f44aa68c5e0..ac8cd20a950 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DateTimeFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DateTimeFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -27,18 +27,12 @@ import java.time.ZonedDateTime; import java.time.temporal.Temporal; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class DateTimeFunctionTest { - private DateAndTimeFunction dateTimeFunction; - - @BeforeEach - void setUp() { - dateTimeFunction = new DateAndTimeFunction(); - } + private static final DateAndTimeFunction dateTimeFunction = DateAndTimeFunction.INSTANCE; @Test void invokeParamStringNull() { @@ -54,22 +48,33 @@ void invokeParamStringNotDateOrTime() { @Test void invokeParamStringDateTime() { - FunctionTestUtil.assertResult(dateTimeFunction.invoke("2017-09-07T10:20:30"), LocalDateTime.of(2017, 9, 7, 10, 20, 30)); - FunctionTestUtil.assertResult(dateTimeFunction.invoke("99999-12-31T11:22:33"), LocalDateTime.of(99999, 12, 31, 11, 22, 33)); + FunctionTestUtil.assertResult(dateTimeFunction.invoke("2017-09-07T10:20:30"), LocalDateTime.of(2017, 9, 7, 10 + , 20, 30)); + FunctionTestUtil.assertResult(dateTimeFunction.invoke("99999-12-31T11:22:33"), LocalDateTime.of(99999, 12, 31 + , 11, 22, 33)); } @Test void invokeParamStringDateTimeZoned() { - FunctionTestUtil.assertResult(dateTimeFunction.invoke("2011-12-31T10:15:30@Europe/Paris"), ZonedDateTime.of(2011, 12, 31, 10, 15, 30, 0, ZoneId.of("Europe/Paris"))); - FunctionTestUtil.assertResult(dateTimeFunction.invoke("2011-12-31T10:15:30.987@Europe/Paris"), ZonedDateTime.of(2011, 12, 31, 10, 15, 30, 987_000_000, ZoneId.of("Europe/Paris"))); - FunctionTestUtil.assertResult(dateTimeFunction.invoke("2011-12-31T10:15:30.123456789@Europe/Paris"), ZonedDateTime.of(2011, 12, 31, 10, 15, 30, 123_456_789, ZoneId.of("Europe/Paris"))); - FunctionTestUtil.assertResult(dateTimeFunction.invoke("999999999-12-31T23:59:59.999999999@Europe/Paris"), ZonedDateTime.of(999999999, 12, 31, 23, 59, 59, 999_999_999, ZoneId.of("Europe/Paris"))); + FunctionTestUtil.assertResult(dateTimeFunction.invoke("2011-12-31T10:15:30@Europe/Paris"), + ZonedDateTime.of(2011, 12, 31, 10, 15, 30, 0, ZoneId.of("Europe/Paris"))); + FunctionTestUtil.assertResult(dateTimeFunction.invoke("2011-12-31T10:15:30.987@Europe/Paris"), + ZonedDateTime.of(2011, 12, 31, 10, 15, 30, 987_000_000, ZoneId.of("Europe/Paris" + ))); + FunctionTestUtil.assertResult(dateTimeFunction.invoke("2011-12-31T10:15:30.123456789@Europe/Paris"), + ZonedDateTime.of(2011, 12, 31, 10, 15, 30, 123_456_789, ZoneId.of("Europe/Paris" + ))); + FunctionTestUtil.assertResult(dateTimeFunction.invoke("999999999-12-31T23:59:59.999999999@Europe/Paris"), + ZonedDateTime.of(999999999, 12, 31, 23, 59, 59, 999_999_999, ZoneId.of("Europe/Paris"))); } @Test void invokeParamStringDateOffset() { - FunctionTestUtil.assertResult(dateTimeFunction.invoke("2017-12-31T23:59:59.999999999+02:00"), ZonedDateTime.of(2017, 12, 31, 23, 59, 59, 999_999_999, ZoneOffset.of("+02:00"))); - FunctionTestUtil.assertResult(dateTimeFunction.invoke("-999999999-12-31T23:59:59.999999999+02:00"), ZonedDateTime.of(-999999999, 12, 31, 23, 59, 59, 999_999_999, ZoneOffset.of("+02:00"))); + FunctionTestUtil.assertResult(dateTimeFunction.invoke("2017-12-31T23:59:59.999999999+02:00"), + ZonedDateTime.of(2017, 12, 31, 23, 59, 59, 999_999_999, ZoneOffset.of("+02:00"))); + FunctionTestUtil.assertResult(dateTimeFunction.invoke("-999999999-12-31T23:59:59.999999999+02:00"), + ZonedDateTime.of(-999999999, 12, 31, 23, 59, 59, 999_999_999, ZoneOffset.of( + "+02:00"))); } @Test @@ -79,14 +84,19 @@ void invokeParamStringDate() { @Test void invokeParamTemporalNulls() { - FunctionTestUtil.assertResultError(dateTimeFunction.invoke((Temporal) null, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(dateTimeFunction.invoke(null, LocalTime.of(10, 6, 20)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(dateTimeFunction.invoke(LocalDate.of(2017, 6, 12), null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(dateTimeFunction.invoke((Temporal) null, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(dateTimeFunction.invoke(null, LocalTime.of(10, 6, 20)), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(dateTimeFunction.invoke(LocalDate.of(2017, 6, 12), null), + InvalidParametersEvent.class); } @Test void invokeParamTemporalWrongTemporal() { - // reminder: 1st parameter accordingly to FEEL Spec Table 58 "date is a date or date time [...] creates a date time from the given date (ignoring any time component)" [that means ignoring any TZ from `date` parameter, too] + // reminder: 1st parameter accordingly to FEEL Spec Table 58 "date is a date or date time [...] creates a + // date time from the given date (ignoring any time component)" [that means ignoring any TZ from `date` + // parameter, too] FunctionTestUtil.assertResultError( dateTimeFunction.invoke( LocalDate.of(2017, 6, 12), diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DecimalFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DecimalFunctionTest.java index 8e335cf1d1d..d56b213393a 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DecimalFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DecimalFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -20,54 +20,56 @@ import java.math.BigDecimal; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class DecimalFunctionTest { - private DecimalFunction decimalFunction; - - @BeforeEach - void setUp() { - decimalFunction = new DecimalFunction(); - } + private static final DecimalFunction decimalFunction = DecimalFunction.INSTANCE; @Test void invokeNull() { - FunctionTestUtil.assertResultError(decimalFunction.invoke((BigDecimal) null, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(decimalFunction.invoke((BigDecimal) null, null), + InvalidParametersEvent.class); FunctionTestUtil.assertResultError(decimalFunction.invoke(BigDecimal.ONE, null), InvalidParametersEvent.class); FunctionTestUtil.assertResultError(decimalFunction.invoke(null, BigDecimal.ONE), InvalidParametersEvent.class); } @Test void invokeRoundingUp() { - FunctionTestUtil.assertResult(decimalFunction.invoke(BigDecimal.valueOf(10.27), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + FunctionTestUtil.assertResult(decimalFunction.invoke(BigDecimal.valueOf(10.27), BigDecimal.ONE), + BigDecimal.valueOf(10.3)); } @Test void invokeRoundingDown() { - FunctionTestUtil.assertResult(decimalFunction.invoke(BigDecimal.valueOf(10.24), BigDecimal.ONE), BigDecimal.valueOf(10.2)); + FunctionTestUtil.assertResult(decimalFunction.invoke(BigDecimal.valueOf(10.24), BigDecimal.ONE), + BigDecimal.valueOf(10.2)); } @Test void invokeRoundingEven() { - FunctionTestUtil.assertResult(decimalFunction.invoke(BigDecimal.valueOf(10.25), BigDecimal.ONE), BigDecimal.valueOf(10.2)); + FunctionTestUtil.assertResult(decimalFunction.invoke(BigDecimal.valueOf(10.25), BigDecimal.ONE), + BigDecimal.valueOf(10.2)); } @Test void invokeRoundingOdd() { - FunctionTestUtil.assertResult(decimalFunction.invoke(BigDecimal.valueOf(10.35), BigDecimal.ONE), BigDecimal.valueOf(10.4)); + FunctionTestUtil.assertResult(decimalFunction.invoke(BigDecimal.valueOf(10.35), BigDecimal.ONE), + BigDecimal.valueOf(10.4)); } @Test void invokeLargerScale() { - FunctionTestUtil.assertResult(decimalFunction.invoke(BigDecimal.valueOf(10.123456789), BigDecimal.valueOf(6)), BigDecimal.valueOf(10.123457)); + FunctionTestUtil.assertResult(decimalFunction.invoke(BigDecimal.valueOf(10.123456789), BigDecimal.valueOf(6)) + , BigDecimal.valueOf(10.123457)); } @Test void invokeOutRangeScale() { - FunctionTestUtil.assertResultError(decimalFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(decimalFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(decimalFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(decimalFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)) + , InvalidParametersEvent.class); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DistinctValuesFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DistinctValuesFunctionTest.java index 5b3af9101c5..f23c0295244 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DistinctValuesFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DistinctValuesFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -23,18 +23,12 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class DistinctValuesFunctionTest { - private DistinctValuesFunction distinctValuesFunction; - - @BeforeEach - void setUp() { - distinctValuesFunction = new DistinctValuesFunction(); - } + private static final DistinctValuesFunction distinctValuesFunction = DistinctValuesFunction.INSTANCE; @Test void invokeNull() { @@ -57,7 +51,8 @@ void invokeParamArray() { @Test void invokeEmptyList() { - FunctionTestUtil.assertResultList(distinctValuesFunction.invoke(Collections.emptyList()), Collections.emptyList()); + FunctionTestUtil.assertResultList(distinctValuesFunction.invoke(Collections.emptyList()), + Collections.emptyList()); } @Test diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DurationFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DurationFunctionTest.java index b2472333139..83c57f664f1 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DurationFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DurationFunctionTest.java @@ -22,19 +22,13 @@ import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalAmount; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.lang.types.impl.ComparablePeriod; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class DurationFunctionTest { - private DurationFunction durationFunction; - - @BeforeEach - void setUp() { - durationFunction = new DurationFunction(); - } + private static final DurationFunction durationFunction = DurationFunction.INSTANCE; @Test void invokeParamStringNull() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/EndsWithFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/EndsWithFunctionTest.java index a5146d0a54d..a3df90c4b37 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/EndsWithFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/EndsWithFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -18,18 +18,12 @@ */ package org.kie.dmn.feel.runtime.functions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class EndsWithFunctionTest { - private EndsWithFunction endsWithFunction; - - @BeforeEach - void setUp() { - endsWithFunction = new EndsWithFunction(); - } + private static final EndsWithFunction endsWithFunction = EndsWithFunction.INSTANCE; @Test void invokeParamsNull() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FlattenFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FlattenFunctionTest.java index 3b9056e65e9..86b5bc900c1 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FlattenFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FlattenFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -22,18 +22,12 @@ import java.util.Arrays; import java.util.Collections; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class FlattenFunctionTest { - private FlattenFunction flattenFunction; - - @BeforeEach - void setUp() { - flattenFunction = new FlattenFunction(); - } + private static final FlattenFunction flattenFunction = FlattenFunction.INSTANCE; @Test void invokeNull() { @@ -42,23 +36,27 @@ void invokeNull() { @Test void invokeParamNotCollection() { - FunctionTestUtil.assertResult(flattenFunction.invoke(BigDecimal.valueOf(10.2)), Collections.singletonList(BigDecimal.valueOf(10.2))); + FunctionTestUtil.assertResult(flattenFunction.invoke(BigDecimal.valueOf(10.2)), + Collections.singletonList(BigDecimal.valueOf(10.2))); FunctionTestUtil.assertResult(flattenFunction.invoke("test"), Collections.singletonList("test")); } @Test void invokeParamCollection() { FunctionTestUtil.assertResult(flattenFunction.invoke(Arrays.asList("test", 1, 2)), Arrays.asList("test", 1, 2)); - FunctionTestUtil.assertResult(flattenFunction.invoke(Arrays.asList("test", 1, 2, Arrays.asList(3, 4))), Arrays.asList("test", 1, 2, 3, 4)); - FunctionTestUtil.assertResult(flattenFunction.invoke(Arrays.asList("test", 1, 2, Arrays.asList(1, 2))), Arrays.asList("test", 1, 2, 1, 2)); + FunctionTestUtil.assertResult(flattenFunction.invoke(Arrays.asList("test", 1, 2, Arrays.asList(3, 4))), + Arrays.asList("test", 1, 2, 3, 4)); + FunctionTestUtil.assertResult(flattenFunction.invoke(Arrays.asList("test", 1, 2, Arrays.asList(1, 2))), + Arrays.asList("test", 1, 2, 1, 2)); FunctionTestUtil.assertResult( flattenFunction.invoke( Arrays.asList("test", 1, Arrays.asList(BigDecimal.ZERO, 3), 2, Arrays.asList(1, 2))), - Arrays.asList("test", 1, BigDecimal.ZERO, 3, 2, 1, 2)); + Arrays.asList("test", 1, BigDecimal.ZERO, 3, 2, 1, 2)); FunctionTestUtil.assertResult( flattenFunction.invoke( - Arrays.asList("test", 1, Arrays.asList(Arrays.asList(10, 15), BigDecimal.ZERO, 3), 2, Arrays.asList(1, 2))), + Arrays.asList("test", 1, Arrays.asList(Arrays.asList(10, 15), BigDecimal.ZERO, 3), 2, + Arrays.asList(1, 2))), Arrays.asList("test", 1, 10, 15, BigDecimal.ZERO, 3, 2, 1, 2)); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FloorFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FloorFunctionTest.java index bf84075681a..739dc196e38 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FloorFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FloorFunctionTest.java @@ -20,18 +20,12 @@ import java.math.BigDecimal; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class FloorFunctionTest { - private FloorFunction floorFunction; - - @BeforeEach - void setUp() { - floorFunction = new FloorFunction(); - } + private static final FloorFunction floorFunction = FloorFunction.INSTANCE; @Test void invokeNull() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/IndexOfFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/IndexOfFunctionTest.java index 3e5a9e00089..9317907bf9b 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/IndexOfFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/IndexOfFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -23,18 +23,12 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class IndexOfFunctionTest { - private IndexOfFunction indexOfFunction; - - @BeforeEach - void setUp() { - indexOfFunction = new IndexOfFunction(); - } + private static final IndexOfFunction indexOfFunction = IndexOfFunction.INSTANCE; @Test void invokeListNull() { @@ -44,8 +38,10 @@ void invokeListNull() { @Test void invokeMatchNull() { - FunctionTestUtil.assertResultList(indexOfFunction.invoke(Collections.emptyList(), null), Collections.emptyList()); - FunctionTestUtil.assertResultList(indexOfFunction.invoke(Collections.singletonList("test"), null), Collections.emptyList()); + FunctionTestUtil.assertResultList(indexOfFunction.invoke(Collections.emptyList(), null), + Collections.emptyList()); + FunctionTestUtil.assertResultList(indexOfFunction.invoke(Collections.singletonList("test"), null), + Collections.emptyList()); FunctionTestUtil.assertResultList( indexOfFunction.invoke(Arrays.asList("test", null), null), Collections.singletonList(BigDecimal.valueOf(2))); @@ -62,7 +58,8 @@ void invokeMatchNull() { @Test void invokeBigDecimal() { - FunctionTestUtil.assertResult(indexOfFunction.invoke(Arrays.asList("test", null, 12), BigDecimal.valueOf(12)), Collections.emptyList()); + FunctionTestUtil.assertResult(indexOfFunction.invoke(Arrays.asList("test", null, 12), BigDecimal.valueOf(12)) + , Collections.emptyList()); FunctionTestUtil.assertResult( indexOfFunction.invoke(Arrays.asList("test", null, BigDecimal.valueOf(12)), BigDecimal.valueOf(12)), Collections.singletonList(BigDecimal.valueOf(3))); @@ -80,12 +77,13 @@ void invokeBigDecimal() { @Test void invokeMatchNotNull() { - FunctionTestUtil.assertResult(indexOfFunction.invoke(Arrays.asList("test", null, 12), "testttt"), Collections.emptyList()); + FunctionTestUtil.assertResult(indexOfFunction.invoke(Arrays.asList("test", null, 12), "testttt"), + Collections.emptyList()); FunctionTestUtil.assertResult( indexOfFunction.invoke(Arrays.asList("test", null, BigDecimal.valueOf(12)), "test"), Collections.singletonList(BigDecimal.valueOf(1))); FunctionTestUtil.assertResult( - indexOfFunction.invoke(Arrays.asList("test", null, "test"),"test"), + indexOfFunction.invoke(Arrays.asList("test", null, "test"), "test"), Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(3))); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/InsertBeforeFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/InsertBeforeFunctionTest.java index a8ef326d606..380b57ffe60 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/InsertBeforeFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/InsertBeforeFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -22,70 +22,80 @@ import java.util.Arrays; import java.util.Collections; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class InsertBeforeFunctionTest { - private InsertBeforeFunction insertBeforeFunction; - - @BeforeEach - void setUp() { - insertBeforeFunction = new InsertBeforeFunction(); - } + private static final InsertBeforeFunction insertBeforeFunction = InsertBeforeFunction.INSTANCE; @Test void invokeListNull() { - FunctionTestUtil.assertResultError(insertBeforeFunction.invoke(null, BigDecimal.ZERO, new Object()), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(insertBeforeFunction.invoke(null, BigDecimal.ZERO, new Object()), + InvalidParametersEvent.class); } @Test void invokePositionNull() { - FunctionTestUtil.assertResultError(insertBeforeFunction.invoke(Collections.emptyList(), null, new Object()), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(insertBeforeFunction.invoke(Collections.emptyList(), null, new Object()), + InvalidParametersEvent.class); } @Test void invokeListPositionNull() { - FunctionTestUtil.assertResultError(insertBeforeFunction.invoke(null, null, new Object()), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(insertBeforeFunction.invoke(null, null, new Object()), + InvalidParametersEvent.class); } @Test void invokePositionZero() { - FunctionTestUtil.assertResultError(insertBeforeFunction.invoke(Collections.emptyList(), BigDecimal.ZERO, new Object()), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(insertBeforeFunction.invoke(Collections.emptyList(), BigDecimal.ZERO, + new Object()), InvalidParametersEvent.class); } @Test void invokePositionOutsideListBounds() { - FunctionTestUtil.assertResultError(insertBeforeFunction.invoke(Collections.emptyList(), BigDecimal.ONE, new Object()), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(insertBeforeFunction.invoke(Collections.emptyList(), BigDecimal.valueOf(-1), new Object()), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(insertBeforeFunction.invoke(Collections.emptyList(), BigDecimal.ONE, + new Object()), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(insertBeforeFunction.invoke(Collections.emptyList(), + BigDecimal.valueOf(-1), new Object()), + InvalidParametersEvent.class); } @Test void invokeInsertIntoEmptyList() { - // According to spec, inserting into empty list shouldn't be possible. For inserting into empty list, user should use append() function. - FunctionTestUtil.assertResultError(insertBeforeFunction.invoke(Collections.emptyList(), BigDecimal.ONE, null), InvalidParametersEvent.class); + // According to spec, inserting into empty list shouldn't be possible. For inserting into empty list, user + // should use append() function. + FunctionTestUtil.assertResultError(insertBeforeFunction.invoke(Collections.emptyList(), BigDecimal.ONE, null) + , InvalidParametersEvent.class); } @Test void invokePositionPositive() { - FunctionTestUtil.assertResult(insertBeforeFunction.invoke(Collections.singletonList("test"), BigDecimal.ONE, null), Arrays.asList(null, "test")); + FunctionTestUtil.assertResult(insertBeforeFunction.invoke(Collections.singletonList("test"), BigDecimal.ONE, + null), Arrays.asList(null, "test")); FunctionTestUtil.assertResult( - insertBeforeFunction.invoke(Arrays.asList("test", null, BigDecimal.ZERO), BigDecimal.valueOf(2), "testtt"), + insertBeforeFunction.invoke(Arrays.asList("test", null, BigDecimal.ZERO), BigDecimal.valueOf(2), + "testtt"), Arrays.asList("test", "testtt", null, BigDecimal.ZERO)); FunctionTestUtil.assertResult( - insertBeforeFunction.invoke(Arrays.asList("test", null, BigDecimal.ZERO), BigDecimal.valueOf(3), "testtt"), + insertBeforeFunction.invoke(Arrays.asList("test", null, BigDecimal.ZERO), BigDecimal.valueOf(3), + "testtt"), Arrays.asList("test", null, "testtt", BigDecimal.ZERO)); } @Test void invokePositionNegative() { - FunctionTestUtil.assertResult(insertBeforeFunction.invoke(Collections.singletonList("test"), BigDecimal.valueOf(-1), null), Arrays.asList(null, "test")); + FunctionTestUtil.assertResult(insertBeforeFunction.invoke(Collections.singletonList("test"), + BigDecimal.valueOf(-1), null), Arrays.asList(null, + "test")); FunctionTestUtil.assertResult( - insertBeforeFunction.invoke(Arrays.asList("test", null, BigDecimal.ZERO), BigDecimal.valueOf(-2), "testtt"), + insertBeforeFunction.invoke(Arrays.asList("test", null, BigDecimal.ZERO), BigDecimal.valueOf(-2), + "testtt"), Arrays.asList("test", "testtt", null, BigDecimal.ZERO)); FunctionTestUtil.assertResult( - insertBeforeFunction.invoke(Arrays.asList("test", null, BigDecimal.ZERO), BigDecimal.valueOf(-3), "testtt"), + insertBeforeFunction.invoke(Arrays.asList("test", null, BigDecimal.ZERO), BigDecimal.valueOf(-3), + "testtt"), Arrays.asList("testtt", "test", null, BigDecimal.ZERO)); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ListContainsFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ListContainsFunctionTest.java index 318bac32367..ac96e85d3f1 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ListContainsFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ListContainsFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -23,23 +23,19 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class ListContainsFunctionTest { - private ListContainsFunction listContainsFunction; - - @BeforeEach - void setUp() { - listContainsFunction = new ListContainsFunction(); - } + private static final ListContainsFunction listContainsFunction = ListContainsFunction.INSTANCE; @Test void invokeListNull() { - FunctionTestUtil.assertResultError(listContainsFunction.invoke((List) null, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(listContainsFunction.invoke(null, new Object()), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(listContainsFunction.invoke((List) null, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(listContainsFunction.invoke(null, new Object()), + InvalidParametersEvent.class); } @Test @@ -67,6 +63,7 @@ void invokeContains() { void invokeNotContains() { FunctionTestUtil.assertResult(listContainsFunction.invoke(Arrays.asList(1, 2, "test"), "testtt"), false); FunctionTestUtil.assertResult(listContainsFunction.invoke(Arrays.asList(1, 2, "test"), 3), false); - FunctionTestUtil.assertResult(listContainsFunction.invoke(Arrays.asList(1, 2, "test"), BigDecimal.valueOf(3)), false); + FunctionTestUtil.assertResult(listContainsFunction.invoke(Arrays.asList(1, 2, "test"), BigDecimal.valueOf(3)) + , false); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java index cdbbd3c6e24..0f105f622d9 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -18,18 +18,12 @@ */ package org.kie.dmn.feel.runtime.functions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class MatchesFunctionTest { - private MatchesFunction matchesFunction; - - @BeforeEach - void setUp() { - matchesFunction = new MatchesFunction(); - } + private final static MatchesFunction matchesFunction = MatchesFunction.INSTANCE; @Test void invokeNull() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MaxFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MaxFunctionTest.java index 561074eb9c5..ddc5e1f81b9 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MaxFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MaxFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -27,19 +27,13 @@ import java.util.List; import java.util.function.Predicate; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.lang.types.impl.ComparablePeriod; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class MaxFunctionTest { - private MaxFunction maxFunction; - - @BeforeEach - void setUp() { - maxFunction = new MaxFunction(); - } + private static final MaxFunction maxFunction = MaxFunction.INSTANCE; @Test void invokeNullList() { @@ -53,7 +47,8 @@ void invokeEmptyList() { @Test void invokeListWithHeterogenousTypes() { - FunctionTestUtil.assertResultError(maxFunction.invoke(Arrays.asList(1, "test", BigDecimal.valueOf(10.2))), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(maxFunction.invoke(Arrays.asList(1, "test", BigDecimal.valueOf(10.2))), + InvalidParametersEvent.class); } @Test @@ -79,12 +74,18 @@ void invokeListOfChronoPeriods() { final ChronoPeriod p2Period = Period.parse("P1M"); final ChronoPeriod p2Comparable = ComparablePeriod.parse("P1M"); Predicate assertion = i -> i.get(ChronoUnit.YEARS) == 1 && i.get(ChronoUnit.MONTHS) == 0; - FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(Collections.singletonList(p1Period)), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(Collections.singletonList(p1Comparable)), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(Arrays.asList(p1Period, p2Period)), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(Arrays.asList(p1Comparable, p2Period)), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(Arrays.asList(p1Period, p2Comparable)), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(Arrays.asList(p1Comparable, p2Comparable)), ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(Collections.singletonList(p1Period)), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(Collections.singletonList(p1Comparable)), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(Arrays.asList(p1Period, p2Period)), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(Arrays.asList(p1Comparable, p2Period)), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(Arrays.asList(p1Period, p2Comparable)), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(Arrays.asList(p1Comparable, p2Comparable)), + ChronoPeriod.class, assertion); } @Test @@ -99,7 +100,8 @@ void invokeEmptyArray() { @Test void invokeArrayWithHeterogenousTypes() { - FunctionTestUtil.assertResultError(maxFunction.invoke(new Object[]{1, "test", BigDecimal.valueOf(10.2)}), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(maxFunction.invoke(new Object[]{1, "test", BigDecimal.valueOf(10.2)}), + InvalidParametersEvent.class); } @Test @@ -125,11 +127,17 @@ void invokeArrayOfChronoPeriods() { final ChronoPeriod p2Period = Period.parse("P1M"); final ChronoPeriod p2Comparable = ComparablePeriod.parse("P1M"); Predicate assertion = i -> i.get(ChronoUnit.YEARS) == 1 && i.get(ChronoUnit.MONTHS) == 0; - FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(new Object[]{p1Period}), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(new Object[]{p1Comparable}), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(new Object[]{p1Period, p2Period}), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(new Object[]{p1Comparable, p2Period}), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(new Object[]{p1Period, p2Comparable}), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(new Object[]{p1Comparable, p2Comparable}), ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(new Object[]{p1Period}), ChronoPeriod.class, + assertion); + FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(new Object[]{p1Comparable}), ChronoPeriod.class, + assertion); + FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(new Object[]{p1Period, p2Period}), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(new Object[]{p1Comparable, p2Period}), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(new Object[]{p1Period, p2Comparable}), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(maxFunction.invoke(new Object[]{p1Comparable, p2Comparable}), + ChronoPeriod.class, assertion); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MeanFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MeanFunctionTest.java index 9a6892a6648..368fe628d86 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MeanFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MeanFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -23,18 +23,12 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class MeanFunctionTest { - private MeanFunction meanFunction; - - @BeforeEach - void setUp() { - meanFunction = new MeanFunction(); - } + private static final MeanFunction meanFunction = MeanFunction.INSTANCE; @Test void invokeNumberNull() { @@ -98,7 +92,8 @@ void invokeListWithIntegers() { @Test void invokeListWithDoubles() { FunctionTestUtil.assertResult(meanFunction.invoke(Arrays.asList(10.0d, 20.0d, 30.0d)), BigDecimal.valueOf(20)); - FunctionTestUtil.assertResult(meanFunction.invoke(Arrays.asList(10.2d, 20.2d, 30.2d)), BigDecimal.valueOf(20.2)); + FunctionTestUtil.assertResult(meanFunction.invoke(Arrays.asList(10.2d, 20.2d, 30.2d)), + BigDecimal.valueOf(20.2)); } @Test diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MinFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MinFunctionTest.java index d41c0e2ccfa..59b1a8634b6 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MinFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MinFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -27,19 +27,13 @@ import java.util.List; import java.util.function.Predicate; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.lang.types.impl.ComparablePeriod; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class MinFunctionTest { - private MinFunction minFunction; - - @BeforeEach - void setUp() { - minFunction = new MinFunction(); - } + private static final MinFunction minFunction = MinFunction.INSTANCE; @Test void invokeNullList() { @@ -53,7 +47,8 @@ void invokeEmptyList() { @Test void invokeListWithHeterogenousTypes() { - FunctionTestUtil.assertResultError(minFunction.invoke(Arrays.asList(1, "test", BigDecimal.valueOf(10.2))), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(minFunction.invoke(Arrays.asList(1, "test", BigDecimal.valueOf(10.2))), + InvalidParametersEvent.class); } @Test @@ -79,12 +74,18 @@ void invokeListOfChronoPeriods() { final ChronoPeriod p2Period = Period.parse("P1M"); final ChronoPeriod p2Comparable = ComparablePeriod.parse("P1M"); Predicate assertion = i -> i.get(ChronoUnit.YEARS) == 0 && i.get(ChronoUnit.MONTHS) == 1; - FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(Collections.singletonList(p2Period)), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(Collections.singletonList(p2Comparable)), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(Arrays.asList(p1Period, p2Period)), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(Arrays.asList(p1Comparable, p2Period)), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(Arrays.asList(p1Period, p2Comparable)), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(Arrays.asList(p1Comparable, p2Comparable)), ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(Collections.singletonList(p2Period)), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(Collections.singletonList(p2Comparable)), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(Arrays.asList(p1Period, p2Period)), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(Arrays.asList(p1Comparable, p2Period)), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(Arrays.asList(p1Period, p2Comparable)), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(Arrays.asList(p1Comparable, p2Comparable)), + ChronoPeriod.class, assertion); } @Test @@ -99,7 +100,8 @@ void invokeEmptyArray() { @Test void invokeArrayWithHeterogenousTypes() { - FunctionTestUtil.assertResultError(minFunction.invoke(new Object[]{1, "test", BigDecimal.valueOf(10.2)}), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(minFunction.invoke(new Object[]{1, "test", BigDecimal.valueOf(10.2)}), + InvalidParametersEvent.class); } @Test @@ -125,11 +127,17 @@ void invokeArrayOfChronoPeriods() { final ChronoPeriod p2Period = Period.parse("P1M"); final ChronoPeriod p2Comparable = ComparablePeriod.parse("P1M"); Predicate assertion = i -> i.get(ChronoUnit.YEARS) == 0 && i.get(ChronoUnit.MONTHS) == 1; - FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[]{p2Period}), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[]{p2Comparable}), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[]{p1Period, p2Period}), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[]{p1Comparable, p2Period}), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[]{p1Period, p2Comparable}), ChronoPeriod.class, assertion); - FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[]{p1Comparable, p2Comparable}), ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[]{p2Period}), ChronoPeriod.class, + assertion); + FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[]{p2Comparable}), ChronoPeriod.class, + assertion); + FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[]{p1Period, p2Period}), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[]{p1Comparable, p2Period}), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[]{p1Period, p2Comparable}), + ChronoPeriod.class, assertion); + FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[]{p1Comparable, p2Comparable}), + ChronoPeriod.class, assertion); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MonthOfYearTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MonthOfYearTest.java index a837fce749a..c77e169f3e4 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MonthOfYearTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MonthOfYearTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -24,25 +24,21 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class MonthOfYearTest { - private MonthOfYearFunction fut; - - @BeforeEach - void setUp() { - fut = MonthOfYearFunction.INSTANCE; - } + private static final MonthOfYearFunction fut = MonthOfYearFunction.INSTANCE; @Test void monthOfYearFunctionTemporalAccessor() { FunctionTestUtil.assertResult(fut.invoke(LocalDate.of(2019, 9, 17)), "September"); FunctionTestUtil.assertResult(fut.invoke(LocalDateTime.of(2019, 9, 17, 0, 0, 0)), "September"); - FunctionTestUtil.assertResult(fut.invoke(OffsetDateTime.of(2019, 9, 17, 0, 0, 0, 0, ZoneOffset.UTC)), "September"); - FunctionTestUtil.assertResult(fut.invoke(ZonedDateTime.of(2019, 9, 17, 0, 0, 0, 0, ZoneOffset.UTC)), "September"); + FunctionTestUtil.assertResult(fut.invoke(OffsetDateTime.of(2019, 9, 17, 0, 0, 0, 0, ZoneOffset.UTC)), + "September"); + FunctionTestUtil.assertResult(fut.invoke(ZonedDateTime.of(2019, 9, 17, 0, 0, 0, 0, ZoneOffset.UTC)), + "September"); FunctionTestUtil.assertResultError(fut.invoke(null), InvalidParametersEvent.class); } } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NotFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NotFunctionTest.java index 1d5aef5cca4..c79073df62c 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NotFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NotFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -20,18 +20,12 @@ import java.math.BigDecimal; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class NotFunctionTest { - private NotFunction notFunction; - - @BeforeEach - void setUp() { - notFunction = new NotFunction(); - } + private static final NotFunction notFunction = NotFunction.INSTANCE; @Test void invokeNull() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NowFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NowFunctionTest.java index adaf8d74819..7bc19492a3c 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NowFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NowFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -21,24 +21,18 @@ import java.time.ZonedDateTime; import java.time.temporal.TemporalAccessor; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.kie.dmn.feel.runtime.functions.extended.NowFunction; import static org.assertj.core.api.Assertions.assertThat; class NowFunctionTest { - private NowFunction nowFunction; - - @BeforeEach - void setUp() { - nowFunction = new NowFunction(); - } + private static final NowFunction nowFunction = NowFunction.INSTANCE; @Test void invoke() { - // The current time that we need to compare will almost never be the same as another one we get for comparison purposes, + // The current time that we need to compare will almost never be the same as another one we get for + // comparison purposes, // because there is some execution between them, so the comparison assertion doesn't make sense. // Note: We cannot guarantee any part of the date to be the same. E.g. in case when the test is executed // at the exact moment when the year is flipped to the next one, we cannot guarantee the year will be the same. @@ -49,5 +43,4 @@ void invoke() { assertThat(result).isNotNull(); assertThat(result).isInstanceOfAny(ZonedDateTime.class); } - } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NumberFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NumberFunctionTest.java index 16c322489e3..0e2ef01e32b 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NumberFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NumberFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -20,18 +20,12 @@ import java.math.BigDecimal; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class NumberFunctionTest { - private NumberFunction numberFunction; - - @BeforeEach - void setUp() { - numberFunction = new NumberFunction(); - } + private static final NumberFunction numberFunction = NumberFunction.INSTANCE; @Test void invokeNull() { @@ -87,8 +81,10 @@ void invokeNumberWithDecimalCharDot() { @Test void invokeNumberWithGroupAndDecimalChar() { FunctionTestUtil.assertResult(numberFunction.invoke("9 876.124", " ", "."), BigDecimal.valueOf(9876.124)); - FunctionTestUtil.assertResult(numberFunction.invoke("9 876 000.124", " ", "."), BigDecimal.valueOf(9876000.124)); - FunctionTestUtil.assertResult(numberFunction.invoke("9.876.000,124", ".", ","), BigDecimal.valueOf(9876000.124)); + FunctionTestUtil.assertResult(numberFunction.invoke("9 876 000.124", " ", "."), + BigDecimal.valueOf(9876000.124)); + FunctionTestUtil.assertResult(numberFunction.invoke("9.876.000,124", ".", ","), + BigDecimal.valueOf(9876000.124)); } @Test diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RangeFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RangeFunctionTest.java similarity index 66% rename from kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RangeFunctionTest.java rename to kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RangeFunctionTest.java index 3fea8c48bdb..08a77bde8ed 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RangeFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RangeFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; import java.math.BigDecimal; import java.time.Duration; @@ -29,7 +29,6 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.lang.ast.AtLiteralNode; import org.kie.dmn.feel.lang.ast.BaseNode; @@ -41,34 +40,29 @@ import org.kie.dmn.feel.lang.types.impl.ComparablePeriod; import org.kie.dmn.feel.runtime.Range; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.FEELFnResult; -import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; import org.kie.dmn.feel.runtime.impl.RangeImpl; import static org.assertj.core.api.Assertions.assertThat; class RangeFunctionTest { - private RangeFunction rangeFunction; - - @BeforeEach - void setUp() { - rangeFunction = new RangeFunction(); - } + private static final RangeFunction rangeFunction = RangeFunction.INSTANCE; @Test void invokeNull() { List from = Arrays.asList(null, " ", "", "[..]"); - from.forEach(it -> FunctionTestUtil.assertResultError(rangeFunction.invoke(it), InvalidParametersEvent.class, it)); + from.forEach(it -> FunctionTestUtil.assertResultError(rangeFunction.invoke(it), InvalidParametersEvent.class, + it)); } @Test void invokeDifferentTypes() { List from = Arrays.asList("[1..\"cheese\"]", - "[1..date(\"1978-09-12\")]", - "[1..date(\"1978-09-12\")]", - "[1..\"upper case(\"aBc4\")\"]"); - from.forEach(it -> FunctionTestUtil.assertResultError(rangeFunction.invoke(it), InvalidParametersEvent.class, it)); + "[1..date(\"1978-09-12\")]", + "[1..date(\"1978-09-12\")]", + "[1..\"upper case(\"aBc4\")\"]"); + from.forEach(it -> FunctionTestUtil.assertResultError(rangeFunction.invoke(it), InvalidParametersEvent.class, + it)); } @Test @@ -81,169 +75,189 @@ void invokeInvalidTypes() { void invoke_LeftNull() { String from = "(..2)"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, null, BigDecimal.valueOf(2), Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, null, BigDecimal.valueOf(2), + Range.RangeBoundary.OPEN), + from); from = "(..\"z\")"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, null, "z", Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, null, "z", Range.RangeBoundary.OPEN), + from); from = "(..\"yz\")"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, null, "yz", Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, null, "yz", Range.RangeBoundary.OPEN), + from); from = "(..date(\"1978-10-13\"))"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, null, LocalDate.of(1978, 10, 13), Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, null, LocalDate.of(1978, 10, 13), + Range.RangeBoundary.OPEN), + from); from = "(..duration(\"P3DT20H14M\"))"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, null, Duration.parse("P3DT20H14M"), Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, null, Duration.parse("P3DT20H14M"), + Range.RangeBoundary.OPEN), + from); from = "(..duration(\"P2Y6M\"))"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, - null, - new ComparablePeriod(Period.parse("P2Y6M")), - Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, + null, + new ComparablePeriod(Period.parse("P2Y6M")), + Range.RangeBoundary.OPEN), + from); } @Test void invoke_RightNull() { String from = "(1..)"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, BigDecimal.ONE, null, Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, BigDecimal.ONE, null, + Range.RangeBoundary.OPEN), + from); from = "(\"a\"..)"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, "a", null, Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, "a", null, Range.RangeBoundary.OPEN), + from); from = "(\"ab\"..)"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, "ab", null, Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, "ab", null, Range.RangeBoundary.OPEN), + from); from = "(date(\"1978-09-12\")..)"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, LocalDate.of(1978, 9, 12), null, Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, LocalDate.of(1978, 9, 12), null, + Range.RangeBoundary.OPEN), + from); from = "(duration(\"P2DT20H14M\")..)"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, Duration.parse("P2DT20H14M"), null, Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, Duration.parse("P2DT20H14M"), null, + Range.RangeBoundary.OPEN), + from); from = "(duration(\"P1Y6M\")..)"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, - new ComparablePeriod(Period.parse("P1Y6M")), - null, - Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, + new ComparablePeriod(Period.parse("P1Y6M")), + null, + Range.RangeBoundary.OPEN), + from); } @Test void invoke_OpenOpenBoundaries() { String from = "(1..2)"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, BigDecimal.ONE, BigDecimal.valueOf(2), Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, BigDecimal.ONE, BigDecimal.valueOf(2), + Range.RangeBoundary.OPEN), + from); from = "(\"a\"..\"z\")"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, "a", "z", Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, "a", "z", Range.RangeBoundary.OPEN), + from); from = "(\"ab\"..\"yz\")"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, "ab", "yz", Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, "ab", "yz", Range.RangeBoundary.OPEN), + from); from = "(date(\"1978-09-12\")..date(\"1978-10-13\"))"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, LocalDate.of(1978, 9, 12), LocalDate.of(1978, 10, 13), Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, LocalDate.of(1978, 9, 12), + LocalDate.of(1978, 10, 13), Range.RangeBoundary.OPEN), + from); from = "(duration(\"P2DT20H14M\")..duration(\"P3DT20H14M\"))"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, Duration.parse("P2DT20H14M"), Duration.parse("P3DT20H14M"), Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, Duration.parse("P2DT20H14M"), + Duration.parse("P3DT20H14M"), Range.RangeBoundary.OPEN), + from); from = "(duration(\"P1Y6M\")..duration(\"P2Y6M\"))"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, - new ComparablePeriod(Period.parse("P1Y6M")), - new ComparablePeriod(Period.parse("P2Y6M")), - Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.OPEN, + new ComparablePeriod(Period.parse("P1Y6M")), + new ComparablePeriod(Period.parse("P2Y6M")), + Range.RangeBoundary.OPEN), + from); } @Test void invoke_OpenClosedBoundaries() { String from = "(1..2]"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, BigDecimal.ONE, BigDecimal.valueOf(2), Range.RangeBoundary.CLOSED), - from); + new RangeImpl(Range.RangeBoundary.OPEN, BigDecimal.ONE, BigDecimal.valueOf(2), + Range.RangeBoundary.CLOSED), + from); from = "(\"a\"..\"z\"]"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, "a", "z", Range.RangeBoundary.CLOSED), - from); + new RangeImpl(Range.RangeBoundary.OPEN, "a", "z", Range.RangeBoundary.CLOSED), + from); from = "(date(\"1978-09-12\")..date(\"1978-10-13\")]"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, LocalDate.of(1978, 9, 12), LocalDate.of(1978, 10, 13), Range.RangeBoundary.CLOSED), - from); + new RangeImpl(Range.RangeBoundary.OPEN, LocalDate.of(1978, 9, 12), + LocalDate.of(1978, 10, 13), Range.RangeBoundary.CLOSED), + from); from = "(duration(\"P2DT20H14M\")..duration(\"P3DT20H14M\")]"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.OPEN, Duration.parse("P2DT20H14M"), Duration.parse("P3DT20H14M"), Range.RangeBoundary.CLOSED), - from); + new RangeImpl(Range.RangeBoundary.OPEN, Duration.parse("P2DT20H14M"), + Duration.parse("P3DT20H14M"), Range.RangeBoundary.CLOSED), + from); } @Test void invoke_ClosedOpenBoundaries() { String from = "[1..2)"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.CLOSED, BigDecimal.ONE, BigDecimal.valueOf(2), Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.CLOSED, BigDecimal.ONE, BigDecimal.valueOf(2) + , Range.RangeBoundary.OPEN), + from); from = "[\"a\"..\"z\")"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.CLOSED, "a", "z", Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.CLOSED, "a", "z", Range.RangeBoundary.OPEN), + from); from = "[date(\"1978-09-12\")..date(\"1978-10-13\"))"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.CLOSED, LocalDate.of(1978, 9, 12), LocalDate.of(1978, 10, 13), Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.CLOSED, LocalDate.of(1978, 9, 12), + LocalDate.of(1978, 10, 13), Range.RangeBoundary.OPEN), + from); from = "[duration(\"P2DT20H14M\")..duration(\"P3DT20H14M\"))"; FunctionTestUtil.assertResult(rangeFunction.invoke("[duration(\"P2DT20H14M\")..duration(\"P3DT20H14M\"))"), - new RangeImpl(Range.RangeBoundary.CLOSED, Duration.parse("P2DT20H14M"), Duration.parse("P3DT20H14M"), Range.RangeBoundary.OPEN), - from); + new RangeImpl(Range.RangeBoundary.CLOSED, Duration.parse("P2DT20H14M"), + Duration.parse("P3DT20H14M"), Range.RangeBoundary.OPEN), + from); } @Test void invoke_ClosedClosedBoundaries() { String from = "[1..2)"; FunctionTestUtil.assertResult(rangeFunction.invoke("[1..2]"), - new RangeImpl(Range.RangeBoundary.CLOSED, BigDecimal.ONE, BigDecimal.valueOf(2), Range.RangeBoundary.CLOSED), - from); + new RangeImpl(Range.RangeBoundary.CLOSED, BigDecimal.ONE, BigDecimal.valueOf(2) + , Range.RangeBoundary.CLOSED), + from); from = "[2..1]"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.CLOSED, BigDecimal.valueOf(2), BigDecimal.ONE, Range.RangeBoundary.CLOSED), - from); + new RangeImpl(Range.RangeBoundary.CLOSED, BigDecimal.valueOf(2), BigDecimal.ONE + , Range.RangeBoundary.CLOSED), + from); from = "[\"a\"..\"z\"]"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.CLOSED, "a", "z", Range.RangeBoundary.CLOSED), - from); + new RangeImpl(Range.RangeBoundary.CLOSED, "a", "z", Range.RangeBoundary.CLOSED), + from); from = "[date(\"1978-09-12\")..date(\"1978-10-13\")]"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.CLOSED, LocalDate.of(1978, 9, 12), LocalDate.of(1978, 10, 13), Range.RangeBoundary.CLOSED), - from); + new RangeImpl(Range.RangeBoundary.CLOSED, LocalDate.of(1978, 9, 12), + LocalDate.of(1978, 10, 13), Range.RangeBoundary.CLOSED), + from); from = "[duration(\"P2DT20H14M\")..duration(\"P3DT20H14M\")]"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.CLOSED, Duration.parse("P2DT20H14M"), Duration.parse("P3DT20H14M"), Range.RangeBoundary.CLOSED), - from); + new RangeImpl(Range.RangeBoundary.CLOSED, Duration.parse("P2DT20H14M"), + Duration.parse("P3DT20H14M"), Range.RangeBoundary.CLOSED), + from); } @Test void invoke_WithOneFunctionNode() { String from = "[number(\"1\", \",\", \".\")\"..2]"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.CLOSED, BigDecimal.ONE, BigDecimal.valueOf(2), Range.RangeBoundary.CLOSED), - from); + new RangeImpl(Range.RangeBoundary.CLOSED, BigDecimal.ONE, BigDecimal.valueOf(2) + , Range.RangeBoundary.CLOSED), + from); from = "[\"a\"..lower case(\"Z\")]"; FunctionTestUtil.assertResult(rangeFunction.invoke(from), - new RangeImpl(Range.RangeBoundary.CLOSED, "a", "z", Range.RangeBoundary.CLOSED), - from); + new RangeImpl(Range.RangeBoundary.CLOSED, "a", "z", Range.RangeBoundary.CLOSED), + from); } @Test @@ -387,7 +401,6 @@ void getNullNode() { assertThat(rangeFunction.getNullNode()).isInstanceOf(NullNode.class); } - private NumberNode getNumberNode() { return (NumberNode) rangeFunction.parse("1"); } @@ -408,7 +421,8 @@ private FunctionInvocationNode getFunctionInvocationNodeA() { return (FunctionInvocationNode) rangeFunction.parse("duration(\"P2DT20H14M\")"); } - // 10.3.2.7 Endpoints can be either a literal or a qualified name of the following types: number, string, date, time, date and + // 10.3.2.7 Endpoints can be either a literal or a qualified name of the following types: number, string, date, + // time, date and //time, or duration. private static Object[][] validFunctionInvocationNodeData() { // Subset of FEELFunctionsTest.data @@ -498,7 +512,8 @@ private static Object[][] validFunctionInvocationNodeData() { }; } - // 10.3.2.7 Endpoints can be either a literal or a qualified name of the following types: number, string, date, time, date and + // 10.3.2.7 Endpoints can be either a literal or a qualified name of the following types: number, string, date, + // time, date and //time, or duration. private static Object[][] invalidFunctionInvocationNodeData() { // Subset of FEELFunctionsTest.data @@ -522,43 +537,68 @@ private static Object[][] invalidFunctionInvocationNodeData() { {"list contains([1, 2, 3], 5)", Boolean.FALSE}, {"sublist( [1, 2, 3, 4, 5 ], 3, 2 )", Arrays.asList(BigDecimal.valueOf(3), BigDecimal.valueOf(4))}, {"sublist( [1, 2, 3, 4, 5 ], -2, 1 )", Collections.singletonList(BigDecimal.valueOf(4))}, - {"sublist( [1, 2, 3, 4, 5 ], -5, 3 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3))}, - {"sublist( [1, 2, 3, 4, 5 ], 1, 3 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3))}, - {"append( [1, 2], 3, 4 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3), BigDecimal.valueOf(4))}, + {"sublist( [1, 2, 3, 4, 5 ], -5, 3 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), + BigDecimal.valueOf(3))}, + {"sublist( [1, 2, 3, 4, 5 ], 1, 3 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), + BigDecimal.valueOf(3))}, + {"append( [1, 2], 3, 4 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), + BigDecimal.valueOf(3), BigDecimal.valueOf(4))}, {"append( [], 3, 4 )", Arrays.asList(BigDecimal.valueOf(3), BigDecimal.valueOf(4))}, {"append( [1, 2] )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2))}, - {"append( [1, 2], null, 4 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), null, BigDecimal.valueOf(4))}, - {"append( 0, 1, 2 )", Arrays.asList(BigDecimal.valueOf(0), BigDecimal.valueOf(1), BigDecimal.valueOf(2))}, - {"concatenate( [1, 2], [3] )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3))}, - {"concatenate( [1, 2], 3, [4] )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3), BigDecimal.valueOf(4))}, - {"insert before( [1, 2, 3], 1, 4 )", Arrays.asList(BigDecimal.valueOf(4), BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3))}, - {"insert before( [1, 2, 3], 3, 4 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(4), BigDecimal.valueOf(3))}, - {"insert before( [1, 2, 3], 3, null )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), null, BigDecimal.valueOf(3))}, - {"insert before( [1, 2, 3], -3, 4 )", Arrays.asList(BigDecimal.valueOf(4), BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3))}, - {"insert before( [1, 2, 3], -1, 4 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(4), BigDecimal.valueOf(3))}, + {"append( [1, 2], null, 4 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), null, + BigDecimal.valueOf(4))}, + {"append( 0, 1, 2 )", Arrays.asList(BigDecimal.valueOf(0), BigDecimal.valueOf(1), + BigDecimal.valueOf(2))}, + {"concatenate( [1, 2], [3] )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), + BigDecimal.valueOf(3))}, + {"concatenate( [1, 2], 3, [4] )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), + BigDecimal.valueOf(3), BigDecimal.valueOf(4))}, + {"insert before( [1, 2, 3], 1, 4 )", Arrays.asList(BigDecimal.valueOf(4), BigDecimal.valueOf(1), + BigDecimal.valueOf(2), BigDecimal.valueOf(3))}, + {"insert before( [1, 2, 3], 3, 4 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), + BigDecimal.valueOf(4), BigDecimal.valueOf(3))}, + {"insert before( [1, 2, 3], 3, null )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), + null, BigDecimal.valueOf(3))}, + {"insert before( [1, 2, 3], -3, 4 )", Arrays.asList(BigDecimal.valueOf(4), BigDecimal.valueOf(1), + BigDecimal.valueOf(2), BigDecimal.valueOf(3))}, + {"insert before( [1, 2, 3], -1, 4 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), + BigDecimal.valueOf(4), BigDecimal.valueOf(3))}, {"remove( [1, 2, 3], 1 )", Arrays.asList(BigDecimal.valueOf(2), BigDecimal.valueOf(3))}, {"remove( [1, 2, 3], 3 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2))}, {"remove( [1, 2, 3], -1 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2))}, {"remove( [1, 2, 3], -3 )", Arrays.asList(BigDecimal.valueOf(2), BigDecimal.valueOf(3))}, - {"reverse( [1, 2, 3] )", Arrays.asList(BigDecimal.valueOf(3), BigDecimal.valueOf(2), BigDecimal.valueOf(1))}, + {"reverse( [1, 2, 3] )", Arrays.asList(BigDecimal.valueOf(3), BigDecimal.valueOf(2), + BigDecimal.valueOf(1))}, {"index of( [1, 2, 3, 2], 2 )", Arrays.asList(BigDecimal.valueOf(2), BigDecimal.valueOf(4))}, {"index of( [1, 2, null, null], null )", Arrays.asList(BigDecimal.valueOf(3), BigDecimal.valueOf(4))}, {"index of( [1, 2, null, null], 1 )", Collections.singletonList(BigDecimal.valueOf(1))}, - {"union( [1, 2, 1], [2, 3], 2, 4 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3), BigDecimal.valueOf(4))}, - {"union( [1, 2, null], 4 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), null, BigDecimal.valueOf(4))}, + {"union( [1, 2, 1], [2, 3], 2, 4 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), + BigDecimal.valueOf(3), BigDecimal.valueOf(4))}, + {"union( [1, 2, null], 4 )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), null, + BigDecimal.valueOf(4))}, {"union( null, 4 )", Arrays.asList(null, BigDecimal.valueOf(4))}, - {"distinct values( [1, 2, 3, 2, 4] )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3), BigDecimal.valueOf(4))}, - {"distinct values( [1, 2, null, 2, 4] )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), null, BigDecimal.valueOf(4))}, + {"distinct values( [1, 2, 3, 2, 4] )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), + BigDecimal.valueOf(3), BigDecimal.valueOf(4))}, + {"distinct values( [1, 2, null, 2, 4] )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), + null, BigDecimal.valueOf(4))}, {"distinct values( 1 )", Collections.singletonList(BigDecimal.valueOf(1))}, - {"sort( [3, 1, 4, 5, 2], function(x,y) x < y )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3), - BigDecimal.valueOf(4), BigDecimal.valueOf(5))}, - {"sort( [3, 1, 4, 5, 2] )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3), - BigDecimal.valueOf(4), BigDecimal.valueOf(5))}, - {"sort( list : [3, 1, 4, 5, 2] )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(3), - BigDecimal.valueOf(4), BigDecimal.valueOf(5))}, - {"sort( [\"c\", \"e\", \"d\", \"a\", \"b\"], function(x,y) x < y )", Arrays.asList("a", "b", "c", "d", "e")}, - {"sort( list : [\"c\", \"e\", \"d\", \"a\", \"b\"], precedes : function(x,y) x < y )", Arrays.asList("a", "b", "c", "d", "e")}, - {"sort( precedes : function(x,y) x < y, list : [\"c\", \"e\", \"d\", \"a\", \"b\"] )", Arrays.asList("a", "b", "c", "d", "e")}, + {"sort( [3, 1, 4, 5, 2], function(x,y) x < y )", Arrays.asList(BigDecimal.valueOf(1), + BigDecimal.valueOf(2), + BigDecimal.valueOf(3), + BigDecimal.valueOf(4), + BigDecimal.valueOf(5))}, + {"sort( [3, 1, 4, 5, 2] )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), + BigDecimal.valueOf(3), + BigDecimal.valueOf(4), BigDecimal.valueOf(5))}, + {"sort( list : [3, 1, 4, 5, 2] )", Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(2), + BigDecimal.valueOf(3), + BigDecimal.valueOf(4), BigDecimal.valueOf(5))}, + {"sort( [\"c\", \"e\", \"d\", \"a\", \"b\"], function(x,y) x < y )", Arrays.asList("a", "b", "c", "d" + , "e")}, + {"sort( list : [\"c\", \"e\", \"d\", \"a\", \"b\"], precedes : function(x,y) x < y )", Arrays.asList( + "a", "b", "c", "d", "e")}, + {"sort( precedes : function(x,y) x < y, list : [\"c\", \"e\", \"d\", \"a\", \"b\"] )", Arrays.asList( + "a", "b", "c", "d", "e")}, {"all( true )", true}, {"all( false )", false}, {"all( [true] )", true}, @@ -581,6 +621,4 @@ private static Object[][] invalidFunctionInvocationNodeData() { {"any( [] )", false}, }; } - - } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RemoveFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RemoveFunctionTest.java index a4f1b0def08..aade71092b6 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RemoveFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RemoveFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -23,42 +23,45 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class RemoveFunctionTest { - private RemoveFunction removeFunction; - - @BeforeEach - void setUp() { - removeFunction = new RemoveFunction(); - } + private static final RemoveFunction removeFunction = RemoveFunction.INSTANCE; @Test void invokeNull() { FunctionTestUtil.assertResultError(removeFunction.invoke((List) null, null), InvalidParametersEvent.class); FunctionTestUtil.assertResultError(removeFunction.invoke(null, BigDecimal.ONE), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(removeFunction.invoke(Collections.emptyList(), null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(removeFunction.invoke(Collections.emptyList(), null), + InvalidParametersEvent.class); } @Test void invokePositionZero() { - FunctionTestUtil.assertResultError(removeFunction.invoke(Collections.singletonList(1), BigDecimal.ZERO), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(removeFunction.invoke(Collections.singletonList(1), BigDecimal.ZERO), + InvalidParametersEvent.class); } @Test void invokePositionOutOfListBounds() { - FunctionTestUtil.assertResultError(removeFunction.invoke(Collections.singletonList(1), BigDecimal.valueOf(2)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(removeFunction.invoke(Collections.singletonList(1), BigDecimal.valueOf(154)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(removeFunction.invoke(Collections.singletonList(1), BigDecimal.valueOf(-2)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(removeFunction.invoke(Collections.singletonList(1), BigDecimal.valueOf(-154)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(removeFunction.invoke(Collections.singletonList(1), BigDecimal.valueOf(2)) + , InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(removeFunction.invoke(Collections.singletonList(1), + BigDecimal.valueOf(154)), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(removeFunction.invoke(Collections.singletonList(1), + BigDecimal.valueOf(-2)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(removeFunction.invoke(Collections.singletonList(1), + BigDecimal.valueOf(-154)), + InvalidParametersEvent.class); } @Test void invokePositionPositive() { - FunctionTestUtil.assertResultList(removeFunction.invoke(Collections.singletonList(1), BigDecimal.ONE), Collections.emptyList()); + FunctionTestUtil.assertResultList(removeFunction.invoke(Collections.singletonList(1), BigDecimal.ONE), + Collections.emptyList()); FunctionTestUtil.assertResultList( removeFunction.invoke(Arrays.asList(1, "test", BigDecimal.valueOf(14)), BigDecimal.ONE), Arrays.asList("test", BigDecimal.valueOf(14))); @@ -72,7 +75,8 @@ void invokePositionPositive() { @Test void invokePositionNegative() { - FunctionTestUtil.assertResultList(removeFunction.invoke(Collections.singletonList(1), BigDecimal.valueOf(-1)), Collections.emptyList()); + FunctionTestUtil.assertResultList(removeFunction.invoke(Collections.singletonList(1), BigDecimal.valueOf(-1)) + , Collections.emptyList()); FunctionTestUtil.assertResultList( removeFunction.invoke(Arrays.asList(1, "test", BigDecimal.valueOf(14)), BigDecimal.valueOf(-1)), Arrays.asList(1, "test")); diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java index 125914338de..8864beaa143 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -18,24 +18,20 @@ */ package org.kie.dmn.feel.runtime.functions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class ReplaceFunctionTest { - private ReplaceFunction replaceFunction; - - @BeforeEach - void setUp() { - replaceFunction = new ReplaceFunction(); - } + private static final ReplaceFunction replaceFunction = ReplaceFunction.INSTANCE; @Test void invokeNull() { FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null), + InvalidParametersEvent.class); FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null), InvalidParametersEvent.class); FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt"), InvalidParametersEvent.class); FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt"), InvalidParametersEvent.class); @@ -43,19 +39,30 @@ void invokeNull() { @Test void invokeNullWithFlags() { - FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt", null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt", null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt", null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt", null), + InvalidParametersEvent.class); FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null, "s"), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null, "s"), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null, "s"), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null, "s"), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt", "s"), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt", "s"), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null, "s"), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null, "s"), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null, "s"), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt", "s"), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt", "s"), + InvalidParametersEvent.class); } @Test diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReverseFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReverseFunctionTest.java index b40e64c186d..13b2e3b28fc 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReverseFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReverseFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -22,18 +22,12 @@ import java.util.Arrays; import java.util.Collections; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class ReverseFunctionTest { - private ReverseFunction reverseFunction; - - @BeforeEach - void setUp() { - reverseFunction = new ReverseFunction(); - } + private static final ReverseFunction reverseFunction = ReverseFunction.INSTANCE; @Test void invokeNull() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundDownFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundDownFunctionTest.java similarity index 62% rename from kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundDownFunctionTest.java rename to kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundDownFunctionTest.java index 37e4742f759..5b58c9fdf4d 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundDownFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundDownFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -16,64 +16,69 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; + +import java.math.BigDecimal; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; - -import java.math.BigDecimal; class RoundDownFunctionTest { - private RoundDownFunction roundDownFunction; - - @BeforeEach - void setUp() { - roundDownFunction = new RoundDownFunction(); - } + private static final RoundDownFunction roundDownFunction = RoundDownFunction.INSTANCE; @Test void invokeNull() { FunctionTestUtil.assertResultError(roundDownFunction.invoke(null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(roundDownFunction.invoke((BigDecimal) null, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(roundDownFunction.invoke(BigDecimal.ONE, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(roundDownFunction.invoke(null, BigDecimal.ONE), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundDownFunction.invoke((BigDecimal) null, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundDownFunction.invoke(BigDecimal.ONE, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundDownFunction.invoke(null, BigDecimal.ONE), + InvalidParametersEvent.class); } @Test void invokeRoundingUp() { FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.27)), BigDecimal.valueOf(10)); - FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.27), BigDecimal.ONE), BigDecimal.valueOf(10.2)); + FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.27), BigDecimal.ONE), + BigDecimal.valueOf(10.2)); } @Test void invokeRoundingDown() { FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.24)), BigDecimal.valueOf(10)); - FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.24), BigDecimal.ONE), BigDecimal.valueOf(10.2)); + FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.24), BigDecimal.ONE), + BigDecimal.valueOf(10.2)); } @Test void invokeRoundingEven() { FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.25)), BigDecimal.valueOf(10)); - FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.25), BigDecimal.ONE), BigDecimal.valueOf(10.2)); + FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.25), BigDecimal.ONE), + BigDecimal.valueOf(10.2)); } @Test void invokeRoundingOdd() { FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.35)), BigDecimal.valueOf(10)); - FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.35), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.35), BigDecimal.ONE), + BigDecimal.valueOf(10.3)); } @Test void invokeLargerScale() { - FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.123456789), BigDecimal.valueOf(6)), BigDecimal.valueOf(10.123456)); + FunctionTestUtil.assertResult(roundDownFunction.invoke(BigDecimal.valueOf(10.123456789), + BigDecimal.valueOf(6)), BigDecimal.valueOf(10.123456)); } @Test void invokeOutRangeScale() { - FunctionTestUtil.assertResultError(roundDownFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(roundDownFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundDownFunction.invoke(BigDecimal.valueOf(1.5), + BigDecimal.valueOf(6177)), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundDownFunction.invoke(BigDecimal.valueOf(1.5), + BigDecimal.valueOf(-6122)), + InvalidParametersEvent.class); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfDownFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundHalfDownFunctionTest.java similarity index 61% rename from kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfDownFunctionTest.java rename to kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundHalfDownFunctionTest.java index d91b548c14b..79d498b1239 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfDownFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundHalfDownFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -16,64 +16,70 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; + +import java.math.BigDecimal; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; - -import java.math.BigDecimal; class RoundHalfDownFunctionTest { - private RoundHalfDownFunction roundHalfDownFunction; - - @BeforeEach - void setUp() { - roundHalfDownFunction = new RoundHalfDownFunction(); - } + private static final RoundHalfDownFunction roundHalfDownFunction = RoundHalfDownFunction.INSTANCE; @Test void invokeNull() { FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke(null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke((BigDecimal) null, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke(BigDecimal.ONE, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke(null, BigDecimal.ONE), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke((BigDecimal) null, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke(BigDecimal.ONE, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke(null, BigDecimal.ONE), + InvalidParametersEvent.class); } @Test void invokeRoundingUp() { FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.27)), BigDecimal.valueOf(10)); - FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.27), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.27), BigDecimal.ONE), + BigDecimal.valueOf(10.3)); } @Test void invokeRoundingDown() { FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.24)), BigDecimal.valueOf(10)); - FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.24), BigDecimal.ONE), BigDecimal.valueOf(10.2)); + FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.24), BigDecimal.ONE), + BigDecimal.valueOf(10.2)); } @Test void invokeRoundingEven() { FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.25)), BigDecimal.valueOf(10)); - FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.25), BigDecimal.ONE), BigDecimal.valueOf(10.2)); + FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.25), BigDecimal.ONE), + BigDecimal.valueOf(10.2)); } @Test void invokeRoundingOdd() { FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.35)), BigDecimal.valueOf(10)); - FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.35), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.35), BigDecimal.ONE), + BigDecimal.valueOf(10.3)); } @Test void invokeLargerScale() { - FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.123456789), BigDecimal.valueOf(6)), BigDecimal.valueOf(10.123457)); + FunctionTestUtil.assertResult(roundHalfDownFunction.invoke(BigDecimal.valueOf(10.123456789), + BigDecimal.valueOf(6)), + BigDecimal.valueOf(10.123457)); } @Test void invokeOutRangeScale() { - FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke(BigDecimal.valueOf(1.5), + BigDecimal.valueOf(6177)), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfDownFunction.invoke(BigDecimal.valueOf(1.5), + BigDecimal.valueOf(-6122)), + InvalidParametersEvent.class); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfUpFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundHalfUpFunctionTest.java similarity index 62% rename from kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfUpFunctionTest.java rename to kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundHalfUpFunctionTest.java index a5afd7a5013..b37deb7d6f9 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundHalfUpFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundHalfUpFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -16,64 +16,69 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; + +import java.math.BigDecimal; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; - -import java.math.BigDecimal; class RoundHalfUpFunctionTest { - private RoundHalfUpFunction roundHalfUpFunction; - - @BeforeEach - void setUp() { - roundHalfUpFunction = new RoundHalfUpFunction(); - } + private static final RoundHalfUpFunction roundHalfUpFunction = RoundHalfUpFunction.INSTANCE; @Test void invokeNull() { FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke(null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke((BigDecimal) null, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke(BigDecimal.ONE, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke(null, BigDecimal.ONE), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke((BigDecimal) null, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke(BigDecimal.ONE, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke(null, BigDecimal.ONE), + InvalidParametersEvent.class); } @Test void invokeRoundingUp() { FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.27)), BigDecimal.valueOf(10)); - FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.27), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.27), BigDecimal.ONE), + BigDecimal.valueOf(10.3)); } @Test void invokeRoundingDown() { FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.24)), BigDecimal.valueOf(10)); - FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.24), BigDecimal.ONE), BigDecimal.valueOf(10.2)); + FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.24), BigDecimal.ONE), + BigDecimal.valueOf(10.2)); } @Test void invokeRoundingEven() { FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.25)), BigDecimal.valueOf(10)); - FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.25), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.25), BigDecimal.ONE), + BigDecimal.valueOf(10.3)); } @Test void invokeRoundingOdd() { FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.35)), BigDecimal.valueOf(10)); - FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.35), BigDecimal.ONE), BigDecimal.valueOf(10.4)); + FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.35), BigDecimal.ONE), + BigDecimal.valueOf(10.4)); } @Test void invokeLargerScale() { - FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.123456789), BigDecimal.valueOf(6)), BigDecimal.valueOf(10.123457)); + FunctionTestUtil.assertResult(roundHalfUpFunction.invoke(BigDecimal.valueOf(10.123456789), + BigDecimal.valueOf(6)), BigDecimal.valueOf(10.123457)); } @Test void invokeOutRangeScale() { - FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke(BigDecimal.valueOf(1.5), + BigDecimal.valueOf(6177)), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundHalfUpFunction.invoke(BigDecimal.valueOf(1.5), + BigDecimal.valueOf(-6122)), + InvalidParametersEvent.class); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundUpFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundUpFunctionTest.java similarity index 70% rename from kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundUpFunctionTest.java rename to kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundUpFunctionTest.java index 2175fe8f5c7..5827e777c8c 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/extended/RoundUpFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundUpFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -16,28 +16,22 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.dmn.feel.runtime.functions.extended; +package org.kie.dmn.feel.runtime.functions; + +import java.math.BigDecimal; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; -import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; - -import java.math.BigDecimal; class RoundUpFunctionTest { - private RoundUpFunction roundUpFunction; - - @BeforeEach - void setUp() { - roundUpFunction = new RoundUpFunction(); - } + private static final RoundUpFunction roundUpFunction = RoundUpFunction.INSTANCE; @Test void invokeNull() { FunctionTestUtil.assertResultError(roundUpFunction.invoke(null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(roundUpFunction.invoke((BigDecimal) null, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundUpFunction.invoke((BigDecimal) null, null), + InvalidParametersEvent.class); FunctionTestUtil.assertResultError(roundUpFunction.invoke(BigDecimal.ONE, null), InvalidParametersEvent.class); FunctionTestUtil.assertResultError(roundUpFunction.invoke(null, BigDecimal.ONE), InvalidParametersEvent.class); } @@ -45,35 +39,42 @@ void invokeNull() { @Test void invokeRoundingUp() { FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.27)), BigDecimal.valueOf(11)); - FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.27), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.27), BigDecimal.ONE), + BigDecimal.valueOf(10.3)); } @Test void invokeRoundingDown() { FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.24)), BigDecimal.valueOf(11)); - FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.24), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.24), BigDecimal.ONE), + BigDecimal.valueOf(10.3)); } @Test void invokeRoundingEven() { FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.25)), BigDecimal.valueOf(11)); - FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.25), BigDecimal.ONE), BigDecimal.valueOf(10.3)); + FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.25), BigDecimal.ONE), + BigDecimal.valueOf(10.3)); } @Test void invokeRoundingOdd() { FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.35)), BigDecimal.valueOf(11)); - FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.35), BigDecimal.ONE), BigDecimal.valueOf(10.4)); + FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.35), BigDecimal.ONE), + BigDecimal.valueOf(10.4)); } @Test void invokeLargerScale() { - FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.123456789), BigDecimal.valueOf(6)), BigDecimal.valueOf(10.123457)); + FunctionTestUtil.assertResult(roundUpFunction.invoke(BigDecimal.valueOf(10.123456789), BigDecimal.valueOf(6)) + , BigDecimal.valueOf(10.123457)); } @Test void invokeOutRangeScale() { - FunctionTestUtil.assertResultError(roundUpFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(roundUpFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundUpFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(6177)), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(roundUpFunction.invoke(BigDecimal.valueOf(1.5), BigDecimal.valueOf(-6122)) + , InvalidParametersEvent.class); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SortFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SortFunctionTest.java index ea35bba6cb1..ffbb96ea34f 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SortFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SortFunctionTest.java @@ -23,7 +23,6 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.lang.EvaluationContext; import org.kie.dmn.feel.lang.Symbol; @@ -32,12 +31,7 @@ class SortFunctionTest { - private SortFunction sortFunction; - - @BeforeEach - void setUp() { - sortFunction = new SortFunction(); - } + private static final SortFunction sortFunction = SortFunction.INSTANCE; @Test void invokeListParamNull() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StartsWithFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StartsWithFunctionTest.java index c4ff1ea5db2..e4dcd3d63b6 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StartsWithFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StartsWithFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -18,22 +18,17 @@ */ package org.kie.dmn.feel.runtime.functions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class StartsWithFunctionTest { - private StartsWithFunction startsWithFunction; - - @BeforeEach - void setUp() { - startsWithFunction = new StartsWithFunction(); - } + private static final StartsWithFunction startsWithFunction = StartsWithFunction.INSTANCE; @Test void invokeNull() { - FunctionTestUtil.assertResultError(startsWithFunction.invoke((String) null, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(startsWithFunction.invoke((String) null, null), + InvalidParametersEvent.class); FunctionTestUtil.assertResultError(startsWithFunction.invoke(null, "test"), InvalidParametersEvent.class); FunctionTestUtil.assertResultError(startsWithFunction.invoke("test", null), InvalidParametersEvent.class); } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringFunctionTest.java index 8f36668a7c5..091c00f43d7 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -33,7 +33,6 @@ import java.util.List; import java.util.Map; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.Range; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; @@ -41,12 +40,7 @@ class StringFunctionTest { - private StringFunction stringFunction; - - @BeforeEach - void setUp() { - stringFunction = new StringFunction(); - } + private static final StringFunction stringFunction = StringFunction.INSTANCE; @Test void invokeNull() { @@ -56,7 +50,8 @@ void invokeNull() { @Test void invokeMaskNull() { FunctionTestUtil.assertResultError(stringFunction.invoke((String) null, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(stringFunction.invoke((String) null, new Object[]{}), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(stringFunction.invoke((String) null, new Object[]{}), + InvalidParametersEvent.class); } @Test @@ -90,19 +85,22 @@ void invokeOffsetTime() { @Test void invokeLocalDateTime() { final LocalDateTime localDateTime = LocalDateTime.now(); - FunctionTestUtil.assertResult(stringFunction.invoke(localDateTime), DateAndTimeFunction.FEEL_DATE_TIME.format(localDateTime)); + FunctionTestUtil.assertResult(stringFunction.invoke(localDateTime), + DateAndTimeFunction.FEEL_DATE_TIME.format(localDateTime)); } @Test void invokeOffsetDateTime() { final OffsetDateTime offsetDateTime = OffsetDateTime.now(); - FunctionTestUtil.assertResult(stringFunction.invoke(offsetDateTime), DateAndTimeFunction.FEEL_DATE_TIME.format(offsetDateTime)); + FunctionTestUtil.assertResult(stringFunction.invoke(offsetDateTime), + DateAndTimeFunction.FEEL_DATE_TIME.format(offsetDateTime)); } @Test void invokeZonedDateTime() { final ZonedDateTime zonedDateTime = ZonedDateTime.now(); - FunctionTestUtil.assertResult(stringFunction.invoke(zonedDateTime), DateAndTimeFunction.REGION_DATETIME_FORMATTER.format(zonedDateTime)); + FunctionTestUtil.assertResult(stringFunction.invoke(zonedDateTime), + DateAndTimeFunction.REGION_DATETIME_FORMATTER.format(zonedDateTime)); } @Test @@ -224,11 +222,13 @@ void invokeContextNonEmpty() { contextMap.put("key1", "value1"); contextMap.put("key2", childContextMap); - FunctionTestUtil.assertResult(stringFunction.invoke(contextMap), "{ key1 : value1, key2 : { childKey1 : childValue1 } }"); + FunctionTestUtil.assertResult(stringFunction.invoke(contextMap), "{ key1 : value1, key2 : { childKey1 : " + + "childValue1 } }"); } @Test void invokeMaskedFormat() { - FunctionTestUtil.assertResult(stringFunction.invoke("%s is here!", new Object[]{"Gorgonzola"}), "Gorgonzola is here!"); + FunctionTestUtil.assertResult(stringFunction.invoke("%s is here!", new Object[]{"Gorgonzola"}), "Gorgonzola " + + "is here!"); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLengthFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLengthFunctionTest.java index 94eceadca52..ea52ff04fb3 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLengthFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLengthFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -20,18 +20,12 @@ import java.math.BigDecimal; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class StringLengthFunctionTest { - private StringLengthFunction stringLengthFunction; - - @BeforeEach - void setUp() { - stringLengthFunction = new StringLengthFunction(); - } + private static final StringLengthFunction stringLengthFunction = StringLengthFunction.INSTANCE; @Test void invokeNull() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLowerCaseFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLowerCaseFunctionTest.java index 7171cffa716..6126be7009e 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLowerCaseFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLowerCaseFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -18,18 +18,12 @@ */ package org.kie.dmn.feel.runtime.functions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class StringLowerCaseFunctionTest { - private StringLowerCaseFunction stringLowerCaseFunction; - - @BeforeEach - void setUp() { - stringLowerCaseFunction = new StringLowerCaseFunction(); - } + private static final StringLowerCaseFunction stringLowerCaseFunction = StringLowerCaseFunction.INSTANCE; @Test void invokeNull() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringUpperCaseFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringUpperCaseFunctionTest.java index 8770234a7b4..846f2c05c26 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringUpperCaseFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringUpperCaseFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -18,18 +18,12 @@ */ package org.kie.dmn.feel.runtime.functions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class StringUpperCaseFunctionTest { - private StringUpperCaseFunction stringUpperCaseFunction; - - @BeforeEach - void setUp() { - stringUpperCaseFunction = new StringUpperCaseFunction(); - } + private static final StringUpperCaseFunction stringUpperCaseFunction = StringUpperCaseFunction.INSTANCE; @Test void invokeNull() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SublistFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SublistFunctionTest.java index ac0f4cfdfc3..d2fd47b27ce 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SublistFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SublistFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -23,59 +23,67 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class SublistFunctionTest { - private SublistFunction sublistFunction; - - @BeforeEach - void setUp() { - sublistFunction = new SublistFunction(); - } + private static final SublistFunction sublistFunction = SublistFunction.INSTANCE; @Test void invokeNull() { FunctionTestUtil.assertResultError(sublistFunction.invoke((List) null, null), InvalidParametersEvent.class); FunctionTestUtil.assertResultError(sublistFunction.invoke(null, BigDecimal.ONE), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(sublistFunction.invoke(Collections.emptyList(), null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sublistFunction.invoke(Collections.emptyList(), null), + InvalidParametersEvent.class); } @Test void invokeStartZero() { - FunctionTestUtil.assertResultError(sublistFunction.invoke(Arrays.asList(1, 2), BigDecimal.ZERO), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sublistFunction.invoke(Arrays.asList(1, 2), BigDecimal.ZERO), + InvalidParametersEvent.class); } @Test void invokeStartOutOfListBounds() { - FunctionTestUtil.assertResultError(sublistFunction.invoke(Arrays.asList(1, 2), BigDecimal.TEN), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(sublistFunction.invoke(Arrays.asList(1, 2), BigDecimal.valueOf(-10)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sublistFunction.invoke(Arrays.asList(1, 2), BigDecimal.TEN), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sublistFunction.invoke(Arrays.asList(1, 2), BigDecimal.valueOf(-10)), + InvalidParametersEvent.class); } @Test void invokeLengthNegative() { - FunctionTestUtil.assertResultError(sublistFunction.invoke(Arrays.asList(1, 2), BigDecimal.valueOf(1), BigDecimal.valueOf(-3)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sublistFunction.invoke(Arrays.asList(1, 2), BigDecimal.valueOf(1), + BigDecimal.valueOf(-3)), + InvalidParametersEvent.class); } @Test void invokeLengthOutOfListBounds() { - FunctionTestUtil.assertResultError(sublistFunction.invoke(Arrays.asList(1, 2), BigDecimal.ONE, BigDecimal.valueOf(3)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(sublistFunction.invoke(Arrays.asList(1, 2), BigDecimal.valueOf(-1), BigDecimal.valueOf(3)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sublistFunction.invoke(Arrays.asList(1, 2), BigDecimal.ONE, + BigDecimal.valueOf(3)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sublistFunction.invoke(Arrays.asList(1, 2), BigDecimal.valueOf(-1), + BigDecimal.valueOf(3)), InvalidParametersEvent.class); } @Test void invokeStartPositive() { - FunctionTestUtil.assertResult(sublistFunction.invoke(Arrays.asList(1, 2, 3), BigDecimal.valueOf(2)), Arrays.asList(2, 3)); - FunctionTestUtil.assertResult(sublistFunction.invoke(Arrays.asList(1, "test", 3), BigDecimal.valueOf(2)), Arrays.asList("test", 3)); - FunctionTestUtil.assertResult(sublistFunction.invoke(Arrays.asList(1, "test", 3), BigDecimal.valueOf(2), BigDecimal.ONE), Collections.singletonList("test")); + FunctionTestUtil.assertResult(sublistFunction.invoke(Arrays.asList(1, 2, 3), BigDecimal.valueOf(2)), + Arrays.asList(2, 3)); + FunctionTestUtil.assertResult(sublistFunction.invoke(Arrays.asList(1, "test", 3), BigDecimal.valueOf(2)), + Arrays.asList("test", 3)); + FunctionTestUtil.assertResult(sublistFunction.invoke(Arrays.asList(1, "test", 3), BigDecimal.valueOf(2), + BigDecimal.ONE), Collections.singletonList("test")); } @Test void invokeStartNegative() { - FunctionTestUtil.assertResult(sublistFunction.invoke(Arrays.asList(1, 2, 3), BigDecimal.valueOf(-2)), Arrays.asList(2, 3)); - FunctionTestUtil.assertResult(sublistFunction.invoke(Arrays.asList(1, "test", 3), BigDecimal.valueOf(-2)), Arrays.asList("test", 3)); - FunctionTestUtil.assertResult(sublistFunction.invoke(Arrays.asList(1, "test", 3), BigDecimal.valueOf(-2), BigDecimal.ONE), Collections.singletonList("test")); + FunctionTestUtil.assertResult(sublistFunction.invoke(Arrays.asList(1, 2, 3), BigDecimal.valueOf(-2)), + Arrays.asList(2, 3)); + FunctionTestUtil.assertResult(sublistFunction.invoke(Arrays.asList(1, "test", 3), BigDecimal.valueOf(-2)), + Arrays.asList("test", 3)); + FunctionTestUtil.assertResult(sublistFunction.invoke(Arrays.asList(1, "test", 3), BigDecimal.valueOf(-2), + BigDecimal.ONE), Collections.singletonList("test")); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringAfterFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringAfterFunctionTest.java index 8aae3b448d1..b152ac5ae54 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringAfterFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringAfterFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -18,22 +18,17 @@ */ package org.kie.dmn.feel.runtime.functions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class SubstringAfterFunctionTest { - private SubstringAfterFunction substringAfterFunction; - - @BeforeEach - void setUp() { - substringAfterFunction = new SubstringAfterFunction(); - } + private static final SubstringAfterFunction substringAfterFunction = SubstringAfterFunction.INSTANCE; @Test void invokeNull() { - FunctionTestUtil.assertResultError(substringAfterFunction.invoke((String) null, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(substringAfterFunction.invoke((String) null, null), + InvalidParametersEvent.class); FunctionTestUtil.assertResultError(substringAfterFunction.invoke(null, "test"), InvalidParametersEvent.class); FunctionTestUtil.assertResultError(substringAfterFunction.invoke("test", null), InvalidParametersEvent.class); } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringBeforeFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringBeforeFunctionTest.java index 8b4b9fb1ec7..c88e5933727 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringBeforeFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringBeforeFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -18,22 +18,17 @@ */ package org.kie.dmn.feel.runtime.functions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class SubstringBeforeFunctionTest { - private SubstringBeforeFunction substringBeforeFunction; - - @BeforeEach - void setUp() { - substringBeforeFunction = new SubstringBeforeFunction(); - } + private static final SubstringBeforeFunction substringBeforeFunction = SubstringBeforeFunction.INSTANCE; @Test void invokeNull() { - FunctionTestUtil.assertResultError(substringBeforeFunction.invoke((String) null, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(substringBeforeFunction.invoke((String) null, null), + InvalidParametersEvent.class); FunctionTestUtil.assertResultError(substringBeforeFunction.invoke(null, "test"), InvalidParametersEvent.class); FunctionTestUtil.assertResultError(substringBeforeFunction.invoke("test", null), InvalidParametersEvent.class); } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringFunctionTest.java index c9f31216961..d32c8078591 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -18,18 +18,12 @@ */ package org.kie.dmn.feel.runtime.functions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class SubstringFunctionTest { - private SubstringFunction substringFunction; - - @BeforeEach - void setUp() { - substringFunction = new SubstringFunction(); - } + private static final SubstringFunction substringFunction = SubstringFunction.INSTANCE; @Test void invokeNull2ParamsMethod() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SumFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SumFunctionTest.java index e701404a614..7602158e5d2 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SumFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SumFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -22,18 +22,12 @@ import java.util.Arrays; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class SumFunctionTest { - private SumFunction sumFunction; - - @BeforeEach - void setUp() { - sumFunction = new SumFunction(); - } + private static final SumFunction sumFunction = SumFunction.INSTANCE; @Test void invokeNumberParamNull() { @@ -60,17 +54,20 @@ void invokeListParam() { @Test void invokeListParamContainsUnsupportedNumber() { - FunctionTestUtil.assertResultError(sumFunction.invoke(Arrays.asList(10, 2, Double.NaN)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sumFunction.invoke(Arrays.asList(10, 2, Double.NaN)), + InvalidParametersEvent.class); } @Test void invokeListParamContainsUnsupportedType() { - FunctionTestUtil.assertResultError(sumFunction.invoke(Arrays.asList(10, "test", 2)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sumFunction.invoke(Arrays.asList(10, "test", 2)), + InvalidParametersEvent.class); } @Test void invokeListParamSupportedTypes() { - FunctionTestUtil.assertResult(sumFunction.invoke(Arrays.asList(4, -1, 12.1, (long) 5, BigDecimal.TEN)), BigDecimal.valueOf(30.1)); + FunctionTestUtil.assertResult(sumFunction.invoke(Arrays.asList(4, -1, 12.1, (long) 5, BigDecimal.TEN)), + BigDecimal.valueOf(30.1)); } @Test @@ -80,16 +77,19 @@ void invokeArrayParam() { @Test void invokeArrayParamContainsUnsupportedNumber() { - FunctionTestUtil.assertResultError(sumFunction.invoke(new Object[]{10, 2, Double.NaN}), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sumFunction.invoke(new Object[]{10, 2, Double.NaN}), + InvalidParametersEvent.class); } @Test void invokeArrayParamContainsUnsupportedType() { - FunctionTestUtil.assertResultError(sumFunction.invoke(new Object[]{10, "test", 2}), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sumFunction.invoke(new Object[]{10, "test", 2}), + InvalidParametersEvent.class); } @Test void invokeArrayParamSupportedTypes() { - FunctionTestUtil.assertResult(sumFunction.invoke(new Object[]{4, -1, 12.1, (long) 5, BigDecimal.TEN}), BigDecimal.valueOf(30.1)); + FunctionTestUtil.assertResult(sumFunction.invoke(new Object[]{4, -1, 12.1, (long) 5, BigDecimal.TEN}), + BigDecimal.valueOf(30.1)); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java index 6e12e099172..63ba79e11bf 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -30,7 +30,6 @@ import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalQueries; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; @@ -40,12 +39,7 @@ class TimeFunctionTest { - private TimeFunction timeFunction; - - @BeforeEach - void setUp() { - timeFunction = new TimeFunction(); - } + private static final TimeFunction timeFunction = TimeFunction.INSTANCE; @Test void invokeStringParamNull() { @@ -64,13 +58,15 @@ void invokeStringParamTimeWrongFormat() { @Test void invokeStringParamNoOffset() { - FunctionTestUtil.assertResult(timeFunction.invoke("10:15:06"), LocalTime.of(10,15,6)); + FunctionTestUtil.assertResult(timeFunction.invoke("10:15:06"), LocalTime.of(10, 15, 6)); } @Test void invokeStringParamWithOffset() { - FunctionTestUtil.assertResult(timeFunction.invoke("10:15:06+01:00"), OffsetTime.of(10,15,6, 0, ZoneOffset.ofHours(1))); - FunctionTestUtil.assertResult(timeFunction.invoke("10:15:06-01:00"), OffsetTime.of(10,15,6, 0, ZoneOffset.ofHours(-1))); + FunctionTestUtil.assertResult(timeFunction.invoke("10:15:06+01:00"), OffsetTime.of(10, 15, 6, 0, + ZoneOffset.ofHours(1))); + FunctionTestUtil.assertResult(timeFunction.invoke("10:15:06-01:00"), OffsetTime.of(10, 15, 6, 0, + ZoneOffset.ofHours(-1))); } @Test @@ -89,7 +85,8 @@ void parseWithZoneIANA() { @Test void invokeWrongIANAformat() { - FunctionTestUtil.assertResultError(timeFunction.invoke("13:20:00+02:00@Europe/Paris"), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(timeFunction.invoke("13:20:00+02:00@Europe/Paris"), + InvalidParametersEvent.class); } @Test @@ -104,7 +101,8 @@ void invokeTemporalAccessorParamUnsupportedAccessor() { @Test void invokeTemporalAccessorParamDate() { - FunctionTestUtil.assertResult(timeFunction.invoke(LocalDate.of(2017, 6, 12)), OffsetTime.of(0, 0, 0, 0, ZoneOffset.UTC)); + FunctionTestUtil.assertResult(timeFunction.invoke(LocalDate.of(2017, 6, 12)), OffsetTime.of(0, 0, 0, 0, + ZoneOffset.UTC)); } @Test @@ -114,7 +112,8 @@ void invokeTemporalAccessorParamTime() { @Test void invokeTemporalAccessorParamDateTime() { - FunctionTestUtil.assertResult(timeFunction.invoke(LocalDateTime.of(2017, 6, 12, 11, 43)), LocalTime.of(11, 43, 0)); + FunctionTestUtil.assertResult(timeFunction.invoke(LocalDateTime.of(2017, 6, 12, 11, 43)), LocalTime.of(11, 43 + , 0)); } @Test @@ -130,12 +129,18 @@ void invokeTimeUnitsParamsNull() { @Test void invokeTimeUnitsParamsUnsupportedNumber() { - FunctionTestUtil.assertResultError(timeFunction.invoke(Double.POSITIVE_INFINITY, 1, 1, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(timeFunction.invoke(Double.NEGATIVE_INFINITY, 1, 1, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(timeFunction.invoke(1, Double.POSITIVE_INFINITY, 1, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(timeFunction.invoke(1, Double.NEGATIVE_INFINITY, 1, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(timeFunction.invoke(1, 1, Double.POSITIVE_INFINITY, null), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(timeFunction.invoke(1, 1, Double.NEGATIVE_INFINITY, null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(timeFunction.invoke(Double.POSITIVE_INFINITY, 1, 1, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(timeFunction.invoke(Double.NEGATIVE_INFINITY, 1, 1, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(timeFunction.invoke(1, Double.POSITIVE_INFINITY, 1, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(timeFunction.invoke(1, Double.NEGATIVE_INFINITY, 1, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(timeFunction.invoke(1, 1, Double.POSITIVE_INFINITY, null), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(timeFunction.invoke(1, 1, Double.NEGATIVE_INFINITY, null), + InvalidParametersEvent.class); } @Test @@ -152,13 +157,19 @@ void invokeTimeUnitsParamsNoOffset() { @Test void invokeTimeUnitsParamsNoOffsetWithNanoseconds() { - FunctionTestUtil.assertResult(timeFunction.invoke(10, 43, BigDecimal.valueOf(15.154), null), LocalTime.of(10, 43, 15, 154000000)); + FunctionTestUtil.assertResult(timeFunction.invoke(10, 43, BigDecimal.valueOf(15.154), null), LocalTime.of(10, + 43, + 15, + 154000000)); } @Test void invokeTimeUnitsParamsWithOffset() { - FunctionTestUtil.assertResult(timeFunction.invoke(10, 43, 15, Duration.ofHours(1)), OffsetTime.of(10, 43, 15, 0, ZoneOffset.ofHours(1))); - FunctionTestUtil.assertResult(timeFunction.invoke(10, 43, 15, Duration.ofHours(-1)), OffsetTime.of(10, 43, 15, 0, ZoneOffset.ofHours(-1))); + FunctionTestUtil.assertResult(timeFunction.invoke(10, 43, 15, Duration.ofHours(1)), OffsetTime.of(10, 43, 15, + 0, + ZoneOffset.ofHours(1))); + FunctionTestUtil.assertResult(timeFunction.invoke(10, 43, 15, Duration.ofHours(-1)), OffsetTime.of(10, 43, 15 + , 0, ZoneOffset.ofHours(-1))); } @Test diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TodayFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TodayFunctionTest.java index 161c4b98d60..6db80988b06 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TodayFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TodayFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -20,22 +20,14 @@ import java.time.LocalDate; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.kie.dmn.feel.runtime.functions.extended.TodayFunction; class TodayFunctionTest { - private TodayFunction todayFunction; - - @BeforeEach - void setUp() { - todayFunction = new TodayFunction(); - } + private static final TodayFunction todayFunction = TodayFunction.INSTANCE; @Test void invoke() { FunctionTestUtil.assertResult(todayFunction.invoke(), LocalDate.now()); } - } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/UnionFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/UnionFunctionTest.java index cc99800a7a7..eb9180f8497 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/UnionFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/UnionFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -22,18 +22,12 @@ import java.util.Arrays; import java.util.Collections; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class UnionFunctionTest { - private UnionFunction unionFunction; - - @BeforeEach - void setUp() { - unionFunction = new UnionFunction(); - } + private static final UnionFunction unionFunction = UnionFunction.INSTANCE; @Test void invokeNull() { @@ -52,13 +46,15 @@ void invokeSingleObject() { @Test void invokeSingleObjectInAList() { - FunctionTestUtil.assertResult(unionFunction.invoke(new Object[]{Collections.singletonList(10)}), Collections.singletonList(10)); + FunctionTestUtil.assertResult(unionFunction.invoke(new Object[]{Collections.singletonList(10)}), + Collections.singletonList(10)); } @Test void invokeSingleObjectInAnArray() { final int[] testArray = new int[]{10}; - FunctionTestUtil.assertResult(unionFunction.invoke(new Object[]{testArray}), Collections.singletonList(testArray)); + FunctionTestUtil.assertResult(unionFunction.invoke(new Object[]{testArray}), + Collections.singletonList(testArray)); } @Test @@ -68,7 +64,8 @@ void invokeListIsNull() { @Test void invokeListContainsNull() { - FunctionTestUtil.assertResult(unionFunction.invoke(new Object[]{Arrays.asList(null, 10, null)}), Arrays.asList(null, 10)); + FunctionTestUtil.assertResult(unionFunction.invoke(new Object[]{Arrays.asList(null, 10, null)}), + Arrays.asList(null, 10)); } @Test @@ -79,7 +76,8 @@ void invokeListsNoDuplicates() { @Test void invokeListsSomeDuplicates() { - final Object[] params = new Object[]{Arrays.asList(10, 8, 3), Arrays.asList(1, 10, 2), Arrays.asList(10, 3, 2, 5)}; + final Object[] params = new Object[]{Arrays.asList(10, 8, 3), Arrays.asList(1, 10, 2), Arrays.asList(10, 3, 2 + , 5)}; FunctionTestUtil.assertResultList(unionFunction.invoke(params), Arrays.asList(10, 8, 3, 1, 2, 5)); } @@ -91,12 +89,14 @@ void invokeListsAllDuplicates() { @Test void invokeListAndSingleObject() { - FunctionTestUtil.assertResultList(unionFunction.invoke(new Object[]{Arrays.asList(10, 4, 5), 1}), Arrays.asList(10, 4, 5, 1)); + FunctionTestUtil.assertResultList(unionFunction.invoke(new Object[]{Arrays.asList(10, 4, 5), 1}), + Arrays.asList(10, 4, 5, 1)); } @Test void invokeListAndSingleObjectWithDuplicates() { - FunctionTestUtil.assertResultList(unionFunction.invoke(new Object[]{5, Arrays.asList(10, 4, 5), 10}), Arrays.asList(5, 10, 4)); + FunctionTestUtil.assertResultList(unionFunction.invoke(new Object[]{5, Arrays.asList(10, 4, 5), 10}), + Arrays.asList(5, 10, 4)); } @Test diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/WeekOfYearTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/WeekOfYearTest.java index d6ca2314cfe..af142a53434 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/WeekOfYearTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/WeekOfYearTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -24,7 +24,6 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; @@ -32,19 +31,16 @@ class WeekOfYearTest { - private WeekOfYearFunction fut; - - @BeforeEach - void setUp() { - fut = WeekOfYearFunction.INSTANCE; - } + private static final WeekOfYearFunction fut = WeekOfYearFunction.INSTANCE; @Test void weekOfYearFunctionTemporalAccessor() { FunctionTestUtil.assertResult(fut.invoke(LocalDate.of(2019, 9, 17)), valueOf(38)); FunctionTestUtil.assertResult(fut.invoke(LocalDateTime.of(2019, 9, 17, 0, 0, 0)), valueOf(38)); - FunctionTestUtil.assertResult(fut.invoke(OffsetDateTime.of(2019, 9, 17, 0, 0, 0, 0, ZoneOffset.UTC)), valueOf(38)); - FunctionTestUtil.assertResult(fut.invoke(ZonedDateTime.of(2019, 9, 17, 0, 0, 0, 0, ZoneOffset.UTC)), valueOf(38)); + FunctionTestUtil.assertResult(fut.invoke(OffsetDateTime.of(2019, 9, 17, 0, 0, 0, 0, ZoneOffset.UTC)), + valueOf(38)); + FunctionTestUtil.assertResult(fut.invoke(ZonedDateTime.of(2019, 9, 17, 0, 0, 0, 0, ZoneOffset.UTC)), + valueOf(38)); FunctionTestUtil.assertResultError(fut.invoke(null), InvalidParametersEvent.class); } } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/YearsAndMonthsFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/YearsAndMonthsFunctionTest.java index 57c36ee134f..f262c512223 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/YearsAndMonthsFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/YearsAndMonthsFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -25,19 +25,13 @@ import java.time.YearMonth; import java.time.temporal.Temporal; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.lang.types.impl.ComparablePeriod; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; class YearsAndMonthsFunctionTest { - private YearsAndMonthsFunction yamFunction; - - @BeforeEach - void setUp() { - yamFunction = new YearsAndMonthsFunction(); - } + private static final YearsAndMonthsFunction yamFunction = YearsAndMonthsFunction.INSTANCE; @Test void invokeNull() { @@ -48,8 +42,10 @@ void invokeNull() { @Test void invokeUnsupportedTemporal() { - FunctionTestUtil.assertResultError(yamFunction.invoke(Instant.EPOCH, Instant.EPOCH), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(yamFunction.invoke(LocalDate.of(2017, 1, 1), Instant.EPOCH), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(yamFunction.invoke(Instant.EPOCH, Instant.EPOCH), + InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(yamFunction.invoke(LocalDate.of(2017, 1, 1), Instant.EPOCH), + InvalidParametersEvent.class); } @Test diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/CountFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/CountFunctionTest.java index 344ff641169..2ac7c800ef3 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/CountFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/CountFunctionTest.java @@ -23,18 +23,12 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; class CountFunctionTest { - private NNCountFunction countFunction; - - @BeforeEach - void setUp() { - countFunction = new NNCountFunction(); - } + private static final NNCountFunction countFunction = NNCountFunction.INSTANCE; @Test void invokeParamListNull() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MaxFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MaxFunctionTest.java index 499b7b5e339..e8cd0308495 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MaxFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MaxFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -23,19 +23,13 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; class MaxFunctionTest { - private NNMaxFunction maxFunction; - - @BeforeEach - void setUp() { - maxFunction = new NNMaxFunction(); - } + private static final NNMaxFunction maxFunction = NNMaxFunction.INSTANCE; @Test void invokeNullList() { @@ -49,7 +43,8 @@ void invokeEmptyList() { @Test void invokeListWithHeterogenousTypes() { - FunctionTestUtil.assertResultError(maxFunction.invoke(Arrays.asList(1, "test", BigDecimal.valueOf(10.2))), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(maxFunction.invoke(Arrays.asList(1, "test", BigDecimal.valueOf(10.2))), + InvalidParametersEvent.class); } @Test @@ -80,7 +75,8 @@ void invokeEmptyArray() { @Test void invokeArrayWithHeterogenousTypes() { - FunctionTestUtil.assertResultError(maxFunction.invoke(new Object[]{1, "test", BigDecimal.valueOf(10.2)}), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(maxFunction.invoke(new Object[]{1, "test", BigDecimal.valueOf(10.2)}), + InvalidParametersEvent.class); } @Test diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MeanFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MeanFunctionTest.java index 6170103b523..c202f581cc8 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MeanFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MeanFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -23,19 +23,13 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; class MeanFunctionTest { - private NNMeanFunction meanFunction; - - @BeforeEach - void setUp() { - meanFunction = new NNMeanFunction(); - } + private static final NNMeanFunction meanFunction = NNMeanFunction.INSTANCE; @Test void invokeNumberNull() { @@ -91,7 +85,8 @@ void invokeListTypeHeterogenous() { @Test void invokeListParamSupportedTypesWithNull() { - FunctionTestUtil.assertResult(meanFunction.invoke(Arrays.asList(20, 30, null, (long) 40, null, BigDecimal.TEN)), BigDecimal.valueOf(25)); + FunctionTestUtil.assertResult(meanFunction.invoke(Arrays.asList(20, 30, null, (long) 40, null, + BigDecimal.TEN)), BigDecimal.valueOf(25)); } @Test @@ -104,7 +99,8 @@ void invokeListWithIntegers() { @Test void invokeListWithDoubles() { FunctionTestUtil.assertResult(meanFunction.invoke(Arrays.asList(10.0d, 20.0d, 30.0d)), BigDecimal.valueOf(20)); - FunctionTestUtil.assertResult(meanFunction.invoke(Arrays.asList(10.2d, 20.2d, 30.2d)), BigDecimal.valueOf(20.2)); + FunctionTestUtil.assertResult(meanFunction.invoke(Arrays.asList(10.2d, 20.2d, 30.2d)), + BigDecimal.valueOf(20.2)); } @Test @@ -139,5 +135,4 @@ void invokeArrayWithDoubles() { void invokeArrayParamSupportedTypesWithNull() { FunctionTestUtil.assertResult(meanFunction.invoke(new Object[]{20, 30, null, (long) 40, null, BigDecimal.TEN}), BigDecimal.valueOf(25)); } - } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MinFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MinFunctionTest.java index cace72fa8e9..3c15bff2208 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MinFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MinFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -23,19 +23,13 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; class MinFunctionTest { - private NNMinFunction minFunction; - - @BeforeEach - void setUp() { - minFunction = new NNMinFunction(); - } + private static final NNMinFunction minFunction = NNMinFunction.INSTANCE; @Test void invokeNullList() { @@ -49,7 +43,8 @@ void invokeEmptyList() { @Test void invokeListWithHeterogenousTypes() { - FunctionTestUtil.assertResultError(minFunction.invoke(Arrays.asList(1, "test", BigDecimal.valueOf(10.2))), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(minFunction.invoke(Arrays.asList(1, "test", BigDecimal.valueOf(10.2))), + InvalidParametersEvent.class); } @Test @@ -57,7 +52,7 @@ void invokeListOfIntegers() { FunctionTestUtil.assertResult(minFunction.invoke(Collections.singletonList(1)), 1); FunctionTestUtil.assertResult(minFunction.invoke(Arrays.asList(null, 1, 2, 3)), 1); FunctionTestUtil.assertResult(minFunction.invoke(Arrays.asList(2, null, 1, 3)), 1); - FunctionTestUtil.assertResult(minFunction.invoke(Arrays.asList(2, 3, 1, null )), 1); + FunctionTestUtil.assertResult(minFunction.invoke(Arrays.asList(2, 3, 1, null)), 1); } @Test @@ -80,7 +75,8 @@ void invokeEmptyArray() { @Test void invokeArrayWithHeterogenousTypes() { - FunctionTestUtil.assertResultError(minFunction.invoke(new Object[]{1, "test", BigDecimal.valueOf(10.2)}), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(minFunction.invoke(new Object[]{1, "test", BigDecimal.valueOf(10.2)}), + InvalidParametersEvent.class); } @Test diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAllFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAllFunctionTest.java index 68919aee554..4bbb690a6b1 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAllFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAllFunctionTest.java @@ -22,98 +22,93 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; class NNAllFunctionTest { - private NNAllFunction NNAllFunction; + private static final NNAllFunction nnAllFunction = NNAllFunction.INSTANCE; - @BeforeEach - void setUp() { - NNAllFunction = new NNAllFunction(); - } @Test void invokeBooleanParamNull() { - FunctionTestUtil.assertResult(NNAllFunction.invoke((Boolean) null), true); + FunctionTestUtil.assertResult(nnAllFunction.invoke((Boolean) null), true); } @Test void invokeBooleanParamTrue() { - FunctionTestUtil.assertResult(NNAllFunction.invoke(true), true); + FunctionTestUtil.assertResult(nnAllFunction.invoke(true), true); } @Test void invokeBooleanParamFalse() { - FunctionTestUtil.assertResult(NNAllFunction.invoke(false), false); + FunctionTestUtil.assertResult(nnAllFunction.invoke(false), false); } @Test void invokeArrayParamNull() { - FunctionTestUtil.assertResult(NNAllFunction.invoke((Object[]) null), true); + FunctionTestUtil.assertResult(nnAllFunction.invoke((Object[]) null), true); } @Test void invokeArrayParamEmptyArray() { - FunctionTestUtil.assertResult(NNAllFunction.invoke(new Object[]{}), true); + FunctionTestUtil.assertResult(nnAllFunction.invoke(new Object[]{}), true); } @Test void invokeArrayParamReturnTrue() { - FunctionTestUtil.assertResult(NNAllFunction.invoke(new Object[]{Boolean.TRUE, Boolean.TRUE}), true); + FunctionTestUtil.assertResult(nnAllFunction.invoke(new Object[]{Boolean.TRUE, Boolean.TRUE}), true); } @Test void invokeArrayParamReturnFalse() { - FunctionTestUtil.assertResult(NNAllFunction.invoke(new Object[]{Boolean.TRUE, Boolean.FALSE}), false); - FunctionTestUtil.assertResult(NNAllFunction.invoke(new Object[]{Boolean.TRUE, null, Boolean.FALSE}), false); + FunctionTestUtil.assertResult(nnAllFunction.invoke(new Object[]{Boolean.TRUE, Boolean.FALSE}), false); + FunctionTestUtil.assertResult(nnAllFunction.invoke(new Object[]{Boolean.TRUE, null, Boolean.FALSE}), false); } @Test void invokeArrayParamReturnNull() { - FunctionTestUtil.assertResult(NNAllFunction.invoke(new Object[]{Boolean.TRUE, null, Boolean.TRUE}), true); + FunctionTestUtil.assertResult(nnAllFunction.invoke(new Object[]{Boolean.TRUE, null, Boolean.TRUE}), true); } @Test void invokeArrayParamTypeHeterogenousArray() { - FunctionTestUtil.assertResultError(NNAllFunction.invoke(new Object[]{Boolean.TRUE, 1}), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(NNAllFunction.invoke(new Object[]{Boolean.FALSE, 1}), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(NNAllFunction.invoke(new Object[]{Boolean.TRUE, null, 1}), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(nnAllFunction.invoke(new Object[]{Boolean.TRUE, 1}), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(nnAllFunction.invoke(new Object[]{Boolean.FALSE, 1}), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(nnAllFunction.invoke(new Object[]{Boolean.TRUE, null, 1}), InvalidParametersEvent.class); } @Test void invokeListParamNull() { - FunctionTestUtil.assertResult(NNAllFunction.invoke((List) null), true); + FunctionTestUtil.assertResult(nnAllFunction.invoke((List) null), true); } @Test void invokeListParamEmptyList() { - FunctionTestUtil.assertResult(NNAllFunction.invoke(Collections.emptyList()), true); + FunctionTestUtil.assertResult(nnAllFunction.invoke(Collections.emptyList()), true); } @Test void invokeListParamReturnTrue() { - FunctionTestUtil.assertResult(NNAllFunction.invoke(Arrays.asList(Boolean.TRUE, Boolean.TRUE)), true); + FunctionTestUtil.assertResult(nnAllFunction.invoke(Arrays.asList(Boolean.TRUE, Boolean.TRUE)), true); } @Test void invokeListParamReturnFalse() { - FunctionTestUtil.assertResult(NNAllFunction.invoke(Arrays.asList(Boolean.TRUE, Boolean.FALSE)), false); - FunctionTestUtil.assertResult(NNAllFunction.invoke(Arrays.asList(Boolean.TRUE, null, Boolean.FALSE)), false); + FunctionTestUtil.assertResult(nnAllFunction.invoke(Arrays.asList(Boolean.TRUE, Boolean.FALSE)), false); + FunctionTestUtil.assertResult(nnAllFunction.invoke(Arrays.asList(Boolean.TRUE, null, Boolean.FALSE)), false); } @Test void invokeListParamReturnNull() { - FunctionTestUtil.assertResult(NNAllFunction.invoke(Arrays.asList(Boolean.TRUE, null, Boolean.TRUE)), true); + FunctionTestUtil.assertResult(nnAllFunction.invoke(Arrays.asList(Boolean.TRUE, null, Boolean.TRUE)), true); } @Test void invokeListParamTypeHeterogenousArray() { - FunctionTestUtil.assertResultError(NNAllFunction.invoke(Arrays.asList(Boolean.TRUE, 1)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(NNAllFunction.invoke(Arrays.asList(Boolean.FALSE, 1)), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(NNAllFunction.invoke(Arrays.asList(Boolean.TRUE, null, 1)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(nnAllFunction.invoke(Arrays.asList(Boolean.TRUE, 1)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(nnAllFunction.invoke(Arrays.asList(Boolean.FALSE, 1)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(nnAllFunction.invoke(Arrays.asList(Boolean.TRUE, null, 1)), InvalidParametersEvent.class); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAnyFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAnyFunctionTest.java index ef3453b7d6e..41c49e4ccbc 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAnyFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAnyFunctionTest.java @@ -22,19 +22,14 @@ import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; class NNAnyFunctionTest { - private NNAnyFunction anyFunction; + private static final NNAnyFunction anyFunction = NNAnyFunction.INSTANCE; - @BeforeEach - void setUp() { - anyFunction = new NNAnyFunction(); - } @Test void invokeBooleanParamNull() { diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/SumFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/SumFunctionTest.java index 4b08bd0200d..9fed1bd7a63 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/SumFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/SumFunctionTest.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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 @@ -22,19 +22,13 @@ import java.util.Arrays; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; import org.kie.dmn.feel.runtime.functions.FunctionTestUtil; class SumFunctionTest { - private NNSumFunction sumFunction; - - @BeforeEach - void setUp() { - sumFunction = new NNSumFunction(); - } + private static final NNSumFunction sumFunction = NNSumFunction.INSTANCE; @Test void invokeNumberParamNull() { @@ -61,22 +55,26 @@ void invokeListParam() { @Test void invokeListParamContainsUnsupportedNumber() { - FunctionTestUtil.assertResultError(sumFunction.invoke(Arrays.asList(10, 2, Double.NaN)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sumFunction.invoke(Arrays.asList(10, 2, Double.NaN)), + InvalidParametersEvent.class); } @Test void invokeListParamContainsUnsupportedType() { - FunctionTestUtil.assertResultError(sumFunction.invoke(Arrays.asList(10, "test", 2)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sumFunction.invoke(Arrays.asList(10, "test", 2)), + InvalidParametersEvent.class); } @Test void invokeListParamSupportedTypes() { - FunctionTestUtil.assertResult(sumFunction.invoke(Arrays.asList(4, -1, 12.1, (long) 5, BigDecimal.TEN)), BigDecimal.valueOf(30.1)); + FunctionTestUtil.assertResult(sumFunction.invoke(Arrays.asList(4, -1, 12.1, (long) 5, BigDecimal.TEN)), + BigDecimal.valueOf(30.1)); } @Test void invokeListParamSupportedTypesWithNull() { - FunctionTestUtil.assertResult(sumFunction.invoke(Arrays.asList(4, -1, 12.1, null, (long) 5, null, BigDecimal.TEN)), BigDecimal.valueOf(30.1)); + FunctionTestUtil.assertResult(sumFunction.invoke(Arrays.asList(4, -1, 12.1, null, (long) 5, null, + BigDecimal.TEN)), BigDecimal.valueOf(30.1)); } @Test @@ -86,21 +84,25 @@ void invokeArrayParam() { @Test void invokeArrayParamContainsUnsupportedNumber() { - FunctionTestUtil.assertResultError(sumFunction.invoke(new Object[]{10, 2, Double.NaN}), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sumFunction.invoke(new Object[]{10, 2, Double.NaN}), + InvalidParametersEvent.class); } @Test void invokeArrayParamContainsUnsupportedType() { - FunctionTestUtil.assertResultError(sumFunction.invoke(new Object[]{10, "test", 2}), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sumFunction.invoke(new Object[]{10, "test", 2}), + InvalidParametersEvent.class); } @Test void invokeArrayParamSupportedTypes() { - FunctionTestUtil.assertResult(sumFunction.invoke(new Object[]{4, -1, 12.1, (long) 5, BigDecimal.TEN}), BigDecimal.valueOf(30.1)); + FunctionTestUtil.assertResult(sumFunction.invoke(new Object[]{4, -1, 12.1, (long) 5, BigDecimal.TEN}), + BigDecimal.valueOf(30.1)); } @Test void invokeArrayParamSupportedTypesWithNull() { - FunctionTestUtil.assertResult(sumFunction.invoke(new Object[]{4, -1, null, 12.1, (long) 5, null, BigDecimal.TEN, null}), BigDecimal.valueOf(30.1)); + FunctionTestUtil.assertResult(sumFunction.invoke(new Object[]{4, -1, null, 12.1, (long) 5, null, + BigDecimal.TEN, null}), BigDecimal.valueOf(30.1)); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-signavio/src/main/java/org/kie/dmn/signavio/MultiInstanceDecisionLogic.java b/kie-dmn/kie-dmn-signavio/src/main/java/org/kie/dmn/signavio/MultiInstanceDecisionLogic.java index e8ccbc9bf93..d9a11187fc1 100644 --- a/kie-dmn/kie-dmn-signavio/src/main/java/org/kie/dmn/signavio/MultiInstanceDecisionLogic.java +++ b/kie-dmn/kie-dmn-signavio/src/main/java/org/kie/dmn/signavio/MultiInstanceDecisionLogic.java @@ -280,25 +280,25 @@ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult d FEELFnResult r; switch (mi.aggregationFunction) { case "SUM": - r = new SumFunction().invoke(invokationResults); + r = SumFunction.INSTANCE.invoke(invokationResults); break; case "MIN": - r = new MinFunction().invoke(invokationResults); + r = MinFunction.INSTANCE.invoke(invokationResults); break; case "MAX": - r = new MaxFunction().invoke(invokationResults); + r = MaxFunction.INSTANCE.invoke(invokationResults); break; case "COUNT": r = FEELFnResult.ofResult(NumberEvalHelper.getBigDecimalOrNull(invokationResults.size())); break; case "ALLTRUE": - r = new AllFunction().invoke(invokationResults); + r = AllFunction.INSTANCE.invoke(invokationResults); break; case "ANYTRUE": - r = new AnyFunction().invoke(invokationResults); + r = AnyFunction.INSTANCE.invoke(invokationResults); break; case "ALLFALSE": - FEELFnResult anyResult = new AnyFunction().invoke(invokationResults); + FEELFnResult anyResult = AnyFunction.INSTANCE.invoke(invokationResults); r = anyResult.map(b -> !b); break; case "COLLECT": From 6c24376bd82f84c23e4bf3fcaf6d849cbfd55402 Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Mon, 1 Jul 2024 17:24:28 +0900 Subject: [PATCH 10/13] [incubator-kie-drools-5847] Flaky KieContainerTest.testIncrementalCompilationSynchronization timeout (#6002) --- .../mvel/integrationtests/KieContainerTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/KieContainerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/KieContainerTest.java index 0bebcd07b8e..7c85701728b 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/KieContainerTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/KieContainerTest.java @@ -27,6 +27,8 @@ import java.util.List; import org.apache.commons.io.IOUtils; +import org.drools.base.definitions.InternalKnowledgePackage; +import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.compiler.compiler.io.Folder; import org.drools.compiler.compiler.io.memory.MemoryFileSystem; import org.drools.compiler.kie.builder.impl.MemoryKieModule; @@ -38,6 +40,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import org.kie.api.KieBase; import org.kie.api.KieServices; import org.kie.api.builder.KieModule; import org.kie.api.builder.Message.Level; @@ -267,6 +270,13 @@ public void testIncrementalCompilationSynchronization() { Thread t = new Thread(() -> { for (int i = 1; i < 10; i++) { + while (!previousRuleExists(kieContainer, i)) { // if rule1 exists, we can change it to rule2 + try { + Thread.sleep(1); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } ReleaseId releaseId1 = kieServices.newReleaseId("org.kie.test", "sync-scanner-test", "1.0." + i); KieUtil.getKieModuleFromDrls(releaseId1, kieBaseTestConfiguration, createDRL("rule" + i)); kieContainer.updateToVersion(releaseId1); @@ -292,6 +302,13 @@ public void testIncrementalCompilationSynchronization() { } } + private static boolean previousRuleExists(KieContainer kieContainer, int i) { + KieBase kieBase = kieContainer.getKieBase(); + InternalKnowledgePackage internalKnowledgePackage = (InternalKnowledgePackage)kieBase.getKiePackage("org.kie.test"); + RuleImpl rule = internalKnowledgePackage.getRule("rule" + (i - 1)); + return rule != null; + } + @Test public void testMemoryFileSystemFolderUniqueness() { KieServices kieServices = KieServices.Factory.get(); From 87181d64bd8b1fcfba84b0bc998d31a7d268cc6b Mon Sep 17 00:00:00 2001 From: Gabriele Cardosi Date: Mon, 1 Jul 2024 12:27:09 +0200 Subject: [PATCH 11/13] [NO-ISSUE#reformat-license] Reformat license header (#6009) Co-authored-by: Gabriele-Cardosi --- .../impact/analysis/graph/json/GraphJsonGenerator.java | 6 +++--- .../drools/impact/analysis/graph/json/JsonOutputTest.java | 6 +++--- .../integrationtests/DeleteSpecificFactActionTest.java | 6 +++--- .../analysis/model/right/DeleteSpecificFactAction.java | 6 +++--- .../impact/analysis/model/right/SpecificProperty.java | 6 +++--- .../drools/model/codegen/execmodel/ConditionalExprTest.java | 6 +++--- .../model/codegen/execmodel/bigdecimaltest/BDFact.java | 6 +++--- .../org/drools/ruleunits/impl/MultipleDataSourceUnit.java | 6 +++--- .../compiler/integrationtests/UnexpectedLoopTest.java | 6 +++--- .../java/org/kie/dmn/core/compiler/UnnamedImportUtils.java | 6 +++--- .../src/main/java/org/kie/dmn/core/util/NamespaceUtil.java | 6 +++--- .../org/kie/dmn/feel/codegen/feel11/ASTCompilerHelper.java | 6 +++--- .../dmn/feel/codegen/feel11/CompilationErrorNotifier.java | 6 +++--- .../kie/dmn/feel/codegen/feel11/DMNCodegenConstants.java | 6 +++--- .../src/main/java/org/kie/dmn/feel/lang/FEELDialect.java | 6 +++--- .../dmn/feel/lang/ast/forexpressioniterators/Direction.java | 6 +++--- .../main/java/org/kie/dmn/feel/lang/impl/FEELBuilder.java | 6 +++--- .../kie/dmn/feel/runtime/functions/ListReplaceFunction.java | 6 +++--- .../feel/runtime/functions/twovaluelogic/NNAllFunction.java | 6 +++--- .../feel/runtime/functions/twovaluelogic/NNAnyFunction.java | 6 +++--- .../runtime/functions/twovaluelogic/NNCountFunction.java | 6 +++--- .../feel/runtime/functions/twovaluelogic/NNMaxFunction.java | 6 +++--- .../src/main/java/org/kie/dmn/feel/util/CodegenUtils.java | 6 +++--- .../ZonedDateTimeRangeIteratorTest.java | 6 +++--- .../java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java | 6 +++--- .../org/kie/dmn/feel/runtime/functions/AllFunctionTest.java | 6 +++--- .../org/kie/dmn/feel/runtime/functions/AnyFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/AppendFunctionTest.java | 6 +++--- .../dmn/feel/runtime/functions/BuiltInFunctionsTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/CeilingFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/CodeFunctionTest.java | 6 +++--- .../dmn/feel/runtime/functions/ConcatenateFunctionTest.java | 6 +++--- .../dmn/feel/runtime/functions/ContainsFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/ContextFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/CountFunctionTest.java | 6 +++--- .../dmn/feel/runtime/functions/DateTimeFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/DecimalFunctionTest.java | 6 +++--- .../feel/runtime/functions/DistinctValuesFunctionTest.java | 6 +++--- .../dmn/feel/runtime/functions/EndsWithFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/FlattenFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/IndexOfFunctionTest.java | 6 +++--- .../feel/runtime/functions/InsertBeforeFunctionTest.java | 6 +++--- .../feel/runtime/functions/ListContainsFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/MatchesFunctionTest.java | 6 +++--- .../org/kie/dmn/feel/runtime/functions/MaxFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/MeanFunctionTest.java | 6 +++--- .../org/kie/dmn/feel/runtime/functions/MinFunctionTest.java | 6 +++--- .../org/kie/dmn/feel/runtime/functions/MonthOfYearTest.java | 6 +++--- .../org/kie/dmn/feel/runtime/functions/NotFunctionTest.java | 6 +++--- .../org/kie/dmn/feel/runtime/functions/NowFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/NumberFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/RangeFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/RemoveFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/ReverseFunctionTest.java | 6 +++--- .../dmn/feel/runtime/functions/RoundDownFunctionTest.java | 6 +++--- .../feel/runtime/functions/RoundHalfDownFunctionTest.java | 6 +++--- .../dmn/feel/runtime/functions/RoundHalfUpFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/RoundUpFunctionTest.java | 6 +++--- .../dmn/feel/runtime/functions/StartsWithFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/StringFunctionTest.java | 6 +++--- .../feel/runtime/functions/StringLengthFunctionTest.java | 6 +++--- .../feel/runtime/functions/StringLowerCaseFunctionTest.java | 6 +++--- .../feel/runtime/functions/StringUpperCaseFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/SublistFunctionTest.java | 6 +++--- .../feel/runtime/functions/SubstringAfterFunctionTest.java | 6 +++--- .../feel/runtime/functions/SubstringBeforeFunctionTest.java | 6 +++--- .../dmn/feel/runtime/functions/SubstringFunctionTest.java | 6 +++--- .../org/kie/dmn/feel/runtime/functions/SumFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/TimeFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/TodayFunctionTest.java | 6 +++--- .../kie/dmn/feel/runtime/functions/UnionFunctionTest.java | 6 +++--- .../org/kie/dmn/feel/runtime/functions/WeekOfYearTest.java | 6 +++--- .../feel/runtime/functions/YearsAndMonthsFunctionTest.java | 6 +++--- .../runtime/functions/twovaluelogic/MaxFunctionTest.java | 6 +++--- .../runtime/functions/twovaluelogic/MeanFunctionTest.java | 6 +++--- .../runtime/functions/twovaluelogic/MinFunctionTest.java | 6 +++--- .../runtime/functions/twovaluelogic/SumFunctionTest.java | 6 +++--- .../java/org/kie/dmn/openapi/impl/BaseNodeSchemaMapper.java | 6 +++--- .../org/kie/dmn/openapi/impl/InfixOpNodeSchemaMapper.java | 6 +++--- .../test/java/org/kie/dmn/openapi/EnumGenerationTest.java | 6 +++--- .../java/org/kie/dmn/openapi/impl/DMNTypeSchemasTest.java | 6 +++--- .../kie/dmn/openapi/impl/FEELFunctionSchemaMapperTest.java | 6 +++--- .../kie/dmn/openapi/impl/InfixOpNodeSchemaMapperTest.java | 6 +++--- .../org/kie/dmn/openapi/impl/RangeNodeSchemaMapperTest.java | 6 +++--- .../org/kie/dmn/openapi/impl/SchemaMapperTestUtils.java | 6 +++--- .../org/kie/dmn/validation/v1_5/DMN15ValidationsTest.java | 6 +++--- 87 files changed, 261 insertions(+), 261 deletions(-) diff --git a/drools-impact-analysis/drools-impact-analysis-graph/drools-impact-analysis-graph-json/src/main/java/org/drools/impact/analysis/graph/json/GraphJsonGenerator.java b/drools-impact-analysis/drools-impact-analysis-graph/drools-impact-analysis-graph-json/src/main/java/org/drools/impact/analysis/graph/json/GraphJsonGenerator.java index e578b434e1e..6a764e2da40 100644 --- a/drools-impact-analysis/drools-impact-analysis-graph/drools-impact-analysis-graph-json/src/main/java/org/drools/impact/analysis/graph/json/GraphJsonGenerator.java +++ b/drools-impact-analysis/drools-impact-analysis-graph/drools-impact-analysis-graph-json/src/main/java/org/drools/impact/analysis/graph/json/GraphJsonGenerator.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/drools-impact-analysis/drools-impact-analysis-graph/drools-impact-analysis-graph-json/src/test/java/org/drools/impact/analysis/graph/json/JsonOutputTest.java b/drools-impact-analysis/drools-impact-analysis-graph/drools-impact-analysis-graph-json/src/test/java/org/drools/impact/analysis/graph/json/JsonOutputTest.java index 1cd927715cd..3a226e1c477 100644 --- a/drools-impact-analysis/drools-impact-analysis-graph/drools-impact-analysis-graph-json/src/test/java/org/drools/impact/analysis/graph/json/JsonOutputTest.java +++ b/drools-impact-analysis/drools-impact-analysis-graph/drools-impact-analysis-graph-json/src/test/java/org/drools/impact/analysis/graph/json/JsonOutputTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/drools-impact-analysis/drools-impact-analysis-itests/src/test/java/org/drools/impact/analysis/integrationtests/DeleteSpecificFactActionTest.java b/drools-impact-analysis/drools-impact-analysis-itests/src/test/java/org/drools/impact/analysis/integrationtests/DeleteSpecificFactActionTest.java index 4458cbc3d53..c87723be523 100644 --- a/drools-impact-analysis/drools-impact-analysis-itests/src/test/java/org/drools/impact/analysis/integrationtests/DeleteSpecificFactActionTest.java +++ b/drools-impact-analysis/drools-impact-analysis-itests/src/test/java/org/drools/impact/analysis/integrationtests/DeleteSpecificFactActionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/drools-impact-analysis/drools-impact-analysis-model/src/main/java/org/drools/impact/analysis/model/right/DeleteSpecificFactAction.java b/drools-impact-analysis/drools-impact-analysis-model/src/main/java/org/drools/impact/analysis/model/right/DeleteSpecificFactAction.java index d2a969d113d..4bdc15a98d9 100644 --- a/drools-impact-analysis/drools-impact-analysis-model/src/main/java/org/drools/impact/analysis/model/right/DeleteSpecificFactAction.java +++ b/drools-impact-analysis/drools-impact-analysis-model/src/main/java/org/drools/impact/analysis/model/right/DeleteSpecificFactAction.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/drools-impact-analysis/drools-impact-analysis-model/src/main/java/org/drools/impact/analysis/model/right/SpecificProperty.java b/drools-impact-analysis/drools-impact-analysis-model/src/main/java/org/drools/impact/analysis/model/right/SpecificProperty.java index 049ab3821ed..98b42345292 100644 --- a/drools-impact-analysis/drools-impact-analysis-model/src/main/java/org/drools/impact/analysis/model/right/SpecificProperty.java +++ b/drools-impact-analysis/drools-impact-analysis-model/src/main/java/org/drools/impact/analysis/model/right/SpecificProperty.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConditionalExprTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConditionalExprTest.java index 89f89561c7d..a8d5908248c 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConditionalExprTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConditionalExprTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/bigdecimaltest/BDFact.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/bigdecimaltest/BDFact.java index de9721e8bc3..22bda86db64 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/bigdecimaltest/BDFact.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/bigdecimaltest/BDFact.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/drools-ruleunits/drools-ruleunits-impl/src/test/java/org/drools/ruleunits/impl/MultipleDataSourceUnit.java b/drools-ruleunits/drools-ruleunits-impl/src/test/java/org/drools/ruleunits/impl/MultipleDataSourceUnit.java index cc066a1af03..1942dd9f26d 100644 --- a/drools-ruleunits/drools-ruleunits-impl/src/test/java/org/drools/ruleunits/impl/MultipleDataSourceUnit.java +++ b/drools-ruleunits/drools-ruleunits-impl/src/test/java/org/drools/ruleunits/impl/MultipleDataSourceUnit.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/UnexpectedLoopTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/UnexpectedLoopTest.java index 69975047075..4a700f65084 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/UnexpectedLoopTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/UnexpectedLoopTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/UnnamedImportUtils.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/UnnamedImportUtils.java index 1d3a963b122..e99ab989d88 100644 --- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/UnnamedImportUtils.java +++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/UnnamedImportUtils.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/util/NamespaceUtil.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/util/NamespaceUtil.java index c26f2339b22..05cefd642de 100644 --- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/util/NamespaceUtil.java +++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/util/NamespaceUtil.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 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 72b2013fcb9..30930577189 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 @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompilationErrorNotifier.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompilationErrorNotifier.java index 7dbc77fb114..b009dd4d847 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompilationErrorNotifier.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/codegen/feel11/CompilationErrorNotifier.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 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 59d96289d39..96520d8689c 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 @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/FEELDialect.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/FEELDialect.java index 4d1d68186cf..9d821f2407f 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/FEELDialect.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/FEELDialect.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/Direction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/Direction.java index 035a5fc9855..d718cdb8b68 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/Direction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/Direction.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/impl/FEELBuilder.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/impl/FEELBuilder.java index 60d4797cea7..405b0bf5a87 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/impl/FEELBuilder.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/impl/FEELBuilder.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ListReplaceFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ListReplaceFunction.java index 1b55434e265..287c4ea637c 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ListReplaceFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ListReplaceFunction.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAllFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAllFunction.java index 203b48287e7..3db980357b5 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAllFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAllFunction.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAnyFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAnyFunction.java index f149cc0f201..06b6d31bafd 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAnyFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNAnyFunction.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNCountFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNCountFunction.java index cfbd32f31ac..328da3d6b08 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNCountFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNCountFunction.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMaxFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMaxFunction.java index 788e22954b7..6db430ce6cf 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMaxFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/NNMaxFunction.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/CodegenUtils.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/CodegenUtils.java index 9eaddf4df80..8d6e753665f 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/CodegenUtils.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/util/CodegenUtils.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ZonedDateTimeRangeIteratorTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ZonedDateTimeRangeIteratorTest.java index 4f5e4d38116..9290ec8fa21 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ZonedDateTimeRangeIteratorTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/forexpressioniterators/ZonedDateTimeRangeIteratorTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java index 81245b662e4..af286aad609 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/custom/ZoneTimeTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AllFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AllFunctionTest.java index 06e35405ee0..b4d9eaa8d7c 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AllFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AllFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AnyFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AnyFunctionTest.java index aa322fb38f0..45aa9d6061a 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AnyFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AnyFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AppendFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AppendFunctionTest.java index 5298f0be4bc..cde80e69282 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AppendFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AppendFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BuiltInFunctionsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BuiltInFunctionsTest.java index 4f25dc1235f..286da3d7a25 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BuiltInFunctionsTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/BuiltInFunctionsTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CeilingFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CeilingFunctionTest.java index b7eaea5785e..b56260d7c18 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CeilingFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CeilingFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CodeFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CodeFunctionTest.java index 0bdbd97ba21..5dba828e2e9 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CodeFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CodeFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ConcatenateFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ConcatenateFunctionTest.java index e7b9e39d74f..aaa095bc09e 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ConcatenateFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ConcatenateFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ContainsFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ContainsFunctionTest.java index 31349953d4a..91cd7f41f12 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ContainsFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ContainsFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ContextFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ContextFunctionTest.java index 7078e33b65c..862728dc0ce 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ContextFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ContextFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CountFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CountFunctionTest.java index aa9591e5b6f..11843594d97 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CountFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/CountFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DateTimeFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DateTimeFunctionTest.java index ac8cd20a950..c03d24e756e 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DateTimeFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DateTimeFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DecimalFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DecimalFunctionTest.java index d56b213393a..935aea3d8df 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DecimalFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DecimalFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DistinctValuesFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DistinctValuesFunctionTest.java index f23c0295244..00d0fec99e1 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DistinctValuesFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DistinctValuesFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/EndsWithFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/EndsWithFunctionTest.java index a3df90c4b37..d3effede808 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/EndsWithFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/EndsWithFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FlattenFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FlattenFunctionTest.java index 86b5bc900c1..bdf3cee58a9 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FlattenFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/FlattenFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/IndexOfFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/IndexOfFunctionTest.java index 9317907bf9b..87d2bcce178 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/IndexOfFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/IndexOfFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/InsertBeforeFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/InsertBeforeFunctionTest.java index 380b57ffe60..08ccd0c952f 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/InsertBeforeFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/InsertBeforeFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ListContainsFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ListContainsFunctionTest.java index ac96e85d3f1..4fd3da99418 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ListContainsFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ListContainsFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java index 0f105f622d9..eeb86f511a9 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MaxFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MaxFunctionTest.java index ddc5e1f81b9..5c8b1f4031e 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MaxFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MaxFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MeanFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MeanFunctionTest.java index 368fe628d86..598e0371607 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MeanFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MeanFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MinFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MinFunctionTest.java index 59b1a8634b6..447eaf6cccf 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MinFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MinFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MonthOfYearTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MonthOfYearTest.java index c77e169f3e4..56eb0aa2b89 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MonthOfYearTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MonthOfYearTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NotFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NotFunctionTest.java index c79073df62c..3dc3b6a8d90 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NotFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NotFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NowFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NowFunctionTest.java index 7bc19492a3c..23263fa1f13 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NowFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NowFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NumberFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NumberFunctionTest.java index 0e2ef01e32b..6e8371d0f39 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NumberFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/NumberFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RangeFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RangeFunctionTest.java index 08a77bde8ed..2ed5fc7d4a9 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RangeFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RangeFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RemoveFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RemoveFunctionTest.java index aade71092b6..09390298708 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RemoveFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RemoveFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java index 8864beaa143..06e1bc4da0e 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReverseFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReverseFunctionTest.java index 13b2e3b28fc..db447d69047 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReverseFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReverseFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundDownFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundDownFunctionTest.java index 5b58c9fdf4d..cba52b38f24 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundDownFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundDownFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundHalfDownFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundHalfDownFunctionTest.java index 79d498b1239..22a92489773 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundHalfDownFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundHalfDownFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundHalfUpFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundHalfUpFunctionTest.java index b37deb7d6f9..70015f3d4d4 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundHalfUpFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundHalfUpFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundUpFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundUpFunctionTest.java index 5827e777c8c..f74f60ce98a 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundUpFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/RoundUpFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StartsWithFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StartsWithFunctionTest.java index e4dcd3d63b6..da935805491 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StartsWithFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StartsWithFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringFunctionTest.java index 091c00f43d7..a549c39931d 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLengthFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLengthFunctionTest.java index ea52ff04fb3..85010aa8bfa 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLengthFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLengthFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLowerCaseFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLowerCaseFunctionTest.java index 6126be7009e..baf71732211 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLowerCaseFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringLowerCaseFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringUpperCaseFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringUpperCaseFunctionTest.java index 846f2c05c26..18e516ebd94 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringUpperCaseFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringUpperCaseFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SublistFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SublistFunctionTest.java index d2fd47b27ce..cad55b9fe2c 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SublistFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SublistFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringAfterFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringAfterFunctionTest.java index b152ac5ae54..8be7ab1d2d4 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringAfterFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringAfterFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringBeforeFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringBeforeFunctionTest.java index c88e5933727..6a86762bdb0 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringBeforeFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringBeforeFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringFunctionTest.java index d32c8078591..5f394949e42 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SubstringFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SumFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SumFunctionTest.java index 7602158e5d2..50d15bf8e64 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SumFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SumFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java index 63ba79e11bf..105ba640dd8 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TodayFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TodayFunctionTest.java index 6db80988b06..bca4c65dc11 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TodayFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TodayFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/UnionFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/UnionFunctionTest.java index eb9180f8497..2f636cd9db8 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/UnionFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/UnionFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/WeekOfYearTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/WeekOfYearTest.java index af142a53434..9b5430311d1 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/WeekOfYearTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/WeekOfYearTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/YearsAndMonthsFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/YearsAndMonthsFunctionTest.java index f262c512223..68dc4325c83 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/YearsAndMonthsFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/YearsAndMonthsFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MaxFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MaxFunctionTest.java index e8cd0308495..602fcd000bc 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MaxFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MaxFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MeanFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MeanFunctionTest.java index c202f581cc8..735f6f3175a 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MeanFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MeanFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MinFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MinFunctionTest.java index 3c15bff2208..7a1b7e3438b 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MinFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/MinFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/SumFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/SumFunctionTest.java index 9fed1bd7a63..c74336bb19d 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/SumFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/twovaluelogic/SumFunctionTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/BaseNodeSchemaMapper.java b/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/BaseNodeSchemaMapper.java index 3922a7381da..ecb987fa815 100644 --- a/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/BaseNodeSchemaMapper.java +++ b/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/BaseNodeSchemaMapper.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/InfixOpNodeSchemaMapper.java b/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/InfixOpNodeSchemaMapper.java index 7fdbed5f30e..6b302363fa3 100644 --- a/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/InfixOpNodeSchemaMapper.java +++ b/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/InfixOpNodeSchemaMapper.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/EnumGenerationTest.java b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/EnumGenerationTest.java index 3e387292db1..f0604cd5000 100644 --- a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/EnumGenerationTest.java +++ b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/EnumGenerationTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/DMNTypeSchemasTest.java b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/DMNTypeSchemasTest.java index 45174987c1c..1f6991ad8c6 100644 --- a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/DMNTypeSchemasTest.java +++ b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/DMNTypeSchemasTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/FEELFunctionSchemaMapperTest.java b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/FEELFunctionSchemaMapperTest.java index d26b8c8fd89..05b5566563f 100644 --- a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/FEELFunctionSchemaMapperTest.java +++ b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/FEELFunctionSchemaMapperTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/InfixOpNodeSchemaMapperTest.java b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/InfixOpNodeSchemaMapperTest.java index 76b768b0eec..42e8e136abe 100644 --- a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/InfixOpNodeSchemaMapperTest.java +++ b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/InfixOpNodeSchemaMapperTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/RangeNodeSchemaMapperTest.java b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/RangeNodeSchemaMapperTest.java index 2035dc3f6fb..a79c66b7ad3 100644 --- a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/RangeNodeSchemaMapperTest.java +++ b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/RangeNodeSchemaMapperTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/SchemaMapperTestUtils.java b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/SchemaMapperTestUtils.java index 3162fe04d2b..044f2a221d1 100644 --- a/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/SchemaMapperTestUtils.java +++ b/kie-dmn/kie-dmn-openapi/src/test/java/org/kie/dmn/openapi/impl/SchemaMapperTestUtils.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 diff --git a/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/v1_5/DMN15ValidationsTest.java b/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/v1_5/DMN15ValidationsTest.java index 78af94a45c3..7eb5e6774df 100644 --- a/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/v1_5/DMN15ValidationsTest.java +++ b/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/v1_5/DMN15ValidationsTest.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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 From a7974cb8bf45161830602322058e5ca2645a7de5 Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Mon, 8 Jul 2024 17:50:28 +0900 Subject: [PATCH 12/13] [incubator-kie-drools-5974] Possible deadlock with KieRepositoryImpl$KieModuleRepo and KieRepositoryScannerImpl (#6006) --- .../kie/builder/impl/KieRepositoryImpl.java | 176 +++++++++++------- .../kie/builder/impl/KieModuleRepoTest.java | 12 +- kie-ci/pom.xml | 21 ++- .../concurrent/ConcurrentBuildTest.java | 118 ++++++++++++ 4 files changed, 257 insertions(+), 70 deletions(-) create mode 100644 kie-ci/src/test/java/org/kie/scanner/concurrent/ConcurrentBuildTest.java diff --git a/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/KieRepositoryImpl.java b/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/KieRepositoryImpl.java index cd20a202a56..104beb73251 100644 --- a/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/KieRepositoryImpl.java +++ b/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/KieRepositoryImpl.java @@ -30,6 +30,7 @@ import java.util.NavigableMap; import java.util.TreeMap; import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.locks.ReentrantLock; import org.drools.compiler.compiler.io.memory.MemoryFileSystem; import org.drools.compiler.kproject.models.KieModuleModelImpl; @@ -70,6 +71,8 @@ public class KieRepositoryImpl private final KieModuleRepo kieModuleRepo; + private final ReentrantLock lock = new ReentrantLock(); + public static void setInternalKieScanner(InternalKieScanner scanner) { synchronized (KieScannerHolder.class) { KieScannerHolder.kieScanner = scanner; @@ -98,7 +101,7 @@ private static InternalKieScanner getInternalKieScanner() { } public KieRepositoryImpl() { - kieModuleRepo = new KieModuleRepo(); + kieModuleRepo = new KieModuleRepo(lock); } public void setDefaultGAV(ReleaseId releaseId) { @@ -192,7 +195,12 @@ private KieModule checkClasspathForKieModule(ReleaseId releaseId) { } private KieModule loadKieModuleFromMavenRepo(ReleaseId releaseId, PomModel pomModel) { - return KieScannerHolder.kieScanner.loadArtifact( releaseId, pomModel ); + try { + lock.lock(); + return KieScannerHolder.kieScanner.loadArtifact(releaseId, pomModel); + } finally { + lock.unlock(); + } } private static class DummyKieScanner @@ -329,6 +337,7 @@ public static class KieModuleRepo { = Integer.parseInt(System.getProperty(CACHE_VERSIONS_MAX_PROPERTY, "10")); // FIELDS ----------------------------------------------------------------------------------------------------------------- + private final ReentrantLock lock; // kieModules evicts based on access-time, not on insertion-time public final Map> kieModules @@ -348,44 +357,59 @@ protected boolean removeEldestEntry( Map.Entry eldest ) { }; // METHODS ---------------------------------------------------------------------------------------------------------------- + public KieModuleRepo(ReentrantLock lock) { + this.lock = lock; + } - public synchronized KieModule remove(ReleaseId releaseId) { - KieModule removedKieModule = null; - String ga = releaseId.getGroupId() + ":" + releaseId.getArtifactId(); - ComparableVersion comparableVersion = new ComparableVersion(releaseId.getVersion()); + public KieModule remove(ReleaseId releaseId) { + try { + lock.lock(); + + KieModule removedKieModule = null; + String ga = releaseId.getGroupId() + ":" + releaseId.getArtifactId(); + ComparableVersion comparableVersion = new ComparableVersion(releaseId.getVersion()); - NavigableMap artifactMap = kieModules.get(ga); - if (artifactMap != null) { - removedKieModule = artifactMap.remove(comparableVersion); - if (artifactMap.isEmpty()) { - kieModules.remove(ga); + NavigableMap artifactMap = kieModules.get(ga); + if (artifactMap != null) { + removedKieModule = artifactMap.remove(comparableVersion); + if (artifactMap.isEmpty()) { + kieModules.remove(ga); + } + oldKieModules.remove(releaseId); } - oldKieModules.remove(releaseId); - } - return removedKieModule; + return removedKieModule; + } finally { + lock.unlock(); + } } - public synchronized void store(KieModule kieModule) { - ReleaseId releaseId = kieModule.getReleaseId(); - String ga = releaseId.getGroupId() + ":" + releaseId.getArtifactId(); - ComparableVersion comparableVersion = new ComparableVersion(releaseId.getVersion()); + public void store(KieModule kieModule) { + try { + lock.lock(); + + ReleaseId releaseId = kieModule.getReleaseId(); + String ga = releaseId.getGroupId() + ":" + releaseId.getArtifactId(); + ComparableVersion comparableVersion = new ComparableVersion(releaseId.getVersion()); - NavigableMap artifactMap = kieModules.get(ga); - if( artifactMap == null ) { - artifactMap = createNewArtifactMap(); - kieModules.put(ga, artifactMap); - } + NavigableMap artifactMap = kieModules.get(ga); + if( artifactMap == null ) { + artifactMap = createNewArtifactMap(); + kieModules.put(ga, artifactMap); + } - KieModule oldReleaseIdKieModule = oldKieModules.get(releaseId); - // variable used in order to test race condition - if (oldReleaseIdKieModule == null) { - KieModule oldKieModule = artifactMap.get(comparableVersion); - if (oldKieModule != null) { - oldKieModules.put( releaseId, oldKieModule ); + KieModule oldReleaseIdKieModule = oldKieModules.get(releaseId); + // variable used in order to test race condition + if (oldReleaseIdKieModule == null) { + KieModule oldKieModule = artifactMap.get(comparableVersion); + if (oldKieModule != null) { + oldKieModules.put( releaseId, oldKieModule ); + } } + artifactMap.put( comparableVersion, kieModule ); + } finally { + lock.unlock(); } - artifactMap.put( comparableVersion, kieModule ); } /** @@ -421,56 +445,72 @@ public KieModule put( ComparableVersion key, KieModule value ) { return newArtifactMap; } - synchronized KieModule loadOldAndRemove(ReleaseId releaseId) { - return oldKieModules.remove(releaseId); + KieModule loadOldAndRemove(ReleaseId releaseId) { + try { + lock.lock(); + return oldKieModules.remove(releaseId); + } finally { + lock.unlock(); + } } - synchronized KieModule load(InternalKieScanner kieScanner, ReleaseId releaseId) { - return load(kieScanner, releaseId, new VersionRange(releaseId.getVersion())); + KieModule load(InternalKieScanner kieScanner, ReleaseId releaseId) { + try { + lock.lock(); + return load(kieScanner, releaseId, new VersionRange(releaseId.getVersion())); + } finally { + lock.unlock(); + } } - synchronized KieModule load(InternalKieScanner kieScanner, ReleaseId releaseId, VersionRange versionRange) { - String ga = releaseId.getGroupId() + ":" + releaseId.getArtifactId(); + KieModule load(InternalKieScanner kieScanner, ReleaseId releaseId, VersionRange versionRange) { + try { + lock.lock(); - NavigableMap artifactMap = kieModules.get(ga); - if ( artifactMap == null || artifactMap.isEmpty() ) { - return null; - } - KieModule kieModule = artifactMap.get(new ComparableVersion(releaseId.getVersion())); - - if (versionRange.fixed) { - if ( kieModule != null && releaseId.isSnapshot() ) { - String oldSnapshotVersion = ((ReleaseIdImpl)kieModule.getReleaseId()).getSnapshotVersion(); - if ( oldSnapshotVersion != null ) { - String currentSnapshotVersion = kieScanner.getArtifactVersion(releaseId); - if (currentSnapshotVersion != null && - new ComparableVersion(currentSnapshotVersion).compareTo(new ComparableVersion(oldSnapshotVersion)) > 0) { - // if the snapshot currently available on the maven repo is newer than the cached one - // return null to enforce the building of this newer version - return null; + String ga = releaseId.getGroupId() + ":" + releaseId.getArtifactId(); + + NavigableMap artifactMap = kieModules.get(ga); + if ( artifactMap == null || artifactMap.isEmpty() ) { + return null; + } + KieModule kieModule = artifactMap.get(new ComparableVersion(releaseId.getVersion())); + + if (versionRange.fixed) { + if ( kieModule != null && releaseId.isSnapshot() ) { + String oldSnapshotVersion = ((ReleaseIdImpl)kieModule.getReleaseId()).getSnapshotVersion(); + if ( oldSnapshotVersion != null ) { + String currentSnapshotVersion = kieScanner.getArtifactVersion(releaseId); + if (currentSnapshotVersion != null && + new ComparableVersion(currentSnapshotVersion).compareTo(new ComparableVersion(oldSnapshotVersion)) > 0) { + // if the snapshot currently available on the maven repo is newer than the cached one + // return null to enforce the building of this newer version + return null; + } } } + return kieModule; } - return kieModule; - } - Map.Entry entry = - versionRange.upperBound == null ? - artifactMap.lastEntry() : - versionRange.upperInclusive ? - artifactMap.floorEntry(new ComparableVersion(versionRange.upperBound)) : - artifactMap.lowerEntry(new ComparableVersion(versionRange.upperBound)); + Map.Entry entry = + versionRange.upperBound == null ? + artifactMap.lastEntry() : + versionRange.upperInclusive ? + artifactMap.floorEntry(new ComparableVersion(versionRange.upperBound)) : + artifactMap.lowerEntry(new ComparableVersion(versionRange.upperBound)); - if ( entry == null ) { - return null; - } + if ( entry == null ) { + return null; + } - if ( versionRange.lowerBound == null ) { - return entry.getValue(); - } + if ( versionRange.lowerBound == null ) { + return entry.getValue(); + } - int comparison = entry.getKey().compareTo(new ComparableVersion(versionRange.lowerBound)); - return comparison > 0 || (comparison == 0 && versionRange.lowerInclusive) ? entry.getValue() : null; + int comparison = entry.getKey().compareTo(new ComparableVersion(versionRange.lowerBound)); + return comparison > 0 || (comparison == 0 && versionRange.lowerInclusive) ? entry.getValue() : null; + } finally { + lock.unlock(); + } } } diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/kie/builder/impl/KieModuleRepoTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/kie/builder/impl/KieModuleRepoTest.java index 089286228ac..23afb8e649d 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/kie/builder/impl/KieModuleRepoTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/kie/builder/impl/KieModuleRepoTest.java @@ -30,6 +30,7 @@ import java.util.concurrent.CyclicBarrier; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.locks.ReentrantLock; import org.drools.compiler.kie.builder.impl.BuildContext; import org.drools.compiler.kie.builder.impl.InternalKieModule; @@ -89,7 +90,7 @@ public class KieModuleRepoTest { @Before public void before() throws Exception { - kieModuleRepo = new KieModuleRepo(); + kieModuleRepo = new KieModuleRepo(new ReentrantLock()); // store the original values as we need to restore them after the test maxSizeGaCacheOrig = KieModuleRepo.MAX_SIZE_GA_CACHE; @@ -139,6 +140,15 @@ private static KieContainerImpl createMockKieContainer( final ReleaseId projectR kieModuleRepoField.setAccessible(true); kieModuleRepoField.set(kieRepository, kieModuleRepo); kieModuleRepoField.setAccessible(false); + // share the lock between KieModuleRepo and KieRepository + final Field KieModuleRepoLockField = KieModuleRepo.class.getDeclaredField("lock"); + KieModuleRepoLockField.setAccessible(true); + Object lock = KieModuleRepoLockField.get(kieModuleRepo); + KieModuleRepoLockField.setAccessible(false); + final Field kieRepositoryImplLockField = KieRepositoryImpl.class.getDeclaredField("lock"); + kieRepositoryImplLockField.setAccessible(true); + kieRepositoryImplLockField.set(kieRepository, lock); + kieRepositoryImplLockField.setAccessible(false); // kie container final KieContainerImpl kieContainerImpl = new KieContainerImpl(mockKieProject, kieRepository); diff --git a/kie-ci/pom.xml b/kie-ci/pom.xml index e4a2f76a294..4e5c85613ba 100644 --- a/kie-ci/pom.xml +++ b/kie-ci/pom.xml @@ -36,6 +36,7 @@ org.kie.ci + org.kie.test.testcategory.TurtleTestCategory @@ -158,7 +159,12 @@ org.assertj assertj-core test - + + + org.kie + kie-test-util + test + @@ -235,4 +241,17 @@ + + + runTurtleTests + + + runTurtleTests + + + + + + + diff --git a/kie-ci/src/test/java/org/kie/scanner/concurrent/ConcurrentBuildTest.java b/kie-ci/src/test/java/org/kie/scanner/concurrent/ConcurrentBuildTest.java new file mode 100644 index 00000000000..f551e52196c --- /dev/null +++ b/kie-ci/src/test/java/org/kie/scanner/concurrent/ConcurrentBuildTest.java @@ -0,0 +1,118 @@ +/** + * 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.scanner.concurrent; + +import java.io.IOException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import org.drools.compiler.kie.builder.impl.InternalKieModule; +import org.drools.core.util.FileManager; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.kie.api.KieServices; +import org.kie.api.builder.ReleaseId; +import org.kie.scanner.AbstractKieCiTest; +import org.kie.scanner.KieMavenRepository; +import org.kie.test.testcategory.TurtleTestCategory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.junit.Assert.assertTrue; +import static org.kie.scanner.KieMavenRepository.getKieMavenRepository; + +@Category(TurtleTestCategory.class) +public class ConcurrentBuildTest extends AbstractKieCiTest { + private static final Logger LOG = LoggerFactory.getLogger(ConcurrentBuildTest.class); + + private FileManager fileManager; + + @Before + public void setUp() throws Exception { + this.fileManager = new FileManager(); + this.fileManager.setUp(); + ReleaseId releaseId = KieServices.Factory.get().newReleaseId("org.kie", "scanner-test", "1.0-SNAPSHOT"); + } + + @After + public void tearDown() throws Exception { + this.fileManager.tearDown(); + } + + // This is TurtleTest. You can run this test with -PrunTurtleTests + @Test(timeout=600000) + public void concurrentBuildWithDependency() throws Exception { + KieServices ks = KieServices.Factory.get(); + KieMavenRepository repository = getKieMavenRepository(); + + final int testLoop = 10; + for (int m = 0; m < testLoop; m++) { + System.out.println("===== test loop " + m + " start"); + + // test-dep-a exists in KieRepositoryImpl$KieModuleRepo + // To resolve test-dep-a, KieRepositoryImpl$KieModuleRepo.load -> KieRepositoryScannerImpl.getArtifactVersion + // , so the lock order is kieModuleRepo -> kieScanner + System.out.println("===== dep A start"); + ReleaseId releaseIdDepA = ks.newReleaseId("org.kie", "test-dep-a", "1.0-SNAPSHOT"); + InternalKieModule kJarDepA = createKieJar(ks, releaseIdDepA, false, "ruleA"); + repository.installArtifact(releaseIdDepA, kJarDepA, createKPom(fileManager, releaseIdDepA)); + + // test-dep-b does not exist in KieRepositoryImpl$KieModuleRepo. Instead, it is installed in local Maven repository + // To resolve test-dep-b, KieRepositoryImpl.loadKieModuleFromMavenRepo -> KieRepositoryImpl$KieModuleRepo.load + // , so the lock order is kieScanner -> kieModuleRepo + // Note: This deadlock scenario happens only in 7.x (before RHDM-2028), because since Drools 8, + // ReleaseIdImpl usage is refactored and we no longer use ReleaseIdImpl.setSnapshotVersion. + // But we keep this test to detect a regression. + System.out.println("===== dep B start"); + ReleaseId releaseIdDepB = ks.newReleaseId("org.kie", "test-dep-b", "1.0-SNAPSHOT"); + InternalKieModule kJarDepB = createKieJarWithDependencies(ks, releaseIdDepB, false, "ruleB", releaseIdDepA); // test-dep-b depends on test-dep-a + repository.installArtifact(releaseIdDepB, kJarDepB, createKPom(fileManager, releaseIdDepB, releaseIdDepA)); + KieServices.Factory.get().getRepository().removeKieModule(releaseIdDepB); + + System.out.println("===== dep artifacts are ready. Start concurrent build"); + + final int maxThread = 20; + ExecutorService executor = Executors.newFixedThreadPool(maxThread); + + for (int n = 0; n < maxThread; n++) { + final int i = n; + executor.execute(() -> { + ReleaseId releaseId = ks.newReleaseId("org.kie", "test-" + i, "1.0-SNAPSHOT"); + try { + ReleaseId myDependencyId = i % 2 == 0 ? releaseIdDepA : releaseIdDepB; + InternalKieModule kJar = createKieJarWithDependencies(ks, releaseId, false, "rule" + i, myDependencyId); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } + + executor.shutdown(); + executor.awaitTermination(300, TimeUnit.SECONDS); + + // cleanup + KieServices.Factory.get().getRepository().removeKieModule(releaseIdDepA); + KieServices.Factory.get().getRepository().removeKieModule(releaseIdDepB); + } + assertTrue(true); // no deadlock + } +} \ No newline at end of file From 8266e17e6f71e3fbe3bacd23bbffbde5ec251a0e Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Mon, 8 Jul 2024 17:53:13 +0900 Subject: [PATCH 13/13] [incubator-kie-drools-6010] Date Between Dates with globals Not Triggering for Executable Model (#6011) --- .../base/rule/accessor/GlobalExtractor.java | 3 + .../execmodel/domain/SimpleDateHolder.java | 44 ++++++++++ .../execmodel/operators/DateOperatorTest.java | 87 +++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/domain/SimpleDateHolder.java create mode 100644 drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/DateOperatorTest.java diff --git a/drools-base/src/main/java/org/drools/base/rule/accessor/GlobalExtractor.java b/drools-base/src/main/java/org/drools/base/rule/accessor/GlobalExtractor.java index 5988701cfcf..40c3ca72d73 100755 --- a/drools-base/src/main/java/org/drools/base/rule/accessor/GlobalExtractor.java +++ b/drools-base/src/main/java/org/drools/base/rule/accessor/GlobalExtractor.java @@ -132,6 +132,9 @@ public boolean equals(final Object obj) { return false; } final GlobalExtractor other = (GlobalExtractor) obj; + if (!(this.identifier.equals(other.identifier))) { + return false; + } return this.objectType.equals( other.objectType ); } diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/domain/SimpleDateHolder.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/domain/SimpleDateHolder.java new file mode 100644 index 00000000000..bc95716773d --- /dev/null +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/domain/SimpleDateHolder.java @@ -0,0 +1,44 @@ +/** + * 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.drools.model.codegen.execmodel.domain; + +import java.util.Date; + +public class SimpleDateHolder { + + private String id; + private final Date date; + + public SimpleDateHolder(String id, Date date) { + this.id = id; + this.date = date; + } + + public Date getDate() { + return date; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } +} diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/DateOperatorTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/DateOperatorTest.java new file mode 100644 index 00000000000..482bf005670 --- /dev/null +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/DateOperatorTest.java @@ -0,0 +1,87 @@ +/** + * 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.drools.model.codegen.execmodel.operators; + +import java.text.ParseException; +import java.text.SimpleDateFormat; + +import org.drools.model.codegen.execmodel.BaseModelTest; +import org.drools.model.codegen.execmodel.domain.Person; +import org.drools.model.codegen.execmodel.domain.SimpleDateHolder; +import org.junit.Ignore; +import org.junit.Test; +import org.kie.api.runtime.KieSession; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DateOperatorTest extends BaseModelTest { + + public DateOperatorTest(RUN_TYPE testRunType) { + super(testRunType); + } + + @Test + public void dateBetweenGlobals() throws ParseException { + String str = + "import " + SimpleDateHolder.class.getCanonicalName() + ";" + + "global java.util.Date $startDate;\n" + + "global java.util.Date $endDate;\n" + + "rule R when\n" + + " SimpleDateHolder(date > $startDate && date < $endDate)\n" + + "then\n" + + "end"; + + KieSession ksession = getKieSession(str); + SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); + ksession.setGlobal("$startDate", sdf.parse("04/01/2019")); + ksession.setGlobal("$endDate", sdf.parse("05/01/2019")); + + SimpleDateHolder holder = new SimpleDateHolder("A", sdf.parse("04/15/2019")); + ksession.insert(holder); + int fired = ksession.fireAllRules(); + + assertThat(fired).isEqualTo(1); + } + + @Test + public void dateBetweenVariables() throws ParseException { + String str = + "import " + SimpleDateHolder.class.getCanonicalName() + ";" + + "rule R when\n" + + " SimpleDateHolder(id == \"A\", $startDate : date)\n" + + " SimpleDateHolder(id == \"B\", $endDate : date)\n" + + " SimpleDateHolder(id == \"C\", date > $startDate && date < $endDate)\n" + + "then\n" + + "end"; + + KieSession ksession = getKieSession(str); + SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); + + SimpleDateHolder holderA = new SimpleDateHolder("A", sdf.parse("04/01/2019")); + SimpleDateHolder holderB = new SimpleDateHolder("B", sdf.parse("05/01/2019")); + SimpleDateHolder holderC = new SimpleDateHolder("C", sdf.parse("04/15/2019")); + + ksession.insert(holderA); + ksession.insert(holderB); + ksession.insert(holderC); + int fired = ksession.fireAllRules(); + + assertThat(fired).isEqualTo(1); + } +}