1 24 25 package org.aspectj.compiler.crosscuts.joinpoints; 26 27 import org.aspectj.compiler.crosscuts.ast.*; 28 import org.aspectj.compiler.base.ast.*; 29 import org.aspectj.compiler.base.*; 30 31 import org.aspectj.compiler.crosscuts.AspectJCompiler; 32 33 import org.aspectj.util.PartialOrder; 34 35 import java.util.*; 36 37 39 40 public class AdvicePlan extends JpPlan { 41 public AspectDec aspectDec; 42 public AdviceDec adviceDec; 43 public JpPlan innerPlan; 44 45 public AdviceDec getAdviceDec() { return adviceDec; } 46 public AspectDec getAspectDec() { return aspectDec; } 47 48 public AdvicePlan(JoinPoint jp, AspectDec aspectDec, AdviceDec adviceDec, JpPlan innerPlan) { 49 super(jp); 50 this.aspectDec = aspectDec; 51 this.adviceDec = adviceDec; 52 this.innerPlan = innerPlan; 53 54 JpPlan other = innerPlan; 56 test = simplify(other.test); 57 ifTest = simplify(other.ifTest); 58 instance = other.instance; 59 bindings = other.bindings; 60 dependencies = other.dependencies; 61 } 62 63 void checkExceptions(AdviceDec adviceDec, JoinPoint joinPoint) { 64 TypeDs _throws = adviceDec.getThrows(); 65 if (_throws == null) return; 66 67 for (int i = 0; i < _throws.size(); i++) { 68 Type t = _throws.get(i).getType(); 69 if (!joinPoint.canThrow(t)) { 70 joinPoint.showError(adviceDec, 71 "can't throw " + t.getPrettyString()); 72 break; 73 } 74 } 75 } 76 77 78 public void wrapJoinPoint(JoinPoint joinPoint) { 79 checkExceptions(adviceDec, joinPoint); 80 adviceDec.wrapJoinPoint(joinPoint, this); 81 } 82 83 84 88 public int compareTo(Object o) { 89 int ret = super.compareTo(o); 90 if (ret != 0) return ret; 91 92 if (!(o instanceof AdvicePlan)) return 0; 93 AdvicePlan otherPlan = (AdvicePlan)o; 94 95 if (this.getAdviceDec().dominates(otherPlan.getAdviceDec())) { 96 return -1; 97 } else if (otherPlan.getAdviceDec().dominates(this.getAdviceDec())) { 98 return +1; 99 } else { 100 return 0; 101 } 102 } 103 104 public boolean matches(JpPlan other) { 105 if (other instanceof AdvicePlan) { 106 return getAdviceDec() == ((AdvicePlan)other).getAdviceDec(); 107 } else { 108 return false; 109 } 110 } 111 112 public int getPreSortOrder() { 113 if (adviceDec instanceof AroundAdviceDec) return AROUND; 114 if (adviceDec instanceof BeforeAdviceDec) return BEFORE; 115 return AFTER; 116 } 117 118 122 public int fallbackCompareTo(Object o) { 123 if (!(o instanceof AdvicePlan)) return 0; 124 AdvicePlan otherPlan = (AdvicePlan)o; 125 126 return getAspectDec().getId().compareTo(otherPlan.getAspectDec().getId()); 129 } 130 131 132 public Exprs makeCallExprs(Expr extraExpr) { 133 Expr instance = getInstance(); 134 135 Exprs exprs = getCallExprs(adviceDec.getFormals()); Type type = adviceDec.getExtraArgType(); 137 if (type != null) { 138 if (type.isEquivalent(getTypeManager().getObjectType())) { 140 extraExpr = extraExpr.getType().makeObject(extraExpr); 142 } 144 145 if (!extraExpr.getType().isCoercableTo(type)) { 146 return null; 148 } 149 extraExpr = getAST().makeCast(type, extraExpr); 150 exprs.add(extraExpr); 151 } 152 if (adviceDec.needsStaticEnclosingJoinPointFormal()) { 153 exprs.add(joinPoint.makeStaticEnclosingJoinPointVarExpr()); 154 } 155 if (adviceDec.needsStaticJoinPointFormal()) { 156 exprs.add(joinPoint.makeStaticJoinPointVarExpr()); 157 } 158 if (adviceDec.needsDynamicJoinPointFormal()) { 159 exprs.add(joinPoint.makeDynamicJoinPointVarExpr()); 162 } 163 return exprs; 164 } 165 166 public Stmt makeCall(Expr extraExpr) { 167 Exprs exprs = makeCallExprs(extraExpr); 168 if (exprs == null) return getAST().makeEmptyStmt(); 169 Expr call = adviceDec.makeCall(instance, exprs); 170 call.setSourceLocation(joinPoint.getTargetNode().getSourceLocation()); 171 Stmt callStmt = getAST().makeStmt(call); 172 return wrapDynamicTest(callStmt); 174 } 175 176 177 public Expr getInstance() { 178 if (instance == null) return null; 179 180 return getAST().makeCast(getAspectDec().getType(), instance); 181 } 182 183 public String toString() { 184 if (adviceDec == null || joinPoint == null) { 185 return super.toString(); 186 } else { 187 return "plan(" + joinPoint.toString() + ", " + adviceDec.toShortString() + ")"; 188 } 189 } 190 191 } 192 | Popular Tags |