Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BB6BA9108 for ; Sat, 11 Feb 2012 17:08:30 +0000 (UTC) Received: (qmail 62891 invoked by uid 500); 11 Feb 2012 17:08:30 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 62798 invoked by uid 500); 11 Feb 2012 17:08:29 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 62791 invoked by uid 99); 11 Feb 2012 17:08:29 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 11 Feb 2012 17:08:29 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 11 Feb 2012 17:08:23 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2B74523888D2 for ; Sat, 11 Feb 2012 17:08:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1243101 - in /commons/proper/jexl/trunk/src: main/java/org/apache/commons/jexl3/ main/java/org/apache/commons/jexl3/internal/ main/java/org/apache/commons/jexl3/internal/introspection/ main/java/org/apache/commons/jexl3/parser/ test/java/o... Date: Sat, 11 Feb 2012 17:08:00 -0000 To: commits@commons.apache.org From: henrib@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120211170801.2B74523888D2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: henrib Date: Sat Feb 11 17:07:59 2012 New Revision: 1243101 URL: http://svn.apache.org/viewvc?rev=1243101&view=rev Log: JEXL-127; refined exception handling, checkstyle Removed: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Frame.java Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlException.java commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Scope.java commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Script.java commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ASTJexlLambda.java commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlException.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlException.java?rev=1243101&r1=1243100&r2=1243101&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlException.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlException.java Sat Feb 11 17:07:59 2012 @@ -23,6 +23,8 @@ import org.apache.commons.jexl3.parser.T import java.lang.reflect.InvocationTargetException; import java.lang.reflect.UndeclaredThrowableException; +import java.util.ArrayList; +import java.util.List; /** * Wraps any error that might occur during interpretation of a script or expression. @@ -66,12 +68,44 @@ public class JexlException extends Runti * @param cause the exception causing the error */ public JexlException(JexlInfo jinfo, String msg, Throwable cause) { - super(msg, unwrap(cause)); + super(msg, clean(unwrap(cause))); mark = null; info = jinfo; } /** + * Cleans a JexlException from any org.apache.commons.jexl3 stack trace element. + * @return this exception + */ + public JexlException clean() { + return clean(this); + } + + /** + * Cleans a Throwable from any org.apache.commons.jexl3 stack trace element. + * @param the throwable type + * @param xthrow the thowable + * @return the throwable + */ + private static X clean(X xthrow) { + if (xthrow != null) { + StackTraceElement[] stack = xthrow.getStackTrace(); + StackTraceElement se = null; + List stackJexl = new ArrayList(); + stackJexl.add(stack[0]); + for (int s = 1; s < stack.length; ++s) { + se = stack[s]; + String className = se.getClassName(); + if (!className.startsWith("org.apache.commons.jexl3")) { + stackJexl.add(se); + } + } + xthrow.setStackTrace(stackJexl.toArray(new StackTraceElement[stackJexl.size()])); + } + return xthrow; + } + + /** * Unwraps the cause of a throwable due to reflection. * @param xthrow the throwable * @return the cause @@ -216,7 +250,6 @@ public class JexlException extends Runti * Creates a new Variable exception instance. * @param node the offending ASTnode * @param var the unknown variable - * @param cause the exception causing the error */ public Variable(JexlNode node, String var) { super(node, var, null); Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java?rev=1243101&r1=1243100&r2=1243101&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java Sat Feb 11 17:07:59 2012 @@ -335,7 +335,7 @@ public class Engine extends JexlEngine { Scope scope = new Scope(null, "#0"); ASTJexlScript script = parse(expr, null, scope); JexlNode node = script.jjtGetChild(0); - Frame frame = script.createFrame(bean); + Scope.Frame frame = script.createFrame(bean); Interpreter interpreter = createInterpreter(context, frame); return node.jjtAccept(interpreter, null); } catch (JexlException xjexl) { @@ -343,7 +343,7 @@ public class Engine extends JexlEngine { logger.warn(xjexl.getMessage(), xjexl.getCause()); return null; } - throw xjexl; + throw xjexl.clean(); } finally { parser.ALLOW_REGISTERS = false; } @@ -366,7 +366,7 @@ public class Engine extends JexlEngine { Scope scope = new Scope(null, "#0", "#1"); ASTJexlScript script = parse(expr, null, scope); JexlNode node = script.jjtGetChild(0); - Frame frame = script.createFrame(bean, value); + Scope.Frame frame = script.createFrame(bean, value); Interpreter interpreter = createInterpreter(context, frame); node.jjtAccept(interpreter, null); } catch (JexlException xjexl) { @@ -374,7 +374,7 @@ public class Engine extends JexlEngine { logger.warn(xjexl.getMessage(), xjexl.getCause()); return; } - throw xjexl; + throw xjexl.clean(); } finally { parser.ALLOW_REGISTERS = false; } @@ -403,7 +403,7 @@ public class Engine extends JexlEngine { logger.warn(xjexl.getMessage(), xjexl.getCause()); return null; } - throw xjexl; + throw xjexl.clean(); } } return result; @@ -448,7 +448,7 @@ public class Engine extends JexlEngine { logger.warn(xjexl.getMessage(), xjexl.getCause()); return null; } - throw xjexl; + throw xjexl.clean(); } } return result; @@ -460,7 +460,7 @@ public class Engine extends JexlEngine { * @param frame the interpreter frame * @return an Interpreter */ - protected Interpreter createInterpreter(JexlContext context, Frame frame) { + protected Interpreter createInterpreter(JexlContext context, Scope.Frame frame) { return new Interpreter(this, context == null ? EMPTY_CONTEXT : context, frame); } @@ -694,9 +694,9 @@ public class Engine extends JexlEngine { cache.put(expr, script); } } catch (TokenMgrError xtme) { - throw new JexlException.Tokenization(jexlInfo, expression, xtme); + throw new JexlException.Tokenization(jexlInfo, expression, xtme).clean(); } catch (ParseException xparse) { - throw new JexlException.Parsing(jexlInfo, expression, xparse); + throw new JexlException.Parsing(jexlInfo, expression, xparse).clean(); } finally { parser.setFrame(null); } @@ -729,7 +729,7 @@ public class Engine extends JexlEngine { StackTraceElement[] stack = xinfo.getStackTrace(); StackTraceElement se = null; Class clazz = getClass(); - for (int s = 1; s < stack.length; ++s, se = null) { + for (int s = 1; s < stack.length; ++s) { se = stack[s]; String className = se.getClassName(); if (!className.equals(clazz.getName())) { Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java?rev=1243101&r1=1243100&r2=1243101&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java Sat Feb 11 17:07:59 2012 @@ -120,7 +120,7 @@ public class Interpreter extends ParserV /** Cache executors. */ protected final boolean cache; /** Registers or arguments. */ - protected final Frame frame; + protected final Scope.Frame frame; /** Cancellation support. */ protected volatile boolean cancelled = false; /** Empty parameters for method matching. */ @@ -130,9 +130,9 @@ public class Interpreter extends ParserV * Creates an interpreter. * @param engine the engine creating this interpreter * @param aContext the context to evaluate expression - * @param frame the engine evaluation frame + * @param eFrame the interpreter evaluation frame */ - protected Interpreter(Engine engine, JexlContext aContext, Frame eFrame) { + protected Interpreter(Engine engine, JexlContext aContext, Scope.Frame eFrame) { this.jexl = engine; this.logger = jexl.logger; this.uberspect = jexl.uberspect; @@ -155,8 +155,13 @@ public class Interpreter extends ParserV this.frame = eFrame; this.functors = null; } - - protected Interpreter(Interpreter copy, Frame eFrame) { + + /** + * Creates a copy of an interpreter, used for function/lambda evaluation. + * @param copy the interpreter to copy + * @param eFrame the interpreter evaluation frame + */ + protected Interpreter(Interpreter copy, Scope.Frame eFrame) { this.jexl = copy.jexl; this.logger = copy.logger; this.uberspect = copy.uberspect; @@ -167,8 +172,8 @@ public class Interpreter extends ParserV this.strictEngine = copy.strictEngine; this.strictArithmetic = copy.strictArithmetic; this.cache = copy.cache; + this.functors = copy.functors; this.frame = eFrame; - this.functors = null; } /** @@ -191,7 +196,7 @@ public class Interpreter extends ParserV logger.warn(xjexl.getMessage(), xjexl.getCause()); return null; } - throw xjexl; + throw xjexl.clean(); } finally { functors = null; } @@ -422,7 +427,7 @@ public class Interpreter extends ParserV // determine initial object & property: JexlNode objectNode = null; - Object object = register >= 0 ? frame.registers[register] : null; + Object object = register >= 0 ? frame.get(register) : null; JexlNode propertyNode = null; Object property = null; boolean isVariable = true; @@ -504,7 +509,7 @@ public class Interpreter extends ParserV } // deal with ant variable; set context if (isRegister) { - frame.registers[register] = right; + frame.set(register, right); return right; } else if (antVar) { if (isVariable && object == null) { @@ -668,7 +673,7 @@ public class Interpreter extends ParserV if (register < 0) { context.set(loopVariable.image, value); } else { - frame.registers[register] = value; + frame.set(register, value); } // execute statement result = statement.jjtAccept(this, data); @@ -766,7 +771,7 @@ public class Interpreter extends ParserV if (data == null) { int register = node.getRegister(); if (register >= 0) { - return frame.registers[register]; + return frame.get(register); } Object value = context.get(name); if (value == null @@ -837,17 +842,32 @@ public class Interpreter extends ParserV } } + /** + * A function closure. + */ private static final class Closure { - Frame frame; - ASTJexlLambda lambda; - Closure(ASTJexlLambda l, Frame f) { + /** The frame. */ + private final Scope.Frame frame; + /** The actual lambda. */ + private final ASTJexlLambda lambda; + /** Creates a closure. + * @param l the lambda + * @param f the interpreter frame + */ + Closure(ASTJexlLambda l, Scope.Frame f) { lambda = l; frame = lambda.createFrame(f); } } + /** + * Evaluates a closure. + * @param closure the closure + * @param argv the arguments + * @return the result of evaluation + */ private Object call(Closure closure, Object[] argv) { - Frame cframe = closure.frame; + Scope.Frame cframe = closure.frame; if (cframe != null) { cframe.assign(argv); } @@ -952,7 +972,7 @@ public class Interpreter extends ParserV if (bean == context) { int register = methodNode.getRegister(); if (register >= 0) { - functor = frame.registers[register]; + functor = frame.get(register); } else { functor = context.get(methodName); } Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Scope.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Scope.java?rev=1243101&r1=1243100&r2=1243101&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Scope.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Scope.java Sat Feb 11 17:07:59 2012 @@ -37,42 +37,38 @@ public final class Scope { */ private int vars; /** - * The number of hoisted variables. - */ - private int hoisted; - /** - * The map of named registers aka script parameters. - * Each parameter is associated to a register and is materialized as an offset in the registers array used + * The map of named varialbes aka script parameters and local variables. + * Each parameter is associated to a register and is materialized as an offset in the stacked array used * during evaluation. */ - private Map namedRegisters = null; + private Map namedVariables = null; /** - * The map of registers to parent registers when hoisted by closure. + * The map of local hoisted variables to parent scope variables, ie closure. */ - private Map hoistedRegisters = null; + private Map hoistedVariables = null; /** * Creates a new scope with a list of parameters. + * @param scope the parent scope if any * @param parameters the list of parameters */ public Scope(Scope scope, String... parameters) { if (parameters != null) { parms = parameters.length; - namedRegisters = new LinkedHashMap(); + namedVariables = new LinkedHashMap(); for (int p = 0; p < parms; ++p) { - namedRegisters.put(parameters[p], p); + namedVariables.put(parameters[p], p); } } else { parms = 0; } vars = 0; - hoisted = 0; parent = scope; } @Override public int hashCode() { - return namedRegisters == null ? 0 : parms ^ namedRegisters.hashCode(); + return namedVariables == null ? 0 : parms ^ namedVariables.hashCode(); } @Override @@ -90,16 +86,16 @@ public final class Scope { return true; } else if (frame == null || parms != frame.parms) { return false; - } else if (namedRegisters == null) { - return frame.namedRegisters == null; + } else if (namedVariables == null) { + return frame.namedVariables == null; } else { - return namedRegisters.equals(frame.namedRegisters); + return namedVariables.equals(frame.namedVariables); } } /** * Checks whether an identifier is a local variable or argument, ie stored in a register. - * If this fails, attempt to solve by hoisting parent registers. + * If this fails, attempt to solve by hoisting parent stacked. * @param name the register name * @return the register index */ @@ -110,24 +106,23 @@ public final class Scope { /** * Checks whether an identifier is a local variable or argument, ie stored in a register. * @param name the register name - * @param hoist whether solving by hoisting parent registers is allowed + * @param hoist whether solving by hoisting parent stacked is allowed * @return the register index */ private Integer getRegister(String name, boolean hoist) { - Integer register = namedRegisters != null ? namedRegisters.get(name) : null; + Integer register = namedVariables != null ? namedVariables.get(name) : null; if (register == null && hoist && parent != null) { Integer pr = parent.getRegister(name, false); if (pr != null) { - if (hoistedRegisters == null) { - hoistedRegisters = new LinkedHashMap(); + if (hoistedVariables == null) { + hoistedVariables = new LinkedHashMap(); } - register = Integer.valueOf(namedRegisters.size()); - if (namedRegisters == null) { - namedRegisters = new LinkedHashMap(); + if (namedVariables == null) { + namedVariables = new LinkedHashMap(); } - namedRegisters.put(name, register); - hoistedRegisters.put(register, pr); - hoisted += 1; + register = Integer.valueOf(namedVariables.size()); + namedVariables.put(name, register); + hoistedVariables.put(register, pr); } } return register; @@ -141,15 +136,15 @@ public final class Scope { * @param name the parameter name */ public void declareParameter(String name) { - if (namedRegisters == null) { - namedRegisters = new LinkedHashMap(); + if (namedVariables == null) { + namedVariables = new LinkedHashMap(); } else if (vars > 0) { throw new IllegalStateException("cant declare parameters after variables"); } - Integer register = namedRegisters.get(name); + Integer register = namedVariables.get(name); if (register == null) { - register = Integer.valueOf(namedRegisters.size()); - namedRegisters.put(name, register); + register = Integer.valueOf(namedVariables.size()); + namedVariables.put(name, register); parms += 1; } } @@ -163,13 +158,13 @@ public final class Scope { * @return the register index storing this variable */ public Integer declareVariable(String name) { - if (namedRegisters == null) { - namedRegisters = new LinkedHashMap(); + if (namedVariables == null) { + namedVariables = new LinkedHashMap(); } - Integer register = namedRegisters.get(name); + Integer register = namedVariables.get(name); if (register == null) { - register = Integer.valueOf(namedRegisters.size()); - namedRegisters.put(name, register); + register = Integer.valueOf(namedVariables.size()); + namedVariables.put(name, register); vars += 1; } return register; @@ -177,21 +172,22 @@ public final class Scope { /** * Creates a frame by copying values up to the number of parameters. - * @param values the argument values + *

