velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r720228 - in /velocity/engine/trunk: src/changes/ src/java/org/apache/velocity/runtime/log/ src/java/org/apache/velocity/runtime/parser/ src/java/org/apache/velocity/runtime/parser/node/ src/parser/ src/test/org/apache/velocity/test/ src/te...
Date Mon, 24 Nov 2008 16:58:34 GMT
Author: nbubna
Date: Mon Nov 24 08:58:33 2008
New Revision: 720228

URL: http://svn.apache.org/viewvc?rev=720228&view=rev
Log:
VELOCITY-644 keep template name in Node for when a ref causes an exception in a macro from
a different template, also have strict ref mode throw VelocityException instead of MIE (thanks
to Byron Foster)

Added:
    velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity644TestCase.java
    velocity/engine/trunk/test/templates/testCase644.vm
Modified:
    velocity/engine/trunk/src/changes/changes.xml
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/Log.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTGENode.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTGTNode.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTLENode.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTLTNode.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/Node.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
    velocity/engine/trunk/src/parser/Parser.jjt
    velocity/engine/trunk/src/test/org/apache/velocity/test/BaseEvalTestCase.java
    velocity/engine/trunk/src/test/org/apache/velocity/test/StrictReferenceTestCase.java

Modified: velocity/engine/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/changes/changes.xml?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/changes/changes.xml (original)
+++ velocity/engine/trunk/src/changes/changes.xml Mon Nov 24 08:58:33 2008
@@ -27,6 +27,11 @@
   <body>
     <release version="1.6" date="In Subversion">
 
+      <action type="fix" dev="nbubna" issue="VELOCITY-644" due-to="Byron Foster">
+          Track template name in Node, to get proper template name in the exception
+          message when a reference in a macro causes that exception.
+      </action>
+
       <action type="fix" dev="nbubna" issue="VELOCITY-352" due-to="Gonzalo Diethelm, Joni
Salonen">
           Update Finnish and Spanish User Guide sections on division operation.
       </action>

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/Log.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/Log.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/Log.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/Log.java Mon Nov 24 08:58:33
2008
@@ -1,5 +1,6 @@
 package org.apache.velocity.runtime.log;
 
+import org.apache.velocity.runtime.parser.node.Node;
 import org.apache.velocity.util.introspection.Info;
 
 /*
@@ -225,7 +226,17 @@
     }
     
     /**
-     * Simply creates a string that formats the template filename allowing with line number
+     * Creates a string that formats the template filename with line number
+     * and column of the given Node. We use this routine to provide a cosistent format for
displaying 
+     * file errors.
+     */
+    public static final String formatFileString(Node node)
+    {
+      return formatFileString(node.getTemplateName(), node.getLine(), node.getColumn());
     
+    }
+    
+    /**
+     * Simply creates a string that formats the template filename with line number
      * and column. We use this routine to provide a cosistent format for displaying 
      * file errors.
      */
@@ -235,7 +246,7 @@
     }
     
     /**
-     * Simply creates a string that formats the template filename allowing with line number
+     * Simply creates a string that formats the template filename with line number
      * and column. We use this routine to provide a cosistent format for displaying 
      * file errors.
      * @param template File name of template, can be null

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java Mon Nov
24 08:58:33 2008
@@ -34,7 +34,7 @@
     /**
      *  Name of current template we are parsing.  Passed to us in parse()
      */
-    String currentTemplateName = "";
+    public String currentTemplateName = "";
 
     VelocityCharStream velcharstream = null;
 

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
Mon Nov 24 08:58:33 2008
@@ -130,8 +130,7 @@
                 /**
                  * Create a new RuntimeMacro
                  */
