1 22 package org.jboss.aop.pointcut; 23 24 import javassist.CtMethod; 25 import javassist.NotFoundException; 26 import javassist.expr.MethodCall; 27 import org.jboss.aop.Advisor; 28 import org.jboss.aop.AspectManager; 29 import org.jboss.aop.pointcut.ast.ASTCall; 30 import org.jboss.aop.pointcut.ast.ASTConstructor; 31 import org.jboss.aop.pointcut.ast.ASTField; 32 import org.jboss.aop.pointcut.ast.ASTHas; 33 import org.jboss.aop.pointcut.ast.ASTHasField; 34 import org.jboss.aop.pointcut.ast.ASTMethod; 35 import org.jboss.aop.pointcut.ast.ASTStart; 36 import org.jboss.aop.pointcut.ast.ASTWithin; 37 import org.jboss.aop.pointcut.ast.ASTWithincode; 38 import org.jboss.aop.pointcut.ast.Node; 39 40 46 public class MethodCallMatcher extends MatcherHelper 47 { 48 MethodCall call; 49 Advisor advisor; 50 51 public MethodCallMatcher(Advisor advisor, MethodCall call, ASTStart start) throws NotFoundException 52 { 53 super(start, advisor.getManager()); 54 this.advisor = advisor; 55 this.call = call; 56 } 57 58 public Object visit(ASTCall node, Object data) 59 { 60 try 61 { 62 if (!(node.getBehavior() instanceof ASTMethod)) return Boolean.FALSE; 63 64 ASTMethod astMethod = (ASTMethod) node.getBehavior(); 65 66 if (astMethod.getClazz().isSimple()) 68 { 69 if (!astMethod.getClazz().matches(call.getClassName())) return Boolean.FALSE; 70 if (!astMethod.getMethodIdentifier().isAnnotation()) 71 { 72 if (!astMethod.getMethodIdentifier().matches(call.getMethodName())) return Boolean.FALSE; 73 } 74 } 75 CtMethod calledMethod = call.getMethod(); 76 Advisor calledAdvisor = AspectManager.instance().getTempClassAdvisor(calledMethod.getDeclaringClass()); 77 MethodMatcher methodMatcher = new MethodMatcher(calledAdvisor, calledMethod, null); 78 return methodMatcher.matches(astMethod); 79 } 80 catch (Exception e) 81 { 82 throw new RuntimeException (e); } 84 } 85 86 public Object visit(ASTHas node, Object data) 87 { 88 try 89 { 90 Node n = node.jjtGetChild(0); 91 CtMethod method = call.getMethod(); 92 if (n instanceof ASTMethod) 93 { 94 return new Boolean (Util.has(method.getDeclaringClass(), (ASTMethod) n, advisor)); 95 } 96 else 97 { 98 return new Boolean (Util.has(method.getDeclaringClass(), (ASTConstructor) n, advisor)); 99 } 100 } 101 catch (NotFoundException e) 102 { 103 throw new RuntimeException (e); } 105 } 106 107 public Object visit(ASTHasField node, Object data) 108 { 109 ASTField f = (ASTField) node.jjtGetChild(0); 110 CtMethod method = null; 111 try 112 { 113 method = call.getMethod(); 114 } 115 catch (NotFoundException e) 116 { 117 throw new RuntimeException (e); } 119 return new Boolean (Util.has(method.getDeclaringClass(), f, advisor)); 120 } 121 122 public Object visit(ASTWithin node, Object data) 123 { 124 WithinMatcher within = null; 125 try 126 { 127 within = new WithinMatcher(advisor, call.where(), null); 128 } 129 catch (NotFoundException e) 130 { 131 throw new RuntimeException (e); } 133 return node.jjtAccept(within, null); 134 } 135 136 public Object visit(ASTWithincode node, Object data) 137 { 138 WithinMatcher within = null; 139 try 140 { 141 within = new WithinMatcher(advisor, call.where(), null); 142 } 143 catch (NotFoundException e) 144 { 145 throw new RuntimeException (e); } 147 return node.jjtAccept(within, null); 148 } 149 150 protected Boolean resolvePointcut(Pointcut p) 151 { 152 try 153 { 154 return new Boolean (p.matchesCall(advisor, call)); 155 } 156 catch (NotFoundException e) 157 { 158 throw new RuntimeException (e); } 160 } 161 162 } 163 | Popular Tags |