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 38 39 public class SimpleTypeName extends GenTypeName { 40 public String toShortString() { 41 if (includeSubTypes) return type.getPrettyString() + "+"; 43 else return type.getPrettyString(); 44 } 45 46 47 public boolean matches(Type type) { 48 if (includeSubTypes) return type.isSubtypeOf(getType()); 49 else return type == getType(); 50 } 51 52 53 public FuzzyBoolean matchesInstance(Type exprType) { 54 Type formalType = getType(); 55 if (formalType.isObject()) return FuzzyBoolean.YES; 57 58 if (formalType.isAssignableFrom(exprType)) return FuzzyBoolean.YES; 59 60 if (exprType.isCoercableTo(formalType)) return FuzzyBoolean.MAYBE; 62 63 return FuzzyBoolean.NO; 64 } 65 66 public JpPlan makePlan(JoinPoint jp, Expr expr) { 67 Type exprType = expr.getType(); 68 Type formalType = getType(); 69 71 if (matchesInstance(exprType).alwaysFalse()) return JpPlan.NO_PLAN; 72 73 JpPlan plan = new JpPlan(jp); 74 75 76 77 if (formalType.isObject()) { 78 return plan; 79 } 80 81 if (formalType.isAssignableFrom(exprType)) { 82 return plan; 83 } 84 85 if (exprType.isCoercableTo(formalType)) { 86 final AST ast = getAST(); 87 88 Expr testExpr = ast.makeParen(ast.makeInstanceof(expr, formalType)); 89 plan.addExprTest(testExpr); 90 return plan; 91 } 92 93 return JpPlan.NO_PLAN; 94 } 95 96 protected Type type; 98 public Type getType() { return type; } 99 public void setType(Type _type) { type = _type; } 100 101 protected boolean includeSubTypes; 102 public boolean getIncludeSubTypes() { return includeSubTypes; } 103 public void setIncludeSubTypes(boolean _includeSubTypes) { includeSubTypes = _includeSubTypes; } 104 105 public SimpleTypeName(SourceLocation location, Type _type, boolean _includeSubTypes) { 106 super(location); 107 setType(_type); 108 setIncludeSubTypes(_includeSubTypes); 109 } 110 protected SimpleTypeName(SourceLocation source) { 111 super(source); 112 } 113 114 public ASTObject copyWalk(CopyWalker walker) { 115 SimpleTypeName ret = new SimpleTypeName(getSourceLocation()); 116 ret.preCopy(walker, this); 117 ret.type = type; 118 ret.includeSubTypes = includeSubTypes; 119 return ret; 120 } 121 122 123 public String getDefaultDisplayName() { 124 return "SimpleTypeName(type: "+type+", "+"includeSubTypes: "+includeSubTypes+")"; 125 } 126 127 } 129 130 | Popular Tags |