KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > annotation > expression > DumpVisitor


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 JavaDoc visit(SimpleNode node, Object JavaDoc 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 JavaDoc visit(ASTRoot node, Object JavaDoc 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 JavaDoc visit(ASTAnnotation node, Object JavaDoc 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 JavaDoc visit(ASTKeyValuePair node, Object JavaDoc 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 JavaDoc visit(ASTArray node, Object JavaDoc 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 JavaDoc visit(ASTIdentifier node, Object JavaDoc data) {
98         System.out.println(indentString() + node);
99         return data;
100     }
101
102     public Object JavaDoc visit(ASTBoolean node, Object JavaDoc data) {
103         System.out.println(indentString() + node);
104         return data;
105     }
106
107     public Object JavaDoc visit(ASTChar node, Object JavaDoc data) {
108         System.out.println(indentString() + node);
109         return data;
110     }
111
112     public Object JavaDoc visit(ASTString node, Object JavaDoc data) {
113         System.out.println(indentString() + node);
114         return data;
115     }
116
117     public Object JavaDoc visit(ASTInteger node, Object JavaDoc data) {
118         System.out.println(indentString() + node);
119         return data;
120     }
121
122     public Object JavaDoc visit(ASTFloat node, Object JavaDoc data) {
123         System.out.println(indentString() + node);
124         return data;
125     }
126
127     public Object JavaDoc visit(ASTHex node, Object JavaDoc data) {
128         System.out.println(indentString() + node);
129         return data;
130     }
131
132     public Object JavaDoc visit(ASTOct node, Object JavaDoc data) {
133         System.out.println(indentString() + node);
134         return data;
135     }
136
137     private String JavaDoc indentString() {
138         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
139         for (int i = 0; i < indent; ++i) {
140             sb.append(" ");
141         }
142         return sb.toString();
143     }
144 }
Popular Tags