Modified: 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/UnifiedJEXLTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/UnifiedJEXLTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/UnifiedJEXLTest.java
 (original)
+++ 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/UnifiedJEXLTest.java
 Tue Dec  6 14:19:33 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.jexl3;
 
+import org.apache.commons.jexl3.internal.Engine;
+import org.apache.commons.jexl3.internal.TemplateEngine;
 import java.io.PrintWriter;
 import java.io.StringReader;
 import java.io.StringWriter;
@@ -32,15 +34,11 @@ import org.apache.commons.logging.LogFac
  * Test cases for the UnifiedEL.
  */
 public class UnifiedJEXLTest extends JexlTestCase {
-    private static final JexlEngine ENGINE = createEngine(false);
+    private static final JexlEngine ENGINE = new 
JexlBuilder().silent(false).cache(128).strict(true).create();
 
-    static {
-        ENGINE.setSilent(false);
-        ENGINE.setCache(128);
-    }
-    private static final UnifiedJEXL EL = new UnifiedJEXL(ENGINE);
-    private static final Log LOG = LogFactory.getLog(UnifiedJEXL.class);
-    private JexlContext context = null;
+    private static final TemplateEngine EL = new 
TemplateEngine((Engine)ENGINE);
+    private static final Log LOG = LogFactory.getLog(JxltEngine.class);
+    private JexlEvalContext context = null;
     private Map<String, Object> vars = null;
 
     @Override
@@ -48,7 +46,7 @@ public class UnifiedJEXLTest extends Jex
         // ensure jul logging is only error
         
java.util.logging.Logger.getLogger(org.apache.commons.jexl3.JexlEngine.class.getName()).setLevel(java.util.logging.Level.SEVERE);
         vars = new HashMap<String, Object>();
-        context = new MapContext(vars);
+        context = new JexlEvalContext(vars);
     }
 
     @Override
