langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/ClassUseMapper.java
changeset 22163 3651128c74eb
parent 22159 682da512ec17
equal deleted inserted replaced
22162:3b3e23e67329 22163:3651128c74eb
    46 
    46 
    47     /**
    47     /**
    48      * Mapping of ClassDocs to set of PackageDoc used by that class.
    48      * Mapping of ClassDocs to set of PackageDoc used by that class.
    49      * Entries may be null.
    49      * Entries may be null.
    50      */
    50      */
    51     public Map<String,Set<PackageDoc>> classToPackage = new HashMap<String,Set<PackageDoc>>();
    51     public Map<String,Set<PackageDoc>> classToPackage = new HashMap<>();
    52 
    52 
    53     /**
    53     /**
    54      * Mapping of Annotations to set of PackageDoc that use the annotation.
    54      * Mapping of Annotations to set of PackageDoc that use the annotation.
    55      */
    55      */
    56     public Map<String,List<PackageDoc>> classToPackageAnnotations = new HashMap<String,List<PackageDoc>>();
    56     public Map<String,List<PackageDoc>> classToPackageAnnotations = new HashMap<>();
    57 
    57 
    58     /**
    58     /**
    59      * Mapping of ClassDocs to set of ClassDoc used by that class.
    59      * Mapping of ClassDocs to set of ClassDoc used by that class.
    60      * Entries may be null.
    60      * Entries may be null.
    61      */
    61      */
    62     public Map<String,Set<ClassDoc>> classToClass = new HashMap<String,Set<ClassDoc>>();
    62     public Map<String,Set<ClassDoc>> classToClass = new HashMap<>();
    63 
    63 
    64     /**
    64     /**
    65      * Mapping of ClassDocs to list of ClassDoc which are direct or
    65      * Mapping of ClassDocs to list of ClassDoc which are direct or
    66      * indirect subclasses of that class.
    66      * indirect subclasses of that class.
    67      * Entries may be null.
    67      * Entries may be null.
    68      */
    68      */
    69     public Map<String,List<ClassDoc>> classToSubclass = new HashMap<String,List<ClassDoc>>();
    69     public Map<String,List<ClassDoc>> classToSubclass = new HashMap<>();
    70 
    70 
    71     /**
    71     /**
    72      * Mapping of ClassDocs to list of ClassDoc which are direct or
    72      * Mapping of ClassDocs to list of ClassDoc which are direct or
    73      * indirect subinterfaces of that interface.
    73      * indirect subinterfaces of that interface.
    74      * Entries may be null.
    74      * Entries may be null.
    75      */
    75      */
    76     public Map<String,List<ClassDoc>> classToSubinterface = new HashMap<String,List<ClassDoc>>();
    76     public Map<String,List<ClassDoc>> classToSubinterface = new HashMap<>();
    77 
    77 
    78     /**
    78     /**
    79      * Mapping of ClassDocs to list of ClassDoc which implement
    79      * Mapping of ClassDocs to list of ClassDoc which implement
    80      * this interface.
    80      * this interface.
    81      * Entries may be null.
    81      * Entries may be null.
    82      */
    82      */
    83     public Map<String,List<ClassDoc>> classToImplementingClass = new HashMap<String,List<ClassDoc>>();
    83     public Map<String,List<ClassDoc>> classToImplementingClass = new HashMap<>();
    84 
    84 
    85     /**
    85     /**
    86      * Mapping of ClassDocs to list of FieldDoc declared as that class.
    86      * Mapping of ClassDocs to list of FieldDoc declared as that class.
    87      * Entries may be null.
    87      * Entries may be null.
    88      */
    88      */
    89     public Map<String,List<FieldDoc>> classToField = new HashMap<String,List<FieldDoc>>();
    89     public Map<String,List<FieldDoc>> classToField = new HashMap<>();
    90 
    90 
    91     /**
    91     /**
    92      * Mapping of ClassDocs to list of MethodDoc returning that class.
    92      * Mapping of ClassDocs to list of MethodDoc returning that class.
    93      * Entries may be null.
    93      * Entries may be null.
    94      */
    94      */
    95     public Map<String,List<MethodDoc>> classToMethodReturn = new HashMap<String,List<MethodDoc>>();
    95     public Map<String,List<MethodDoc>> classToMethodReturn = new HashMap<>();
    96 
    96 
    97     /**
    97     /**
    98      * Mapping of ClassDocs to list of MethodDoc having that class
    98      * Mapping of ClassDocs to list of MethodDoc having that class
    99      * as an arg.
    99      * as an arg.
   100      * Entries may be null.
   100      * Entries may be null.
   101      */
   101      */
   102     public Map<String,List<ExecutableMemberDoc>> classToMethodArgs = new HashMap<String,List<ExecutableMemberDoc>>();
   102     public Map<String,List<ExecutableMemberDoc>> classToMethodArgs = new HashMap<>();
   103 
   103 
   104     /**
   104     /**
   105      * Mapping of ClassDocs to list of MethodDoc which throws that class.
   105      * Mapping of ClassDocs to list of MethodDoc which throws that class.
   106      * Entries may be null.
   106      * Entries may be null.
   107      */
   107      */
   108     public Map<String,List<ExecutableMemberDoc>> classToMethodThrows = new HashMap<String,List<ExecutableMemberDoc>>();
   108     public Map<String,List<ExecutableMemberDoc>> classToMethodThrows = new HashMap<>();
   109 
   109 
   110     /**
   110     /**
   111      * Mapping of ClassDocs to list of ConstructorDoc having that class
   111      * Mapping of ClassDocs to list of ConstructorDoc having that class
   112      * as an arg.
   112      * as an arg.
   113      * Entries may be null.
   113      * Entries may be null.
   114      */
   114      */
   115     public Map<String,List<ExecutableMemberDoc>> classToConstructorArgs = new HashMap<String,List<ExecutableMemberDoc>>();
   115     public Map<String,List<ExecutableMemberDoc>> classToConstructorArgs = new HashMap<>();
   116 
   116 
   117     /**
   117     /**
   118      * Mapping of ClassDocs to list of ConstructorDoc which throws that class.
   118      * Mapping of ClassDocs to list of ConstructorDoc which throws that class.
   119      * Entries may be null.
   119      * Entries may be null.
   120      */
   120      */
   121     public Map<String,List<ExecutableMemberDoc>> classToConstructorThrows = new HashMap<String,List<ExecutableMemberDoc>>();
   121     public Map<String,List<ExecutableMemberDoc>> classToConstructorThrows = new HashMap<>();
   122 
   122 
   123     /**
   123     /**
   124      * The mapping of AnnotationTypeDocs to constructors that use them.
   124      * The mapping of AnnotationTypeDocs to constructors that use them.
   125      */
   125      */
   126     public Map<String,List<ConstructorDoc>> classToConstructorAnnotations = new HashMap<String,List<ConstructorDoc>>();
   126     public Map<String,List<ConstructorDoc>> classToConstructorAnnotations = new HashMap<>();
   127 
   127 
   128     /**
   128     /**
   129      * The mapping of AnnotationTypeDocs to Constructor parameters that use them.
   129      * The mapping of AnnotationTypeDocs to Constructor parameters that use them.
   130      */
   130      */
   131     public Map<String,List<ExecutableMemberDoc>> classToConstructorParamAnnotation = new HashMap<String,List<ExecutableMemberDoc>>();
   131     public Map<String,List<ExecutableMemberDoc>> classToConstructorParamAnnotation = new HashMap<>();
   132 
   132 
   133     /**
   133     /**
   134      * The mapping of ClassDocs to Constructor arguments that use them as type parameters.
   134      * The mapping of ClassDocs to Constructor arguments that use them as type parameters.
   135      */
   135      */
   136     public Map<String,List<ExecutableMemberDoc>> classToConstructorDocArgTypeParam = new HashMap<String,List<ExecutableMemberDoc>>();
   136     public Map<String,List<ExecutableMemberDoc>> classToConstructorDocArgTypeParam = new HashMap<>();
   137 
   137 
   138     /**
   138     /**
   139      * The mapping of ClassDocs to ClassDocs that use them as type parameters.
   139      * The mapping of ClassDocs to ClassDocs that use them as type parameters.
   140      */
   140      */
   141     public Map<String,List<ClassDoc>> classToClassTypeParam = new HashMap<String,List<ClassDoc>>();
   141     public Map<String,List<ClassDoc>> classToClassTypeParam = new HashMap<>();
   142 
   142 
   143     /**
   143     /**
   144      * The mapping of AnnotationTypeDocs to ClassDocs that use them.
   144      * The mapping of AnnotationTypeDocs to ClassDocs that use them.
   145      */
   145      */
   146     public Map<String,List<ClassDoc>> classToClassAnnotations = new HashMap<String,List<ClassDoc>>();
   146     public Map<String,List<ClassDoc>> classToClassAnnotations = new HashMap<>();
   147 
   147 
   148     /**
   148     /**
   149      * The mapping of ClassDocs to ExecutableMemberDocs that use them as type parameters.
   149      * The mapping of ClassDocs to ExecutableMemberDocs that use them as type parameters.
   150      */
   150      */
   151     public Map<String,List<MethodDoc>> classToExecMemberDocTypeParam = new HashMap<String,List<MethodDoc>>();
   151     public Map<String,List<MethodDoc>> classToExecMemberDocTypeParam = new HashMap<>();
   152 
   152 
   153     /**
   153     /**
   154      * The mapping of ClassDocs to ExecutableMemberDocs arguments that use them as type parameters.
   154      * The mapping of ClassDocs to ExecutableMemberDocs arguments that use them as type parameters.
   155      */
   155      */
   156     public Map<String,List<ExecutableMemberDoc>> classToExecMemberDocArgTypeParam = new HashMap<String,List<ExecutableMemberDoc>>();
   156     public Map<String,List<ExecutableMemberDoc>> classToExecMemberDocArgTypeParam = new HashMap<>();
   157 
   157 
   158     /**
   158     /**
   159      * The mapping of AnnotationTypeDocs to ExecutableMemberDocs that use them.
   159      * The mapping of AnnotationTypeDocs to ExecutableMemberDocs that use them.
   160      */
   160      */
   161     public Map<String,List<MethodDoc>> classToExecMemberDocAnnotations = new HashMap<String,List<MethodDoc>>();
   161     public Map<String,List<MethodDoc>> classToExecMemberDocAnnotations = new HashMap<>();
   162 
   162 
   163     /**
   163     /**
   164      * The mapping of ClassDocs to ExecutableMemberDocs that have return type
   164      * The mapping of ClassDocs to ExecutableMemberDocs that have return type
   165      * with type parameters of that class.
   165      * with type parameters of that class.
   166      */
   166      */
   167     public Map<String,List<MethodDoc>> classToExecMemberDocReturnTypeParam = new HashMap<String,List<MethodDoc>>();
   167     public Map<String,List<MethodDoc>> classToExecMemberDocReturnTypeParam = new HashMap<>();
   168 
   168 
   169     /**
   169     /**
   170      * The mapping of AnnotationTypeDocs to MethodDoc parameters that use them.
   170      * The mapping of AnnotationTypeDocs to MethodDoc parameters that use them.
   171      */
   171      */
   172     public Map<String,List<ExecutableMemberDoc>> classToExecMemberDocParamAnnotation = new HashMap<String,List<ExecutableMemberDoc>>();
   172     public Map<String,List<ExecutableMemberDoc>> classToExecMemberDocParamAnnotation = new HashMap<>();
   173 
   173 
   174     /**
   174     /**
   175      * The mapping of ClassDocs to FieldDocs that use them as type parameters.
   175      * The mapping of ClassDocs to FieldDocs that use them as type parameters.
   176      */
   176      */
   177     public Map<String,List<FieldDoc>> classToFieldDocTypeParam = new HashMap<String,List<FieldDoc>>();
   177     public Map<String,List<FieldDoc>> classToFieldDocTypeParam = new HashMap<>();
   178 
   178 
   179     /**
   179     /**
   180      * The mapping of AnnotationTypeDocs to FieldDocs that use them.
   180      * The mapping of AnnotationTypeDocs to FieldDocs that use them.
   181      */
   181      */
   182     public Map<String,List<FieldDoc>> annotationToFieldDoc = new HashMap<String,List<FieldDoc>>();
   182     public Map<String,List<FieldDoc>> annotationToFieldDoc = new HashMap<>();
   183 
   183 
   184 
   184 
   185     public ClassUseMapper(RootDoc root, ClassTree classtree) {
   185     public ClassUseMapper(RootDoc root, ClassTree classtree) {
   186         this.classtree = classtree;
   186         this.classtree = classtree;
   187 
   187 
   232      * Return all subclasses of a class AND fill-in classToSubclass map.
   232      * Return all subclasses of a class AND fill-in classToSubclass map.
   233      */
   233      */
   234     private Collection<ClassDoc> subclasses(ClassDoc cd) {
   234     private Collection<ClassDoc> subclasses(ClassDoc cd) {
   235         Collection<ClassDoc> ret = classToSubclass.get(cd.qualifiedName());
   235         Collection<ClassDoc> ret = classToSubclass.get(cd.qualifiedName());
   236         if (ret == null) {
   236         if (ret == null) {
   237             ret = new TreeSet<ClassDoc>();
   237             ret = new TreeSet<>();
   238             List<ClassDoc> subs = classtree.subclasses(cd);
   238             List<ClassDoc> subs = classtree.subclasses(cd);
   239             if (subs != null) {
   239             if (subs != null) {
   240                 ret.addAll(subs);
   240                 ret.addAll(subs);
   241                 for (ClassDoc sub : subs) {
   241                 for (ClassDoc sub : subs) {
   242                     ret.addAll(subclasses(sub));
   242                     ret.addAll(subclasses(sub));
   251      * Return all subinterfaces of an interface AND fill-in classToSubinterface map.
   251      * Return all subinterfaces of an interface AND fill-in classToSubinterface map.
   252      */
   252      */
   253     private Collection<ClassDoc> subinterfaces(ClassDoc cd) {
   253     private Collection<ClassDoc> subinterfaces(ClassDoc cd) {
   254         Collection<ClassDoc> ret = classToSubinterface.get(cd.qualifiedName());
   254         Collection<ClassDoc> ret = classToSubinterface.get(cd.qualifiedName());
   255         if (ret == null) {
   255         if (ret == null) {
   256             ret = new TreeSet<ClassDoc>();
   256             ret = new TreeSet<>();
   257             List<ClassDoc> subs = classtree.subinterfaces(cd);
   257             List<ClassDoc> subs = classtree.subinterfaces(cd);
   258             if (subs != null) {
   258             if (subs != null) {
   259                 ret.addAll(subs);
   259                 ret.addAll(subs);
   260                 for (ClassDoc sub : subs) {
   260                 for (ClassDoc sub : subs) {
   261                     ret.addAll(subinterfaces(sub));
   261                     ret.addAll(subinterfaces(sub));
   273      * and classToSubinterface maps.
   273      * and classToSubinterface maps.
   274      */
   274      */
   275     private Collection<ClassDoc> implementingClasses(ClassDoc cd) {
   275     private Collection<ClassDoc> implementingClasses(ClassDoc cd) {
   276         Collection<ClassDoc> ret = classToImplementingClass.get(cd.qualifiedName());
   276         Collection<ClassDoc> ret = classToImplementingClass.get(cd.qualifiedName());
   277         if (ret == null) {
   277         if (ret == null) {
   278             ret = new TreeSet<ClassDoc>();
   278             ret = new TreeSet<>();
   279             List<ClassDoc> impl = classtree.implementingclasses(cd);
   279             List<ClassDoc> impl = classtree.implementingclasses(cd);
   280             if (impl != null) {
   280             if (impl != null) {
   281                 ret.addAll(impl);
   281                 ret.addAll(impl);
   282                 for (ClassDoc anImpl : impl) {
   282                 for (ClassDoc anImpl : impl) {
   283                     ret.addAll(subclasses(anImpl));
   283                     ret.addAll(subclasses(anImpl));
   295      * Determine classes used by a method or constructor, so they can be
   295      * Determine classes used by a method or constructor, so they can be
   296      * inverse mapped.
   296      * inverse mapped.
   297      */
   297      */
   298     private void mapExecutable(ExecutableMemberDoc em) {
   298     private void mapExecutable(ExecutableMemberDoc em) {
   299         boolean isConstructor = em.isConstructor();
   299         boolean isConstructor = em.isConstructor();
   300         List<Type> classArgs = new ArrayList<Type>();
   300         List<Type> classArgs = new ArrayList<>();
   301         for (Parameter param : em.parameters()) {
   301         for (Parameter param : em.parameters()) {
   302             Type pcd = param.type();
   302             Type pcd = param.type();
   303             // primitives don't get mapped, also avoid dups
   303             // primitives don't get mapped, also avoid dups
   304             if ((!param.type().isPrimitive()) &&
   304             if ((!param.type().isPrimitive()) &&
   305                 !classArgs.contains(pcd) &&
   305                 !classArgs.contains(pcd) &&
   324     }
   324     }
   325 
   325 
   326     private <T> List<T> refList(Map<String,List<T>> map, ClassDoc cd) {
   326     private <T> List<T> refList(Map<String,List<T>> map, ClassDoc cd) {
   327         List<T> list = map.get(cd.qualifiedName());
   327         List<T> list = map.get(cd.qualifiedName());
   328         if (list == null) {
   328         if (list == null) {
   329             List<T> l = new ArrayList<T>();
   329             list = new ArrayList<>();
   330             list = l;
       
   331             map.put(cd.qualifiedName(), list);
   330             map.put(cd.qualifiedName(), list);
   332         }
   331         }
   333         return list;
   332         return list;
   334     }
   333     }
   335 
   334 
   336     private Set<PackageDoc> packageSet(ClassDoc cd) {
   335     private Set<PackageDoc> packageSet(ClassDoc cd) {
   337         Set<PackageDoc> pkgSet = classToPackage.get(cd.qualifiedName());
   336         Set<PackageDoc> pkgSet = classToPackage.get(cd.qualifiedName());
   338         if (pkgSet == null) {
   337         if (pkgSet == null) {
   339             pkgSet = new TreeSet<PackageDoc>();
   338             pkgSet = new TreeSet<>();
   340             classToPackage.put(cd.qualifiedName(), pkgSet);
   339             classToPackage.put(cd.qualifiedName(), pkgSet);
   341         }
   340         }
   342         return pkgSet;
   341         return pkgSet;
   343     }
   342     }
   344 
   343 
   345     private Set<ClassDoc> classSet(ClassDoc cd) {
   344     private Set<ClassDoc> classSet(ClassDoc cd) {
   346         Set<ClassDoc> clsSet = classToClass.get(cd.qualifiedName());
   345         Set<ClassDoc> clsSet = classToClass.get(cd.qualifiedName());
   347         if (clsSet == null) {
   346         if (clsSet == null) {
   348             Set<ClassDoc> s = new TreeSet<ClassDoc>();
   347             clsSet = new TreeSet<>();
   349             clsSet = s;
       
   350             classToClass.put(cd.qualifiedName(), clsSet);
   348             classToClass.put(cd.qualifiedName(), clsSet);
   351         }
   349         }
   352         return clsSet;
   350         return clsSet;
   353     }
   351     }
   354 
   352