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 2006/10/11 00:53:30 UTC
svn commit: r462627 -
/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
Author: henning
Date: Tue Oct 10 15:53:30 2006
New Revision: 462627
URL: http://svn.apache.org/viewvc?view=rev&rev=462627
Log:
Check whether the current macro test is not actually a macro invocation
but a reference inside another macro definition. If yes, do not report
an error about the size of the argument list but fail silently.
Fixes VELOCITY-71.
Modified:
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java?view=diff&rev=462627&r1=462626&r2=462627
==============================================================================
--- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java (original)
+++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java Tue Oct 10 15:53:30 2006
@@ -22,12 +22,14 @@
import java.io.Writer;
import java.util.HashMap;
+import org.apache.commons.lang.StringUtils;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.context.VMContext;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.parser.ParserTreeConstants;
import org.apache.velocity.runtime.parser.Token;
+import org.apache.velocity.runtime.parser.node.ASTDirective;
import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.runtime.parser.node.SimpleNode;
import org.apache.velocity.runtime.visitor.VMReferenceMungeVisitor;
@@ -243,6 +245,23 @@
if ( getNumArgs() != i )
{
+ // If we have a not-yet defined macro, we do get no arguments because
+ // the syntax tree looks different than with a already defined macro.
+ // But we do know that we must be in a macro definition context somewhere up the
+ // syntax tree.
+ // Check for that, if it is true, suppress the error message.
+ // Fixes VELOCITY-71.
+
+ for (Node parent = node.jjtGetParent(); parent != null; )
+ {
+ if ((parent instanceof ASTDirective) &&
+ StringUtils.equals(((ASTDirective) parent).getDirectiveName(), "macro"))
+ {
+ return;
+ }
+ parent = parent.jjtGetParent();
+ }
+
rsvc.getLog().error("VM #" + macroName + ": error : too " +
((getNumArgs() > i) ? "few" : "many") +
" arguments to macro. Wanted " + getNumArgs() +
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org