You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by he...@apache.org on 2005/10/29 21:11:33 UTC

svn commit: r329469 - in /jakarta/velocity/core/trunk/src: java/org/apache/velocity/exception/ java/org/apache/velocity/runtime/directive/ java/org/apache/velocity/runtime/parser/ parser/

Author: henning
Date: Sat Oct 29 12:11:10 2005
New Revision: 329469

URL: http://svn.apache.org/viewcvs?rev=329469&view=rev
Log:
MacroParseException is some sort of relative to
TemplateParseException. Find a common Interface
(ExtendedParseException) which allows the ParseErrorException to deal
with template name, line number and colum number from both exceptions
in an uniform way.

Update the parser and the MacroParseException to always have full
information to report (don't put it just in the message, give it to
the ParseErrorException).


Modified:
    jakarta/velocity/core/trunk/src/java/org/apache/velocity/exception/ParseErrorException.java
    jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java
    jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/MacroParseException.java
    jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java
    jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj
    jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/TemplateParseException.java
    jakarta/velocity/core/trunk/src/parser/Parser.jjt

Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/exception/ParseErrorException.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/exception/ParseErrorException.java?rev=329469&r1=329468&r2=329469&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/exception/ParseErrorException.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/exception/ParseErrorException.java Sat Oct 29 12:11:10 2005
@@ -28,6 +28,7 @@
  *  information, consult the runtime log.
  *
  * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
  * @version $Id$
  */
 public class ParseErrorException extends VelocityException
@@ -35,7 +36,7 @@
     /**
      * Version Id for serializable
      */
-    private static final long serialVersionUID = -6665197935086306474L;
+    private static final long serialVersionUID = -6665197935086306473L;
 
     /**
      * The column number of the parsing error, or -1 if not defined.
@@ -73,13 +74,13 @@
 
         // Don't use a second C'tor, TemplateParseException is a subclass of
         // ParseException...
-        if (pex instanceof TemplateParseException)
+        if (pex instanceof ExtendedParseException)
         {
-            TemplateParseException tpex = (TemplateParseException) pex;
+            ExtendedParseException xpex = (ExtendedParseException) pex;
 
-            columnNumber = tpex.getColumnNumber();
-            lineNumber = tpex.getLineNumber();
-            templateName = tpex.getTemplateName();
+            columnNumber = xpex.getColumnNumber();
+            lineNumber = xpex.getLineNumber();
+            templateName = xpex.getTemplateName();
         }
         else
         {

Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java?rev=329469&r1=329468&r2=329469&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java Sat Oct 29 12:11:10 2005
@@ -48,6 +48,7 @@
  *  macro.  It is used inline in the parser when processing a directive.
  *
  * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
  * @version $Id$
  */
 public class Macro extends Directive
@@ -110,7 +111,7 @@
      *  objects, and if not currently used, adds it to the macro
      *  Factory.
      */ 
-    public static void processAndRegister(RuntimeServices rs,  Node node,
+    public static void processAndRegister(RuntimeServices rs,  Token t, Node node,
                                           String sourceTemplate)
         throws IOException, ParseException
     {
@@ -139,7 +140,7 @@
                               "argument to #macro(). #args = " + numArgs);
 
             throw new MacroParseException("First argument to #macro() must be " +
-                    " macro name.");
+                    " macro name.", sourceTemplate, t);
         }
 
         /*
@@ -153,7 +154,7 @@
             throw new MacroParseException("First argument to #macro() must be a"
                     + " token without surrounding \' or \", which specifies"
                     + " the macro name.  Currently it is a "
-                    + ParserTreeConstants.jjtNodeName[firstType]);
+                    + ParserTreeConstants.jjtNodeName[firstType], sourceTemplate, t);
         }
 
         /*

Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/MacroParseException.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/MacroParseException.java?rev=329469&r1=329468&r2=329469&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/MacroParseException.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/MacroParseException.java Sat Oct 29 12:11:10 2005
@@ -16,7 +16,9 @@
  * limitations under the License.
  */
 
+import org.apache.velocity.exception.ExtendedParseException;
 import org.apache.velocity.runtime.parser.ParseException;
