commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
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 GMT
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



Mime
View raw message