1 22 package org.aspectj.tools.ajdoc; 23 24 import org.aspectj.compiler.base.ast.TypeDec; 25 import org.aspectj.compiler.base.ast.World; 26 27 import com.sun.javadoc.ClassDoc; 28 import com.sun.javadoc.PackageDoc; 29 30 import java.util.ArrayList ; 31 import java.util.Collection ; 32 import java.util.Collections ; 33 import java.util.HashSet ; 34 import java.util.Iterator ; 35 import java.util.List ; 36 import java.util.Set ; 37 38 44 public class RootDocImpl 45 extends DocImpl 46 implements org.aspectj.ajdoc.RootDoc, 47 Quietable { 48 49 50 private final Set specifiedPackages; 51 52 53 private final Set specifiedClasses; 54 55 56 private final Set packages = new HashSet (); 57 58 59 private final Set classes = new HashSet (); 60 61 62 private final String [][] options; 63 64 65 private final World world; 66 67 68 private final AccessChecker filter; 69 70 public RootDocImpl(World world, String [][] options, 71 Collection pkgnames, Collection classnames, 72 AccessChecker filter) { 73 this.world = world; 74 this.options = options; 75 this.filter = (null != filter ? filter : AccessChecker.PUBLIC); 76 Set set = createSpecifiedPackages(pkgnames); 77 specifiedPackages = set; set = createSpecifiedClasses(classnames); 79 specifiedClasses = Collections.unmodifiableSet(set); 80 addSpecifiedPackages(); 85 addSpecifiedClasses(); 86 setupDominatesRelations(); 87 ensureWorldInclusion(); 88 } 89 93 94 100 public ClassDoc[] classes() { 101 return (ClassDoc[])classes.toArray 102 (new org.aspectj.ajdoc.ClassDoc[classes.size()]); 103 } 104 105 116 public ClassDoc classNamed(String className) { 117 ClassDoc[] docs = classes(); 118 for (int i = 0; i < docs.length; i++) { 119 ClassDoc doc = docs[i]; 120 if (doc.name().equals(className)) { 121 return doc; 122 } 123 } 124 return null; 125 } 126 127 138 public PackageDoc packageNamed(String packageName) { 139 for (Iterator i = packages.iterator(); i.hasNext();) { 140 PackageDoc doc = (PackageDoc)i.next(); 141 if (doc.name().equals(packageName)) { 142 return doc; 143 } 144 } 145 return null; 146 } 147 148 154 public World world() { 155 return world; 156 } 157 158 163 public String [][] options() { 164 return options; 165 } 166 167 173 public ClassDoc[] specifiedClasses() { 174 return (ClassDoc[])specifiedClasses.toArray 175 (new org.aspectj.ajdoc.ClassDoc[specifiedClasses.size()]); 176 } 177 178 184 public PackageDoc[] specifiedPackages() { 185 return (PackageDoc[])specifiedPackages.toArray 186 (new org.aspectj.ajdoc.PackageDoc[specifiedPackages.size()]); 187 } 188 189 190 194 195 196 private boolean notice = true; 197 198 199 public void quiet() { notice = false; } 200 201 202 public void speak() { notice = true; } 203 204 205 209 210 216 public void printError(String msg) { 217 err().printError(msg); 218 } 219 220 226 public void printNotice(String msg) { 227 if (notice) err().printNotice(msg); 228 } 229 230 236 public void printWarning(String msg) { 237 err().printWarning(msg); 238 } 239 240 241 245 246 251 public String name() { 252 return "who knows???"; 253 } 254 255 256 260 261 266 private HashSet createSpecifiedPackages(Collection pkgnames) { 267 HashSet result = new HashSet (); 268 for (Iterator i = pkgnames.iterator(); i.hasNext();) { 269 String pkgname = (String )i.next(); 270 PackageDocImpl pkgdoc = PackageDocImpl.getPackageDoc(pkgname); 271 pkgdoc.setIncluded(true); 272 result.add(pkgdoc); 273 } 274 return result; 275 } 276 private void addWorldTypes() { 277 for (Iterator i = world.getTypes().iterator(); i.hasNext();) { 278 TypeDec td = (TypeDec)i.next(); 279 ClassDocImpl cd = ClassDocImpl.getInstance(td); 280 addClass(cd); 281 cd.setIncluded(filter.canAccess(td)); 282 } 283 } 284 285 291 private HashSet createSpecifiedClasses(Collection classnames) { 292 HashSet result = new HashSet (); 293 if (classnames != null) { 294 for (Iterator i = classnames.iterator(); i.hasNext();) { 295 String classname = (String )i.next(); 296 for (Iterator j = world.getTypes().iterator(); j.hasNext();) { 297 TypeDec td = (TypeDec)j.next(); 298 if (filter.canAccess(td)) { 299 ClassDoc cd = ClassDocImpl.getInstance(td); 300 if (cd.qualifiedName().equals(classname)) { 301 result.add(cd); 302 ClassDoc[] inners = cd.innerClasses(); if (null != inners) { 305 for (int l = 0; l < inners.length; l++) { 306 result.add(inners[l]); 307 } 308 } 309 break; 310 } 311 } 312 } 313 } 315 } 316 return result; 317 } 318 319 private void addSpecifiedClasses() { 320 for (Iterator i = new ArrayList (specifiedClasses).iterator(); i.hasNext();) { 321 ClassDoc cd = (ClassDoc)i.next(); 322 addClass(cd); 323 } 324 } 325 326 private void addSpecifiedPackages() { 327 for (Iterator i = new ArrayList (specifiedPackages).iterator(); i.hasNext();) { 328 PackageDoc pd = (PackageDoc)i.next(); 329 ClassDoc[] allClasses = pd.allClasses(); 330 if (allClasses.length == 0) { 331 specifiedPackages.remove(pd); 332 } else { 333 for (int j = 0; j < allClasses.length; j++) { 334 addClass(allClasses[j]); 335 } 336 } 337 } 338 } 339 340 345 private void addClass(ClassDoc cd) { 346 if (null == cd) return; 347 ClassDocImpl impl = (ClassDocImpl) cd; 348 if (filter.canAccess(impl.typeDec()) 349 && (!classes.contains(impl))) { 350 impl.setIncluded(true); 351 classes.add(impl); 352 packages.add(impl.containingPackage()); 353 ClassDoc[] inners = impl.innerClasses(); 354 for (int i = 0; i < inners.length; i++) { 355 addClass(inners[i]); 356 } 357 } } 359 360 361 private void setupDominatesRelations() { 362 List aspects = new ArrayList (); 364 ClassDoc[] classes = classes(); 365 for (int i = 0; i < classes.length; i++) { 366 ClassDocImpl cd = (ClassDocImpl)classes[i]; 367 if (cd.isAspect()) { 368 aspects.add(cd); 369 } 370 } 371 372 for (Iterator i = aspects.iterator(); i.hasNext();) { 374 AspectDocImpl aspect1 = (AspectDocImpl)i.next(); 375 for (Iterator j = aspects.iterator(); j.hasNext();) { 376 AspectDocImpl aspect2 = (AspectDocImpl)j.next(); 377 if (aspect1.dominates(aspect2)) { 378 aspect1.addDominatee(aspect2); 379 aspect2.addDominator(aspect1); 380 } 381 } 382 } 383 } 384 385 392 private void ensureWorldInclusion() { 393 for (Iterator i = world.getTypes().iterator(); i.hasNext();) { 394 TypeDec td = (TypeDec)i.next(); 395 ClassDocImpl cd = ClassDocImpl.getInstance(td); 396 boolean isIncluded = cd.isIncluded(); 397 boolean shouldInclude = filter.canAccess(td); 399 if (shouldInclude != isIncluded) { 400 cd.setIncluded(shouldInclude); 401 } 402 } 403 } 404 } 405 | Popular Tags |