Author: byron
Date: Sun Jan 11 03:22:15 2009
New Revision: 733452

URL: http://svn.apache.org/viewvc?rev=733452&view=rev
Log:
Create argument error message for macros only if we need it

Modified:
    
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java

Modified: 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java?rev=733452&r1=733451&r2=733452&view=diff
==============================================================================
--- 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
 (original)
+++ 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
 Sun Jan 11 03:22:15 2009
@@ -244,6 +244,19 @@
         maxCallDepth = rsvc.getInt(RuntimeConstants.VM_MAX_DEPTH);
     }
     
+
+    /**
+     * Build an error message for not providing the correct number of arguments
+     */
+    private String buildErrorMsg(Node node)
+    {
+      int i = node.jjtGetNumChildren();  // the number of arguments this call 
provided
+      String msg = "VM #" + macroName + ": too "
+        + ((getNumArgs() > i) ? "few" : "many") + " arguments to macro. Wanted 
"
+        + getNumArgs() + " got " + i;      
+      return msg;
+    }
+    
     /**
      * check if we are calling this macro with the right number of arguments.  
If 
      * we are not, and strictArguments is active, then throw 
TemplateInitException.
@@ -251,26 +264,23 @@
      */
     public void checkArgs(InternalContextAdapter context, Node node)
     {
-        // check how many arguments we got
+        // check how many arguments we have
         int i = node.jjtGetNumChildren();
 
         // Throw exception for invalid number of arguments?
         if (getNumArgs() != i)
         {
-            String msg = "VM #" + macroName + ": too "
-                    + ((getNumArgs() > i) ? "few" : "many") + " arguments to 
macro. Wanted "
-                    + getNumArgs() + " got " + i;
-
             if (strictArguments)
             {
                 /**
                  * indicate col/line assuming it starts at 0 - this will be 
corrected one call up
                  */
-                throw new TemplateInitException(msg, 
context.getCurrentTemplateName(), 0, 0);
+                throw new TemplateInitException(buildErrorMsg(node), 
+                    context.getCurrentTemplateName(), 0, 0);
             }
-            else
+            else if (rsvc.getLog().isDebugEnabled())
             {
-                rsvc.getLog().debug(msg);
+                rsvc.getLog().debug(buildErrorMsg(node));
                 return;
             }
         }


Reply via email to