This captures the hoisted variables values.

+ * @param frame the caller frame * @return the arguments array */ - public Frame createFrame(Frame caller) { - if (namedRegisters != null) { - Object[] arguments = new Object[namedRegisters.size()]; - if (caller != null && hoistedRegisters != null && parent != null) { - for (Map.Entry hoist : hoistedRegisters.entrySet()) { + public Frame createFrame(Frame frame) { + if (namedVariables != null) { + Object[] arguments = new Object[namedVariables.size()]; + if (frame != null && hoistedVariables != null && parent != null) { + for (Map.Entry hoist : hoistedVariables.entrySet()) { Integer target = hoist.getKey(); Integer source = hoist.getValue(); - Object arg = caller.registers[source.intValue()]; + Object arg = frame.get(source.intValue()); arguments[target.intValue()] = arg; } } - return new Frame(arguments, namedRegisters.keySet().toArray(new String[namedRegisters.size()])); + return new Frame(arguments); } else { return null; } @@ -206,22 +202,22 @@ public final class Scope { } /** - * Gets this script registers, i.e. parameters and local variables. + * Gets this script stacked, i.e. parameters and local variables. * @return the register names */ public String[] getRegisters() { - return namedRegisters != null ? namedRegisters.keySet().toArray(new String[0]) : new String[0]; + return namedVariables != null ? namedVariables.keySet().toArray(new String[0]) : new String[0]; } /** - * Gets this script parameters, i.e. registers assigned before creating local variables. + * Gets this script parameters, i.e. stacked assigned before creating local variables. * @return the parameter names */ public String[] getParameters() { - if (namedRegisters != null && parms > 0) { + if (namedVariables != null && parms > 0) { String[] pa = new String[parms]; int p = 0; - for (Map.Entry entry : namedRegisters.entrySet()) { + for (Map.Entry entry : namedVariables.entrySet()) { if (entry.getValue().intValue() < parms) { pa[p++] = entry.getKey(); } @@ -233,14 +229,14 @@ public final class Scope { } /** - * Gets this script local variable, i.e. registers assigned to local variables. + * Gets this script local variable, i.e. stacked assigned to local variables. * @return the parameter names */ public String[] getLocalVariables() { - if (namedRegisters != null && vars > 0) { + if (namedVariables != null && vars > 0) { String[] pa = new String[parms]; int p = 0; - for (Map.Entry entry : namedRegisters.entrySet()) { + for (Map.Entry entry : namedVariables.entrySet()) { if (entry.getValue().intValue() >= parms) { pa[p++] = entry.getKey(); } @@ -250,5 +246,51 @@ public final class Scope { return null; } } - + + /** + * A call frame, created from a scope, stores the arguments and local variables in a "stack frame" (sic). + * @since 3.0 + */ + public static final class Frame { + /** The actual stack frame. */ + private final Object[] stack; + + /** + * Creates a new frame. + * @param r the stack frame + */ + public Frame(Object[] r) { + stack = r; + } + + /** + * Gets a value. + * @param s the offset in this frame + * @return the stacked value + */ + public Object get(int s) { + return stack[s]; + } + + /** + * Sets a value. + * @param r the offset in this frame + * @param value the value to set in this frame + */ + public void set(int r, Object value) { + stack[r] = value; + } + + /** + * Assign values to this frame. + * @param values the values + * @return this frame + */ + public Frame assign(Object... values) { + if (stack != null && values != null && values.length > 0) { + System.arraycopy(values, 0, stack, 0, Math.min(stack.length, values.length)); + } + return this; + } + } } Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Script.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Script.java?rev=1243101&r1=1243100&r2=1243101&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Script.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Script.java Sat Feb 11 17:07:59 2012 @@ -57,7 +57,7 @@ public class Script implements JexlScrip if (script.jjtGetNumChildren() < 1) { return null; } - Frame frame = script.createFrame((Object[]) null); + Scope.Frame frame = script.createFrame((Object[]) null); Interpreter interpreter = jexl.createInterpreter(context, frame); return interpreter.interpret(script.jjtGetChild(0)); } @@ -94,7 +94,7 @@ public class Script implements JexlScrip */ @Override public Object execute(JexlContext context) { - Frame frame = script.createFrame((Object[]) null); + Scope.Frame frame = script.createFrame((Object[]) null); Interpreter interpreter = jexl.createInterpreter(context, frame); return interpreter.interpret(script); } @@ -104,7 +104,7 @@ public class Script implements JexlScrip */ @Override public Object execute(JexlContext context, Object... args) { - Frame frame = script.createFrame(args != null && args.length > 0? args : null); + Scope.Frame frame = script.createFrame(args != null && args.length > 0? args : null); Interpreter interpreter = jexl.createInterpreter(context, frame); return interpreter.interpret(script); } Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java?rev=1243101&r1=1243100&r2=1243101&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java Sat Feb 11 17:07:59 2012 @@ -257,7 +257,7 @@ public final class TemplateEngine extend @Override public final TemplateExpression prepare(JexlContext context) { try { - Frame frame = context instanceof TemplateContext + Scope.Frame frame = context instanceof TemplateContext ? ((TemplateContext) context).getFrame() : null; Interpreter interpreter = jexl.createInterpreter(context, frame); @@ -275,7 +275,7 @@ public final class TemplateEngine extend @Override public final Object evaluate(JexlContext context) { try { - Frame frame = context instanceof TemplateContext + Scope.Frame frame = context instanceof TemplateContext ? ((TemplateContext) context).getFrame() : null; Interpreter interpreter = jexl.createInterpreter(context, frame); @@ -973,7 +973,7 @@ public final class TemplateEngine extend @Override public TemplateScript prepare(JexlContext context) { - Frame frame = script.createFrame((Object[]) null); + Scope.Frame frame = script.createFrame((Object[]) null); TemplateContext tcontext = new TemplateContext(context, frame, exprs, null); TemplateExpression[] immediates = new TemplateExpression[exprs.length]; for (int e = 0; e < exprs.length; ++e) { @@ -989,7 +989,7 @@ public final class TemplateEngine extend @Override public void evaluate(JexlContext context, Writer writer, Object... args) { - Frame frame = script.createFrame(args); + Scope.Frame frame = script.createFrame(args); TemplateContext tcontext = new TemplateContext(context, frame, exprs, writer); Interpreter interpreter = jexl.createInterpreter(tcontext, frame); interpreter.interpret(script); @@ -1009,7 +1009,7 @@ public final class TemplateEngine extend /** The writer used to output. */ private final Writer writer; /** The call frame. */ - private final Frame frame; + private final Scope.Frame frame; /** * Creates a TemplateScript context instance. @@ -1018,7 +1018,7 @@ public final class TemplateEngine extend * @param expressions the list of TemplateExpression from the TemplateScript to evaluate * @param out the output writer */ - protected TemplateContext(JexlContext jcontext, Frame jframe, + protected TemplateContext(JexlContext jcontext, Scope.Frame jframe, UnifiedExpression[] expressions, Writer out) { wrap = jcontext; frame = jframe; @@ -1030,7 +1030,7 @@ public final class TemplateEngine extend * Gets this context calling frame. * @return the engine frame */ - public Frame getFrame() { + public Scope.Frame getFrame() { return frame; } Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java?rev=1243101&r1=1243100&r2=1243101&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java Sat Feb 11 17:07:59 2012 @@ -201,7 +201,7 @@ public class Uberspect implements JexlUb } // last, look for get("foo") if we did not try yet if (property != null && !(identifier instanceof String)) { - // if that didn't work, look for set("foo") + // if that didn't work, look for get("foo") executor = DuckGetExecutor.discover(is, claz, property); if (executor != null) { return executor; Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ASTJexlLambda.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ASTJexlLambda.java?rev=1243101&r1=1243100&r2=1243101&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ASTJexlLambda.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ASTJexlLambda.java Sat Feb 11 17:07:59 2012 @@ -16,7 +16,7 @@ */ package org.apache.commons.jexl3.parser; -import org.apache.commons.jexl3.internal.Frame; +import org.apache.commons.jexl3.internal.Scope; /** * Enhanced script to allow parameters declaration. @@ -35,9 +35,9 @@ public class ASTJexlLambda extends ASTJe * @param values the argument values * @return the arguments array */ - public Frame createFrame(Frame frame, Object... values) { + public Scope.Frame createFrame(Scope.Frame frame, Object... values) { if (scope != null) { - Frame cframe = scope.createFrame(frame); + Scope.Frame cframe = scope.createFrame(frame); if (cframe != null) { return cframe.assign(values); } Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java?rev=1243101&r1=1243100&r2=1243101&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java Sat Feb 11 17:07:59 2012 @@ -16,8 +16,6 @@ */ package org.apache.commons.jexl3.parser; -import org.apache.commons.jexl3.internal.Engine; -import org.apache.commons.jexl3.internal.Frame; import org.apache.commons.jexl3.internal.Scope; /** @@ -60,13 +58,14 @@ public class ASTJexlScript extends JexlN * @param values the argument values * @return the arguments array */ - public Frame createFrame(Object... values) { + public Scope.Frame createFrame(Object... values) { if (scope != null) { - Frame frame = scope.createFrame(null); - return frame != null? frame.assign(values) : null; - } else { - return null; - } + Scope.Frame frame = scope.createFrame(null); + if (frame != null) { + return frame.assign(values); + } + } + return null; } /** Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java?rev=1243101&r1=1243100&r2=1243101&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java Sat Feb 11 17:07:59 2012 @@ -16,13 +16,12 @@ */ package org.apache.commons.jexl3.parser; -import java.io.Reader; -import java.util.Stack; import org.apache.commons.jexl3.JexlException; import org.apache.commons.jexl3.JexlInfo; -import org.apache.commons.jexl3.internal.Engine; import org.apache.commons.jexl3.internal.Scope; +import java.util.Stack; + /** * The base class for parsing, manages the parameter/local variable frame. * @author henri Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt?rev=1243101&r1=1243100&r2=1243101&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt Sat Feb 11 17:07:59 2012 @@ -114,7 +114,6 @@ PARSER_END(Parser) | < COLON : ":" > | < COMMA : "," > | < DOT : "." > - | < LAMBDA : "->" > } <*> TOKEN : { /* CONDITIONALS */ Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java?rev=1243101&r1=1243100&r2=1243101&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java (original) +++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java Sat Feb 11 17:07:59 2012 @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; import org.apache.commons.jexl3.junit.Asserter; @@ -181,7 +182,7 @@ public class ArithmeticTest extends Jexl public void testCoercions() throws Exception { asserter.assertExpression("1", new Integer(1)); // numerics default to Integer - asserter.assertExpression("5L", new Long(5)); + asserter.assertExpression("5L", new Long(5)); asserter.setVariable("I2", new Integer(2)); asserter.setVariable("L2", new Long(2)); @@ -225,6 +226,22 @@ public class ArithmeticTest extends Jexl } } + public static class IterableContainer implements Iterable { + private final Set values; + + public IterableContainer(int[] is) { + values = new HashSet(); + for (int value : is) { + values.add(value); + } + } + + @Override + public Iterator iterator() { + return values.iterator(); + } + } + public void testRegexp() throws Exception { asserter.setVariable("str", "abc456"); asserter.assertExpression("str =~ '.*456'", Boolean.TRUE); @@ -249,7 +266,7 @@ public class ArithmeticTest extends Jexl // check in/not-in on array, list, map, set and duck-type collection int[] ai = {2, 4, 42, 54}; List al = new ArrayList(); - for(int i : ai) { + for (int i : ai) { al.add(i); } Map am = new HashMap(); @@ -258,19 +275,19 @@ public class ArithmeticTest extends Jexl am.put(42, "forty-two"); am.put(54, "fifty-four"); MatchingContainer ad = new MatchingContainer(ai); + IterableContainer ic = new IterableContainer(ai); Set as = ad.values; - Object[] vars = { ai, al, am, ad, as }; - - for(Object var : vars) { + Object[] vars = {ai, al, am, ad, as, ic}; + + for (Object var : vars) { asserter.setVariable("container", var); - for(int x : ai) { + for (int x : ai) { asserter.setVariable("x", x); asserter.assertExpression("x =~ container", Boolean.TRUE); } asserter.setVariable("x", 169); asserter.assertExpression("x !~ container", Boolean.TRUE); } - } /** Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java?rev=1243101&r1=1243100&r2=1243101&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java (original) +++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java Sat Feb 11 17:07:59 2012 @@ -495,7 +495,7 @@ public class IssuesTest extends JexlTest public String getPropA() { return propA; } - + public String uppercase(String str) { return str.toUpperCase(); } @@ -718,9 +718,6 @@ public class IssuesTest extends JexlTest assertTrue((Boolean) result); } - - - public static class Foo125 { public String method() { return "OK"; @@ -739,4 +736,23 @@ public class IssuesTest extends JexlTest JexlContext jc = new Foo125Context(jexl, new Foo125()); assertEquals("OK", e.evaluate(jc)); } + + public static class ThrowNPE { + public String method() { + throw new NullPointerException("ThrowNPE"); + } + } + + public void test126() throws Exception { + JexlEngine jexl = new Engine(); + JexlExpression e = jexl.createExpression("method()"); + JexlContext jc = new ObjectContext(jexl, new ThrowNPE()); + try { + e.evaluate(jc); + fail("Should have thrown NPE"); + } catch(JexlException xany) { + Throwable xth = xany.getCause(); + assertEquals(NullPointerException.class, xth.getClass()); + } + } }