1 24 25 package org.aspectj.compiler.crosscuts.ast; 26 27 import org.aspectj.compiler.base.ast.*; 28 import org.aspectj.compiler.base.cst.*; 29 30 import java.util.*; 31 32 import org.aspectj.compiler.base.*; 33 34 42 43 public class PointcutDec extends Dec { 44 47 public void walkInnerInfo(InnerInfoPass w) { 48 int context = w.inMember(true); 49 super.walkInnerInfo(w); 50 w.restoreContext(context); 51 } 52 53 public ASTObject postFixAST(final ASTFixerPass fixer) { 55 return null; 56 } 57 58 public void checkSpec() { 59 if (isStatic()) { 60 getCompiler().warnVersion("1.0beta1", this, 61 "pointcut declarations may not be static"); 62 } 63 64 if (resultTypeD != null) { 65 getCompiler().warnVersion("1.0beta1", this, 66 "pointcut declarations don't use returns clause"); 67 } 68 69 if (isAbstract()) { 70 if (isPrivate()) { 71 showError("abstract private pointcut can never be implemented"); 72 } 73 } 74 75 if (!isAbstract() && !(pcd == null || pcd instanceof EmptyPcd)) { 79 for (int i=0; i<formals.size(); i++) { 80 if (!formals.get(i).isBound) { 81 formals.get(i).showError("not bound in this PCD"); 83 } 84 } 85 } 86 } 87 88 public void preScope(ScopeWalker walker) { 90 walker.pushScope(makeBlockScope(walker)); 91 } 93 public ASTObject postScope(ScopeWalker walker) { walker.popScope(); return this; } 94 95 public String toShortString() { 96 return modifiers.toShortString() + " " + 97 getDeclaringType().toShortString() + "." + id + 98 formals.toShortString(); 99 } 100 101 public String getKind() { return "pointcut"; } 102 103 public SemanticObject makeCorrespondingSemanticObject() { 104 return new PointcutSO(this); 105 } 106 107 public boolean isAbstract(PlanData planData) { 108 if (pcd == null || pcd instanceof EmptyPcd) return true; 109 return false; } 111 112 public boolean conflictsWith(Dec otherDec) { 113 if (!getId().equals(otherDec.getId())) return false; 115 if (!this.isAccessible(otherDec) && !otherDec.isAccessible(this)) return false; 116 117 return true; 118 } 119 120 121 void showOverrideError(Dec other, String message) { 122 String overrideKind = "override"; 123 showError(toShortString() + " cannot " + overrideKind + " " + 124 other.toShortString() + "; " + message); 125 } 126 127 public boolean checkOverride(Type inType, Dec otherDec) { 128 PointcutDec other = (PointcutDec)otherDec; 129 if (other.getModifiers().isFinal()) { 130 showOverrideError(other, "overridden pointcut is final"); 131 } else if (getModifiers().isWeakerThan(other.getModifiers())) { 132 showOverrideError(other, 133 "attempting to assign weaker access privileges; was " + 134 other.getModifiers().toShortString()); 135 } else if (!getFormals().matches(other.getFormals())) { 136 showOverrideError(other, 137 "signatures must match exactly; expected " 138 + other.getFormals().toShortString()); 139 } 140 return false; 141 } 142 143 160 161 protected Modifiers modifiers; 163 public Modifiers getModifiers() { return modifiers; } 164 public void setModifiers(Modifiers _modifiers) { 165 if (_modifiers != null) _modifiers.setParent(this); 166 modifiers = _modifiers; 167 } 168 169 protected String id; 170 public String getId() { return id; } 171 public void setId(String _id) { id = _id; } 172 173 protected TypeD resultTypeD; 174 public TypeD getResultTypeD() { return resultTypeD; } 175 public void setResultTypeD(TypeD _resultTypeD) { 176 if (_resultTypeD != null) _resultTypeD.setParent(this); 177 resultTypeD = _resultTypeD; 178 } 179 180 protected Formals formals; 181 public Formals getFormals() { return formals; } 182 public void setFormals(Formals _formals) { 183 if (_formals != null) _formals.setParent(this); 184 formals = _formals; 185 } 186 187 protected Pcd pcd; 188 public Pcd getPcd() { return pcd; } 189 public void setPcd(Pcd _pcd) { 190 if (_pcd != null) _pcd.setParent(this); 191 pcd = _pcd; 192 } 193 194 public PointcutDec(SourceLocation location, Modifiers _modifiers, String _id, TypeD _resultTypeD, Formals _formals, Pcd _pcd) { 195 super(location); 196 setModifiers(_modifiers); 197 setId(_id); 198 setResultTypeD(_resultTypeD); 199 setFormals(_formals); 200 setPcd(_pcd); 201 } 202 protected PointcutDec(SourceLocation source) { 203 super(source); 204 } 205 206 public ASTObject copyWalk(CopyWalker walker) { 207 PointcutDec ret = new PointcutDec(getSourceLocation()); 208 ret.preCopy(walker, this); 209 if (modifiers != null) ret.setModifiers( (Modifiers)walker.process(modifiers) ); 210 ret.id = id; 211 if (resultTypeD != null) ret.setResultTypeD( (TypeD)walker.process(resultTypeD) ); 212 if (formals != null) ret.setFormals( (Formals)walker.process(formals) ); 213 if (pcd != null) ret.setPcd( (Pcd)walker.process(pcd) ); 214 return ret; 215 } 216 217 public ASTObject getChildAt(int childIndex) { 218 switch(childIndex) { 219 case 0: return modifiers; 220 case 1: return resultTypeD; 221 case 2: return formals; 222 case 3: return pcd; 223 default: return super.getChildAt(childIndex); 224 } 225 } 226 public String getChildNameAt(int childIndex) { 227 switch(childIndex) { 228 case 0: return "modifiers"; 229 case 1: return "resultTypeD"; 230 case 2: return "formals"; 231 case 3: return "pcd"; 232 default: return super.getChildNameAt(childIndex); 233 } 234 } 235 public void setChildAt(int childIndex, ASTObject child) { 236 switch(childIndex) { 237 case 0: setModifiers((Modifiers)child); return; 238 case 1: setResultTypeD((TypeD)child); return; 239 case 2: setFormals((Formals)child); return; 240 case 3: setPcd((Pcd)child); return; 241 default: super.setChildAt(childIndex, child); return; 242 } 243 } 244 public int getChildCount() { 245 return 4; 246 } 247 248 public String getDefaultDisplayName() { 249 return "PointcutDec(id: "+id+")"; 250 } 251 252 } 254 | Popular Tags |