001: /**************************************************************************************
002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package org.codehaus.aspectwerkz.annotation.expression;
008:
009: import org.codehaus.aspectwerkz.annotation.expression.ast.ASTAnnotation;
010: import org.codehaus.aspectwerkz.annotation.expression.ast.ASTArray;
011: import org.codehaus.aspectwerkz.annotation.expression.ast.ASTBoolean;
012: import org.codehaus.aspectwerkz.annotation.expression.ast.ASTChar;
013: import org.codehaus.aspectwerkz.annotation.expression.ast.ASTFloat;
014: import org.codehaus.aspectwerkz.annotation.expression.ast.ASTHex;
015: import org.codehaus.aspectwerkz.annotation.expression.ast.ASTIdentifier;
016: import org.codehaus.aspectwerkz.annotation.expression.ast.ASTInteger;
017: import org.codehaus.aspectwerkz.annotation.expression.ast.ASTKeyValuePair;
018: import org.codehaus.aspectwerkz.annotation.expression.ast.ASTOct;
019: import org.codehaus.aspectwerkz.annotation.expression.ast.ASTRoot;
020: import org.codehaus.aspectwerkz.annotation.expression.ast.ASTString;
021: import org.codehaus.aspectwerkz.annotation.expression.ast.AnnotationParserVisitor;
022: import org.codehaus.aspectwerkz.annotation.expression.ast.SimpleNode;
023:
024: /**
025: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
026: */
027: public class DumpVisitor implements AnnotationParserVisitor {
028: private ASTRoot m_root;
029:
030: private int indent = 0;
031:
032: private DumpVisitor(final ASTRoot root) {
033: m_root = root;
034: }
035:
036: public static void dumpAST(final ASTRoot root) {
037: DumpVisitor dumper = new DumpVisitor(root);
038: dumper.visit(dumper.m_root, null);
039: }
040:
041: public Object visit(SimpleNode node, Object data) {
042: System.out.println(indentString() + node);
043: ++indent;
044: int nr = node.jjtGetNumChildren();
045: for (int i = 0; i < nr; i++) {
046: data = node.jjtGetChild(i).jjtAccept(this , data);
047: }
048: --indent;
049: return data;
050: }
051:
052: public Object visit(ASTRoot node, Object data) {
053: System.out.println(indentString() + node);
054: ++indent;
055: int nr = node.jjtGetNumChildren();
056: for (int i = 0; i < nr; i++) {
057: data = node.jjtGetChild(i).jjtAccept(this , data);
058: }
059: --indent;
060: return data;
061: }
062:
063: public Object visit(ASTAnnotation node, Object data) {
064: System.out.println(indentString() + node);
065: ++indent;
066: int nr = node.jjtGetNumChildren();
067: for (int i = 0; i < nr; i++) {
068: data = node.jjtGetChild(i).jjtAccept(this , data);
069: }
070: --indent;
071: return data;
072: }
073:
074: public Object visit(ASTKeyValuePair node, Object data) {
075: System.out.println(indentString() + node);
076: ++indent;
077: int nr = node.jjtGetNumChildren();
078: for (int i = 0; i < nr; i++) {
079: data = node.jjtGetChild(i).jjtAccept(this , data);
080: }
081: --indent;
082: return data;
083: }
084:
085: public Object visit(ASTArray node, Object data) {
086: System.out.println(indentString() + node);
087: ++indent;
088: int nr = node.jjtGetNumChildren();
089: for (int i = 0; i < nr; i++) {
090: data = node.jjtGetChild(i).jjtAccept(this , data);
091: }
092: --indent;
093: return data;
094: }
095:
096: public Object visit(ASTIdentifier node, Object data) {
097: System.out.println(indentString() + node);
098: return data;
099: }
100:
101: public Object visit(ASTBoolean node, Object data) {
102: System.out.println(indentString() + node);
103: return data;
104: }
105:
106: public Object visit(ASTChar node, Object data) {
107: System.out.println(indentString() + node);
108: return data;
109: }
110:
111: public Object visit(ASTString node, Object data) {
112: System.out.println(indentString() + node);
113: return data;
114: }
115:
116: public Object visit(ASTInteger node, Object data) {
117: System.out.println(indentString() + node);
118: return data;
119: }
120:
121: public Object visit(ASTFloat node, Object data) {
122: System.out.println(indentString() + node);
123: return data;
124: }
125:
126: public Object visit(ASTHex node, Object data) {
127: System.out.println(indentString() + node);
128: return data;
129: }
130:
131: public Object visit(ASTOct node, Object data) {
132: System.out.println(indentString() + node);
133: return data;
134: }
135:
136: private String indentString() {
137: StringBuffer sb = new StringBuffer();
138: for (int i = 0; i < indent; ++i) {
139: sb.append(" ");
140: }
141: return sb.toString();
142: }
143: }
|