+import org.apache.velocity.runtime.parser.Token;
 
 /**
  *  Exception to indicate problem happened while constructing #macro()
@@ -24,17 +26,62 @@
  *  For internal use in parser - not to be passed to app level
  *
  * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
+ * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
  * @version $Id$
  */
-public class MacroParseException extends ParseException
+public class MacroParseException
+        extends ParseException
+        implements ExtendedParseException
 {
+    private final String templateName;
+
     /**
      * Version Id for serializable
      */
-    private static final long serialVersionUID = -4985224672336070691L;
+    private static final long serialVersionUID = -4985224672336070690L;
 
-    public MacroParseException(String msg)
+    public MacroParseException(final String msg, final String templateName, final Token currentToken)
     {
         super(msg);
+        this.currentToken = currentToken;
+        this.templateName = templateName;
+    }
+
+    /**
+     * returns the Template name where this exception occured.
+     */
+    public String getTemplateName()
+    {
+        return templateName;
+    }
+
+    /**
+     * returns the line number where this exception occured.
+     */
+    public int getLineNumber()
+    {
+        if ((currentToken != null) && (currentToken.next != null))
+        {
+            return currentToken.next.beginLine;
+        }
+        else
+        {
+            return -1;
+        }
+    }
+
+    /**
+     * returns the column number where this exception occured.
+     */
+    public int getColumnNumber()
+    {
+        if ((currentToken != null) && (currentToken.next != null))
+        {
+            return currentToken.next.beginColumn;
+        }
+        else
+        {
+            return -1;
+        }
     }
 }

Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java?rev=329469&r1=329468&r2=329469&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java Sat Oct 29 12:11:10 2005
@@ -22,6 +22,7 @@
  *
  * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
  * @version $Id$
 */
 public class Parser/*@bgen(jjtree)*/implements ParserTreeConstants, ParserConstants {/*@bgen(jjtree)*/
@@ -110,7 +111,7 @@
              *  Macro specification
              */
             rsvc.getLog().error("Parser Error: #macro() : " + templateName, mee);
-            throw new ParseException(mee.getMessage());
+            throw mee;
         }
         catch (ParseException pe)
         {
@@ -742,10 +743,7 @@
                         {if (true) throw new MacroParseException("Invalid arg #"
                             + argPos + " in "
                             + (isVM ? "VM " : "directive " )
-                            + t.image
-                            + " at line " + t.beginLine + ", column "
-                            + t.beginColumn
-                            + " in template " + currentTemplateName);}
+                            + t.image, currentTemplateName, t);}
                     }
                 }
                 else
@@ -757,9 +755,7 @@
                         {if (true) throw new MacroParseException("Invalid first arg "
                             + " in #macro() directive - must be a"
                             + " word token (no \' or \" surrounding)"
-                            + " at line " + t.beginLine + ", column "
-                            + t.beginColumn
-                            + " in template " + currentTemplateName);}
+                            + " at line " + t.beginLine + ", column ", currentTemplateName, t);}
                     }
                 }
 