-                directive = new RuntimeMacro(directiveName,
-                        context.getCurrentTemplateName());
+                directive = new RuntimeMacro(directiveName, getTemplateName());
                 directive.setLocation( getLine(), getColumn() );
         
                 /**

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTGENode.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTGENode.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTGENode.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTGENode.java
Mon Nov 24 08:58:33 2008
@@ -21,6 +21,7 @@
 
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.runtime.log.Log;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.util.TemplateNumber;
 
@@ -88,9 +89,7 @@
                            + jjtGetChild( (left == null? 0 : 1) ).literal()
                            + ") of '>=' operation has null value."
                            + " Operation not possible. "
-                           + context.getCurrentTemplateName() + " [line "
-                           + getLine()
-                           + ", column " + getColumn() + "]");
+                           + Log.formatFileString(this));
             return false;
         }
 
@@ -115,8 +114,7 @@
         {
             log.error((!(left instanceof Number) ? "Left" : "Right")
                            + " side of '>=' operation is not a Number. "
-                           +  context.getCurrentTemplateName() + " [line " + getLine()
-                           + ", column " + getColumn() + "]");
+                           + Log.formatFileString(this));
 
             return false;
         }

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTGTNode.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTGTNode.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTGTNode.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTGTNode.java
Mon Nov 24 08:58:33 2008
@@ -21,6 +21,7 @@
 
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.runtime.log.Log;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.util.TemplateNumber;
 
@@ -88,9 +89,7 @@
                            + jjtGetChild( (left == null? 0 : 1) ).literal()
                            + ") of '>' operation has null value."
                            + " Operation not possible. "
-                           + context.getCurrentTemplateName() + " [line "
-                           + getLine()
-                           + ", column " + getColumn() + "]");
+                           + Log.formatFileString(this));
             return false;
         }
 
@@ -114,8 +113,7 @@
         {
             log.error((!(left instanceof Number) ? "Left" : "Right")
                            + " side of '>=' operation is not a Numbere. "
-                           +  context.getCurrentTemplateName() + " [line " + getLine()
-                           + ", column " + getColumn() + "]");
+                           + Log.formatFileString(this));
 
             return false;
         }

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
Mon Nov 24 08:58:33 2008
@@ -103,8 +103,7 @@
 
         identifier = getFirstToken().image;
 
-        uberInfo = new Info(context.getCurrentTemplateName(),
-                getLine(), getColumn());
+        uberInfo = new Info(getTemplateName(), getLine(), getColumn());
 
         strictRef = rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false);
         
@@ -226,7 +225,7 @@
                       + " in  " + o.getClass()
                       + " threw exception "
                       + ite.getTargetException().toString(),
-                      ite.getTargetException(), vg.getMethodName(), context.getCurrentTemplateName(),
this.getLine(), this.getColumn());
+                      ite.getTargetException(), vg.getMethodName(), getTemplateName(), this.getLine(),
this.getColumn());
                 }
             }
             else
@@ -240,7 +239,7 @@
                 + " in  " + o.getClass()
                 + " threw exception "
                 + ite.getTargetException().toString(),
-                ite.getTargetException(), vg.getMethodName(), context.getCurrentTemplateName(),
this.getLine(), this.getColumn());
+                ite.getTargetException(), vg.getMethodName(), getTemplateName(), this.getLine(),
this.getColumn());
 
 
             }

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java
Mon Nov 24 08:58:33 2008
@@ -24,6 +24,7 @@
 
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.runtime.log.Log;
 import org.apache.velocity.runtime.parser.Parser;
 
 /**
@@ -88,8 +89,7 @@
             log.error((left == null ? "Left" : "Right")
                            + " side of range operator [n..m] has null value."
                            + " Operation not possible. "
-                           +  context.getCurrentTemplateName() + " [line " + getLine()
-                           + ", column " + getColumn() + "]");
+                           + Log.formatFileString(this));
             return null;
         }
 
@@ -102,9 +102,7 @@
             log.error((!(left instanceof Number) ? "Left" : "Right")
                            + " side of range operator is not a valid type. "
                            + "Currently only integers (1,2,3...) and the Number type are
supported. "
-                           + context.getCurrentTemplateName() + " [line " + getLine()
-                           + ", column " + getColumn() + ']');
-
+                           + Log.formatFileString(this));
             return null;
         }
 

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTLENode.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTLENode.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTLENode.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTLENode.java
Mon Nov 24 08:58:33 2008
@@ -21,6 +21,7 @@
 
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.runtime.log.Log;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.util.TemplateNumber;
 
@@ -88,9 +89,7 @@
                            + jjtGetChild( (left == null? 0 : 1) ).literal()
                            + ") of '<=' operation has null value."
                            + " Operation not possible. "
-                           + context.getCurrentTemplateName() + " [line "
-                           + getLine()
-                           + ", column " + getColumn() + "]");
+                           + Log.formatFileString(this));
             return false;
         }
 
@@ -113,8 +112,7 @@
         {
             log.error((!(left instanceof Number) ? "Left" : "Right")
                            + " side of '>=' operation is not a Number. "
-                           +  context.getCurrentTemplateName() + " [line " + getLine()
-                           + ", column " + getColumn() + "]");
+                           + Log.formatFileString(this));
 
             return false;
         }

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTLTNode.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTLTNode.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTLTNode.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTLTNode.java
Mon Nov 24 08:58:33 2008
@@ -21,6 +21,7 @@
 
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.runtime.log.Log;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.util.TemplateNumber;
 
@@ -88,9 +89,7 @@
                            + jjtGetChild( (left == null? 0 : 1) ).literal()
                            + ") of '<' operation has null value."
                            + " Operation not possible. "
-                           + context.getCurrentTemplateName() + " [line "
-                           + getLine()
-                           + ", column " + getColumn() + "]");
+                           + Log.formatFileString(this));
             return false;
         }
 
@@ -114,8 +113,7 @@
         {
             log.error((!(left instanceof Number) ? "Left" : "Right")
                            + " side of '>=' operation is not a valid Number. "
-                           +  context.getCurrentTemplateName() + " [line " + getLine()
-                           + ", column " + getColumn() + "]");
+                           + Log.formatFileString(this));
 
             return false;
         }

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
Mon Nov 24 08:58:33 2008
@@ -104,7 +104,7 @@
          * make an uberinfo - saves new's later on
          */
 
