1 22 package org.jboss.aop.pointcut.ast; 23 24 import java.io.StringReader ; 25 26 public class PointcutParserTester implements PointcutExpressionParserVisitor 27 { 28 private int indent = 0; 29 30 private String indentString() 31 { 32 StringBuffer sb = new StringBuffer (); 33 for (int i = 0; i < indent; ++i) 34 { 35 sb.append(" "); 36 } 37 return sb.toString(); 38 } 39 40 41 42 public Object visit(SimpleNode node, Object data) 43 { 44 System.out.println(indentString() + node + 45 ": acceptor not unimplemented in subclass?"); 46 ++indent; 47 data = node.childrenAccept(this, data); 48 --indent; 49 return data; 50 } 51 52 public Object visit(ASTStart node, Object data) 53 { 54 System.out.println(indentString() + node); 55 ++indent; 56 data = node.childrenAccept(this, data); 57 --indent; 58 return data; 59 } 60 61 public Object visit(ASTHas node, Object data) 62 { 63 System.out.println(indentString() + node); 64 ++indent; 65 data = node.childrenAccept(this, data); 66 --indent; 67 return data; 68 } 69 70 public Object visit(ASTHasField node, Object data) 71 { 72 System.out.println(indentString() + node); 73 ++indent; 74 data = node.childrenAccept(this, data); 75 --indent; 76 return data; 77 } 78 79 public Object visit(ASTExecutionOnly node, Object data) 80 { 81 return null; 82 } 83 84 public Object visit(ASTBoolean node, Object data) 85 { 86 System.out.println(indentString() + node); 87 ++indent; 88 data = node.childrenAccept(this, data); 89 --indent; 90 return data; 91 } 92 93 public Object visit(ASTField node, Object data) 94 { 95 System.out.print(indentString()); 96 if (node.attributes != null) 97 { 98 for (int i = 0; i < node.attributes.size(); i++) 99 { 100 ASTAttribute attr = (ASTAttribute) node.attributes.get(i); 101 System.out.print(attr.attribute + " "); 102 } 103 } 104 System.out.print(node.getTypeExpression() + " "); 105 System.out.println(node.getClassExpr() + "." + node.getFieldExpr()); 106 return data; 107 } 108 109 public Object visit(ASTMethod node, Object data) 110 { 111 System.out.print(indentString()); 112 System.out.print(node.getReturnTypeExpression() + " "); 113 if (node.attributes != null) 114 { 115 for (int i = 0; i < node.attributes.size(); i++) 116 { 117 ASTAttribute attr = (ASTAttribute) node.attributes.get(i); 118 System.out.print(attr.attribute + " "); 119 } 120 } 121 System.out.print(node.getClassExpr() + "." + node.getMethodExpr() + "("); 122 if (node.parameters != null && !node.isAnyParameters()) 123 { 124 for (int i = 0; i < node.parameters.size(); i++) 125 { 126 if (i > 0) System.out.print(", "); 127 System.out.print(node.parameters.get(i)); 128 } 129 } 130 else if (node.isAnyParameters()) 131 { 132 System.out.print(".."); 133 } 134 System.out.println(")"); 135 return data; 136 } 137 138 public Object visit(ASTConstructor node, Object data) 139 { 140 System.out.print(indentString()); 141 if (node.attributes != null) 142 { 143 for (int i = 0; i < node.attributes.size(); i++) 144 { 145 ASTAttribute attr = (ASTAttribute) node.attributes.get(i); 146 System.out.print(attr.attribute + " "); 147 } 148 } 149 System.out.print(node.getClassExpr() + "("); 150 if (node.parameters != null && !node.isAnyParameters()) 151 { 152 for (int i = 0; i < node.parameters.size(); i++) 153 { 154 if (i > 0) System.out.print(", "); 155 System.out.print(node.parameters.get(i)); 156 } 157 } 158 else if (node.isAnyParameters()) 159 { 160 System.out.print(".."); 161 } 162 163 System.out.println(")"); 164 return data; 165 } 166 167 public Object visit(ASTParameter node, Object data) 168 { 169 return null; 170 } 171 172 public Object visit(ASTComposite node, Object data) 173 { 174 System.out.println(indentString() + node); 175 ++indent; 176 data = node.childrenAccept(this, data); 177 --indent; 178 return data; 179 } 180 181 public Object visit(ASTCFlowExpression node, Object data) 182 { 183 System.out.println(indentString() + node); 184 ++indent; 185 data = node.childrenAccept(this, data); 186 --indent; 187 return data; 188 } 189 public Object visit(ASTCFlow node, Object data) 190 { 191 System.out.println(indentString() + node); 192 ++indent; 193 data = node.childrenAccept(this, data); 194 --indent; 195 return data; 196 } 197 198 public Object visit(ASTSub node, Object data) 199 { 200 System.out.println(indentString() + node); 201 ++indent; 202 data = node.childrenAccept(this, data); 203 --indent; 204 return data; 205 } 206 207 public Object visit(ASTAnd node, Object data) 208 { 209 System.out.println(indentString() + node); 210 ++indent; 211 data = node.childrenAccept(this, data); 212 --indent; 213 return data; 214 } 215 216 public Object visit(ASTOr node, Object data) 217 { 218 System.out.println(indentString() + node); 219 ++indent; 220 data = node.childrenAccept(this, data); 221 --indent; 222 return data; 223 } 224 225 public Object visit(ASTNot node, Object data) 226 { 227 System.out.println(indentString() + node); 228 ++indent; 229 data = node.childrenAccept(this, data); 230 --indent; 231 return data; 232 } 233 234 public Object visit(ASTNotCFlow node, Object data) 235 { 236 System.out.println(indentString() + node); 237 ++indent; 238 data = node.childrenAccept(this, data); 239 --indent; 240 return data; 241 } 242 243 public Object visit(ASTCFlowBoolean node, Object data) 244 { 245 System.out.println(indentString() + node); 246 ++indent; 247 data = node.childrenAccept(this, data); 248 --indent; 249 return data; 250 } 251 252 public Object visit(ASTCompositeCFlow node, Object data) 253 { 254 System.out.println(indentString() + node); 255 ++indent; 256 data = node.childrenAccept(this, data); 257 --indent; 258 return data; 259 } 260 261 public Object visit(ASTOrCFlow node, Object data) 262 { 263 System.out.println(indentString() + node); 264 ++indent; 265 data = node.childrenAccept(this, data); 266 --indent; 267 return data; 268 } 269 270 public Object visit(ASTAndCFlow node, Object data) 271 { 272 System.out.println(indentString() + node); 273 ++indent; 274 data = node.childrenAccept(this, data); 275 --indent; 276 return data; 277 } 278 279 public Object visit(ASTSubCFlow node, Object data) 280 { 281 System.out.println(indentString() + node); 282 ++indent; 283 data = node.childrenAccept(this, data); 284 --indent; 285 return data; 286 } 287 288 public Object visit(ASTAll node, Object data) 289 { 290 System.out.println(indentString() + node); 291 ++indent; 292 System.out.println(indentString() + node.getClasseExpression()); 293 --indent; 294 return data; 295 } 296 297 public Object visit(ASTFieldExecution node, Object data) 298 { 299 System.out.println(indentString() + node); 300 ++indent; 301 data = node.childrenAccept(this, data); 302 --indent; 303 return data; 304 } 305 306 public Object visit(ASTCall node, Object data) 307 { 308 System.out.println(indentString() + node); 309 ++indent; 310 data = node.getBehavior().jjtAccept(this, data); 311 --indent; 312 return data; 313 } 314 315 public Object visit(ASTExecution node, Object data) 316 { 317 System.out.println(indentString() + node); 318 ++indent; 319 data = node.childrenAccept(this, data); 320 --indent; 321 return data; 322 } 323 324 public Object visit(ASTConstruction node, Object data) 325 { 326 System.out.println(indentString() + node); 327 ++indent; 328 data = node.childrenAccept(this, data); 329 --indent; 330 return data; 331 } 332 333 public Object visit(ASTGet node, Object data) 334 { 335 System.out.println(indentString() + node); 336 ++indent; 337 data = node.childrenAccept(this, data); 338 --indent; 339 return data; 340 } 341 342 public Object visit(ASTSet node, Object data) 343 { 344 System.out.println(indentString() + node); 345 ++indent; 346 data = node.childrenAccept(this, data); 347 --indent; 348 return data; 349 } 350 351 public Object visit(ASTPointcut node, Object data) 352 { 353 System.out.println(indentString() + node); 354 ++indent; 355 data = node.childrenAccept(this, data); 356 --indent; 357 return data; 358 } 359 360 public Object visit(ASTWithin node, Object data) 361 { 362 System.out.println(indentString() + node); 363 ++indent; 364 data = node.childrenAccept(this, data); 365 --indent; 366 return data; 367 } 368 369 public Object visit(ASTWithincode node, Object data) 370 { 371 System.out.println(indentString() + node); 372 ++indent; 373 data = node.childrenAccept(this, data); 374 --indent; 375 return data; 376 } 377 public Object visit(ASTAttribute node, Object data) 378 { 379 return null; 380 } 381 382 public Object visit(ASTException node, Object data) 383 { 384 return null; 385 } 386 387 public Object visit(ASTAllParameter node, Object data) 388 { 389 return null; 390 } 391 392 public static void main(String args[]) 393 { 394 System.out.println("----" + args[0]); 395 StringReader reader = new StringReader (args[0]); 396 PointcutExpressionParser t = new PointcutExpressionParser(reader); 397 try 400 { 401 ASTStart n = t.Start(); 402 PointcutExpressionParserVisitor v = new PointcutParserTester(); 403 n.jjtAccept(v, null); 404 } 405 catch (Exception e) 406 { 407 System.out.println("Oops."); 408 System.out.println(e.getMessage()); 409 e.printStackTrace(); 410 } 411 } 412 } 413 414 415 | Popular Tags |