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 E43F46B81 for ; Sun, 17 Jul 2011 19:57:19 +0000 (UTC) Received: (qmail 2066 invoked by uid 500); 17 Jul 2011 19:57:19 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 1783 invoked by uid 500); 17 Jul 2011 19:57:18 -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 1776 invoked by uid 99); 17 Jul 2011 19:57:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 17 Jul 2011 19:57:18 +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; Sun, 17 Jul 2011 19:57:16 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A0A382388901 for ; Sun, 17 Jul 2011 19:56:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1147705 - in /commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2: Interpreter.java JexlEngine.java JexlException.java parser/JexlNode.java Date: Sun, 17 Jul 2011 19:56:56 -0000 To: commits@commons.apache.org From: henrib@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110717195656.A0A382388901@eris.apache.org> Author: henrib Date: Sun Jul 17 19:56:53 2011 New Revision: 1147705 URL: http://svn.apache.org/viewvc?rev=1147705&view=rev Log: Related to JEXL-116: * sub-classed JexlException (Method, Variable, etc) to allow better control over error reporting Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlException.java commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/JexlNode.java Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java?rev=1147705&r1=1147704&r2=1147705&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java Sun Jul 17 19:56:53 2011 @@ -794,7 +794,7 @@ public class Interpreter implements Pars && !(node.jjtGetParent() instanceof ASTReference) && !context.has(name) && !isTernaryProtected(node)) { - JexlException xjexl = new JexlException(node, "undefined variable " + name); + JexlException xjexl = new JexlException.Variable(node, name); return unknownVariable(xjexl); } return value; @@ -944,7 +944,7 @@ public class Interpreter implements Pars vm = uberspect.getMethod(data, methodName, argv, node); } if (vm == null) { - xjexl = new JexlException(node, "unknown or ambiguous method", null); + xjexl = new JexlException.Method(node, methodName); } } if (xjexl == null) { @@ -987,7 +987,7 @@ public class Interpreter implements Pars ctor = uberspect.getConstructor(cobject, argv, node); } if (ctor == null) { - xjexl = new JexlException(node, "unknown constructor", null); + xjexl = new JexlException.Method(node, cobject.toString()); } } if (xjexl == null) { @@ -1041,7 +1041,7 @@ public class Interpreter implements Pars vm = uberspect.getMethod(namespace, function, argv, node); } if (vm == null) { - xjexl = new JexlException(node, "unknown function", null); + xjexl = new JexlException.Method(node, function); } } if (xjexl == null) { @@ -1184,7 +1184,7 @@ public class Interpreter implements Pars } if (result == null) { if (isVariable && !context.has(variableName.toString()) && !isTernaryProtected(node)) { - JexlException xjexl = new JexlException(node, "undefined variable " + variableName.toString()); + JexlException xjexl = new JexlException.Variable(node, variableName.toString()); return unknownVariable(xjexl); } } Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java?rev=1147705&r1=1147704&r2=1147705&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java Sun Jul 17 19:56:53 2011 @@ -1023,9 +1023,9 @@ public class JexlEngine { cache.put(expr, script); } } catch (TokenMgrError xtme) { - throw new JexlException(info, "!!! " + expression + " !!!" + ", tokenization failed", xtme); + throw new JexlException.Tokenization(info, expression, xtme); } catch (ParseException xparse) { - throw new JexlException(info, "!!! " + expression + " !!!" + ", parsing failed", xparse); + throw new JexlException.Parsing(info, expression, xparse); } finally { parser.setNamedRegisters(null); } Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlException.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlException.java?rev=1147705&r1=1147704&r2=1147705&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlException.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlException.java Sun Jul 17 19:56:53 2011 @@ -31,6 +31,7 @@ public class JexlException extends Runti protected final JexlInfo info; /** A marker to use in NPEs stating a null operand error. */ public static final String NULL_OPERAND = "jexl.null"; + /** * Creates a new JexlException. * @param node the node causing the error @@ -77,6 +78,118 @@ public class JexlException extends Runti mark = null; info = dbg; } + + /** + * Accesses detailed message. + * @return the message + */ + protected String detailedMessage() { + return super.getMessage(); + } + + /** + * The exception thrown when tokenization fails. + */ + public static class Tokenization extends JexlException { + /** + * Creates a new Tokenization exception instance. + * @param node the location info + * @param expr the expression + */ + public Tokenization(JexlInfo node, CharSequence expr, Throwable cause) { + super(node, expr.toString(), cause); + } + + /** + * @return the expression + */ + public String getExpression() { + return super.detailedMessage(); + } + + @Override + protected String detailedMessage() { + return "!!! " + getExpression() + " !!!" + ", tokenization failed"; + } + } + + /** + * The exception thrown parsing fails. + */ + public static class Parsing extends JexlException { + /** + * Creates a new Variable exception instance. + * @param node the offending ASTnode + * @param expr the unknown variable + */ + public Parsing(JexlInfo node, CharSequence expr, Throwable cause) { + super(node, expr.toString(), cause); + } + + /** + * @return the expression + */ + public String getExpression() { + return super.detailedMessage(); + } + + @Override + protected String detailedMessage() { + return "!!! " + getExpression() + " !!!" + ", parsing failed"; + } + } + + /** + * The exception thrown when a variable is unknown. + */ + public static class Variable extends JexlException { + /** + * Creates a new Variable exception instance. + * @param node the offending ASTnode + * @param var the unknown variable + */ + public Variable(JexlNode node, String var) { + super(node, var); + } + + /** + * @return the variable name + */ + public String getVariable() { + return super.detailedMessage(); + } + + @Override + protected String detailedMessage() { + return "undefined variable " + getVariable(); + } + } + + /** + * The exception thrown when a method or ctor is unknown, ambiguous or inaccessible. + */ + public static class Method extends JexlException { + /** + * Creates a new Method exception instance. + * @param node the offending ASTnode + * @param name the unknown method + */ + public Method(JexlNode node, String name) { + super(node, name); + } + + /** + * @return the method name + */ + public String getMethod() { + return super.detailedMessage(); + } + + @Override + protected String detailedMessage() { + return "unknown, ambiguous or inaccessible method " + getMethod(); + } + } /** * The class of exceptions that will force the interpreter to return, allways behaving in strict mode. @@ -122,7 +235,7 @@ public class JexlException extends Runti } return ""; } - + /** * Detailed info message about this error. * Format is "debug![begin,end]: string \n msg" where: @@ -149,9 +262,9 @@ public class JexlException extends Runti msg.append("'"); } msg.append(' '); - msg.append(super.getMessage()); + msg.append(detailedMessage()); Throwable cause = getCause(); - if (cause != null && NULL_OPERAND == cause.getMessage()) { + if (cause != null && (Object) NULL_OPERAND == cause.getMessage()) { msg.append(" caused by null operand"); } return msg.toString(); Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/JexlNode.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/JexlNode.java?rev=1147705&r1=1147704&r2=1147705&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/JexlNode.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/JexlNode.java Sun Jul 17 19:56:53 2011 @@ -16,6 +16,7 @@ */ package org.apache.commons.jexl2.parser; +import org.apache.commons.jexl2.DebugInfo; import org.apache.commons.jexl2.JexlInfo; /** @@ -42,11 +43,11 @@ public abstract class JexlNode extends S super(p, id); } - public JexlInfo getInfo() { + public DebugInfo getInfo() { JexlNode node = this; while (node != null) { - if (node.value instanceof JexlInfo) { - return (JexlInfo) node.value; + if (node.value instanceof DebugInfo) { + return (DebugInfo) node.value; } node = node.jjtGetParent(); } @@ -55,9 +56,10 @@ public abstract class JexlNode extends S /** {@inheritDoc} */ public String debugString() { - JexlInfo info = getInfo(); + DebugInfo info = getInfo(); return info != null? info.debugString() : ""; } + /** * Whether this node is a constant node