@@ -846,7 +842,7 @@
 
         if (doItNow)
         {
-            Macro.processAndRegister(rsvc, jjtn000, currentTemplateName);
+            Macro.processAndRegister(rsvc, t, jjtn000, currentTemplateName);
         }
 
         /*
@@ -2513,6 +2509,17 @@
     finally { jj_save(11, xla); }
   }
 
+  final private boolean jj_3R_81() {
+    if (jj_scan_token(COMMA)) return true;
+    if (jj_3R_24()) return true;
+    return false;
+  }
+
+  final private boolean jj_3_8() {
+    if (jj_3R_28()) return true;
+    return false;
+  }
+
   final private boolean jj_3R_25() {
     if (jj_3R_20()) return true;
     return false;
@@ -2588,6 +2595,11 @@
     return false;
   }
 
+  final private boolean jj_3_2() {
+    if (jj_scan_token(DOUBLE_ESCAPE)) return true;
+    return false;
+  }
+
   final private boolean jj_3R_33() {
     if (jj_scan_token(IDENTIFIER)) return true;
     Token xsp;
@@ -2623,11 +2635,6 @@
     return false;
   }
 
-  final private boolean jj_3_2() {
-    if (jj_scan_token(DOUBLE_ESCAPE)) return true;
-    return false;
-  }
-
   final private boolean jj_3R_77() {
     if (jj_3R_63()) return true;
     return false;
@@ -2807,6 +2814,11 @@
     return false;
   }
 
+  final private boolean jj_3R_22() {
+    if (jj_3R_35()) return true;
+    return false;
+  }
+
   final private boolean jj_3R_68() {
     if (jj_3R_35()) return true;
     return false;
@@ -2853,12 +2865,12 @@
     return false;
   }
 
-  final private boolean jj_3R_22() {
-    if (jj_3R_35()) return true;
+  final private boolean jj_3R_82() {
+    if (jj_3R_20()) return true;
     return false;
   }
 
-  final private boolean jj_3R_82() {
+  final private boolean jj_3R_21() {
     if (jj_3R_20()) return true;
     return false;
   }
@@ -2878,6 +2890,11 @@
     return false;
   }
 
+  final private boolean jj_3_1() {
+    if (jj_3R_20()) return true;
+    return false;
+  }
+
   final private boolean jj_3R_60() {
     if (jj_scan_token(LBRACKET)) return true;
     Token xsp;
@@ -2904,16 +2921,6 @@
     return false;
   }
 
-  final private boolean jj_3R_21() {
-    if (jj_3R_20()) return true;
-    return false;
-  }
-
-  final private boolean jj_3_1() {
-    if (jj_3R_20()) return true;
-    return false;
-  }
-
   final private boolean jj_3R_63() {
     if (jj_scan_token(LBRACKET)) return true;
     Token xsp;
@@ -2930,6 +2937,11 @@
     return false;
   }
 
+  final private boolean jj_3R_45() {
+    if (jj_3R_65()) return true;
+    return false;
+  }
+
   final private boolean jj_3_5() {
     if (jj_3R_24()) return true;
     if (jj_scan_token(COLON)) return true;
@@ -2942,8 +2954,8 @@
     return false;
   }
 
-  final private boolean jj_3R_45() {
-    if (jj_3R_65()) return true;
+  final private boolean jj_3R_44() {
+    if (jj_3R_64()) return true;
     return false;
   }
 
@@ -2959,11 +2971,6 @@
     return false;
   }
 
-  final private boolean jj_3R_44() {
-    if (jj_3R_64()) return true;
-    return false;
-  }
-
   final private boolean jj_3_3() {
     if (jj_scan_token(LBRACKET)) return true;
     Token xsp;
@@ -3077,23 +3084,23 @@
     return false;
   }
 
-  final private boolean jj_3R_27() {
-    if (jj_3R_55()) return true;
+  final private boolean jj_3R_59() {
+    if (jj_scan_token(STRING_LITERAL)) return true;
     return false;
   }
 
-  final private boolean jj_3R_59() {
-    if (jj_scan_token(STRING_LITERAL)) return true;
+  final private boolean jj_3R_35() {
+    if (jj_scan_token(INTEGER_LITERAL)) return true;
     return false;
   }
 
-  final private boolean jj_3R_32() {
-    if (jj_3R_35()) return true;
+  final private boolean jj_3R_27() {
+    if (jj_3R_55()) return true;
     return false;
   }
 
-  final private boolean jj_3R_35() {
-    if (jj_scan_token(INTEGER_LITERAL)) return true;
+  final private boolean jj_3R_32() {
+    if (jj_3R_35()) return true;
     return false;
   }
 
@@ -3113,17 +3120,6 @@
   }
 
   final private boolean jj_3_10() {
-    if (jj_3R_28()) return true;
-    return false;
-  }
-
-  final private boolean jj_3R_81() {
-    if (jj_scan_token(COMMA)) return true;
-    if (jj_3R_24()) return true;
-    return false;
-  }
-
-  final private boolean jj_3_8() {
     if (jj_3R_28()) return true;
     return false;
   }

Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj?rev=329469&r1=329468&r2=329469&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj Sat Oct 29 12:11:10 2005
@@ -73,6 +73,7 @@
  *
  * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
  * @version $Id$
 */
 public class Parser/*@bgen(jjtree)*/implements ParserTreeConstants/*@egen*/
