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 WithinCodePcd extends Pcd { 39 public String toShortString() { 40 return "withincode(" + getCodePattern().toShortString() + ")"; 41 } 42 public void checkStatic() { } 43 44 47 private CodeDec matchingEnclosingCodeDec(CodeDec codeDec) { 48 while (codeDec != null) { 49 JoinPoint jp; 51 if (codeDec instanceof ConstructorDec) { 52 jp = new ConstructorExecutionJp((ConstructorDec)codeDec); 53 } else if (codeDec instanceof MethodDec) { 54 jp = new MethodExecutionJp((MethodDec)codeDec); 55 } else { 56 return null; 58 } 59 60 61 if (getCodePattern().matches(jp).alwaysTrue()) return codeDec; 62 63 if (!codeDec.getDeclaringType().getTypeDec().isLocal()) break; 64 codeDec = codeDec.getEnclosingCodeDec(); 65 } 66 67 return null; 68 } 69 70 71 public JpPlanner makePlanner(PlanData planData) { 72 return new JpPlanner() { 73 public FuzzyBoolean fastMatch(JoinPoint jp) { 74 ASTObject sourceLocation = jp.getSourceLocation(); 75 if (sourceLocation == null) return FuzzyBoolean.NEVER; 76 77 CodeDec codeDec; 78 if (sourceLocation instanceof CodeDec) { 79 codeDec = (CodeDec)sourceLocation; 80 } else { 81 codeDec = sourceLocation.getEnclosingCodeDec(); 82 } 83 if (codeDec == null) return FuzzyBoolean.NO; 84 85 codeDec = matchingEnclosingCodeDec(codeDec); 86 if (codeDec == null) return FuzzyBoolean.NO; 87 else return FuzzyBoolean.YES; 88 } 89 }; 90 } 91 92 protected CodePattern codePattern; 94 public CodePattern getCodePattern() { return codePattern; } 95 public void setCodePattern(CodePattern _codePattern) { 96 if (_codePattern != null) _codePattern.setParent(this); 97 codePattern = _codePattern; 98 } 99 100 public WithinCodePcd(SourceLocation location, CodePattern _codePattern) { 101 super(location); 102 setCodePattern(_codePattern); 103 } 104 protected WithinCodePcd(SourceLocation source) { 105 super(source); 106 } 107 108 public ASTObject copyWalk(CopyWalker walker) { 109 WithinCodePcd ret = new WithinCodePcd(getSourceLocation()); 110 ret.preCopy(walker, this); 111 if (codePattern != null) ret.setCodePattern( (CodePattern)walker.process(codePattern) ); 112 return ret; 113 } 114 115 public ASTObject getChildAt(int childIndex) { 116 switch(childIndex) { 117 case 0: return codePattern; 118 default: return super.getChildAt(childIndex); 119 } 120 } 121 public String getChildNameAt(int childIndex) { 122 switch(childIndex) { 123 case 0: return "codePattern"; 124 default: return super.getChildNameAt(childIndex); 125 } 126 } 127 public void setChildAt(int childIndex, ASTObject child) { 128 switch(childIndex) { 129 case 0: setCodePattern((CodePattern)child); return; 130 default: super.setChildAt(childIndex, child); return; 131 } 132 } 133 public int getChildCount() { 134 return 1; 135 } 136 137 public String getDefaultDisplayName() { 138 return "WithinCodePcd()"; 139 } 140 141 } 143 144 | Popular Tags |