-        uberInfo = new Info(context.getCurrentTemplateName(),
+        uberInfo = new Info(getTemplateName(),
                 getLine(),getColumn());
         /*
          *  this is about all we can do
@@ -189,7 +189,7 @@
                  *  cache it
                  */
 
-                method = rsvc.getUberspect().getMethod(o, methodName, params, new Info(context.getCurrentTemplateName(),
getLine(), getColumn()));
+                method = rsvc.getUberspect().getMethod(o, methodName, params, new Info(getTemplateName(),
getLine(), getColumn()));
 
                 if ((method != null) && (o != null))
                 {
@@ -339,7 +339,7 @@
                     + methodName + "' in  " + o.getClass()
                     + " threw exception "
                     + e.toString(),
-                    e, methodName, context.getCurrentTemplateName(), this.getLine(), this.getColumn());
+                    e, methodName, getTemplateName(), this.getLine(), this.getColumn());
             }
         }
         else
@@ -353,7 +353,7 @@
             + methodName + "' in  " + o.getClass()
             + " threw exception "
             + t.toString(),
-            t, methodName, context.getCurrentTemplateName(), this.getLine(), this.getColumn());
+            t, methodName, getTemplateName(), this.getLine(), this.getColumn());
         }
     }
 

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
Mon Nov 24 08:58:33 2008
@@ -139,8 +139,7 @@
          * make an uberinfo - saves new's later on
          */
 
-        uberInfo = new Info(context.getCurrentTemplateName(),
-                getLine(),getColumn());
+        uberInfo = new Info(getTemplateName(), getLine(),getColumn());
 
         /*
          * track whether we log invalid references
@@ -183,18 +182,6 @@
     }
 
     /**
-     * Returns the template name, once init() has been called.
-     */
-    public String getTemplateName()
-    {
-        if (uberInfo == null)
-        {
-            return null;
-        }
-        return uberInfo.getTemplateName();
-    }
-
-    /**
      *  Returns the 'root string', the reference key
      * @return the root string.
      */
@@ -256,10 +243,10 @@
                      * to call a method or property on a null value.
                      */
                     String name = jjtGetChild(i).getFirstToken().image;
-                    throw new MethodInvocationException("Attempted to access '"  
-                        + name + "' on a null value", null, name, uberInfo.getTemplateName(),
-                        jjtGetChild(i).getLine(), jjtGetChild(i).getColumn());
-                  
+                    throw new VelocityException("Attempted to access '"  
+                        + name + "' on a null value at "
+                        + Log.formatFileString(uberInfo.getTemplateName(),
+                        + jjtGetChild(i).getLine(), jjtGetChild(i).getColumn()));       
          
                 }
                 previousResult = result;
                 result = jjtGetChild(i).execute(result,context);
@@ -320,8 +307,7 @@
 
             log.error("Method " + mie.getMethodName()
                       + " threw exception for reference $" + rootString + " in "
-                      + Log.formatFileString(context.getCurrentTemplateName(),
-                                             getLine(), getColumn()));
+                      + Log.formatFileString(this));
             mie.setReferenceName(rootString);
             throw mie;
         }
