1 24 25 package org.aspectj.compiler.crosscuts.ast; 26 import org.aspectj.compiler.base.ast.*; 27 import org.aspectj.compiler.crosscuts.joinpoints.*; 28 29 import org.aspectj.compiler.base.JavaCompiler; 30 import org.aspectj.util.FuzzyBoolean; 31 32 import java.util.*; 33 34 38 public class WithinPcd extends Pcd { 39 public String toShortString() { 40 return "within(" + getTypeName().toShortString() + ")"; 41 } 42 public void checkStatic() { } 43 44 48 private TypeDec matchingEnclosingTypeDec(TypeDec typeDec) { 49 while (typeDec != null) { 50 if (getTypeName().matches(typeDec.getType())) return typeDec; 51 typeDec = typeDec.getEnclosingTypeDec(); 52 } 53 return null; 54 } 55 56 57 public JpPlanner makePlanner(PlanData planData) { 58 return new JpPlanner() { 59 public FuzzyBoolean fastMatch(JoinPoint jp) { 60 ASTObject sourceLocation = jp.getSourceLocation(); 61 if (sourceLocation == null) return FuzzyBoolean.NEVER; 62 TypeDec typeDec = sourceLocation.getLexicalType().getTypeDec(); 63 TypeDec matchingTypeDec = matchingEnclosingTypeDec(typeDec); 64 if (matchingTypeDec == null) return FuzzyBoolean.NO; 65 else return FuzzyBoolean.YES; 66 } 67 }; 68 } 69 70 protected GenTypeName typeName; 72 public GenTypeName getTypeName() { return typeName; } 73 public void setTypeName(GenTypeName _typeName) { 74 if (_typeName != null) _typeName.setParent(this); 75 typeName = _typeName; 76 } 77 78 public WithinPcd(SourceLocation location, GenTypeName _typeName) { 79 super(location); 80 setTypeName(_typeName); 81 } 82 protected WithinPcd(SourceLocation source) { 83 super(source); 84 } 85 86 public ASTObject copyWalk(CopyWalker walker) { 87 WithinPcd ret = new WithinPcd(getSourceLocation()); 88 ret.preCopy(walker, this); 89 if (typeName != null) ret.setTypeName( (GenTypeName)walker.process(typeName) ); 90 return ret; 91 } 92 93 public ASTObject getChildAt(int childIndex) { 94 switch(childIndex) { 95 case 0: return typeName; 96 default: return super.getChildAt(childIndex); 97 } 98 } 99 public String getChildNameAt(int childIndex) { 100 switch(childIndex) { 101 case 0: return "typeName"; 102 default: return super.getChildNameAt(childIndex); 103 } 104 } 105 public void setChildAt(int childIndex, ASTObject child) { 106 switch(childIndex) { 107 case 0: setTypeName((GenTypeName)child); return; 108 default: super.setChildAt(childIndex, child); return; 109 } 110 } 111 public int getChildCount() { 112 return 1; 113 } 114 115 public String getDefaultDisplayName() { 116 return "WithinPcd()"; 117 } 118 119 } 121 122 | Popular Tags |