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 55ba9f5  JEXL-307: fix features being lost during parsing Task 
#JEXL-307 - Variable redeclaration option
55ba9f5 is described below

commit 55ba9f5f5ca4a76883ea5ccff0f54a2b3d770470
Author: henrib <hen...@apache.org>
AuthorDate: Fri Dec 20 13:15:52 2019 +0100

    JEXL-307: fix features being lost during parsing
    Task #JEXL-307 - Variable redeclaration option
---
 .../org/apache/commons/jexl3/internal/Script.java  |  7 +++++
 .../org/apache/commons/jexl3/parser/Parser.jjt     |  1 +
 .../java/org/apache/commons/jexl3/LexicalTest.java | 34 ++++++++++++++++++----
 3 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/commons/jexl3/internal/Script.java 
b/src/main/java/org/apache/commons/jexl3/internal/Script.java
index 2baa25c..c458242 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Script.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Script.java
@@ -271,6 +271,13 @@ public class Script implements JexlScript, JexlExpression {
     public JexlInfo getInfo() {
         return script.jexlInfo();
     }
+     
+    /**
+     * @return the script features
+     */
+    public JexlFeatures getFeatures() {
+        return script.getFeatures();
+    }
 
     /**
      * Gets this script variables.
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 0cad9e0..e3d5e03 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
+++ b/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
@@ -62,6 +62,7 @@ public final class Parser extends JexlParser
             ReInit(new java.io.StringReader(jexlSrc));
             ASTJexlScript script = jexlFeatures.supportsScript()? 
JexlScript(scope) : JexlExpression(scope);
             script.jjtSetValue(info);
+            script.setFeatures(jexlFeatures);
             script.setPragmas(pragmas != null
                              ? 
Collections.<String,Object>unmodifiableMap(pragmas)
                              : Collections.<String,Object>emptyMap());
diff --git a/src/test/java/org/apache/commons/jexl3/LexicalTest.java 
b/src/test/java/org/apache/commons/jexl3/LexicalTest.java
index eac41eb..a87b88b 100644
--- a/src/test/java/org/apache/commons/jexl3/LexicalTest.java
+++ b/src/test/java/org/apache/commons/jexl3/LexicalTest.java
@@ -21,6 +21,7 @@ import java.io.StringWriter;
 import java.util.Map;
 import java.util.Set;
 import org.apache.commons.jexl3.internal.LexicalScope;
+import org.apache.commons.jexl3.internal.Script;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -552,17 +553,17 @@ public class LexicalTest {
         JexlScript e = jexl.createScript(str);
         JexlContext ctxt = new MapContext();
         Object o = e.execute(ctxt);
-        Assert.assertEquals(0, o);
+        Assert.assertEquals(0, o);    
     }
-    
+
     public static class VarContext extends MapContext implements 
JexlContext.PragmaProcessor, JexlContext.OptionsHandle {
         private JexlOptions options = new JexlOptions();
-        
+
         JexlOptions snatchOptions() {
             JexlOptions o = options;
             options = new JexlOptions();
             return o;
-}
+        }
 
         @Override
         public void processPragma(String key, Object value) {
@@ -578,9 +579,30 @@ public class LexicalTest {
         public JexlOptions getEngineOptions() {
             return options;
         }
+    } 
+                
+    @Test
+    public void testInternalLexicalFeatures() throws Exception {
+        String str = "42";
+        JexlFeatures f = new JexlFeatures();
+        f.lexical(true);
+        f.lexicalShade(true);
+        JexlEngine jexl = new JexlBuilder().features(f).create();
+        JexlScript e = jexl.createScript(str);
+        VarContext vars = new VarContext();
+        JexlOptions opts = vars.getEngineOptions();
+        // so we can see the effect of features on options
+        opts.setSharedInstance(true);
+        Script script = (Script) e;
+        JexlFeatures features = script.getFeatures();
+        Assert.assertTrue(features.isLexical());
+        Assert.assertTrue(features.isLexicalShade());
+        Object result = e.execute(vars);
+        Assert.assertEquals(42, result);
+        Assert.assertTrue(opts.isLexical());
+        Assert.assertTrue(opts.isLexicalShade());
     }
-
-        
+    
     @Test
     public void testOptionsPragma() throws Exception {
         try {

Reply via email to