1 22 package org.jboss.aop.pointcut; 23 24 import org.jboss.aop.AspectManager; 25 import org.jboss.aop.pointcut.ast.ASTAll; 26 import org.jboss.aop.pointcut.ast.ASTAllParameter; 27 import org.jboss.aop.pointcut.ast.ASTAnd; 28 import org.jboss.aop.pointcut.ast.ASTAndCFlow; 29 import org.jboss.aop.pointcut.ast.ASTAttribute; 30 import org.jboss.aop.pointcut.ast.ASTBoolean; 31 import org.jboss.aop.pointcut.ast.ASTCFlow; 32 import org.jboss.aop.pointcut.ast.ASTCFlowBoolean; 33 import org.jboss.aop.pointcut.ast.ASTCFlowExpression; 34 import org.jboss.aop.pointcut.ast.ASTCall; 35 import org.jboss.aop.pointcut.ast.ASTComposite; 36 import org.jboss.aop.pointcut.ast.ASTCompositeCFlow; 37 import org.jboss.aop.pointcut.ast.ASTConstructor; 38 import org.jboss.aop.pointcut.ast.ASTException; 39 import org.jboss.aop.pointcut.ast.ASTExecution; 40 import org.jboss.aop.pointcut.ast.ASTExecutionOnly; 41 import org.jboss.aop.pointcut.ast.ASTField; 42 import org.jboss.aop.pointcut.ast.ASTFieldExecution; 43 import org.jboss.aop.pointcut.ast.ASTGet; 44 import org.jboss.aop.pointcut.ast.ASTHas; 45 import org.jboss.aop.pointcut.ast.ASTHasField; 46 import org.jboss.aop.pointcut.ast.ASTMethod; 47 import org.jboss.aop.pointcut.ast.ASTNot; 48 import org.jboss.aop.pointcut.ast.ASTNotCFlow; 49 import org.jboss.aop.pointcut.ast.ASTOr; 50 import org.jboss.aop.pointcut.ast.ASTOrCFlow; 51 import org.jboss.aop.pointcut.ast.ASTParameter; 52 import org.jboss.aop.pointcut.ast.ASTPointcut; 53 import org.jboss.aop.pointcut.ast.ASTSet; 54 import org.jboss.aop.pointcut.ast.ASTStart; 55 import org.jboss.aop.pointcut.ast.ASTSub; 56 import org.jboss.aop.pointcut.ast.ASTSubCFlow; 57 import org.jboss.aop.pointcut.ast.ASTWithin; 58 import org.jboss.aop.pointcut.ast.ASTWithincode; 59 import org.jboss.aop.pointcut.ast.Node; 60 import org.jboss.aop.pointcut.ast.PointcutExpressionParserVisitor; 61 import org.jboss.aop.pointcut.ast.SimpleNode; 62 import org.jboss.aop.pointcut.ast.ASTConstruction; 63 64 70 public class PointcutStats implements PointcutExpressionParserVisitor 71 { 72 protected ASTStart start; 73 protected AspectManager manager; 74 protected boolean execution = false; 75 protected boolean construction = false; 76 protected boolean call = false; 77 protected boolean within = false; 78 protected boolean get = false; 79 protected boolean set = false; 80 protected boolean withincode = false; 81 82 83 public PointcutStats(ASTStart start, AspectManager manager) 84 { 85 this.start = start; 86 this.manager = manager; 87 } 88 89 public boolean isExecution() 90 { 91 return execution; 92 } 93 94 public boolean isConstruction() 95 { 96 return construction; 97 } 98 99 public boolean isCall() 100 { 101 return call; 102 } 103 104 public boolean isWithin() 105 { 106 return within; 107 } 108 109 public boolean isGet() 110 { 111 return get; 112 } 113 114 public boolean isSet() 115 { 116 return set; 117 } 118 119 public boolean isWithincode() 120 { 121 return withincode; 122 } 123 124 125 public boolean matches() 126 { 127 return ((Boolean ) visit(start, null)).booleanValue(); 128 } 129 130 public Object visit(ASTStart node, Object data) 131 { 132 return node.jjtGetChild(0).jjtAccept(this, data); 133 } 134 135 public Object visit(ASTExecutionOnly node, Object data) 136 { 137 throw new RuntimeException ("SHOULD NEVER BE CALLED!"); 138 } 139 140 public Object visit(ASTBoolean node, Object data) 141 { 142 return node.jjtGetChild(0).jjtAccept(this, data); 143 } 144 145 public Object visit(ASTComposite node, Object data) 146 { 147 return node.jjtGetChild(0).jjtAccept(this, data); 148 } 149 150 public Object visit(ASTNot node, Object data) 151 { 152 153 Boolean bool = (Boolean ) node.jjtGetChild(0).jjtAccept(this, data); 154 boolean val = bool.booleanValue(); 155 return val ? Boolean.FALSE : Boolean.TRUE; 156 } 157 158 public Object visit(ASTSub node, Object data) 159 { 160 for (int i = 0; i < node.jjtGetNumChildren(); i++) 161 { 162 data = node.jjtGetChild(i).jjtAccept(this, data); 163 } 164 return data; 165 } 166 167 public Object visit(ASTAnd node, Object left) 168 { 169 Node andChild = node.jjtGetChild(0); andChild.jjtAccept(this, Boolean.FALSE); 171 return Boolean.FALSE; 172 } 173 174 public Object visit(ASTOr node, Object left) 175 { 176 Node orChild = node.jjtGetChild(0); orChild.jjtAccept(this, Boolean.FALSE); 178 return Boolean.FALSE; 179 } 180 181 private void setAllTrue() 182 { 183 execution = true; 185 call = true; 186 within = true; 187 get = true; 188 set = true; 189 withincode = true; 190 } 191 192 public Object visit(ASTPointcut node, Object data) 193 { 194 if (manager == null) 195 { 196 setAllTrue(); 197 } 198 Pointcut p = manager.getPointcut(node.getPointcutName()); 199 if (p instanceof PointcutExpression) 200 { 201 PointcutExpression expr = (PointcutExpression) p; 202 PointcutStats stats = expr.getStats(); 203 if (stats != null) 204 { 205 execution |= stats.isExecution(); 206 call |= stats.isCall(); 207 within |= stats.isWithin(); 208 get |= stats.isGet(); 209 set |= stats.isSet(); 210 withincode |= stats.isWithincode(); 211 } 212 else 213 { 214 setAllTrue(); 215 } 216 } 217 else 218 { 219 setAllTrue(); 220 221 } 222 return Boolean.FALSE; 223 } 224 225 public Object visit(ASTAll node, Object data) 226 { 227 execution = true; 228 get = true; 229 set = true; 230 return Boolean.FALSE; 231 } 232 233 public Object visit(ASTCFlowExpression node, Object data) 234 { 235 return Boolean.FALSE; 236 } 237 238 239 public Object visit(ASTCall node, Object data) 240 { 241 call = true; 242 return Boolean.FALSE; 243 } 244 245 public Object visit(ASTWithin node, Object data) 246 { 247 within = true; 248 return Boolean.FALSE; 249 } 250 251 public Object visit(ASTWithincode node, Object data) 252 { 253 withincode = true; 254 return Boolean.FALSE; 255 } 256 257 public Object visit(ASTExecution node, Object data) 258 { 259 execution = true; 260 return Boolean.FALSE; 261 } 262 263 public Object visit(ASTConstruction node, Object data) 264 { 265 construction = true; 266 return Boolean.FALSE; 267 } 268 269 public Object visit(ASTGet node, Object data) 270 { 271 get = true; 272 return Boolean.FALSE; 273 } 274 275 public Object visit(ASTSet node, Object data) 276 { 277 set = true; 278 return Boolean.FALSE; 279 } 280 281 public Object visit(ASTFieldExecution node, Object data) 282 { 283 get = set = true; 284 return Boolean.FALSE; 285 } 286 287 289 290 public Object visit(SimpleNode node, Object data) 291 { 292 return Boolean.FALSE; 293 } 294 295 public Object visit(ASTCFlowBoolean node, Object data) 296 { 297 return Boolean.FALSE; 298 } 299 300 public Object visit(ASTNotCFlow node, Object data) 301 { 302 return Boolean.FALSE; 303 } 304 305 public Object visit(ASTCompositeCFlow node, Object data) 306 { 307 return Boolean.FALSE; 308 } 309 310 public Object visit(ASTSubCFlow node, Object data) 311 { 312 return Boolean.FALSE; 313 } 314 315 public Object visit(ASTAndCFlow node, Object data) 316 { 317 return Boolean.FALSE; 318 } 319 320 public Object visit(ASTOrCFlow node, Object data) 321 { 322 return Boolean.FALSE; 323 } 324 325 public Object visit(ASTCFlow node, Object data) 326 { 327 return Boolean.FALSE; 328 } 329 330 public Object visit(ASTMethod node, Object data) 331 { 332 return Boolean.FALSE; 333 } 334 335 public Object visit(ASTAttribute node, Object data) 336 { 337 return Boolean.FALSE; 338 } 339 340 public Object visit(ASTConstructor node, Object data) 341 { 342 return Boolean.FALSE; 343 } 344 345 public Object visit(ASTParameter node, Object data) 346 { 347 return Boolean.FALSE; 348 } 349 350 public Object visit(ASTAllParameter node, Object data) 351 { 352 return Boolean.FALSE; 353 } 354 355 public Object visit(ASTField node, Object data) 356 { 357 return Boolean.FALSE; 358 } 359 360 public Object visit(ASTException node, Object data) 361 { 362 return Boolean.FALSE; 363 } 364 365 public Object visit(ASTHas node, Object data) 366 { 367 return Boolean.FALSE; 368 } 369 370 public Object visit(ASTHasField node, Object data) 371 { 372 return Boolean.FALSE; 373 } 374 375 376 } 377 | Popular Tags |