1 24 25 package org.aspectj.compiler.crosscuts.ast; 26 import org.aspectj.compiler.base.ast.*; 27 import org.aspectj.compiler.base.*; 28 import org.aspectj.compiler.crosscuts.joinpoints.*; 29 import org.aspectj.compiler.base.cst.*; 30 31 import org.aspectj.util.FuzzyBoolean; 32 33 37 38 public class VarTypeName extends GenTypeName { 39 public String toShortString() { 40 return formalDec.getName(); 41 } 42 43 public boolean matches(Type type) { 44 return false; 46 } 47 48 public FuzzyBoolean matchesInstance(Type exprType) { 49 Type formalType = formalDec.getType(); 50 if (formalType.isObject()) return FuzzyBoolean.YES; 51 52 if (formalType.isAssignableFrom(exprType)) return FuzzyBoolean.YES; 53 54 if (exprType.isCoercableTo(formalType)) return FuzzyBoolean.MAYBE; 56 57 return FuzzyBoolean.NO; 58 } 59 60 public JpPlan makePlan(JoinPoint jp, Expr expr) { 61 Type exprType = expr.getType(); 62 Type formalType = formalDec.getType(); 63 64 if (matchesInstance(exprType).alwaysFalse()) return JpPlan.NO_PLAN; 65 66 JpPlan plan = new JpPlan(jp); 67 68 70 if (formalType.isObject()) { 71 if (exprType.isPrimitive()) { 72 expr = exprType.makeObject(expr); 73 } 74 plan.bindExpr(formalDec, expr); 75 return plan; 76 } 77 78 if (formalType.isAssignableFrom(exprType)) { 79 plan.bindExpr(formalDec, expr); 80 return plan; 81 } 82 83 if (exprType.isCoercableTo(formalType)) { 84 final AST ast = getAST(); 85 86 Expr testExpr = ast.makeParen(ast.makeInstanceof(expr, formalType)); 87 plan.addExprTest(testExpr); 88 plan.bindExpr(formalDec, expr); 89 return plan; 90 } 91 92 return JpPlan.NO_PLAN; 93 } 94 95 protected FormalDec formalDec; 97 public FormalDec getFormalDec() { return formalDec; } 98 public void setFormalDec(FormalDec _formalDec) { formalDec = _formalDec; } 99 100 public VarTypeName(SourceLocation location, FormalDec _formalDec) { 101 super(location); 102 setFormalDec(_formalDec); 103 } 104 protected VarTypeName(SourceLocation source) { 105 super(source); 106 } 107 108 public ASTObject copyWalk(CopyWalker walker) { 109 VarTypeName ret = new VarTypeName(getSourceLocation()); 110 ret.preCopy(walker, this); 111 ret.formalDec = formalDec; 112 return ret; 113 } 114 115 116 public String getDefaultDisplayName() { 117 return "VarTypeName(formalDec: "+formalDec+")"; 118 } 119 120 } 122 123 | Popular Tags |