This is an automated email from the ASF dual-hosted git repository. henrib pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-jexl.git
The following commit(s) were added to refs/heads/master by this push: new 656fceaa JEXL-379, JEXL-380: Documentation and tidy; 656fceaa is described below commit 656fceaa1ca27f719a98213a05f5f6aea637ed25 Author: henrib <hen...@apache.org> AuthorDate: Mon Sep 12 19:35:36 2022 +0200 JEXL-379, JEXL-380: Documentation and tidy; --- pom.xml | 4 +-- .../commons/jexl3/internal/InterpreterBase.java | 22 ------------- src/site/xdoc/reference/syntax.xml | 36 ++++++++++++++++------ 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/pom.xml b/pom.xml index afe9666b..92aacc37 100644 --- a/pom.xml +++ b/pom.xml @@ -56,9 +56,9 @@ <japicmp.skip>false</japicmp.skip> <commons.rat.version>0.14</commons.rat.version> <commons.japicmp.version>0.16.0</commons.japicmp.version> - <commons.pmd.version>3.18.0</commons.pmd.version> + <commons.pmd.version>3.19.0</commons.pmd.version> <commons.pmd-impl.version>6.48.0</commons.pmd-impl.version> - <commons.spotbugs.version>4.7.1.1</commons.spotbugs.version> + <commons.spotbugs.version>4.7.2.0</commons.spotbugs.version> <!-- override of Jacoco properties defined in CP52 --> <commons.jacoco.version>0.8.8</commons.jacoco.version> diff --git a/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java b/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java index 2e3572f8..e8dd199b 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java +++ b/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java @@ -563,28 +563,6 @@ public abstract class InterpreterBase extends ParserVisitor { return null; } - /** - * Checks whether a reference child node holds a local variable reference. - * @param node the reference node - * @param which the child we are checking - * @return true if child is local variable, false otherwise - */ - protected boolean isLocalVariable(final ASTReference node, final int which) { - return (node.jjtGetNumChildren() > which - && node.jjtGetChild(which) instanceof ASTIdentifier - && ((ASTIdentifier) node.jjtGetChild(which)).getSymbol() >= 0); - } - - /** - * Checks whether a reference child node holds a function call. - * @param node the reference node - * @return true if child is function call, false otherwise - */ - protected boolean isFunctionCall(final ASTReference node) { - return (node.jjtGetNumChildren() > 0 - && node.jjtGetChild(0) instanceof ASTFunctionNode); - } - /** * Pretty-prints a failing property (de)reference. * <p>Used by calls to unsolvableProperty(...).</p> diff --git a/src/site/xdoc/reference/syntax.xml b/src/site/xdoc/reference/syntax.xml index ea45e800..1ec211e5 100644 --- a/src/site/xdoc/reference/syntax.xml +++ b/src/site/xdoc/reference/syntax.xml @@ -136,18 +136,25 @@ <p>Although pragmas are statements, they are <em>not</em> evaluated at runtime; they are constants associated to the script after parsing. It is expected that user code accesses the pragma map from scripts to alter some functions behavior.</p> - <p>The are two built-in pragmas:</p> + <p>The are 3 built-in pragmas:</p> <p> <b>jexl.options</b> overrides the evaluation options using the option-flags syntax. <code>#pragma jexl.options "+strict -safe +lexical +lexicalShade"</code> will let the script run with - the options strict being true, safe false, lexical true and lexical-shade true.</p> - + the options strict being true, safe false, lexical true and lexical-shade true. + </p> <p> <b>jexl.namespace.<i>ns_prefix</i></b> declares a namespace valid for the script execution lifetime, the value being the fully-qualified namespace class-name. <code>#pragma jexl.namespace.str java.lang.String</code> declare 'str' as the namespace using the String class. </p> + <p> + <b>jexl.import</b> works in conjunction with the 'new' operator. + It declares the packages that a <code>new ClassIdentifier(...)</code> will visit - in + declaration order - to resolve the class name into a fully-qualified class-name. + <code>#pragma jexl.import java.net</code> will allow executing <code> let url = new URL("https://commons.apache.org");</code>, + the URL class name being solved as the java.net.URL fully-qualified class-name. + </p> </td> </tr> <tr> @@ -216,6 +223,7 @@ <li><code>var fun = (x, y) -> { x + y }</code></li> <li><code>var fun = (let x, let y) -> { x + y }</code></li> <li><code>const fun = (const x, const y) -> { x + y }</code></li> + <li><code>function fun(const x, const y) { x + y }</code></li> </ul> If the function has only one argument the parentheses may be omitted <code>var fun = x -> { x * x }</code>. @@ -539,6 +547,10 @@ as arguments to the constructor for the class considered.</p> <p>In case of multiple constructors, JEXL will make the best effort to find the most appropriate non ambiguous constructor to call.</p> + <p> + Alternatively, using <code>#pragma jexl.import java.lang</code>code>, one can use the + following syntax: <code>new Double(10)</code>. + </p> </td> </tr> <tr> @@ -987,17 +999,23 @@ <td>for</td> <td> <p>Loop through items of an Array, Collection, Map, Iterator or Enumeration, e.g. - <code>for (item : list) { + <code>for (let item : list) { x = x + item; }</code> - Where <code>item</code> is a context variable.</p> - <p>The following syntax is also supported: - <code>for (var item : list) { + Where <code>list</code> is a context variable pointing to any iterable structure. + </p> + <p>The following syntax using a context variable is also supported: + <code>for (item : list) { x = x + item; }</code> + Note that the loop variable <code>item</code> is accessible after loop evaluation</p> + <p>Finally, the conventional syntax using a local variable, initial value, loop condition and + loop step is supported. + <code>for (let i = 0; i < size(list); ++i) { + x = x + list[i]; + }</code> - Where <code>item</code> is a local variable.</p> - <p>Note that the loop variable <code>item</code> is accessible after loop evaluation</p> + Where <code>item</code> is a local variable pointing to an array-like structure.</p> <p>The JEXL 1.1 syntax using <code>foreach(item in list)</code> is now <strong>unsupported</strong>.</p> </td> </tr>