You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2019/04/01 15:55:09 UTC
[commons-jexl] branch master updated: JEXL-288: fix grammar,
add test
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 94be437 JEXL-288: fix grammar, add test
94be437 is described below
commit 94be4377345033cc20c64f35e8fa5b5d9f35d8c2
Author: henrib <he...@apache.org>
AuthorDate: Mon Apr 1 17:54:33 2019 +0200
JEXL-288: fix grammar, add test
---
RELEASE-NOTES.txt | 1 +
.../apache/commons/jexl3/internal/Interpreter.java | 7 +++----
.../org/apache/commons/jexl3/parser/Parser.jjt | 2 +-
src/site/xdoc/changes.xml | 3 +++
.../org/apache/commons/jexl3/AnnotationTest.java | 23 +++++++++++++++++++++-
5 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index a4d6744..e0c2989 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -49,6 +49,7 @@ New Features in 3.2:
====================
* JEXL-295: Add unary plus operator
+* JEXL-288: Annotation can not be specified for a standalone statement
* JEXL-275: Allow safe navigation as option
* JEXL-274: Handle soft and hard stack overflow
* JEXL-273: Add do...while(...) loops
diff --git a/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java b/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
index 6582cd8..7844369 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
@@ -17,7 +17,6 @@
//CSOFF: FileLength
package org.apache.commons.jexl3.internal;
-
import org.apache.commons.jexl3.JexlArithmetic;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.JexlEngine;
@@ -29,6 +28,7 @@ import org.apache.commons.jexl3.introspection.JexlMethod;
import org.apache.commons.jexl3.introspection.JexlPropertyGet;
import org.apache.commons.jexl3.introspection.JexlPropertySet;
import org.apache.commons.jexl3.introspection.JexlUberspect.PropertyResolver;
+
import org.apache.commons.jexl3.parser.ASTAddNode;
import org.apache.commons.jexl3.parser.ASTAndNode;
import org.apache.commons.jexl3.parser.ASTAnnotatedStatement;
@@ -103,6 +103,7 @@ import org.apache.commons.jexl3.parser.ASTSubNode;
import org.apache.commons.jexl3.parser.ASTTernaryNode;
import org.apache.commons.jexl3.parser.ASTTrueNode;
import org.apache.commons.jexl3.parser.ASTUnaryMinusNode;
+import org.apache.commons.jexl3.parser.ASTUnaryPlusNode;
import org.apache.commons.jexl3.parser.ASTVar;
import org.apache.commons.jexl3.parser.ASTWhileStatement;
import org.apache.commons.jexl3.parser.JexlNode;
@@ -113,8 +114,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
-import org.apache.commons.jexl3.parser.ASTUnaryPlusNode;
-
/**
* An interpreter of JEXL syntax.
@@ -598,7 +597,7 @@ public class Interpreter extends InterpreterBase {
// attempt to recoerce to literal class
if ((number instanceof Number)) {
// cache if number literal and negate is idempotent
- if (valNode instanceof ASTNumberLiteral ) {
+ if (valNode instanceof ASTNumberLiteral) {
number = arithmetic.narrowNumber((Number) number, ((ASTNumberLiteral) valNode).getLiteralClass());
if (arithmetic.isNegateStable()) {
node.jjtSetValue(number);
diff --git a/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt b/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
index 04681f1..c463e02 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
+++ b/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
@@ -310,7 +310,7 @@ void Annotation() #Annotation :
void AnnotatedStatement() #AnnotatedStatement() : {}
{
- (LOOKAHEAD(<ANNOTATION>) Annotation())+ (LOOKAHEAD(<VAR>) Var() | LOOKAHEAD(1) Block() | Expression())
+ (LOOKAHEAD(<ANNOTATION>) Annotation())+ (LOOKAHEAD(1) Block() | Statement())
}
void Statement() #void : {}
diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml
index 08691be..ed91a03 100644
--- a/src/site/xdoc/changes.xml
+++ b/src/site/xdoc/changes.xml
@@ -41,6 +41,9 @@
<action dev="henrib" type="fix" issue="JEXL-289" due-to="Dmitri Blinov">
Passing undeclared function parameter can overwrite a local function variable
</action>
+ <action dev="henrib" type="add" issue="JEXL-288" due-to="Dmitri Blinov">
+ Annotation can not be specified for a standalone statement
+ </action>
<action dev="henrib" type="fix" issue="JEXL-287" due-to="Dmitri Blinov">
Wrong resolution of local variables
</action>
diff --git a/src/test/java/org/apache/commons/jexl3/AnnotationTest.java b/src/test/java/org/apache/commons/jexl3/AnnotationTest.java
index fc03571..b36cd24 100644
--- a/src/test/java/org/apache/commons/jexl3/AnnotationTest.java
+++ b/src/test/java/org/apache/commons/jexl3/AnnotationTest.java
@@ -189,7 +189,28 @@ public class AnnotationTest extends JexlTestCase {
Assert.assertTrue(jc.getNames().contains("synchronized"));
}
-
+ @Test
+ public void testNoArgStatement() throws Exception {
+ AnnotationContext jc = new AnnotationContext();
+ JexlEngine jexl = new JexlBuilder().create();
+ JexlScript e = jexl.createScript("@synchronized if (true) 2 * 3 * 7; else -42;");
+ Object r = e.execute(jc);
+ Assert.assertEquals(42, r);
+ Assert.assertEquals(1, jc.getCount());
+ Assert.assertTrue(jc.getNames().contains("synchronized"));
+ }
+
+ @Test
+ public void testHoistingStatement() throws Exception {
+ AnnotationContext jc = new AnnotationContext();
+ JexlEngine jexl = new JexlBuilder().create();
+ JexlScript e = jexl.createScript("var t = 1; @synchronized for(var x : [2,3,7]) t *= x; t");
+ Object r = e.execute(jc);
+ Assert.assertEquals(42, r);
+ Assert.assertEquals(1, jc.getCount());
+ Assert.assertTrue(jc.getNames().contains("synchronized"));
+ }
+
@Test
public void testOneArg() throws Exception {
AnnotationContext jc = new AnnotationContext();