@@ -101,7 +99,7 @@ public class UnifiedJEXLTest extends Jex
 
     public void testStatement() throws Exception {
         vars.put("froboz", new Froboz(123));
-        UnifiedJEXL.Expression check = EL.parse("${froboz.value = 32; 
froboz.plus10(); froboz.value}");
+        JxltEngine.UnifiedExpression check = 
EL.createExpression("${froboz.value = 32; froboz.plus10(); froboz.value}");
         Object o = check.evaluate(context);
         assertEquals("Result is not 42", new Integer(42), o);
         Set<List<String>> evars = check.getVariables();
@@ -109,8 +107,8 @@ public class UnifiedJEXLTest extends Jex
     }
 
     public void testAssign() throws Exception {
-        UnifiedJEXL.Expression assign = EL.parse("${froboz.value = 10}");
-        UnifiedJEXL.Expression check = EL.parse("${froboz.value}");
+        JxltEngine.UnifiedExpression assign = 
EL.createExpression("${froboz.value = 10}");
+        JxltEngine.UnifiedExpression check = 
EL.createExpression("${froboz.value}");
         Object o = assign.evaluate(context);
         assertEquals("Result is not 10", new Integer(10), o);
         o = check.evaluate(context);
@@ -119,7 +117,7 @@ public class UnifiedJEXLTest extends Jex
 
     public void testComposite() throws Exception {
         String source = "Dear ${p} ${name};";
-        UnifiedJEXL.Expression expr = EL.parse(source);
+        JxltEngine.UnifiedExpression expr = EL.createExpression(source);
         vars.put("p", "Mr");
         vars.put("name", "Doe");
         assertTrue("expression should be immediate", expr.isImmediate());
@@ -134,14 +132,14 @@ public class UnifiedJEXLTest extends Jex
 
     public void testPrepareEvaluate() throws Exception {
         final String source = "Dear #{p} ${name};";
-        UnifiedJEXL.Expression expr = EL.parse("Dear #{p} ${name};");
+        JxltEngine.UnifiedExpression expr = EL.createExpression("Dear #{p} 
${name};");
         assertTrue("expression should be deferred", expr.isDeferred());
 
         Set<List<String>> evars = expr.getVariables();
         assertEquals(1, evars.size());
         assertTrue(evars.contains(Arrays.asList("name")));
         vars.put("name", "Doe");
-        UnifiedJEXL.Expression phase1 = expr.prepare(context);
+        JxltEngine.UnifiedExpression phase1 = expr.prepare(context);
         String as = phase1.asString();
         assertEquals("Dear ${p} Doe;", as);
         Set<List<String>> evars1 = phase1.getVariables();
@@ -159,7 +157,7 @@ public class UnifiedJEXLTest extends Jex
 
     public void testNested() throws Exception {
         final String source = "#{${hi}+'.world'}";
-        UnifiedJEXL.Expression expr = EL.parse(source);
+        JxltEngine.UnifiedExpression expr = EL.createExpression(source);
 
         Set<List<String>> evars = expr.getVariables();
         assertEquals(1, evars.size());
@@ -177,8 +175,8 @@ public class UnifiedJEXLTest extends Jex
     public void testImmediate() throws Exception {
         JexlContext none = null;
         final String source = "${'Hello ' + 'World!'}";
-        UnifiedJEXL.Expression expr = EL.parse(source);
-        UnifiedJEXL.Expression prepared = expr.prepare(none);
+        JxltEngine.UnifiedExpression expr = EL.createExpression(source);
+        JxltEngine.UnifiedExpression prepared = expr.prepare(none);
         assertEquals("prepare should return same expression", "Hello World!", 
prepared.asString());
         Object o = expr.evaluate(none);
         assertTrue("expression should be immediate", expr.isImmediate());
@@ -190,7 +188,7 @@ public class UnifiedJEXLTest extends Jex
     public void testConstant() throws Exception {
         JexlContext none = null;
         final String source = "Hello World!";
-        UnifiedJEXL.Expression expr = EL.parse(source);
+        JxltEngine.UnifiedExpression expr = EL.createExpression(source);
         assertTrue("prepare should return same expression", expr.prepare(none) 
== expr);
         Object o = expr.evaluate(none);
         assertTrue("expression should be immediate", expr.isImmediate());
@@ -202,7 +200,7 @@ public class UnifiedJEXLTest extends Jex
     public void testDeferred() throws Exception {
         JexlContext none = null;
         final String source = "#{'world'}";
-        UnifiedJEXL.Expression expr = EL.parse(source);
+        JxltEngine.UnifiedExpression expr = EL.createExpression(source);
         assertTrue("expression should be deferred", expr.isDeferred());
         String as = expr.prepare(none).asString();
         assertEquals("prepare should return immediate version", "${'world'}", 
as);
@@ -214,26 +212,26 @@ public class UnifiedJEXLTest extends Jex
 
     public void testEscape() throws Exception {
         JexlContext none = null;
-        UnifiedJEXL.Expression expr;
+        JxltEngine.UnifiedExpression expr;
         Object o;
-        // $ and # are escapable in UnifiedJEXL
-        expr = EL.parse("\\#{'world'}");
+        // $ and # are escapable in TemplateEngine
+        expr = EL.createExpression("\\#{'world'}");
         o = expr.evaluate(none);
         assertEquals("#{'world'}", o);
-        expr = EL.parse("\\${'world'}");
+        expr = EL.createExpression("\\${'world'}");
         o = expr.evaluate(none);
         assertEquals("${'world'}", o);
     }
 
     public void testEscapeString() throws Exception {
-        UnifiedJEXL.Expression expr = EL.parse("\\\"${'world\\'s 
finest'}\\\"");
+        JxltEngine.UnifiedExpression expr = 
EL.createExpression("\\\"${'world\\'s finest'}\\\"");
         JexlContext none = null;
         Object o = expr.evaluate(none);
         assertEquals("\"world's finest\"", o);
     }
 
     public void testNonEscapeString() throws Exception {
-        UnifiedJEXL.Expression expr = EL.parse("c:\\some\\windows\\path");
+        JxltEngine.UnifiedExpression expr = 
EL.createExpression("c:\\some\\windows\\path");
         JexlContext none = null;
         Object o = expr.evaluate(none);
         assertEquals("c:\\some\\windows\\path", o);
@@ -241,11 +239,11 @@ public class UnifiedJEXLTest extends Jex
 
     public void testMalformed() throws Exception {
         try {
-            UnifiedJEXL.Expression expr = EL.parse("${'world'");
+            JxltEngine.UnifiedExpression expr = 
EL.createExpression("${'world'");
             JexlContext none = null;
             expr.evaluate(none);
             fail("should be malformed");
-        } catch (UnifiedJEXL.Exception xjexl) {
+        } catch (JxltEngine.Exception xjexl) {
             // expected
             String xmsg = xjexl.getMessage();
             LOG.warn(xmsg);
@@ -254,11 +252,11 @@ public class UnifiedJEXLTest extends Jex
 
     public void testMalformedNested() throws Exception {
         try {
-            UnifiedJEXL.Expression expr = EL.parse("#{${hi} world}");
+            JxltEngine.UnifiedExpression expr = EL.createExpression("#{${hi} 
world}");
             JexlContext none = null;
             expr.evaluate(none);
             fail("should be malformed");
-        } catch (UnifiedJEXL.Exception xjexl) {
+        } catch (JxltEngine.Exception xjexl) {
             // expected
             String xmsg = xjexl.getMessage();
             LOG.warn(xmsg);
@@ -267,11 +265,11 @@ public class UnifiedJEXLTest extends Jex
 
     public void testBadContextNested() throws Exception {
         try {
-            UnifiedJEXL.Expression expr = EL.parse("#{${hi}+'.world'}");
+            JxltEngine.UnifiedExpression expr = 
EL.createExpression("#{${hi}+'.world'}");
             JexlContext none = null;
             expr.evaluate(none);
             fail("should be malformed");
-        } catch (UnifiedJEXL.Exception xjexl) {
+        } catch (JxltEngine.Exception xjexl) {
             // expected
             String xmsg = xjexl.getMessage();
             LOG.warn(xmsg);
@@ -280,19 +278,19 @@ public class UnifiedJEXLTest extends Jex
 
     public void testCharAtBug() throws Exception {
         vars.put("foo", "abcdef");
-        UnifiedJEXL.Expression expr = 
EL.parse("${foo.substring(2,4)/*comment*/}");
+        JxltEngine.UnifiedExpression expr = 
EL.createExpression("${foo.substring(2,4)/*comment*/}");
         Object o = expr.evaluate(context);
         assertEquals("cd", o);
 
         vars.put("bar", "foo");
         try {
-            ENGINE.setSilent(true);
-            expr = EL.parse("#{${bar}+'.charAt(-2)'}");
+            context.setSilent(true);
+            expr = EL.createExpression("#{${bar}+'.charAt(-2)'}");
             expr = expr.prepare(context);
             o = expr.evaluate(context);
             assertEquals(null, o);
         } finally {
-            ENGINE.setSilent(false);
+            context.setSilent(false);
         }
 
     }
@@ -302,7 +300,7 @@ public class UnifiedJEXLTest extends Jex
         StringWriter strw;
         String output;
 
-        UnifiedJEXL.Template t = EL.createTemplate(source);
+        JxltEngine.Template t = EL.createTemplate(source);
 
         vars.put("x", 42);
         strw = new StringWriter();
@@ -325,7 +323,7 @@ public class UnifiedJEXLTest extends Jex
         StringWriter strw;
         String output;
 
-        UnifiedJEXL.Template t = EL.createTemplate("$$", new 
StringReader(source), "x");
+        JxltEngine.Template t = EL.createTemplate("$$", new 
StringReader(source), "x");
         String dstr = t.asString();
         assertNotNull(dstr);
 
@@ -346,13 +344,13 @@ public class UnifiedJEXLTest extends Jex
                + "${l10n}=#{x}\n"
                + "$$ }\n";
         int[] args = { 42 };
-        UnifiedJEXL.Template tl10n = EL.createTemplate(source, "list");
+        JxltEngine.Template tl10n = EL.createTemplate(source, "list");
         String dstr = tl10n.asString();
         assertNotNull(dstr);
         context.set("l10n", "valeur");
-        UnifiedJEXL.Template tpFR = tl10n.prepare(context);
+        JxltEngine.Template tpFR = tl10n.prepare(context);
         context.set("l10n", "value");
-        UnifiedJEXL.Template tpEN = tl10n.prepare(context);
+        JxltEngine.Template tpEN = tl10n.prepare(context);
         context.set("l10n", null);
         
         StringWriter strw;
@@ -379,7 +377,7 @@ public class UnifiedJEXLTest extends Jex
                 + "The value ${x} is under fourty-two\n"
                 + "$$   }\n"
                 + "$$ }\n";
-        UnifiedJEXL.Template t = EL.createTemplate("$$", new 
StringReader(test42), "list");
+        JxltEngine.Template t = EL.createTemplate("$$", new 
StringReader(test42), "list");
         StringWriter strw = new StringWriter();
         int[] list = {1, 3, 5, 42, 169};
         t.evaluate(context, strw, list);
@@ -416,7 +414,7 @@ public class UnifiedJEXLTest extends Jex
     public void testWriter() throws Exception {
         Froboz froboz = new Froboz(42);
         Writer writer = new FrobozWriter(new StringWriter());
-        UnifiedJEXL.Template t = EL.createTemplate("$$", new 
StringReader("$$$jexl.print(froboz)"), "froboz");
+        JxltEngine.Template t = EL.createTemplate("$$", new 
StringReader("$$$jexl.print(froboz)"), "froboz");
         t.evaluate(context, writer, froboz);
         assertEquals("froboz{42}", writer.toString());
     }

Modified: 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/VarTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/VarTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/VarTest.java 
(original)
+++ 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/VarTest.java 
Tue Dec  6 14:19:33 2011
@@ -22,23 +22,25 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
-import java.util.logging.Logger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * Tests local variables.
  */
 public class VarTest extends JexlTestCase {
-    static final Logger LOGGER = Logger.getLogger(VarTest.class.getName());
+    static final Log LOGGER = LogFactory.getLog(VarTest.class.getName());
 
     public VarTest(String testName) {
         super(testName);
     }
     
     public void testStrict() throws Exception {
-        JexlContext map = new MapContext();
-        JexlContext ctxt = new ReadonlyContext(new MapContext());
-        JEXL.setStrict(true);
-        Script e;
+        JexlEvalContext map = new JexlEvalContext();
+        JexlContext ctxt = new ReadonlyContext(map, map);
+        map.setStrict(true);
+        map.setSilent(false);
+        JexlScript e;
         
         e = JEXL.createScript("x");
         try {
@@ -66,24 +68,25 @@ public class VarTest extends JexlTestCas
     }
 
     public void testLocalBasic() throws Exception {
-        Script e = JEXL.createScript("var x; x = 42");
+        JexlScript e = JEXL.createScript("var x; x = 42");
         Object o = e.execute(null);
         assertEquals("Result is not 42", new Integer(42), o);
     }
 
     public void testLocalSimple() throws Exception {
-        Script e = JEXL.createScript("var x = 21; x + x");
+        JexlScript e = JEXL.createScript("var x = 21; x + x");
         Object o = e.execute(null);
         assertEquals("Result is not 42", new Integer(42), o);
     }
 
     public void testLocalFor() throws Exception {
-        Script e = JEXL.createScript("var y  = 0; for(var x : [5, 17, 20]) { y 
= y + x; } y;");
+        JexlScript e = JEXL.createScript("var y  = 0; for(var x : [5, 17, 20]) 
{ y = y + x; } y;");
         Object o = e.execute(null);
         assertEquals("Result is not 42", new Integer(42), o);
     }
 
     public static class NumbersContext extends MapContext implements 
NamespaceResolver {
+        @Override
         public Object resolveNamespace(String name) {
             return name == null ? this : null;
         }
@@ -95,7 +98,7 @@ public class VarTest extends JexlTestCas
 
     public void testLocalForFunc() throws Exception {
         JexlContext jc = new NumbersContext();
-        Script e = JEXL.createScript("var y  = 0; for(var x : numbers()) { y = 
y + x; } y;");
+        JexlScript e = JEXL.createScript("var y  = 0; for(var x : numbers()) { 
y = y + x; } y;");
         Object o = e.execute(jc);
         assertEquals("Result is not 42", new Integer(42), o);
     }

Modified: 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/WhileTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/WhileTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/WhileTest.java 
(original)
+++ 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/WhileTest.java 
Tue Dec  6 14:19:33 2011
@@ -28,7 +28,7 @@ public class WhileTest extends JexlTestC
     }
 
     public void testSimpleWhileFalse() throws Exception {
-        Expression e = JEXL.createExpression("while (false) ;");
+        JexlExpression e = JEXL.createExpression("while (false) ;");
         JexlContext jc = new MapContext();
 
         Object o = e.evaluate(jc);
@@ -36,7 +36,7 @@ public class WhileTest extends JexlTestC
     }
     
     public void testWhileExecutesExpressionWhenLooping() throws Exception {
-        Expression e = JEXL.createExpression("while (x < 10) x = x + 1;");
+        JexlExpression e = JEXL.createExpression("while (x < 10) x = x + 1;");
         JexlContext jc = new MapContext();
         jc.set("x", new Integer(1));
 
@@ -45,7 +45,7 @@ public class WhileTest extends JexlTestC
     }
 
     public void testWhileWithBlock() throws Exception {
-        Expression e = JEXL.createExpression("while (x < 10) { x = x + 1; y = 
y * 2; }");
+        JexlExpression e = JEXL.createExpression("while (x < 10) { x = x + 1; 
y = y * 2; }");
         JexlContext jc = new MapContext();
         jc.set("x", new Integer(1));
         jc.set("y", new Integer(1));

Modified: 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/ArrayTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/ArrayTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/ArrayTest.java
 (original)
+++ 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/ArrayTest.java
 Tue Dec  6 14:19:33 2011
@@ -18,13 +18,14 @@
 package org.apache.commons.jexl3.examples;
 
 import junit.framework.TestCase;
-import org.apache.commons.jexl3.Expression;
+import org.apache.commons.jexl3.JexlExpression;
 import org.apache.commons.jexl3.JexlContext;
 import org.apache.commons.jexl3.JexlEngine;
 import org.apache.commons.jexl3.MapContext;
 
 import java.util.List;
 import java.util.ArrayList;
+import org.apache.commons.jexl3.JexlBuilder;
 
 /**
  *  Simple example to show how to access arrays.
@@ -40,7 +41,7 @@ public class ArrayTest extends TestCase 
          * First step is to retrieve an instance of a JexlEngine;
          * it might be already existing and shared or created anew.
          */
-        JexlEngine jexl = new JexlEngine();
+        JexlEngine jexl = new JexlBuilder().create();
         /*
          *  Second make a jexlContext and put stuff in it
          */
@@ -52,7 +53,7 @@ public class ArrayTest extends TestCase 
         l.add(two);
         jc.set("array", l);
 
-        Expression e = jexl.createExpression("array[1]");
+        JexlExpression e = jexl.createExpression("array[1]");
         Object o = e.evaluate(jc);
         out.print("Object @ location 1 = ", o, two);
 

Modified: 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/MethodPropertyTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/MethodPropertyTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/MethodPropertyTest.java
 (original)
+++ 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/examples/MethodPropertyTest.java
 Tue Dec  6 14:19:33 2011
@@ -18,7 +18,8 @@
 package org.apache.commons.jexl3.examples;
 
 import junit.framework.TestCase;
-import org.apache.commons.jexl3.Expression;
+import org.apache.commons.jexl3.JexlBuilder;
+import org.apache.commons.jexl3.JexlExpression;
 import org.apache.commons.jexl3.JexlContext;
 import org.apache.commons.jexl3.JexlEngine;
 import org.apache.commons.jexl3.MapContext;
@@ -37,7 +38,7 @@ public class MethodPropertyTest extends 
          * First step is to retrieve an instance of a JexlEngine;
          * it might be already existing and shared or created anew.
          */
-        JexlEngine jexl = new JexlEngine();
+        JexlEngine jexl = new JexlBuilder().create();
         /*
          *  Second make a jexlContext and put stuff in it
          */
@@ -55,7 +56,7 @@ public class MethodPropertyTest extends 
         /*
          *  access a method w/o args
          */
-        Expression e = jexl.createExpression("foo.getFoo()");
+        JexlExpression e = jexl.createExpression("foo.getFoo()");
         Object o = e.evaluate(jc);
         out.print("value returned by the method getFoo() is : ", o, 
foo.getFoo());
 

Added: 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/Util.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/Util.java?rev=1210927&view=auto
==============================================================================
--- 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/Util.java
 (added)
+++ 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/Util.java
 Tue Dec  6 14:19:33 2011
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2011 The Apache Software Foundation.
+ *
+ * Licensed 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.apache.commons.jexl3.internal;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.jexl3.JexlEngine;
+import org.apache.commons.jexl3.JexlScript;
+import org.apache.commons.jexl3.parser.ASTJexlScript;
+import org.apache.commons.jexl3.parser.JexlNode;
+
+/**
+ *
+ * @author henri
+ */
+public class Util {
+    
+    /**
+     * Will force testing the debugger for each derived test class by
+     * recreating each expression from the JexlNode in the JexlEngine cache &
+     * testing them for equality with the origin.
+     * @throws Exception
+     */
+    public static void debuggerCheck(JexlEngine ijexl) throws Exception {
+        Engine  jexl = (Engine) ijexl;
+        // without a cache, nothing to check
+        if (jexl == null || jexl.cache == null) {
+            return;
+        }
+        Engine jdbg = new Engine();
+        jdbg.parser.ALLOW_REGISTERS = true;
+        Debugger dbg = new Debugger();
+        // iterate over all expression in cache
+        Iterator<Map.Entry<String,ASTJexlScript>> inodes = 
jexl.cache.entrySet().iterator();
+        while (inodes.hasNext()) {
+            Map.Entry<String,ASTJexlScript> entry = inodes.next();
+            JexlNode node = entry.getValue();
+            // recreate expr string from AST
+            dbg.debug(node);
+            String expressiondbg = dbg.data();
+            // recreate expr from string
+            Script exprdbg = jdbg.createScript(expressiondbg);
+            // make arg cause become the root cause
+            JexlNode root = exprdbg.script;
+            while (root.jjtGetParent() != null) {
+                root = root.jjtGetParent();
+            }
+            // test equality
+            String reason = checkEquals(root, node);
+            if (reason != null) {
+                throw new RuntimeException("debugger equal failed: "
+                                           + expressiondbg
+                                           +" /**** "  +reason+" **** */ "
+                                           + entry.getKey());
+            }
+        }
+    }
+
+    /**
+     * Creates a list of all descendants of a script including itself.
+     * @param script the script to flatten
+     * @return the descendants-and-self list
+     */
+    protected static ArrayList<JexlNode> flatten(JexlNode node) {
+        ArrayList<JexlNode> list = new ArrayList<JexlNode>();
+        flatten(list, node);
+        return list;
+    }
+
+    /**
+     * Recursively adds all children of a script to the list of descendants.
+     * @param list the list of descendants to add to
+     * @param script the script & descendants to add
+     */
+    private static void flatten(List<JexlNode> list, JexlNode node) {
+        int nc = node.jjtGetNumChildren();
+        list.add(node);
+        for(int c = 0; c < nc; ++c) {
+            flatten(list, node.jjtGetChild(c));
+        }
+    }
+
+    /**
+     * Checks the equality of 2 nodes by comparing all their descendants.
+     * Descendants must have the same class and same image if non null.
+     * @param lhs the left script
+     * @param rhs the right script
+     * @return null if true, a reason otherwise
+     */
+    private static String checkEquals(JexlNode lhs, JexlNode rhs) {
+        if (lhs != rhs) {
+            ArrayList<JexlNode> lhsl = flatten(lhs);
+            ArrayList<JexlNode> rhsl = flatten(rhs);
+            if (lhsl.size() != rhsl.size()) {
+                 return "size: " + lhsl.size() + " != " + rhsl.size();
+            }
+            for(int n = 0; n < lhsl.size(); ++n) {
+                lhs = lhsl.get(n);
+                rhs = rhsl.get(n);
+                if (lhs.getClass() != rhs.getClass()) {
+                    return "class: " + lhs.getClass() + " != " + 
rhs.getClass();
+                }
+                if ((lhs.image == null && rhs.image != null)
+                    || (lhs.image != null && rhs.image == null)) {
+                    return "image: " + lhs.image + " != " + rhs.image;
+                }
+                if (lhs.image != null && !lhs.image.equals(rhs.image)) {
+                    return "image: " + lhs.image + " != " + rhs.image;
+                }
+            }
+        }
+        return null;
+    }
+    
+    /**
+     * A helper class to help debug AST problems.
+     * @param e the script
+     * @return an indented version of the AST
+     */
+    protected static String flattenedStr(JexlScript e) {
+        return "";//e.getText() + "\n" + flattenedStr(((Script)e).script);
+    }
+
+    static private String indent(JexlNode node) {
+        StringBuilder strb = new StringBuilder();
+        while (node != null) {
+            strb.append("  ");
+            node = node.jjtGetParent();
+        }
+        return strb.toString();
+    }
+
+
+    private String flattenedStr(JexlNode node) {
+        ArrayList<JexlNode> flattened = flatten(node);
+        StringBuilder strb = new StringBuilder();
+        for (JexlNode flat : flattened) {
+            strb.append(indent(flat));
+            strb.append(flat.getClass().getSimpleName());
+            if (flat.image != null) {
+                strb.append(" = ");
+                strb.append(flat.image);
+            }
+            strb.append("\n");
+        }
+        return strb.toString();
+    }
+}

Propchange: 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/Util.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java
 (original)
+++ 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java
 Tue Dec  6 14:19:33 2011
@@ -16,29 +16,25 @@
  */
 package org.apache.commons.jexl3.internal.introspection;
 
+import org.apache.commons.jexl3.internal.introspection.Uberspect;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 
-import org.apache.commons.jexl3.JexlEngine;
+import org.apache.commons.jexl3.internal.Engine;
 import org.apache.commons.jexl3.JexlTestCase;
-import org.apache.commons.jexl3.JexlEngine;
-import org.apache.commons.jexl3.JexlTestCase;
-import org.apache.commons.jexl3.introspection.Uberspect;
 
-import org.apache.commons.jexl3.internal.AbstractExecutor;
-import org.apache.commons.jexl3.internal.PropertyGetExecutor;
-import org.apache.commons.jexl3.internal.PropertySetExecutor;
-import org.apache.commons.jexl3.internal.DuckGetExecutor;
-import org.apache.commons.jexl3.internal.DuckSetExecutor;
-import org.apache.commons.jexl3.internal.ListGetExecutor;
-import org.apache.commons.jexl3.internal.Introspector;
-import org.apache.commons.jexl3.internal.MapGetExecutor;
-import org.apache.commons.jexl3.internal.MapSetExecutor;
-import org.apache.commons.jexl3.internal.ListSetExecutor;
-import org.apache.commons.jexl3.introspection.Uberspect;
+import org.apache.commons.jexl3.internal.introspection.AbstractExecutor;
+import org.apache.commons.jexl3.internal.introspection.PropertyGetExecutor;
+import org.apache.commons.jexl3.internal.introspection.PropertySetExecutor;
+import org.apache.commons.jexl3.internal.introspection.DuckGetExecutor;
+import org.apache.commons.jexl3.internal.introspection.DuckSetExecutor;
+import org.apache.commons.jexl3.internal.introspection.ListGetExecutor;
+import org.apache.commons.jexl3.internal.introspection.MapGetExecutor;
+import org.apache.commons.jexl3.internal.introspection.MapSetExecutor;
+import org.apache.commons.jexl3.internal.introspection.ListSetExecutor;
 
 /**
  * Tests for checking introspection discovery.
@@ -46,6 +42,9 @@ import org.apache.commons.jexl3.introspe
  * @since 2.0
  */
 public class DiscoveryTest extends JexlTestCase {
+    public DiscoveryTest() {
+        super("DiscoveryTest");
+    }
 
     public static class Duck {
         private String value;
@@ -103,20 +102,19 @@ public class DiscoveryTest extends JexlT
 
 
     public void testBeanIntrospection() throws Exception {
-        Uberspect uber = JexlEngine.getUberspect(null);
-        Introspector intro = (Introspector) uber;
+        Uberspect uber = Engine.getUberspect(null);
         Bean bean = new Bean("JEXL", "LXEJ");
 
-        AbstractExecutor.Get get = intro.getGetExecutor(bean, "value");
-        AbstractExecutor.Set set  = intro.getSetExecutor(bean, "value", "foo");
+        AbstractExecutor.Get get = uber.getGetExecutor(bean, "value");
+        AbstractExecutor.Set set  = uber.getSetExecutor(bean, "value", "foo");
         assertTrue("bean property getter", get instanceof PropertyGetExecutor);
         assertTrue("bean property setter", set instanceof PropertySetExecutor);
         // introspector and uberspect should return same result
         assertEquals(get, uber.getPropertyGet(bean, "value", null));
         assertEquals(set, uber.getPropertySet(bean, "value", "foo", null));
         // different property should return different setter/getter
-        assertFalse(get.equals(intro.getGetExecutor(bean, "eulav")));
-        assertFalse(set.equals(intro.getSetExecutor(bean, "eulav", "foo")));
+        assertFalse(get.equals(uber.getGetExecutor(bean, "eulav")));
+        assertFalse(set.equals(uber.getSetExecutor(bean, "eulav", "foo")));
         // setter returns argument
         Object bar = set.execute(bean, "bar");
         assertEquals("bar", bar);
@@ -132,20 +130,19 @@ public class DiscoveryTest extends JexlT
     }
 
     public void testDuckIntrospection() throws Exception {
-        Uberspect uber = JexlEngine.getUberspect(null);
-        Introspector intro = (Introspector) uber;
+        Uberspect uber = Engine.getUberspect(null);
         Duck duck = new Duck("JEXL", "LXEJ");
 
-        AbstractExecutor.Get get = intro.getGetExecutor(duck, "value");
-        AbstractExecutor.Set set  = intro.getSetExecutor(duck, "value", "foo");
+        AbstractExecutor.Get get = uber.getGetExecutor(duck, "value");
+        AbstractExecutor.Set set  = uber.getSetExecutor(duck, "value", "foo");
         assertTrue("duck property getter", get instanceof DuckGetExecutor);
         assertTrue("duck property setter", set instanceof DuckSetExecutor);
         // introspector and uberspect should return same result
         assertEquals(get, uber.getPropertyGet(duck, "value", null));
         assertEquals(set, uber.getPropertySet(duck, "value", "foo", null));
         // different property should return different setter/getter
-        assertFalse(get.equals(intro.getGetExecutor(duck, "eulav")));
-        assertFalse(set.equals(intro.getSetExecutor(duck, "eulav", "foo")));
+        assertFalse(get.equals(uber.getGetExecutor(duck, "eulav")));
+        assertFalse(set.equals(uber.getSetExecutor(duck, "eulav", "foo")));
         // setter returns argument
         Object bar = set.execute(duck, "bar");
         assertEquals("bar", bar);
@@ -160,22 +157,21 @@ public class DiscoveryTest extends JexlT
     }
 
     public void testListIntrospection() throws Exception {
-        Uberspect uber = JexlEngine.getUberspect(null);
-        Introspector intro = (Introspector) uber;
+        Uberspect uber = Engine.getUberspect(null);
         List<Object> list = new ArrayList<Object>();
         list.add("LIST");
         list.add("TSIL");
 
-        AbstractExecutor.Get get = intro.getGetExecutor(list, 
Integer.valueOf(1));
-        AbstractExecutor.Set set  = intro.getSetExecutor(list, 
Integer.valueOf(1), "foo");
+        AbstractExecutor.Get get = uber.getGetExecutor(list, 
Integer.valueOf(1));
+        AbstractExecutor.Set set  = uber.getSetExecutor(list, 
Integer.valueOf(1), "foo");
         assertTrue("list property getter", get instanceof ListGetExecutor);
         assertTrue("list property setter", set instanceof ListSetExecutor);
         // introspector and uberspect should return same result
         assertEquals(get, uber.getPropertyGet(list, Integer.valueOf(1), null));
         assertEquals(set, uber.getPropertySet(list, Integer.valueOf(1), "foo", 
null));
         // different property should return different setter/getter
-        assertFalse(get.equals(intro.getGetExecutor(list, 
Integer.valueOf(0))));
-        assertFalse(get.equals(intro.getSetExecutor(list, Integer.valueOf(0), 
"foo")));
+        assertFalse(get.equals(uber.getGetExecutor(list, Integer.valueOf(0))));
+        assertFalse(get.equals(uber.getSetExecutor(list, Integer.valueOf(0), 
"foo")));
         // setter returns argument
         Object bar = set.execute(list, "bar");
         assertEquals("bar", bar);
@@ -191,22 +187,21 @@ public class DiscoveryTest extends JexlT
     }
 
     public void testMapIntrospection() throws Exception {
-        Uberspect uber = JexlEngine.getUberspect(null);
-        Introspector intro = (Introspector) uber;
+        Uberspect uber = Engine.getUberspect(null);
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("value", "MAP");
         map.put("eulav", "PAM");
 
-        AbstractExecutor.Get get = intro.getGetExecutor(map, "value");
-        AbstractExecutor.Set set  = intro.getSetExecutor(map, "value", "foo");
+        AbstractExecutor.Get get = uber.getGetExecutor(map, "value");
+        AbstractExecutor.Set set  = uber.getSetExecutor(map, "value", "foo");
         assertTrue("map property getter", get instanceof MapGetExecutor);
         assertTrue("map property setter", set instanceof MapSetExecutor);
         // introspector and uberspect should return same result
         assertEquals(get, uber.getPropertyGet(map, "value", null));
         assertEquals(set, uber.getPropertySet(map, "value", "foo", null));
         // different property should return different setter/getter
-        assertFalse(get.equals(intro.getGetExecutor(map, "eulav")));
-        assertFalse(get.equals(intro.getSetExecutor(map, "eulav", "foo")));
+        assertFalse(get.equals(uber.getGetExecutor(map, "eulav")));
+        assertFalse(get.equals(uber.getSetExecutor(map, "eulav", "foo")));
         // setter returns argument
         Object bar = set.execute(map, "bar");
         assertEquals("bar", bar);

Modified: 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/MethodKeyTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/MethodKeyTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/MethodKeyTest.java
 (original)
+++ 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/internal/introspection/MethodKeyTest.java
 Tue Dec  6 14:19:33 2011
@@ -38,7 +38,7 @@ public class MethodKeyTest extends TestC
     
     // A set of instances corresponding to the classes
     private static final Object[] ARGS = {
-        new Boolean(true),
+        Boolean.TRUE,
         new Byte((byte) 1),
         new Character('2'),
         new Double(4d),

Modified: 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/Asserter.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/Asserter.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/Asserter.java
 (original)
+++ 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/Asserter.java
 Tue Dec  6 14:19:33 2011
@@ -22,13 +22,12 @@ import java.util.Map;
 
 import junit.framework.Assert;
 
-import org.apache.commons.jexl3.Expression;
+import org.apache.commons.jexl3.JexlEvalContext;
+import org.apache.commons.jexl3.JexlExpression;
 import org.apache.commons.jexl3.JexlArithmetic;
 import org.apache.commons.jexl3.JexlContext;
-import org.apache.commons.jexl3.MapContext;
 import org.apache.commons.jexl3.JexlEngine;
 import org.apache.commons.jexl3.JexlException;
-import org.apache.commons.jexl3.JexlThreadedArithmetic;
 
 /**
  * A utility class for performing JUnit based assertions using Jexl
@@ -41,7 +40,7 @@ public class Asserter extends Assert {
     /** variables used during asserts. */
     private final Map<String, Object> variables = new HashMap<String, 
Object>();
     /** context to use during asserts. */
-    private final JexlContext context = new MapContext(variables);
+    private final JexlEvalContext context = new JexlEvalContext(variables);
     /** Jexl engine to use during Asserts. */
     private final JexlEngine engine;
 
@@ -69,6 +68,22 @@ public class Asserter extends Assert {
     public JexlContext getContext() {
         return context;
     }
+    
+    public void setStrict(boolean s) {
+        context.setStrict(s, s);
+    }
+    
+    public void setStrict(boolean es, boolean as) {
+        context.setStrict(es, as);
+    }
+    
+    public void setSilent(boolean silent) {
+        context.setSilent(silent);
+    }
+    
+    public void clearOptions() {
+        context.clearOptions();
+    }
 
     /**
      * Performs an assertion that the value of the given Jexl expression 
@@ -80,7 +95,7 @@ public class Asserter extends Assert {
      * fails
      */
     public void assertExpression(String expression, Object expected) throws 
Exception {
-        Expression exp = engine.createExpression(expression);
+        JexlExpression exp = engine.createExpression(expression);
         Object value = exp.evaluate(context);
         if (expected instanceof BigDecimal) {
             JexlArithmetic jexla = engine.getArithmetic();
@@ -99,24 +114,14 @@ public class Asserter extends Assert {
      * @throws Exception if the expression did not fail or the exception did 
not match the expected pattern
      */
     public void failExpression(String expression, String matchException) 
throws Exception {
-        boolean[] flags = {engine.isLenient(), engine.isSilent()};
         try {
-            if (engine.getArithmetic() instanceof JexlThreadedArithmetic) {
-                engine.setLenient(false);
-            }
-            engine.setSilent(false);
-            Expression exp = engine.createExpression(expression);
+            JexlExpression exp = engine.createExpression(expression);
             exp.evaluate(context);
             fail("expression: " + expression);
         } catch (JexlException xjexl) {
             if (matchException != null && 
!xjexl.getMessage().matches(matchException)) {
                 fail("expression: " + expression + ", expected: " + 
matchException + ", got " + xjexl.getMessage());
             }
-        } finally {
-            if (engine.getArithmetic() instanceof JexlThreadedArithmetic) {
-                engine.setLenient(flags[0]);
-            }
-            engine.setSilent(flags[1]);
         }
     }
 

Modified: 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/AsserterTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/AsserterTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/AsserterTest.java
 (original)
+++ 
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/junit/AsserterTest.java
 Tue Dec  6 14:19:33 2011
@@ -20,9 +20,7 @@ package org.apache.commons.jexl3.junit;
 import junit.framework.AssertionFailedError;
 
 import org.apache.commons.jexl3.Foo;
-import org.apache.commons.jexl3.JexlEngine;
 import org.apache.commons.jexl3.JexlTestCase;
-import org.apache.commons.jexl3.JexlEngine;
 
 /**
  *  Simple testcases
@@ -50,9 +48,8 @@ public class AsserterTest extends JexlTe
     }
 
     public void testVariable() throws Exception {
-        JexlEngine jexl = new JexlEngine();
-        jexl.setSilent(true);
-        Asserter asserter = new Asserter(jexl);
+        Asserter asserter = new Asserter(JEXL);
+        asserter.setSilent(true);
         asserter.setVariable("foo", new Foo());
         asserter.setVariable("person", "James");
 


Reply via email to