@@ -422,7 +408,7 @@
 
             if (logOnNull && referenceType != QUIET_REFERENCE && log.isDebugEnabled())
             {
-                log.debug("Null reference [template '" + context.getCurrentTemplateName()
+                log.debug("Null reference [template '" + getTemplateName()
                         + "', line " + this.getLine() + ", column " + this.getColumn() +
"] : "
                         + this.literal() + " cannot be resolved.");
             }
@@ -609,7 +595,7 @@
                 + identifier + "' in  " + result.getClass()
                 + " threw exception "
                 + ite.getTargetException().toString(),
-               ite.getTargetException(), identifier, context.getCurrentTemplateName(), this.getLine(),
this.getColumn());
+               ite.getTargetException(), identifier, getTemplateName(), this.getLine(), this.getColumn());
         }
         /**
          * pass through application level runtime exceptions

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
Mon Nov 24 08:58:33 2008
@@ -27,6 +27,7 @@
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.log.Log;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.util.introspection.Info;
 
@@ -101,7 +102,7 @@
     
             super.init( context, data );
     
-            uberInfo = new Info(context.getCurrentTemplateName(),
+            uberInfo = new Info(getTemplateName(),
                     getLine(), getColumn());
     
             right = getRightHandSide();
@@ -159,8 +160,7 @@
                     if (doit && rsvc.getLog().isDebugEnabled())
                     {
                         rsvc.getLog().debug("RHS of #set statement is null. Context will
not be modified. "
-                                      + context.getCurrentTemplateName() + " [line " + getLine()
-                                      + ", column " + getColumn() + "]");
+                                      + Log.formatFileString(this));
                     }
                 }
                 

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/Node.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/Node.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/Node.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/Node.java Mon Nov
24 08:58:33 2008
@@ -199,4 +199,9 @@
      * @return The current column position.
      */
     public int getColumn();
+    
+    /**
+     * @return the file name of the template
+     */
+    public String getTemplateName();
 }

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/SimpleNode.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
Mon Nov 24 08:58:33 2008
@@ -55,6 +55,7 @@
     protected int id;
 
     /** */
+    // TODO - It seems that this field is only valid when parsing, and should not be kept
around.    
     protected Parser parser;
 
     /** */
@@ -71,6 +72,9 @@
 
     /** */
     protected Token last;
+    
+    
+    protected String templateName;
 
     /**
      * @param i
@@ -88,6 +92,7 @@
     {
         this(i);
         parser = p;
+        templateName = parser.currentTemplateName;
     }
 
     /**
@@ -251,10 +256,7 @@
      */
     protected String getLocation(InternalContextAdapter context)
     {
-        return new StrBuilder(50)
-            .append(context.getCurrentTemplateName())
-            .append(" [line ").append(getLine())
-            .append(", column ").append(getColumn()).append("]").toString();
+        return Log.formatFileString(this);
     }
 
     // All additional methods
@@ -433,5 +435,10 @@
             .append("tokens", tokens)
             .toString();
     }
+
+    public String getTemplateName()
+    {
+      return templateName;
+    }
 }
 

Modified: velocity/engine/trunk/src/parser/Parser.jjt
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/parser/Parser.jjt?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/parser/Parser.jjt (original)
+++ velocity/engine/trunk/src/parser/Parser.jjt Mon Nov 24 08:58:33 2008
@@ -111,7 +111,7 @@
     /**
      *  Name of current template we are parsing.  Passed to us in parse()
      */
-    String currentTemplateName = "";
+    public String currentTemplateName = "";
 
     VelocityCharStream velcharstream = null;
 

Modified: velocity/engine/trunk/src/test/org/apache/velocity/test/BaseEvalTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/BaseEvalTestCase.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/BaseEvalTestCase.java (original)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/BaseEvalTestCase.java Mon Nov
24 08:58:33 2008
@@ -138,9 +138,10 @@
         return null;
     }
 
