1 24 package org.aspectj.compiler.crosscuts.joinpoints; 25 26 import org.aspectj.compiler.base.ast.*; 27 import org.aspectj.compiler.crosscuts.ast.*; 28 29 import org.aspectj.compiler.base.JavaCompiler; 30 import org.aspectj.util.JavaStrings; 31 32 import java.util.*; 33 34 35 public class MethodCallJp extends CallJp { 36 public MethodCallJp(CallExpr callExpr, JoinPoint enclosingJp) { 37 super(callExpr, enclosingJp); 38 } 39 40 public static final Kind KIND = new Kind("method-call", METHOD_CALL); 41 42 public Kind getKind() { return KIND; } 43 44 public boolean isMethodCall() { return true; } 45 46 public Type getTargetExprType() { 47 if (getCalledCodeDec().isStatic()) return null; 48 return getCallExpr().getExpr().getType(); 49 } 50 51 public Type getTargetType() { 52 return getCallExpr().getExpr().getType(); 53 } 54 55 protected AnyCallExpr makeBasicInnerCall(Expr targetExpr, Exprs argsExprs) { 56 AnyCallExpr innerCall = getCallExpr(); 57 innerCall = (AnyCallExpr)innerCall.copy(); 58 innerCall.setArgs(argsExprs); 59 innerCall.setExpr(targetExpr); 60 return innerCall; 61 } 62 63 protected ASTObject makeInnerCall(Expr targetExpr, Exprs argsExprs) { 64 AnyCallExpr innerCall = makeBasicInnerCall(targetExpr, argsExprs); 65 66 if (skipTypes != null) { 67 ASTObject ret = innerCall; 68 boolean isVoid = innerCall.getType().isVoid(); 69 70 for (Iterator i = skipTypes.entrySet().iterator(); i.hasNext(); ) { 71 Map.Entry entry = (Map.Entry)i.next(); 72 Type type = (Type)entry.getKey(); 73 MethodDec md = (MethodDec)entry.getValue(); 74 75 final AST ast = getAST(); 76 if (md.isStatic()) { 77 return ast.makeStaticCall(md.getMethod(), (Exprs)innerArgs.copy()); 78 } 79 80 Expr innerExpr = (Expr)targetExpr.copy(); 81 82 if (!innerExpr.getType().isCoercableTo(type)) continue; 83 84 Expr skipCall = ast.makeCall(md.getMethod(), 85 ast.makeCast(type, innerExpr), 86 (Exprs)innerArgs.copy()); 87 88 if (innerExpr.getType().isSubtypeOf(type)) { 89 return skipCall; 90 } else { 91 Expr instanceTest = ast.makeInstanceof((Expr)innerExpr.copy(), type); 92 if (isVoid) { 93 Stmt stmt; 94 if (ret instanceof Stmt) stmt = (Stmt)ret; 95 else stmt = ast.makeStmt((Expr)ret); 96 ret = ast.makeIf(instanceTest, ast.makeStmt(skipCall), stmt); 97 } else { 98 ret = ast.makeTriTest(instanceTest, skipCall, (Expr)ret); 99 } 100 } 101 } 102 return ret; 103 } 104 return innerCall; 105 } 106 107 protected void preImplement() { 108 if (!hasPlans()) return; 109 110 CodeDec codeDec = getCalledCodeDec(); 111 MethodDec targetMethodDec = (MethodDec)codeDec; 112 113 boolean needsCallSiteAdvice = false; 114 Map skipAdviceOnTypes = new HashMap(); 115 116 118 for (Iterator i = targetMethodDec.getMatchingMethods().iterator(); i.hasNext(); ) { 119 MethodDec dec = (MethodDec)i.next(); 120 CalleeSideCallJp targetPoint = 122 (CalleeSideCallJp)getWorld().calleeSideCallPoints.get(dec); 123 if (targetPoint == null || !targetPoint.hasPlans()) { 125 needsCallSiteAdvice = true; 126 } else { 127 skipAdviceOnTypes.put(targetPoint.getCodeDec().getDeclaringType(), 128 targetPoint.getPostMethodDec()); 129 if (this.plansMatch(targetPoint)) { 130 } else { 132 needsCallSiteAdvice = true; 133 } 134 } 135 } 136 137 if (!needsCallSiteAdvice) { 138 forgetPlans(); 140 } else if (skipAdviceOnTypes.size() > 0) { 141 Set keepTypes = Type.filterTopTypes(skipAdviceOnTypes.keySet()); 142 skipAdviceOnTypes.keySet().retainAll(keepTypes); 143 skipAdviceOnTypes(skipAdviceOnTypes); 144 } 145 146 } 148 149 private Map skipTypes = null; 150 public void skipAdviceOnTypes(Map onTypes) { 151 skipTypes = onTypes; 153 } 154 } 155 | Popular Tags |