@@ -165,7 +166,7 @@
              *  Macro specification
              */
             rsvc.getLog().error("Parser Error: #macro() : " + templateName, mee);
-            throw new ParseException(mee.getMessage());
+            throw mee;
         }
         catch (ParseException pe)
         {
@@ -1505,10 +1506,7 @@
                         throw new MacroParseException("Invalid arg #"
                             + argPos + " in "
                             + (isVM ? "VM " : "directive " )
-                            + t.image
-                            + " at line " + t.beginLine + ", column "
-                            + t.beginColumn
-                            + " in template " + currentTemplateName);
+                            + t.image, currentTemplateName, t);
                     }
                 }
                 else
@@ -1520,9 +1518,7 @@
                         throw new MacroParseException("Invalid first arg "
                             + " in #macro() directive - must be a"
                             + " word token (no \' or \" surrounding)"
-                            + " at line " + t.beginLine + ", column "
-                            + t.beginColumn
-                            + " in template " + currentTemplateName);
+                            + " at line " + t.beginLine + ", column ", currentTemplateName, t);
                     }
                 }
 
@@ -1587,7 +1583,7 @@
 
         if (doItNow)
         {
-            Macro.processAndRegister(rsvc, jjtn000, currentTemplateName);
+            Macro.processAndRegister(rsvc, t, jjtn000, currentTemplateName);
         }
 
         /*

Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/TemplateParseException.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/TemplateParseException.java?rev=329469&r1=329468&r2=329469&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/TemplateParseException.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/TemplateParseException.java Sat Oct 29 12:11:10 2005
@@ -1,5 +1,7 @@
 package org.apache.velocity.runtime.parser;
 
+import org.apache.velocity.exception.ExtendedParseException;
+
 /*
  * Copyright 2000-2004 The Apache Software Foundation.
  *
@@ -22,9 +24,12 @@
  *
  * @see org.apache.velocity.runtime.parser.ParseException
  *
+ * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
+ * @version $Id$
  */
 public class TemplateParseException
         extends ParseException
+        implements ExtendedParseException
 {
     /**
      * This is the name of the template which contains the parsing error, or

Modified: jakarta/velocity/core/trunk/src/parser/Parser.jjt
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/parser/Parser.jjt?rev=329469&r1=329468&r2=329469&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/parser/Parser.jjt (original)
+++ jakarta/velocity/core/trunk/src/parser/Parser.jjt Sat Oct 29 12:11:10 2005
@@ -97,6 +97,7 @@
  *
  * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
  * @version $Id$
 */
 public class Parser
@@ -186,7 +187,7 @@
              *  Macro specification
              */
             rsvc.getLog().error("Parser Error: #macro() : " + templateName, mee);
-            throw new ParseException(mee.getMessage());
+            throw mee;
         }
         catch (ParseException pe)
         {
@@ -1383,10 +1384,7 @@
                         throw new MacroParseException("Invalid arg #"
                             + argPos + " in "
                             + (isVM ? "VM " : "directive " )
-                            + t.image
-                            + " at line " + t.beginLine + ", column "
-                            + t.beginColumn
-                            + " in template " + currentTemplateName);
+                            + t.image, currentTemplateName, t);
                     }
                 }
                 else
@@ -1398,9 +1396,7 @@
                         throw new MacroParseException("Invalid first arg "
                             + " in #macro() directive - must be a"
                             + " word token (no \' or \" surrounding)"
-                            + " at line " + t.beginLine + ", column "
-                            + t.beginColumn
-                            + " in template " + currentTemplateName);
+                            + " at line " + t.beginLine + ", column ", currentTemplateName, t);
                     }
                 }
 
@@ -1433,7 +1429,7 @@
 
         if (doItNow)
         {
-            Macro.processAndRegister(rsvc, jjtThis, currentTemplateName);
+            Macro.processAndRegister(rsvc, t, jjtThis, currentTemplateName);
         }
 
         /*



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org