src/share/classes/com/sun/tools/doclets/internal/toolkit/util/ClassUseMapper.java

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 1985
0e6577980181
parent 0
959103a6100f
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.doclets.internal.toolkit.util;
aoqi@0 27
aoqi@0 28 import java.util.*;
aoqi@0 29
aoqi@0 30 import com.sun.javadoc.*;
aoqi@0 31
aoqi@0 32 /**
aoqi@0 33 * Map all class uses for a given class.
aoqi@0 34 *
aoqi@0 35 * <p><b>This is NOT part of any supported API.
aoqi@0 36 * If you write code that depends on this, you do so at your own risk.
aoqi@0 37 * This code and its internal interfaces are subject to change or
aoqi@0 38 * deletion without notice.</b>
aoqi@0 39 *
aoqi@0 40 * @since 1.2
aoqi@0 41 * @author Robert G. Field
aoqi@0 42 */
aoqi@0 43 public class ClassUseMapper {
aoqi@0 44
aoqi@0 45 private final ClassTree classtree;
aoqi@0 46
aoqi@0 47 /**
aoqi@0 48 * Mapping of ClassDocs to set of PackageDoc used by that class.
aoqi@0 49 * Entries may be null.
aoqi@0 50 */
aoqi@0 51 public Map<String,Set<PackageDoc>> classToPackage = new HashMap<String,Set<PackageDoc>>();
aoqi@0 52
aoqi@0 53 /**
aoqi@0 54 * Mapping of Annotations to set of PackageDoc that use the annotation.
aoqi@0 55 */
aoqi@0 56 public Map<String,List<PackageDoc>> classToPackageAnnotations = new HashMap<String,List<PackageDoc>>();
aoqi@0 57
aoqi@0 58 /**
aoqi@0 59 * Mapping of ClassDocs to set of ClassDoc used by that class.
aoqi@0 60 * Entries may be null.
aoqi@0 61 */
aoqi@0 62 public Map<String,Set<ClassDoc>> classToClass = new HashMap<String,Set<ClassDoc>>();
aoqi@0 63
aoqi@0 64 /**
aoqi@0 65 * Mapping of ClassDocs to list of ClassDoc which are direct or
aoqi@0 66 * indirect subclasses of that class.
aoqi@0 67 * Entries may be null.
aoqi@0 68 */
aoqi@0 69 public Map<String,List<ClassDoc>> classToSubclass = new HashMap<String,List<ClassDoc>>();
aoqi@0 70
aoqi@0 71 /**
aoqi@0 72 * Mapping of ClassDocs to list of ClassDoc which are direct or
aoqi@0 73 * indirect subinterfaces of that interface.
aoqi@0 74 * Entries may be null.
aoqi@0 75 */
aoqi@0 76 public Map<String,List<ClassDoc>> classToSubinterface = new HashMap<String,List<ClassDoc>>();
aoqi@0 77
aoqi@0 78 /**
aoqi@0 79 * Mapping of ClassDocs to list of ClassDoc which implement
aoqi@0 80 * this interface.
aoqi@0 81 * Entries may be null.
aoqi@0 82 */
aoqi@0 83 public Map<String,List<ClassDoc>> classToImplementingClass = new HashMap<String,List<ClassDoc>>();
aoqi@0 84
aoqi@0 85 /**
aoqi@0 86 * Mapping of ClassDocs to list of FieldDoc declared as that class.
aoqi@0 87 * Entries may be null.
aoqi@0 88 */
aoqi@0 89 public Map<String,List<FieldDoc>> classToField = new HashMap<String,List<FieldDoc>>();
aoqi@0 90
aoqi@0 91 /**
aoqi@0 92 * Mapping of ClassDocs to list of MethodDoc returning that class.
aoqi@0 93 * Entries may be null.
aoqi@0 94 */
aoqi@0 95 public Map<String,List<MethodDoc>> classToMethodReturn = new HashMap<String,List<MethodDoc>>();
aoqi@0 96
aoqi@0 97 /**
aoqi@0 98 * Mapping of ClassDocs to list of MethodDoc having that class
aoqi@0 99 * as an arg.
aoqi@0 100 * Entries may be null.
aoqi@0 101 */
aoqi@0 102 public Map<String,List<ExecutableMemberDoc>> classToMethodArgs = new HashMap<String,List<ExecutableMemberDoc>>();
aoqi@0 103
aoqi@0 104 /**
aoqi@0 105 * Mapping of ClassDocs to list of MethodDoc which throws that class.
aoqi@0 106 * Entries may be null.
aoqi@0 107 */
aoqi@0 108 public Map<String,List<ExecutableMemberDoc>> classToMethodThrows = new HashMap<String,List<ExecutableMemberDoc>>();
aoqi@0 109
aoqi@0 110 /**
aoqi@0 111 * Mapping of ClassDocs to list of ConstructorDoc having that class
aoqi@0 112 * as an arg.
aoqi@0 113 * Entries may be null.
aoqi@0 114 */
aoqi@0 115 public Map<String,List<ExecutableMemberDoc>> classToConstructorArgs = new HashMap<String,List<ExecutableMemberDoc>>();
aoqi@0 116
aoqi@0 117 /**
aoqi@0 118 * Mapping of ClassDocs to list of ConstructorDoc which throws that class.
aoqi@0 119 * Entries may be null.
aoqi@0 120 */
aoqi@0 121 public Map<String,List<ExecutableMemberDoc>> classToConstructorThrows = new HashMap<String,List<ExecutableMemberDoc>>();
aoqi@0 122
aoqi@0 123 /**
aoqi@0 124 * The mapping of AnnotationTypeDocs to constructors that use them.
aoqi@0 125 */
aoqi@0 126 public Map<String,List<ConstructorDoc>> classToConstructorAnnotations = new HashMap<String,List<ConstructorDoc>>();
aoqi@0 127
aoqi@0 128 /**
aoqi@0 129 * The mapping of AnnotationTypeDocs to Constructor parameters that use them.
aoqi@0 130 */
aoqi@0 131 public Map<String,List<ExecutableMemberDoc>> classToConstructorParamAnnotation = new HashMap<String,List<ExecutableMemberDoc>>();
aoqi@0 132
aoqi@0 133 /**
aoqi@0 134 * The mapping of ClassDocs to Constructor arguments that use them as type parameters.
aoqi@0 135 */
aoqi@0 136 public Map<String,List<ExecutableMemberDoc>> classToConstructorDocArgTypeParam = new HashMap<String,List<ExecutableMemberDoc>>();
aoqi@0 137
aoqi@0 138 /**
aoqi@0 139 * The mapping of ClassDocs to ClassDocs that use them as type parameters.
aoqi@0 140 */
aoqi@0 141 public Map<String,List<ClassDoc>> classToClassTypeParam = new HashMap<String,List<ClassDoc>>();
aoqi@0 142
aoqi@0 143 /**
aoqi@0 144 * The mapping of AnnotationTypeDocs to ClassDocs that use them.
aoqi@0 145 */
aoqi@0 146 public Map<String,List<ClassDoc>> classToClassAnnotations = new HashMap<String,List<ClassDoc>>();
aoqi@0 147
aoqi@0 148 /**
aoqi@0 149 * The mapping of ClassDocs to ExecutableMemberDocs that use them as type parameters.
aoqi@0 150 */
aoqi@0 151 public Map<String,List<MethodDoc>> classToExecMemberDocTypeParam = new HashMap<String,List<MethodDoc>>();
aoqi@0 152
aoqi@0 153 /**
aoqi@0 154 * The mapping of ClassDocs to ExecutableMemberDocs arguments that use them as type parameters.
aoqi@0 155 */
aoqi@0 156 public Map<String,List<ExecutableMemberDoc>> classToExecMemberDocArgTypeParam = new HashMap<String,List<ExecutableMemberDoc>>();
aoqi@0 157
aoqi@0 158 /**
aoqi@0 159 * The mapping of AnnotationTypeDocs to ExecutableMemberDocs that use them.
aoqi@0 160 */
aoqi@0 161 public Map<String,List<MethodDoc>> classToExecMemberDocAnnotations = new HashMap<String,List<MethodDoc>>();
aoqi@0 162
aoqi@0 163 /**
aoqi@0 164 * The mapping of ClassDocs to ExecutableMemberDocs that have return type
aoqi@0 165 * with type parameters of that class.
aoqi@0 166 */
aoqi@0 167 public Map<String,List<MethodDoc>> classToExecMemberDocReturnTypeParam = new HashMap<String,List<MethodDoc>>();
aoqi@0 168
aoqi@0 169 /**
aoqi@0 170 * The mapping of AnnotationTypeDocs to MethodDoc parameters that use them.
aoqi@0 171 */
aoqi@0 172 public Map<String,List<ExecutableMemberDoc>> classToExecMemberDocParamAnnotation = new HashMap<String,List<ExecutableMemberDoc>>();
aoqi@0 173
aoqi@0 174 /**
aoqi@0 175 * The mapping of ClassDocs to FieldDocs that use them as type parameters.
aoqi@0 176 */
aoqi@0 177 public Map<String,List<FieldDoc>> classToFieldDocTypeParam = new HashMap<String,List<FieldDoc>>();
aoqi@0 178
aoqi@0 179 /**
aoqi@0 180 * The mapping of AnnotationTypeDocs to FieldDocs that use them.
aoqi@0 181 */
aoqi@0 182 public Map<String,List<FieldDoc>> annotationToFieldDoc = new HashMap<String,List<FieldDoc>>();
aoqi@0 183
aoqi@0 184
aoqi@0 185 public ClassUseMapper(RootDoc root, ClassTree classtree) {
aoqi@0 186 this.classtree = classtree;
aoqi@0 187
aoqi@0 188 // Map subclassing, subinterfacing implementing, ...
aoqi@0 189 for (Iterator<ClassDoc> it = classtree.baseclasses().iterator(); it.hasNext();) {
aoqi@0 190 subclasses(it.next());
aoqi@0 191 }
aoqi@0 192 for (Iterator<ClassDoc> it = classtree.baseinterfaces().iterator(); it.hasNext();) {
aoqi@0 193 // does subinterfacing as side-effect
aoqi@0 194 implementingClasses(it.next());
aoqi@0 195 }
aoqi@0 196 // Map methods, fields, constructors using a class.
aoqi@0 197 ClassDoc[] classes = root.classes();
aoqi@0 198 for (int i = 0; i < classes.length; i++) {
aoqi@0 199 PackageDoc pkg = classes[i].containingPackage();
aoqi@0 200 mapAnnotations(classToPackageAnnotations, pkg, pkg);
aoqi@0 201 ClassDoc cd = classes[i];
aoqi@0 202 mapTypeParameters(classToClassTypeParam, cd, cd);
aoqi@0 203 mapAnnotations(classToClassAnnotations, cd, cd);
aoqi@0 204 FieldDoc[] fields = cd.fields();
aoqi@0 205 for (int j = 0; j < fields.length; j++) {
aoqi@0 206 FieldDoc fd = fields[j];
aoqi@0 207 mapTypeParameters(classToFieldDocTypeParam, fd, fd);
aoqi@0 208 mapAnnotations(annotationToFieldDoc, fd, fd);
aoqi@0 209 if (! fd.type().isPrimitive()) {
aoqi@0 210 add(classToField, fd.type().asClassDoc(), fd);
aoqi@0 211 }
aoqi@0 212 }
aoqi@0 213 ConstructorDoc[] cons = cd.constructors();
aoqi@0 214 for (int j = 0; j < cons.length; j++) {
aoqi@0 215 mapAnnotations(classToConstructorAnnotations, cons[j], cons[j]);
aoqi@0 216 mapExecutable(cons[j]);
aoqi@0 217 }
aoqi@0 218 MethodDoc[] meths = cd.methods();
aoqi@0 219 for (int j = 0; j < meths.length; j++) {
aoqi@0 220 MethodDoc md = meths[j];
aoqi@0 221 mapExecutable(md);
aoqi@0 222 mapTypeParameters(classToExecMemberDocTypeParam, md, md);
aoqi@0 223 mapAnnotations(classToExecMemberDocAnnotations, md, md);
aoqi@0 224 if (! (md.returnType().isPrimitive() || md.returnType() instanceof TypeVariable)) {
aoqi@0 225 mapTypeParameters(classToExecMemberDocReturnTypeParam,
aoqi@0 226 md.returnType(), md);
aoqi@0 227 add(classToMethodReturn, md.returnType().asClassDoc(), md);
aoqi@0 228 }
aoqi@0 229 }
aoqi@0 230 }
aoqi@0 231 }
aoqi@0 232
aoqi@0 233 /**
aoqi@0 234 * Return all subclasses of a class AND fill-in classToSubclass map.
aoqi@0 235 */
aoqi@0 236 private Collection<ClassDoc> subclasses(ClassDoc cd) {
aoqi@0 237 Collection<ClassDoc> ret = classToSubclass.get(cd.qualifiedName());
aoqi@0 238 if (ret == null) {
aoqi@0 239 ret = new TreeSet<ClassDoc>();
aoqi@0 240 List<ClassDoc> subs = classtree.subclasses(cd);
aoqi@0 241 if (subs != null) {
aoqi@0 242 ret.addAll(subs);
aoqi@0 243 for (Iterator<ClassDoc> it = subs.iterator(); it.hasNext();) {
aoqi@0 244 ret.addAll(subclasses(it.next()));
aoqi@0 245 }
aoqi@0 246 }
aoqi@0 247 addAll(classToSubclass, cd, ret);
aoqi@0 248 }
aoqi@0 249 return ret;
aoqi@0 250 }
aoqi@0 251
aoqi@0 252 /**
aoqi@0 253 * Return all subinterfaces of an interface AND fill-in classToSubinterface map.
aoqi@0 254 */
aoqi@0 255 private Collection<ClassDoc> subinterfaces(ClassDoc cd) {
aoqi@0 256 Collection<ClassDoc> ret = classToSubinterface.get(cd.qualifiedName());
aoqi@0 257 if (ret == null) {
aoqi@0 258 ret = new TreeSet<ClassDoc>();
aoqi@0 259 List<ClassDoc> subs = classtree.subinterfaces(cd);
aoqi@0 260 if (subs != null) {
aoqi@0 261 ret.addAll(subs);
aoqi@0 262 for (Iterator<ClassDoc> it = subs.iterator(); it.hasNext();) {
aoqi@0 263 ret.addAll(subinterfaces(it.next()));
aoqi@0 264 }
aoqi@0 265 }
aoqi@0 266 addAll(classToSubinterface, cd, ret);
aoqi@0 267 }
aoqi@0 268 return ret;
aoqi@0 269 }
aoqi@0 270
aoqi@0 271 /**
aoqi@0 272 * Return all implementing classes of an interface (including
aoqi@0 273 * all subclasses of implementing classes and all classes
aoqi@0 274 * implementing subinterfaces) AND fill-in both classToImplementingClass
aoqi@0 275 * and classToSubinterface maps.
aoqi@0 276 */
aoqi@0 277 private Collection<ClassDoc> implementingClasses(ClassDoc cd) {
aoqi@0 278 Collection<ClassDoc> ret = classToImplementingClass.get(cd.qualifiedName());
aoqi@0 279 if (ret == null) {
aoqi@0 280 ret = new TreeSet<ClassDoc>();
aoqi@0 281 List<ClassDoc> impl = classtree.implementingclasses(cd);
aoqi@0 282 if (impl != null) {
aoqi@0 283 ret.addAll(impl);
aoqi@0 284 for (Iterator<ClassDoc> it = impl.iterator(); it.hasNext();) {
aoqi@0 285 ret.addAll(subclasses(it.next()));
aoqi@0 286 }
aoqi@0 287 }
aoqi@0 288 for (Iterator<ClassDoc> it = subinterfaces(cd).iterator(); it.hasNext();) {
aoqi@0 289 ret.addAll(implementingClasses(it.next()));
aoqi@0 290 }
aoqi@0 291 addAll(classToImplementingClass, cd, ret);
aoqi@0 292 }
aoqi@0 293 return ret;
aoqi@0 294 }
aoqi@0 295
aoqi@0 296 /**
aoqi@0 297 * Determine classes used by a method or constructor, so they can be
aoqi@0 298 * inverse mapped.
aoqi@0 299 */
aoqi@0 300 private void mapExecutable(ExecutableMemberDoc em) {
aoqi@0 301 Parameter[] params = em.parameters();
aoqi@0 302 boolean isConstructor = em.isConstructor();
aoqi@0 303 List<Type> classArgs = new ArrayList<Type>();
aoqi@0 304 for (int k = 0; k < params.length; k++) {
aoqi@0 305 Type pcd = params[k].type();
aoqi@0 306 // primitives don't get mapped, also avoid dups
aoqi@0 307 if ((! params[k].type().isPrimitive()) &&
aoqi@0 308 ! classArgs.contains(pcd) &&
aoqi@0 309 ! (pcd instanceof TypeVariable)) {
aoqi@0 310 add(isConstructor? classToConstructorArgs :classToMethodArgs,
aoqi@0 311 pcd.asClassDoc(), em);
aoqi@0 312 classArgs.add(pcd);
aoqi@0 313 mapTypeParameters(isConstructor?
aoqi@0 314 classToConstructorDocArgTypeParam : classToExecMemberDocArgTypeParam,
aoqi@0 315 pcd, em);
aoqi@0 316 }
aoqi@0 317 mapAnnotations(
aoqi@0 318 isConstructor ?
aoqi@0 319 classToConstructorParamAnnotation :
aoqi@0 320 classToExecMemberDocParamAnnotation,
aoqi@0 321 params[k], em);
aoqi@0 322 }
aoqi@0 323 ClassDoc[] thr = em.thrownExceptions();
aoqi@0 324 for (int k = 0; k < thr.length; k++) {
aoqi@0 325 add(isConstructor? classToConstructorThrows : classToMethodThrows,
aoqi@0 326 thr[k], em);
aoqi@0 327 }
aoqi@0 328 }
aoqi@0 329
aoqi@0 330 private <T> List<T> refList(Map<String,List<T>> map, ClassDoc cd) {
aoqi@0 331 List<T> list = map.get(cd.qualifiedName());
aoqi@0 332 if (list == null) {
aoqi@0 333 List<T> l = new ArrayList<T>();
aoqi@0 334 list = l;
aoqi@0 335 map.put(cd.qualifiedName(), list);
aoqi@0 336 }
aoqi@0 337 return list;
aoqi@0 338 }
aoqi@0 339
aoqi@0 340 private Set<PackageDoc> packageSet(ClassDoc cd) {
aoqi@0 341 Set<PackageDoc> pkgSet = classToPackage.get(cd.qualifiedName());
aoqi@0 342 if (pkgSet == null) {
aoqi@0 343 pkgSet = new TreeSet<PackageDoc>();
aoqi@0 344 classToPackage.put(cd.qualifiedName(), pkgSet);
aoqi@0 345 }
aoqi@0 346 return pkgSet;
aoqi@0 347 }
aoqi@0 348
aoqi@0 349 private Set<ClassDoc> classSet(ClassDoc cd) {
aoqi@0 350 Set<ClassDoc> clsSet = classToClass.get(cd.qualifiedName());
aoqi@0 351 if (clsSet == null) {
aoqi@0 352 Set<ClassDoc> s = new TreeSet<ClassDoc>();
aoqi@0 353 clsSet = s;
aoqi@0 354 classToClass.put(cd.qualifiedName(), clsSet);
aoqi@0 355 }
aoqi@0 356 return clsSet;
aoqi@0 357 }
aoqi@0 358
aoqi@0 359 private <T extends ProgramElementDoc> void add(Map<String,List<T>> map, ClassDoc cd, T ref) {
aoqi@0 360 // add to specified map
aoqi@0 361 refList(map, cd).add(ref);
aoqi@0 362
aoqi@0 363 // add ref's package to package map and class map
aoqi@0 364 packageSet(cd).add(ref.containingPackage());
aoqi@0 365
aoqi@0 366 classSet(cd).add(ref instanceof MemberDoc?
aoqi@0 367 ((MemberDoc)ref).containingClass() :
aoqi@0 368 (ClassDoc)ref);
aoqi@0 369 }
aoqi@0 370
aoqi@0 371 private void addAll(Map<String,List<ClassDoc>> map, ClassDoc cd, Collection<ClassDoc> refs) {
aoqi@0 372 if (refs == null) {
aoqi@0 373 return;
aoqi@0 374 }
aoqi@0 375 // add to specified map
aoqi@0 376 refList(map, cd).addAll(refs);
aoqi@0 377
aoqi@0 378 Set<PackageDoc> pkgSet = packageSet(cd);
aoqi@0 379 Set<ClassDoc> clsSet = classSet(cd);
aoqi@0 380 // add ref's package to package map and class map
aoqi@0 381 for (Iterator<ClassDoc> it = refs.iterator(); it.hasNext();) {
aoqi@0 382 ClassDoc cls = it.next();
aoqi@0 383 pkgSet.add(cls.containingPackage());
aoqi@0 384 clsSet.add(cls);
aoqi@0 385
aoqi@0 386 }
aoqi@0 387 }
aoqi@0 388
aoqi@0 389 /**
aoqi@0 390 * Map the ClassDocs to the ProgramElementDocs that use them as
aoqi@0 391 * type parameters.
aoqi@0 392 *
aoqi@0 393 * @param map the map the insert the information into.
aoqi@0 394 * @param doc the doc whose type parameters are being checked.
aoqi@0 395 * @param holder the holder that owns the type parameters.
aoqi@0 396 */
aoqi@0 397 private <T extends ProgramElementDoc> void mapTypeParameters(Map<String,List<T>> map, Object doc,
aoqi@0 398 T holder) {
aoqi@0 399 TypeVariable[] typeVariables;
aoqi@0 400 if (doc instanceof ClassDoc) {
aoqi@0 401 typeVariables = ((ClassDoc) doc).typeParameters();
aoqi@0 402 } else if (doc instanceof WildcardType) {
aoqi@0 403 Type[] extendsBounds = ((WildcardType) doc).extendsBounds();
aoqi@0 404 for (int k = 0; k < extendsBounds.length; k++) {
aoqi@0 405 addTypeParameterToMap(map, extendsBounds[k], holder);
aoqi@0 406 }
aoqi@0 407 Type[] superBounds = ((WildcardType) doc).superBounds();
aoqi@0 408 for (int k = 0; k < superBounds.length; k++) {
aoqi@0 409 addTypeParameterToMap(map, superBounds[k], holder);
aoqi@0 410 }
aoqi@0 411 return;
aoqi@0 412 } else if (doc instanceof ParameterizedType) {
aoqi@0 413 Type[] typeArguments = ((ParameterizedType) doc).typeArguments();
aoqi@0 414 for (int k = 0; k < typeArguments.length; k++) {
aoqi@0 415 addTypeParameterToMap(map, typeArguments[k], holder);
aoqi@0 416 }
aoqi@0 417 return;
aoqi@0 418 } else if (doc instanceof ExecutableMemberDoc) {
aoqi@0 419 typeVariables = ((ExecutableMemberDoc) doc).typeParameters();
aoqi@0 420 } else if (doc instanceof FieldDoc) {
aoqi@0 421 Type fieldType = ((FieldDoc) doc).type();
aoqi@0 422 mapTypeParameters(map, fieldType, holder);
aoqi@0 423 return;
aoqi@0 424 } else {
aoqi@0 425 return;
aoqi@0 426 }
aoqi@0 427 for (int i = 0; i < typeVariables.length; i++) {
aoqi@0 428 Type[] bounds = typeVariables[i].bounds();
aoqi@0 429 for (int j = 0; j < bounds.length; j++) {
aoqi@0 430 addTypeParameterToMap(map, bounds[j], holder);
aoqi@0 431 }
aoqi@0 432 }
aoqi@0 433 }
aoqi@0 434
aoqi@0 435 /**
aoqi@0 436 * Map the AnnotationType to the ProgramElementDocs that use them as
aoqi@0 437 * type parameters.
aoqi@0 438 *
aoqi@0 439 * @param map the map the insert the information into.
aoqi@0 440 * @param doc the doc whose type parameters are being checked.
aoqi@0 441 * @param holder the holder that owns the type parameters.
aoqi@0 442 */
aoqi@0 443 private <T extends ProgramElementDoc> void mapAnnotations(Map<String,List<T>> map, Object doc,
aoqi@0 444 T holder) {
aoqi@0 445 AnnotationDesc[] annotations;
aoqi@0 446 boolean isPackage = false;
aoqi@0 447 if (doc instanceof ProgramElementDoc) {
aoqi@0 448 annotations = ((ProgramElementDoc) doc).annotations();
aoqi@0 449 } else if (doc instanceof PackageDoc) {
aoqi@0 450 annotations = ((PackageDoc) doc).annotations();
aoqi@0 451 isPackage = true;
aoqi@0 452 } else if (doc instanceof Parameter) {
aoqi@0 453 annotations = ((Parameter) doc).annotations();
aoqi@0 454 } else {
aoqi@0 455 throw new DocletAbortException("should not happen");
aoqi@0 456 }
aoqi@0 457 for (int i = 0; i < annotations.length; i++) {
aoqi@0 458 AnnotationTypeDoc annotationDoc = annotations[i].annotationType();
aoqi@0 459 if (isPackage)
aoqi@0 460 refList(map, annotationDoc).add(holder);
aoqi@0 461 else
aoqi@0 462 add(map, annotationDoc, holder);
aoqi@0 463 }
aoqi@0 464 }
aoqi@0 465
aoqi@0 466
aoqi@0 467 /**
aoqi@0 468 * Map the AnnotationType to the ProgramElementDocs that use them as
aoqi@0 469 * type parameters.
aoqi@0 470 *
aoqi@0 471 * @param map the map the insert the information into.
aoqi@0 472 * @param doc the doc whose type parameters are being checked.
aoqi@0 473 * @param holder the holder that owns the type parameters.
aoqi@0 474 */
aoqi@0 475 private <T extends PackageDoc> void mapAnnotations(Map<String,List<T>> map, PackageDoc doc,
aoqi@0 476 T holder) {
aoqi@0 477 AnnotationDesc[] annotations;
aoqi@0 478 annotations = doc.annotations();
aoqi@0 479 for (int i = 0; i < annotations.length; i++) {
aoqi@0 480 AnnotationTypeDoc annotationDoc = annotations[i].annotationType();
aoqi@0 481 refList(map, annotationDoc).add(holder);
aoqi@0 482 }
aoqi@0 483 }
aoqi@0 484
aoqi@0 485 private <T extends ProgramElementDoc> void addTypeParameterToMap(Map<String,List<T>> map, Type type,
aoqi@0 486 T holder) {
aoqi@0 487 if (type instanceof ClassDoc) {
aoqi@0 488 add(map, (ClassDoc) type, holder);
aoqi@0 489 } else if (type instanceof ParameterizedType) {
aoqi@0 490 add(map, ((ParameterizedType) type).asClassDoc(), holder);
aoqi@0 491 }
aoqi@0 492 mapTypeParameters(map, type, holder);
aoqi@0 493 }
aoqi@0 494 }

mercurial