-    protected Exception assertEvalExceptionAt(String evil, int line, int col)
+    protected Exception assertEvalExceptionAt(String evil, String template,
+                                              int line, int col)
     {
-        String loc = "[line "+line+", column "+col+"]";
+        String loc = template+"[line "+line+", column "+col+"]";
         if (DEBUG)
         {
             engine.getLog().info("Expectation: Exception at "+loc);
@@ -157,6 +158,11 @@
         return e;
     }
 
+    protected Exception assertEvalExceptionAt(String evil, int line, int col)
+    {
+         return assertEvalExceptionAt(evil, "", line, col);
+    }
+
     protected String evaluate(String template)
     {
         StringWriter writer = new StringWriter();

Modified: velocity/engine/trunk/src/test/org/apache/velocity/test/StrictReferenceTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/StrictReferenceTestCase.java?rev=720228&r1=720227&r2=720228&view=diff
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/StrictReferenceTestCase.java (original)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/StrictReferenceTestCase.java Mon
Nov 24 08:58:33 2008
@@ -1,6 +1,7 @@
 package org.apache.velocity.test;
 
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.VelocityException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.runtime.RuntimeConstants;
 
@@ -121,17 +122,17 @@
         fargo.next = new Fargo();
         context.put("fargo", fargo);
 
-        assertMethodEx("$NULL.bogus");
-        assertMethodEx("$fargo.nullVal.bogus");
-        assertMethodEx("$fargo.next.nullVal.bogus");
-        assertMethodEx("#if (\"junk\" == $fargo.nullVal.bogus)#end");
-        assertMethodEx("#if ($fargo.nullVal.bogus > 2)#end");
-        assertMethodEx("#set($fargo.next.nullVal.bogus = \"junk\")");
-        assertMethodEx("#set($foo = $NULL.bogus)");
-        assertMethodEx("#foreach($item in $fargo.next.nullVal.bogus)#end");
+        assertVelocityEx("$NULL.bogus");
+        assertVelocityEx("$fargo.nullVal.bogus");
+        assertVelocityEx("$fargo.next.nullVal.bogus");
+        assertVelocityEx("#if (\"junk\" == $fargo.nullVal.bogus)#end");
+        assertVelocityEx("#if ($fargo.nullVal.bogus > 2)#end");
+        assertVelocityEx("#set($fargo.next.nullVal.bogus = \"junk\")");
+        assertVelocityEx("#set($foo = $NULL.bogus)");
+        assertVelocityEx("#foreach($item in $fargo.next.nullVal.bogus)#end");
 
         evaluate("$fargo.prop.toString()");
-        assertMethodEx("#set($fargo.prop = $NULL)$fargo.prop.next");
+        assertVelocityEx("#set($fargo.prop = $NULL)$fargo.prop.next");
 
         // make sure no exceptions are thrown here
         evaluate("$fargo.next.next");
@@ -166,6 +167,14 @@
     }
 
     /**
+     * Assert that we get a VelocityException when calling evaluate
+     */
+    public void assertVelocityEx(String template)
+    {
+        assertEvalException(template, VelocityException.class);
+    }
+
+    /**
      * Assert that we get a MethodInvocationException when calling evaluate
      */
     public void assertParseEx(String template)

Added: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity644TestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity644TestCase.java?rev=720228&view=auto
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity644TestCase.java
(added)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity644TestCase.java
Mon Nov 24 08:58:33 2008
@@ -0,0 +1,57 @@
+package org.apache.velocity.test.issues;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.    
+ */
+
+import org.apache.velocity.test.BaseEvalTestCase;
+import org.apache.velocity.runtime.RuntimeConstants;
+
+/**
+ * This class tests VELOCITY-644.  Make sure the reported filename
+ * is correct in exceptions when an error occurs in another template file.
+ */
+public class Velocity644TestCase extends BaseEvalTestCase
+{
+    public Velocity644TestCase(String name)
+    {
+        super(name);
+    }
+  
+    public void setUp() throws Exception
+    {
+        super.setUp();
+        engine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, "test/templates/");
+        engine.setProperty(RuntimeConstants.VM_LIBRARY, "testCase644.vm");
+        engine.setProperty(RuntimeConstants.RUNTIME_REFERENCES_STRICT, Boolean.TRUE);
+        engine.setProperty(RuntimeConstants.SKIP_INVALID_ITERATOR, Boolean.FALSE);
+        context.put("NULL", null);
+    }
+
+    public void test629()
+    {
+        // Calling a null method
+        assertEvalExceptionAt("#nullMethod()", "testCase644.vm", 9, 8);
+        // An invalid array
+        assertEvalExceptionAt("#arrayError()", "testCase644.vm", 4, 8);
+        // An invalid reference
+        assertEvalExceptionAt("#badRef()", "testCase644.vm", 13, 3);
+        // Non iterable object
+        assertEvalExceptionAt("#forloop()", "testCase644.vm", 18, 18);
+    }
+}

Added: velocity/engine/trunk/test/templates/testCase644.vm
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/test/templates/testCase644.vm?rev=720228&view=auto
==============================================================================
--- velocity/engine/trunk/test/templates/testCase644.vm (added)
+++ velocity/engine/trunk/test/templates/testCase644.vm Mon Nov 24 08:58:33 2008
@@ -0,0 +1,20 @@
+
+#macro(arrayError)
+  #set($foo = [])
+  $foo.get(2)
+#end
+
+#macro(nullMethod)
+  #set($foo = $NULL)
+  $foo.bar
+#end
+
+#macro(badRef)
+  $bar
+#end
+
+#macro(forloop)
+  #set($val = 1)
+  #foreach($i in $val)
+  #end
+#end



Mime
View raw message