View Javadoc

    1   /***************************************************************************************
    2    * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved.                 *
    3    * http://aspectwerkz.codehaus.org                                                    *
    4    * ---------------------------------------------------------------------------------- *
    5    * The software in this package is published under the terms of the LGPL license      *
    6    * a copy of which has been included with this distribution in the license.txt file.  *
    7    **************************************************************************************/
    8   package org.codehaus.aspectwerkz.annotation.expression;
    9
    10  import org.codehaus.aspectwerkz.annotation.expression.ast.ASTAnnotation;
    11  import org.codehaus.aspectwerkz.annotation.expression.ast.ASTArray;
    12  import org.codehaus.aspectwerkz.annotation.expression.ast.ASTBoolean;
    13  import org.codehaus.aspectwerkz.annotation.expression.ast.ASTChar;
    14  import org.codehaus.aspectwerkz.annotation.expression.ast.ASTFloat;
    15  import org.codehaus.aspectwerkz.annotation.expression.ast.ASTHex;
    16  import org.codehaus.aspectwerkz.annotation.expression.ast.ASTIdentifier;
    17  import org.codehaus.aspectwerkz.annotation.expression.ast.ASTInteger;
    18  import org.codehaus.aspectwerkz.annotation.expression.ast.ASTKeyValuePair;
    19  import org.codehaus.aspectwerkz.annotation.expression.ast.ASTOct;
    20  import org.codehaus.aspectwerkz.annotation.expression.ast.ASTRoot;
    21  import org.codehaus.aspectwerkz.annotation.expression.ast.ASTString;
    22  import org.codehaus.aspectwerkz.annotation.expression.ast.AnnotationParserVisitor;
    23  import org.codehaus.aspectwerkz.annotation.expression.ast.SimpleNode;
    24
    25  /***
    26   * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
    27   */
    28  public class DumpVisitor implements AnnotationParserVisitor {
    29      private ASTRoot m_root;
    30
    31      private int indent = 0;
    32
    33      private DumpVisitor(final ASTRoot root) {
    34          m_root = root;
    35      }
    36
    37      public static void dumpAST(final ASTRoot root) {
    38          DumpVisitor dumper = new DumpVisitor(root);
    39          dumper.visit(dumper.m_root, null);
    40      }
    41
    42      public Object visit(SimpleNode node, Object data) {
    43          System.out.println(indentString() + node);
    44          ++indent;
    45          int nr = node.jjtGetNumChildren();
    46          for (int i = 0; i < nr; i++) {
    47              data = node.jjtGetChild(i).jjtAccept(this, data);
    48          }
    49          --indent;
    50          return data;
    51      }
    52
    53      public Object visit(ASTRoot node, Object data) {
    54          System.out.println(indentString() + node);
    55          ++indent;
    56          int nr = node.jjtGetNumChildren();
    57          for (int i = 0; i < nr; i++) {
    58              data = node.jjtGetChild(i).jjtAccept(this, data);
    59          }
    60          --indent;
    61          return data;
    62      }
    63
    64      public Object visit(ASTAnnotation node, Object data) {
    65          System.out.println(indentString() + node);
    66          ++indent;
    67          int nr = node.jjtGetNumChildren();
    68          for (int i = 0; i < nr; i++) {
    69              data = node.jjtGetChild(i).jjtAccept(this, data);
    70          }
    71          --indent;
    72          return data;
    73      }
    74
    75      public Object visit(ASTKeyValuePair node, Object data) {
    76          System.out.println(indentString() + node);
    77          ++indent;
    78          int nr = node.jjtGetNumChildren();
    79          for (int i = 0; i < nr; i++) {
    80              data = node.jjtGetChild(i).jjtAccept(this, data);
    81          }
    82          --indent;
    83          return data;
    84      }
    85
    86      public Object visit(ASTArray node, Object data) {
    87          System.out.println(indentString() + node);
    88          ++indent;
    89          int nr = node.jjtGetNumChildren();
    90          for (int i = 0; i < nr; i++) {
    91              data = node.jjtGetChild(i).jjtAccept(this, data);
    92          }
    93          --indent;
    94          return data;
    95      }
    96
    97      public Object visit(ASTIdentifier node, Object data) {
    98          System.out.println(indentString() + node);
    99          return data;
    100     }
    101
    102     public Object visit(ASTBoolean node, Object data) {
    103         System.out.println(indentString() + node);
    104         return data;
    105     }
    106
    107     public Object visit(ASTChar node, Object data) {
    108         System.out.println(indentString() + node);
    109         return data;
    110     }
    111
    112     public Object visit(ASTString node, Object data) {
    113         System.out.println(indentString() + node);
    114         return data;
    115     }
    116
    117     public Object visit(ASTInteger node, Object data) {
    118         System.out.println(indentString() + node);
    119         return data;
    120     }
    121
    122     public Object visit(ASTFloat node, Object data) {
    123         System.out.println(indentString() + node);
    124         return data;
    125     }
    126
    127     public Object visit(ASTHex node, Object data) {
    128         System.out.println(indentString() + node);
    129         return data;
    130     }
    131
    132     public Object visit(ASTOct node, Object data) {
    133         System.out.println(indentString() + node);
    134         return data;
    135     }
    136
    137     private String indentString() {
    138         StringBuffer sb = new StringBuffer();
    139         for (int i = 0; i < indent; ++i) {
    140             sb.append(" ");
    141         }
    142         return sb.toString();
    143     }
    144 }