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.*; 29 import org.aspectj.compiler.crosscuts.joinpoints.*; 30 import org.aspectj.compiler.base.cst.*; 31 32 import java.util.*; 33 34 39 public class AspectDec extends ClassDec { 40 public String getKind() { return "aspect"; } 41 42 public Type getSuperClassType() { 43 return super.getSuperClassType(); 45 } 46 47 public PerClause findPerClause() { return getPerClause(); } 48 49 public AspectDec getParentAspect() { 50 Type superType = getSuperClassType(); 51 if (superType.isAspect()) return (AspectDec)((NameType)superType).getTypeDec(); 52 return null; 53 } 54 55 public void checkSpec() { 56 super.checkSpec(); 57 if (getType().isSubtypeOf(getTypeManager().getSerializableType()) && 58 !getOptions().XserializableAspects) { 59 showError("aspects may not implement java.io.Serializable"); 60 } 61 if (getType().isSubtypeOf(getTypeManager().getCloneableType())) { 62 showError("aspects may not implement java.lang.Cloneable"); 63 } 64 65 if (isInnerType() && !isStatic()) { 66 showError("inner aspects must be static"); 67 } 68 } 69 70 71 protected boolean explicitDominates(AspectDec otherAspect) { 72 if (dominates == null) { 73 if (getParentAspect() != null) { 74 return getParentAspect().explicitDominates(otherAspect); 75 } else { 76 return false; 77 } 78 } 79 return dominates.matches(otherAspect.getType()); 80 } 81 82 public boolean dominates(AspectDec otherAspect) { 83 if (otherAspect == this) return false; 84 85 if (explicitDominates(otherAspect)) return true; 86 if (otherAspect.explicitDominates(this)) return false; 87 88 if (getType().isStrictSubtypeOf(otherAspect.getType())) return true; 89 return false; 91 } 92 93 public boolean hasAdvicesOrIntroductions() { 94 return true; 95 } 96 97 protected void maybeShowWarning(Dec dec) { } 98 99 public List getIntroductions() { 100 return introductions; 101 } 102 103 List introductions = new LinkedList(); 104 public void addDec(Dec dec) { 105 if (dec instanceof AdviceDec) { 106 return; 107 } else if (dec instanceof IntroducedDec) { 108 introductions.add(dec); 109 } else if (dec instanceof ShowErrorDec) { 110 return; 111 } else if (dec instanceof SoftThrowableDec) { 112 return; 113 } else if (dec instanceof IntroducedSuperDec) { 114 introductions.add(dec); 115 } else { 116 super.addDec(dec); 117 } 118 } 119 120 121 public void postIntroductionFinish() { 122 super.postIntroductionFinish(); 123 124 if (perClause == null) { 125 if (getParentAspect() == null) { 126 setPerClause(new PerSingleton(getSourceLocation())); 127 } else { 128 setPerClause((PerClause)getParentAspect().getPerClause().copy()); 129 } 130 } 131 132 if (getParentAspect() != null && !getParentAspect().isAbstract()) { 133 superClass.showError("can only extend abstract aspects, not " 134 + getParentAspect().getType().getString()); 135 return; 136 } 137 138 139 if (!isAbstract()) { 140 getPerClause().setupAspect(); 141 } 142 } 143 144 private Map extraPlanners = new HashMap(); 145 public Map getExtraPlanners() { return extraPlanners; } 146 147 protected void walkExtendsAndImplements(ScopeWalker walker) { 148 if (perClause instanceof PerThisOrTarget) { 150 getModifiers().setPublic(true); 151 } 152 153 if (dominates != null) walker.process(dominates); 154 super.walkExtendsAndImplements(walker); 155 } 156 157 protected void walkBody(ScopeWalker walker) { 158 if (perClause != null) walker.process(perClause); 159 super.walkBody(walker); 160 } 161 162 public void addConstructorDec(ConstructorDec constructorDec) { 163 if (constructorDec.getFormals().size() != 0) { 164 constructorDec.showError("only 0-argument constructors allowed in an aspect"); 165 return; 166 } 167 super.addConstructorDec(constructorDec); 168 } 169 170 171 172 173 protected List myJpPlannerMakers = null; 174 public List getJpPlannerMakers() { 175 if (myJpPlannerMakers != null) return myJpPlannerMakers; 176 177 List ret = new LinkedList(); 178 final int N = getBody().size(); 179 for (int i = 0; i < N; i++) { 180 Dec dec = getBody().get(i); 181 if (dec instanceof JpPlannerMaker) { 182 ret.add(dec); 183 } 184 } 185 186 AspectDec parentAspect = getParentAspect(); 187 if (parentAspect != null) { 188 if (!parentAspect.isAbstract()) { 189 showError("only abstract aspects can be extended, " + parentAspect.toShortString() + " is not abstract"); 190 } 191 192 ret.addAll(parentAspect.getJpPlannerMakers()); 193 } 194 195 myJpPlannerMakers = ret; 196 return ret; 197 } 198 199 200 245 246 249 251 public boolean isInner() { return false; } 252 253 protected GenTypeName dominates; 255 public GenTypeName getDominates() { return dominates; } 256 public void setDominates(GenTypeName _dominates) { 257 if (_dominates != null) _dominates.setParent(this); 258 dominates = _dominates; 259 } 260 261 protected PerClause perClause; 262 public PerClause getPerClause() { return perClause; } 263 public void setPerClause(PerClause _perClause) { 264 if (_perClause != null) _perClause.setParent(this); 265 perClause = _perClause; 266 } 267 268 public AspectDec(SourceLocation location, Modifiers _modifiers, String _id, TypeD _superClass, TypeDs _superInterfaces, GenTypeName _dominates, PerClause _perClause, Decs _body) { 269 super(location, _modifiers, _id, _superClass, _superInterfaces, _body); 270 setDominates(_dominates); 271 setPerClause(_perClause); 272 } 273 protected AspectDec(SourceLocation source) { 274 super(source); 275 } 276 277 public ASTObject copyWalk(CopyWalker walker) { 278 AspectDec ret = new AspectDec(getSourceLocation()); 279 ret.preCopy(walker, this); 280 if (modifiers != null) ret.setModifiers( (Modifiers)walker.process(modifiers) ); 281 ret.id = id; 282 if (superClass != null) ret.setSuperClass( (TypeD)walker.process(superClass) ); 283 if (superInterfaces != null) ret.setSuperInterfaces( (TypeDs)walker.process(superInterfaces) ); 284 if (dominates != null) ret.setDominates( (GenTypeName)walker.process(dominates) ); 285 if (perClause != null) ret.setPerClause( (PerClause)walker.process(perClause) ); 286 if (body != null) ret.setBody( (Decs)walker.process(body) ); 287 return ret; 288 } 289 290 public ASTObject getChildAt(int childIndex) { 291 switch(childIndex) { 292 case 0: return modifiers; 293 case 1: return superClass; 294 case 2: return superInterfaces; 295 case 3: return dominates; 296 case 4: return perClause; 297 case 5: return body; 298 default: return super.getChildAt(childIndex); 299 } 300 } 301 public String getChildNameAt(int childIndex) { 302 switch(childIndex) { 303 case 0: return "modifiers"; 304 case 1: return "superClass"; 305 case 2: return "superInterfaces"; 306 case 3: return "dominates"; 307 case 4: return "perClause"; 308 case 5: return "body"; 309 default: return super.getChildNameAt(childIndex); 310 } 311 } 312 public void setChildAt(int childIndex, ASTObject child) { 313 switch(childIndex) { 314 case 0: setModifiers((Modifiers)child); return; 315 case 1: setSuperClass((TypeD)child); return; 316 case 2: setSuperInterfaces((TypeDs)child); return; 317 case 3: setDominates((GenTypeName)child); return; 318 case 4: setPerClause((PerClause)child); return; 319 case 5: setBody((Decs)child); return; 320 default: super.setChildAt(childIndex, child); return; 321 } 322 } 323 public int getChildCount() { 324 return 6; 325 } 326 327 public String getDefaultDisplayName() { 328 return "AspectDec(id: "+id+")"; 329 } 330 331 } 333 334 | Popular Tags |