24 */
25 package jdk.javadoc.internal.doclets.toolkit.util;
26
27 import java.util.*;
28
29 import javax.lang.model.element.AnnotationMirror;
30 import javax.lang.model.element.Element;
31 import javax.lang.model.element.ExecutableElement;
32 import javax.lang.model.element.PackageElement;
33 import javax.lang.model.element.TypeElement;
34 import javax.lang.model.element.TypeParameterElement;
35 import javax.lang.model.element.VariableElement;
36 import javax.lang.model.type.ArrayType;
37 import javax.lang.model.type.DeclaredType;
38 import javax.lang.model.type.ErrorType;
39 import javax.lang.model.type.TypeMirror;
40 import javax.lang.model.type.TypeVariable;
41 import javax.lang.model.type.WildcardType;
42 import javax.lang.model.util.ElementFilter;
43 import javax.lang.model.util.Elements;
44 import javax.lang.model.util.SimpleElementVisitor9;
45 import javax.lang.model.util.SimpleTypeVisitor9;
46 import javax.lang.model.util.Types;
47
48 import jdk.javadoc.doclet.DocletEnvironment;
49 import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
50
51 import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.*;
52
53 /**
54 * Map all class uses for a given class.
55 *
56 * <p>
57 * <b>This is NOT part of any supported API. If you write code that depends on this, you do so at
58 * your own risk. This code and its internal interfaces are subject to change or deletion without
59 * notice.</b>
60 *
61 * @author Robert G. Field
62 */
63 public class ClassUseMapper {
64
466
467 Set<PackageElement> pkgSet = packageSet(te);
468 Set<TypeElement> clsSet = classSet(te);
469 // add ref's package to package map and class map
470 for (TypeElement cls : refs) {
471 pkgSet.add(utils.containingPackage(cls));
472 clsSet.add(cls);
473 }
474 }
475
476 /**
477 * Map the TypeElements to the members that use them as type parameters.
478 *
479 * @param map the map the insert the information into.
480 * @param element the te whose type parameters are being checked.
481 * @param holder the holder that owns the type parameters.
482 */
483 private <T extends Element> void mapTypeParameters(final Map<TypeElement, List<T>> map,
484 Element element, final T holder) {
485
486 SimpleElementVisitor9<Void, Void> elementVisitor
487 = new SimpleElementVisitor9<Void, Void>() {
488
489 private void addParameters(TypeParameterElement e) {
490 for (TypeMirror type : utils.getBounds(e)) {
491 addTypeParameterToMap(map, type, holder);
492 }
493 }
494
495 @Override
496 public Void visitType(TypeElement e, Void p) {
497 for (TypeParameterElement param : e.getTypeParameters()) {
498 addParameters(param);
499 }
500 return null;
501 }
502
503 @Override
504 public Void visitExecutable(ExecutableElement e, Void p) {
505 for (TypeParameterElement param : e.getTypeParameters()) {
506 addParameters(param);
507 }
543
544 // ParameterizedType
545 @Override
546 public Void visitDeclared(DeclaredType t, Void p) {
547 for (TypeMirror targ : t.getTypeArguments()) {
548 addTypeParameterToMap(map, targ, holder);
549 }
550 return null;
551 }
552 };
553 tv.visit(aType);
554 }
555
556 /**
557 * Map the AnnotationType to the members that use them as type parameters.
558 *
559 * @param map the map the insert the information into.
560 * @param e whose type parameters are being checked.
561 * @param holder owning the type parameters.
562 */
563 private <T extends Element> void mapAnnotations(final Map<TypeElement, List<T>> map,
564 Element e, final T holder) {
565 new SimpleElementVisitor9<Void, Void>() {
566
567 void addAnnotations(Element e) {
568 for (AnnotationMirror a : e.getAnnotationMirrors()) {
569 add(map, (TypeElement) a.getAnnotationType().asElement(), holder);
570 }
571 }
572
573 @Override
574 public Void visitPackage(PackageElement e, Void p) {
575 for (AnnotationMirror a : e.getAnnotationMirrors()) {
576 refList(map, (TypeElement) a.getAnnotationType().asElement()).add(holder);
577 }
578 return null;
579 }
580
581 @Override
582 protected Void defaultAction(Element e, Void p) {
583 addAnnotations(e);
584 return null;
585 }
|
24 */
25 package jdk.javadoc.internal.doclets.toolkit.util;
26
27 import java.util.*;
28
29 import javax.lang.model.element.AnnotationMirror;
30 import javax.lang.model.element.Element;
31 import javax.lang.model.element.ExecutableElement;
32 import javax.lang.model.element.PackageElement;
33 import javax.lang.model.element.TypeElement;
34 import javax.lang.model.element.TypeParameterElement;
35 import javax.lang.model.element.VariableElement;
36 import javax.lang.model.type.ArrayType;
37 import javax.lang.model.type.DeclaredType;
38 import javax.lang.model.type.ErrorType;
39 import javax.lang.model.type.TypeMirror;
40 import javax.lang.model.type.TypeVariable;
41 import javax.lang.model.type.WildcardType;
42 import javax.lang.model.util.ElementFilter;
43 import javax.lang.model.util.Elements;
44 import javax.lang.model.util.SimpleElementVisitor14;
45 import javax.lang.model.util.SimpleTypeVisitor9;
46 import javax.lang.model.util.Types;
47
48 import jdk.javadoc.doclet.DocletEnvironment;
49 import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
50
51 import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.*;
52
53 /**
54 * Map all class uses for a given class.
55 *
56 * <p>
57 * <b>This is NOT part of any supported API. If you write code that depends on this, you do so at
58 * your own risk. This code and its internal interfaces are subject to change or deletion without
59 * notice.</b>
60 *
61 * @author Robert G. Field
62 */
63 public class ClassUseMapper {
64
466
467 Set<PackageElement> pkgSet = packageSet(te);
468 Set<TypeElement> clsSet = classSet(te);
469 // add ref's package to package map and class map
470 for (TypeElement cls : refs) {
471 pkgSet.add(utils.containingPackage(cls));
472 clsSet.add(cls);
473 }
474 }
475
476 /**
477 * Map the TypeElements to the members that use them as type parameters.
478 *
479 * @param map the map the insert the information into.
480 * @param element the te whose type parameters are being checked.
481 * @param holder the holder that owns the type parameters.
482 */
483 private <T extends Element> void mapTypeParameters(final Map<TypeElement, List<T>> map,
484 Element element, final T holder) {
485
486 @SuppressWarnings("preview")
487 SimpleElementVisitor14<Void, Void> elementVisitor
488 = new SimpleElementVisitor14<Void, Void>() {
489
490 private void addParameters(TypeParameterElement e) {
491 for (TypeMirror type : utils.getBounds(e)) {
492 addTypeParameterToMap(map, type, holder);
493 }
494 }
495
496 @Override
497 public Void visitType(TypeElement e, Void p) {
498 for (TypeParameterElement param : e.getTypeParameters()) {
499 addParameters(param);
500 }
501 return null;
502 }
503
504 @Override
505 public Void visitExecutable(ExecutableElement e, Void p) {
506 for (TypeParameterElement param : e.getTypeParameters()) {
507 addParameters(param);
508 }
544
545 // ParameterizedType
546 @Override
547 public Void visitDeclared(DeclaredType t, Void p) {
548 for (TypeMirror targ : t.getTypeArguments()) {
549 addTypeParameterToMap(map, targ, holder);
550 }
551 return null;
552 }
553 };
554 tv.visit(aType);
555 }
556
557 /**
558 * Map the AnnotationType to the members that use them as type parameters.
559 *
560 * @param map the map the insert the information into.
561 * @param e whose type parameters are being checked.
562 * @param holder owning the type parameters.
563 */
564 @SuppressWarnings("preview")
565 private <T extends Element> void mapAnnotations(final Map<TypeElement, List<T>> map,
566 Element e, final T holder) {
567 new SimpleElementVisitor14<Void, Void>() {
568
569 void addAnnotations(Element e) {
570 for (AnnotationMirror a : e.getAnnotationMirrors()) {
571 add(map, (TypeElement) a.getAnnotationType().asElement(), holder);
572 }
573 }
574
575 @Override
576 public Void visitPackage(PackageElement e, Void p) {
577 for (AnnotationMirror a : e.getAnnotationMirrors()) {
578 refList(map, (TypeElement) a.getAnnotationType().asElement()).add(holder);
579 }
580 return null;
581 }
582
583 @Override
584 protected Void defaultAction(Element e, Void p) {
585 addAnnotations(e);
586 return null;
587 }
|