1 4 package com.tc.aspectwerkz.expression; 5 6 import com.tc.aspectwerkz.expression.ast.*; 7 8 14 public class DumpVisitor implements ExpressionParserVisitor { 15 private Node m_root; 16 17 private int indent = 0; 18 19 private DumpVisitor(final Node root) { 20 m_root = root; 21 } 22 23 public static void dumpAST(final Node root) { 24 DumpVisitor dumper = new DumpVisitor(root); 25 dumper.visit((SimpleNode) dumper.m_root, null); 26 } 27 28 public Object visit(SimpleNode node, Object data) { 29 System.out.println(indentString() + node); 30 ++indent; 31 data = node.jjtGetChild(0).jjtAccept(this, data); 32 --indent; 33 return data; 34 } 35 36 public Object visit(ASTRoot node, Object data) { 37 System.out.println(indentString() + node); 38 ++indent; 39 data = node.jjtGetChild(0).jjtAccept(this, data); 40 --indent; 41 return data; 42 } 43 44 public Object visit(ASTExpression node, Object data) { 45 System.out.println(indentString() + node); 46 ++indent; 47 data = node.jjtGetChild(0).jjtAccept(this, data); 48 --indent; 49 return data; 50 } 51 52 public Object visit(ASTOr node, Object data) { 53 System.out.println(indentString() + node); 54 ++indent; 55 for (int i = 0; i < node.jjtGetNumChildren(); i++) { 56 data = node.jjtGetChild(i).jjtAccept(this, data); 57 } 58 --indent; 59 return data; 60 } 61 62 public Object visit(ASTAnd node, Object data) { 63 System.out.println(indentString() + node); 64 ++indent; 65 for (int i = 0; i < node.jjtGetNumChildren(); i++) { 66 data = node.jjtGetChild(i).jjtAccept(this, data); 67 } 68 --indent; 69 return data; 70 } 71 72 public Object visit(ASTNot node, Object data) { 73 System.out.println(indentString() + node); 74 ++indent; 75 data = node.jjtGetChild(0).jjtAccept(this, data); 76 --indent; 77 return data; 78 } 79 80 public Object visit(ASTExecution node, Object data) { 81 System.out.println(indentString() + node); 82 ++indent; 83 data = node.jjtGetChild(0).jjtAccept(this, data); 84 --indent; 85 return data; 86 } 87 88 public Object visit(ASTCall node, Object data) { 89 System.out.println(indentString() + node); 90 ++indent; 91 data = node.jjtGetChild(0).jjtAccept(this, data); 92 --indent; 93 return data; 94 } 95 96 public Object visit(ASTSet node, Object data) { 97 System.out.println(indentString() + node); 98 ++indent; 99 data = node.jjtGetChild(0).jjtAccept(this, data); 100 --indent; 101 return data; 102 } 103 104 public Object visit(ASTGet node, Object data) { 105 System.out.println(indentString() + node); 106 ++indent; 107 data = node.jjtGetChild(0).jjtAccept(this, data); 108 --indent; 109 return data; 110 } 111 112 public Object visit(ASTHandler node, Object data) { 113 System.out.println(indentString() + node); 114 ++indent; 115 data = node.jjtGetChild(0).jjtAccept(this, data); 116 --indent; 117 return data; 118 } 119 120 public Object visit(ASTWithin node, Object data) { 121 System.out.println(indentString() + node); 122 ++indent; 123 data = node.jjtGetChild(0).jjtAccept(this, data); 124 --indent; 125 return data; 126 } 127 128 public Object visit(ASTWithinCode node, Object data) { 129 System.out.println(indentString() + node); 130 ++indent; 131 data = node.jjtGetChild(0).jjtAccept(this, data); 132 --indent; 133 return data; 134 } 135 136 public Object visit(ASTStaticInitialization node, Object data) { 137 System.out.println(indentString() + node); 138 ++indent; 139 data = node.jjtGetChild(0).jjtAccept(this, data); 140 --indent; 141 return data; 142 } 143 144 public Object visit(ASTIf node, Object data) { 145 System.out.println(indentString() + "if()"); 146 return data; 147 } 148 149 public Object visit(ASTCflow node, Object data) { 150 System.out.println(indentString() + node); 151 ++indent; 152 data = node.jjtGetChild(0).jjtAccept(this, data); 153 --indent; 154 return data; 155 } 156 157 public Object visit(ASTCflowBelow node, Object data) { 158 System.out.println(indentString() + node); 159 ++indent; 160 data = node.jjtGetChild(0).jjtAccept(this, data); 161 --indent; 162 return data; 163 } 164 165 166 public Object visit(ASTHasMethod node, Object data) { 167 System.out.println(indentString() + node); 168 ++indent; 169 data = node.jjtGetChild(0).jjtAccept(this, data); 170 --indent; 171 return data; 172 } 173 174 175 public Object visit(ASTHasField node, Object data) { 176 System.out.println(indentString() + node); 177 ++indent; 178 data = node.jjtGetChild(0).jjtAccept(this, data); 179 --indent; 180 return data; 181 } 182 183 public Object visit(ASTTarget node, Object data) { 184 System.out.println(indentString() + node); 185 ++indent; 186 System.out.println(node.getIdentifier()); 187 --indent; 188 return data; 189 } 190 191 public Object visit(ASTThis node, Object data) { 192 System.out.println(indentString() + node); 193 ++indent; 194 System.out.println(node.getIdentifier()); 195 --indent; 196 return data; 197 } 198 199 public Object visit(ASTClassPattern node, Object data) { 200 System.out.println(indentString() + node); 201 ++indent; 202 int nr = node.jjtGetNumChildren(); 203 for (int i = 0; i < nr; i++) { 204 data = node.jjtGetChild(i).jjtAccept(this, data); 205 } 206 --indent; 207 return data; 208 } 209 210 public Object visit(ASTMethodPattern node, Object data) { 211 System.out.println(indentString() + node); 212 ++indent; 213 int nr = node.jjtGetNumChildren(); 214 for (int i = 0; i < nr; i++) { 215 data = node.jjtGetChild(i).jjtAccept(this, data); 216 } 217 --indent; 218 return data; 219 } 220 221 public Object visit(ASTConstructorPattern node, Object data) { 222 System.out.println(indentString() + node); 223 ++indent; 224 int nr = node.jjtGetNumChildren(); 225 for (int i = 0; i < nr; i++) { 226 data = node.jjtGetChild(i).jjtAccept(this, data); 227 } 228 --indent; 229 return data; 230 } 231 232 public Object visit(ASTFieldPattern node, Object data) { 233 System.out.println(indentString() + node); 234 ++indent; 235 int nr = node.jjtGetNumChildren(); 236 for (int i = 0; i < nr; i++) { 237 data = node.jjtGetChild(i).jjtAccept(this, data); 238 } 239 --indent; 240 return data; 241 } 242 243 public Object visit(ASTPointcutReference node, Object data) { 244 System.out.println(indentString() + node); 245 return data; 246 } 247 248 public Object visit(ASTParameter node, Object data) { 249 System.out.println(indentString() + node); 250 return data; 251 } 252 253 public Object visit(ASTArgs node, Object data) { 254 System.out.println(indentString() + node); 255 ++indent; 256 if (node.jjtGetNumChildren() > 0) { 257 data = node.jjtGetChild(0).jjtAccept(this, data); 258 } 259 --indent; 260 return data; 261 } 262 263 public Object visit(ASTArgParameter node, Object data) { 264 System.out.println(indentString() + node); 265 return data; 266 } 267 268 public Object visit(ASTAttribute node, Object data) { 269 System.out.println(indentString() + node); 270 return data; 271 } 272 273 public Object visit(ASTModifier node, Object data) { 274 System.out.println(indentString() + node); 275 return data; 276 } 277 278 private String indentString() { 279 StringBuffer sb = new StringBuffer (); 280 for (int i = 0; i < indent; ++i) { 281 sb.append(" "); 282 } 283 return sb.toString(); 284 } 285 } | Popular Tags |