From 3662b162ac906d7088ceb58937e7f8cae64147c3 Mon Sep 17 00:00:00 2001 From: Henrib Date: Tue, 27 Aug 2024 20:12:00 +0200 Subject: [PATCH] JEXL-425, JEXL-426, JEXL-427 : checkstyle --- .../apache/commons/jexl3/JexlArithmetic.java | 8 ---- .../commons/jexl3/parser/ASTAmbiguous.java | 1 + .../commons/jexl3/parser/ASTJexlScript.java | 4 +- .../commons/jexl3/parser/ASTJxltLiteral.java | 2 +- .../apache/commons/jexl3/parser/JexlNode.java | 2 +- .../jexl3/parser/TokenMgrException.java | 3 +- .../apache/commons/jexl3/FeaturesTest.java | 1 - .../apache/commons/jexl3/Issues400Test.java | 42 ++++++++++++++++++- 8 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java index a04b0e25e..76d1a7d70 100644 --- a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java +++ b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java @@ -2070,14 +2070,6 @@ public BigInteger toBigInteger(final Object val) { + val.getClass().getName() + ":(" + val + ")"); } - public Object falsy(Object arg) { - return false; - } - - public Object truthy(Object arg) { - return true; - } - /** * Coerce to a primitive boolean. *

Double.NaN, null, "false" and empty string coerce to false.

diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTAmbiguous.java b/src/main/java/org/apache/commons/jexl3/parser/ASTAmbiguous.java index 83ef0d816..bdad8b766 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/ASTAmbiguous.java +++ b/src/main/java/org/apache/commons/jexl3/parser/ASTAmbiguous.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.commons.jexl3.parser; public final class ASTAmbiguous extends JexlNode { diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java b/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java index 93fc7feac..82bf757d4 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java +++ b/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java @@ -31,9 +31,9 @@ public class ASTJexlScript extends JexlLexicalNode { /** The pragmas. */ private Map pragmas; /** Features. */ - private transient JexlFeatures features = null; + private transient JexlFeatures features; /** The script scope. */ - private transient Scope scope = null; + private transient Scope scope; public ASTJexlScript(final int id) { super(id); diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTJxltLiteral.java b/src/main/java/org/apache/commons/jexl3/parser/ASTJxltLiteral.java index e358cc42a..3827d2483 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/ASTJxltLiteral.java +++ b/src/main/java/org/apache/commons/jexl3/parser/ASTJxltLiteral.java @@ -24,7 +24,7 @@ public final class ASTJxltLiteral extends JexlNode implements JexlNode.JxltHandl /** The actual literal value. */ private String literal; /** The expression (parsed). */ - private transient JxltEngine.Expression jxltExpression = null; + private transient JxltEngine.Expression jxltExpression; ASTJxltLiteral(final int id) { super(id); diff --git a/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java b/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java index 998af8a42..3171e41a6 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java +++ b/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java @@ -55,7 +55,7 @@ public interface JxltHandle { *

Used to parse expressions for templates. */ public static class Info extends JexlInfo { - JexlNode node = null; + JexlNode node; /** * Default ctor. diff --git a/src/main/java/org/apache/commons/jexl3/parser/TokenMgrException.java b/src/main/java/org/apache/commons/jexl3/parser/TokenMgrException.java index 07c271d32..1d0e04480 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/TokenMgrException.java +++ b/src/main/java/org/apache/commons/jexl3/parser/TokenMgrException.java @@ -127,7 +127,8 @@ protected static String addEscapes(final String str) { private int column; /** Full Constructor. */ - public TokenMgrException(final boolean EOFSeen, final int lexState, final int errorLine, final int errorColumn, final String errorAfter, final int curChar, final int reason) { + public TokenMgrException(final boolean EOFSeen, final int lexState, final int errorLine, final int errorColumn, + final String errorAfter, final int curChar, final int reason) { eof = EOFSeen; state = lexState; line = errorLine; diff --git a/src/test/java/org/apache/commons/jexl3/FeaturesTest.java b/src/test/java/org/apache/commons/jexl3/FeaturesTest.java index 8939dbd94..dc3923ec4 100644 --- a/src/test/java/org/apache/commons/jexl3/FeaturesTest.java +++ b/src/test/java/org/apache/commons/jexl3/FeaturesTest.java @@ -16,7 +16,6 @@ */ package org.apache.commons.jexl3; -import static org.apache.commons.jexl3.JexlFeatures.CONST_CAPTURE; import static org.apache.commons.jexl3.JexlFeatures.REF_CAPTURE; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/src/test/java/org/apache/commons/jexl3/Issues400Test.java b/src/test/java/org/apache/commons/jexl3/Issues400Test.java index 26a8cd446..54a99ffb7 100644 --- a/src/test/java/org/apache/commons/jexl3/Issues400Test.java +++ b/src/test/java/org/apache/commons/jexl3/Issues400Test.java @@ -493,7 +493,7 @@ public void testSortArray() { assertEquals("42", result); } - @Test public void test426() { + @Test public void test426a() { String src = "let x = 10;\n" + "let foo = () -> {\n" + "x += 2;\n" + @@ -510,6 +510,46 @@ public void testSortArray() { assertEquals(42, result); } + @Test public void test426b() { + String src = "let x = 10; let f = () -> { x + 2 }; x = 40; f()"; + final JexlBuilder builder = new JexlBuilder().features(new JexlFeatures().constCapture(true).referenceCapture(true)); + final JexlEngine jexl = builder.create(); + JexlScript script; + Object result; + script = jexl.createScript(src); + result = script.execute(null); + assertEquals(42, result); + } + + @Test public void test426c() { + String src = "let x = 10; let f = () -> { x + 2 }; x = 40; f"; + final JexlBuilder builder = new JexlBuilder().features(new JexlFeatures().constCapture(true).referenceCapture(true)); + final JexlEngine jexl = builder.create(); + JexlScript script; + Object result; + script = jexl.createScript(src); + result = script.execute(null); + assertTrue(result instanceof JexlScript); + script = jexl.createScript("f()", "f"); + result = script.execute(null, result); + assertEquals(42, result); + } + + @Test public void test426d() { + String src = "let x = 10; let f = () -> { let x = 142; x }; x = 40; f"; + final JexlBuilder builder = new JexlBuilder().features(new JexlFeatures().referenceCapture(true)); + final JexlEngine jexl = builder.create(); + JexlScript script; + Object result; + script = jexl.createScript(src); + result = script.execute(null); + assertTrue(result instanceof JexlScript); + script = jexl.createScript("f()", "f"); + result = script.execute(null, result); + assertEquals(142, result); + } + + @Test public void test427a() { String src = "(x, y, z) -> x && y && z"; final JexlBuilder builder = new JexlBuilder().features(new JexlFeatures().constCapture(true));