Logo Search packages:      
Sourcecode: velocity version File versions  Download package

NodeViewMode.java

package org.apache.velocity.runtime.visitor;

/*
 * Copyright 2001,2004 The Apache Software Foundation.
 * 
 * Licensed 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.runtime.parser.Token;
import org.apache.velocity.runtime.parser.node.*;

/**
 * This class is simply a visitor implementation
 * that traverses the AST, produced by the Velocity
 * parsing process, and creates a visual structure
 * of the AST. This is primarily used for
 * debugging, but it useful for documentation
 * as well.
 *
 * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
 * @version $Id: NodeViewMode.java,v 1.6.4.1 2004/03/03 23:23:03 geirm Exp $
 */
00033 public class NodeViewMode extends BaseVisitor
{
    private int indent = 0;
    private boolean showTokens = true;

    /** Indent child nodes to help visually identify
      *  the structure of the AST.
      */
00041     private String indentString()
    {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < indent; ++i)
        {
            sb.append("  ");
        }
        return sb.toString();
    }

    /**
      * Display the type of nodes and optionally the
      * first token.
      */
00055     private Object showNode(Node node, Object data)
    {
        String tokens = "";
        String special = "";
        Token t;
        
        if (showTokens)
        {
            t = node.getFirstToken();
            
            if (t.specialToken != null && ! t.specialToken.image.startsWith("##"))
                special = t.specialToken.image;
            
            tokens = " -> " + special + t.image;
        }            
        
        System.out.println(indentString() + node + tokens);
        ++indent;
        data = node.childrenAccept(this, data);
        --indent;
        return data;
    }

    /** Display a SimpleNode */
00079     public Object visit(SimpleNode node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTprocess node */
00085     public Object visit(ASTprocess node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTExpression node */
00091     public Object visit(ASTExpression node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTAssignment node ( = ) */
00097     public Object visit(ASTAssignment node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTOrNode ( || ) */
00103     public Object visit(ASTOrNode node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTAndNode ( && ) */
00109     public Object visit(ASTAndNode node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTEQNode ( == ) */
00115     public Object visit(ASTEQNode node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTNENode ( != ) */
00121     public Object visit(ASTNENode node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTLTNode ( < ) */
00127     public Object visit(ASTLTNode node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTGTNode ( > ) */
00133     public Object visit(ASTGTNode node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTLENode ( <= ) */
00139     public Object visit(ASTLENode node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTGENode ( >= ) */
00145     public Object visit(ASTGENode node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTAddNode ( + ) */
00151     public Object visit(ASTAddNode node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTSubtractNode ( - ) */
00157     public Object visit(ASTSubtractNode node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTMulNode ( * ) */
00163     public Object visit(ASTMulNode node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTDivNode ( / ) */
00169     public Object visit(ASTDivNode node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTModNode ( % ) */
00175     public Object visit(ASTModNode node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTNotNode ( ! ) */
00181     public Object visit(ASTNotNode node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTNumberLiteral node  */
00187     public Object visit(ASTNumberLiteral node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTStringLiteral node */
00193     public Object visit(ASTStringLiteral node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTIdentifier node */
00199     public Object visit(ASTIdentifier node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTMethod node */
00205     public Object visit(ASTMethod node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTReference node */
00211     public Object visit(ASTReference node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTTrue node */
00217     public Object visit(ASTTrue node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTFalse node */
00223     public Object visit(ASTFalse node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTBlock node */
00229     public Object visit(ASTBlock node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTText node */
00235     public Object visit(ASTText node, Object data)
    { 
        return showNode(node,data); 
    }
    
    /** Display an ASTIfStatement node */
00241     public Object visit(ASTIfStatement node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTElseStatement node */
00247     public Object visit(ASTElseStatement node, Object data)
    { 
        return showNode(node,data);
    }
    
    /** Display an ASTElseIfStatement node */
00253     public Object visit(ASTElseIfStatement node, Object data)
    { 
        return showNode(node,data);
    }
    
    public Object visit(ASTObjectArray node, Object data)
    { 
        return showNode(node,data);
    }

    public Object visit(ASTDirective node, Object data)
    { 
        return showNode(node,data);
    }

    public Object visit(ASTWord node, Object data)
    { 
        return showNode(node,data);
    }
    
    public Object visit(ASTSetDirective node, Object data)
    { 
        return showNode(node,data);
    }
}

Generated by  Doxygen 1.6.0   Back to index