1 22 package org.aspectj.tools.ajdoc; 23 24 import org.aspectj.ajdoc.AdviceDoc; 25 import org.aspectj.ajdoc.AspectDoc; 26 import org.aspectj.ajdoc.IntroductionDoc; 27 import org.aspectj.ajdoc.OfClauseDoc; 28 import org.aspectj.compiler.base.ast.Decs; 29 import org.aspectj.compiler.crosscuts.ast.AdviceDec; 30 import org.aspectj.compiler.crosscuts.ast.AspectDec; 31 import org.aspectj.compiler.crosscuts.ast.IntroducedSuperDec; 32 33 import com.sun.javadoc.ClassDoc; 34 35 import java.util.ArrayList ; 36 import java.util.Collection ; 37 import java.util.Collections ; 38 import java.util.HashSet ; 39 import java.util.Iterator ; 40 import java.util.List ; 41 42 public class AspectDocImpl extends ClassDocImpl implements AspectDoc { 43 44 45 private final Collection advice; 46 47 48 private final Collection introductions; 49 50 51 private final OfClauseDoc ofClause; 52 53 54 private final Collection dominators = new ArrayList (); 55 56 57 private final Collection dominatees = new ArrayList (); 58 59 66 public AspectDocImpl(ClassDoc containingClass, AspectDec aspectDec) { 67 super(containingClass, aspectDec); 68 introductions = createIntroductions(); 69 advice = createAdvice(); 70 ofClause = createOfClause(); 71 } 72 73 82 public AdviceDocImpl docForDec(AdviceDec dec) { 83 for (Iterator i = advice.iterator(); i.hasNext();) { 84 AdviceDocImpl ad = (AdviceDocImpl)i.next(); 85 if (ad.dec() == dec) return ad; 86 } 87 return null; 88 } 89 90 100 public IntroducedSuperDocImpl introDocForDec(IntroducedSuperDec dec) { 101 for (Iterator i = introductions.iterator(); i.hasNext();) { 102 ProgramElementDocImpl id = (ProgramElementDocImpl)i.next(); 103 if (id.dec() == dec) return (IntroducedSuperDocImpl)id; 104 } 105 return null; 106 } 107 108 113 protected AspectDec aspectDec() { 114 return (AspectDec)typeDec(); 115 } 116 117 123 public AdviceDoc[] advice() { 124 return (AdviceDocImpl[])advice.toArray 125 (new AdviceDocImpl[advice.size()]); 126 } 127 128 134 public AspectDoc[] dominatees() { 135 return (AspectDoc[])dominatees.toArray 136 (new AspectDoc[dominatees.size()]); 137 } 138 139 145 public AspectDoc[] dominators() { 146 return (AspectDoc[])dominators.toArray 147 (new AspectDoc[dominators.size()]); 148 } 149 150 157 public IntroductionDoc[] introductions() { 158 return (IntroductionDocImpl[])introductions.toArray 159 (new IntroductionDocImpl[introductions.size()]); 160 } 161 162 167 public OfClauseDoc ofClause() { 168 return ofClause; 169 } 170 171 176 public boolean isAspect() { 177 return true; 178 } 179 180 189 public boolean dominates(AspectDoc other) { 190 if (!(other instanceof AspectDocImpl)) { 191 return false; 192 } 193 return aspectDec().dominates(((AspectDocImpl)other).aspectDec()); 194 } 195 196 208 public void addDominator(AspectDoc dominator) { 209 dominators.add(dominator); 210 } 211 212 224 public void addDominatee(AspectDoc dominatee) { 225 dominatees.add(dominatee); 226 } 227 228 235 private Collection createIntroductions() { 236 Decs decs = aspectDec().getBody(); 237 if (decs.size() < 1) return Collections.EMPTY_LIST; 238 Collection list = new HashSet (); 239 for (Iterator i = decs.getList().iterator(); i.hasNext();) { 240 Object o = IntroductionDocImpl.getInstance(this, i.next()); 241 if (o != null) list.add(o); 242 } 243 return list; 244 } 245 246 253 private Collection createAdvice() { 254 List decs = aspectDec().getJpPlannerMakers(); 256 if (null != decs) { 257 final int QUIT = 2; 258 for (int tries = 0; tries < QUIT; tries++) { 259 try { 260 for (Iterator i = decs.iterator(); i.hasNext();) { 261 Object o = i.next(); 262 if (!(o instanceof AdviceDec)) { 263 i.remove(); 264 } 265 } 266 tries = QUIT; 267 } catch (UnsupportedOperationException o) { 268 if (0 != tries) { 269 tries = QUIT; 270 } else { 271 ArrayList list = new ArrayList (); 272 list.addAll(decs); 273 decs = list; 274 } 275 } 276 } 277 } 278 279 if ((null == decs) || (decs.size() < 1)) { 280 return Collections.EMPTY_LIST; 281 } 282 283 List list = new ArrayList (); 284 for (Iterator i = decs.iterator(); i.hasNext();) { 285 list.add(new AdviceDocImpl(this, (AdviceDec)i.next())); 286 } 287 return list; 288 } 289 290 297 private OfClauseDoc createOfClause() { 298 return OfClauseDocImpl.getInstance(aspectDec().getPerClause()); 299 } 300 } 301 | Popular Tags |