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