langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriterImpl.java
changeset 44684 6ce4d52084e8
parent 44564 4e1df2513486
child 44689 53c703004306
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriterImpl.java	Tue Apr 11 17:26:52 2017 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriterImpl.java	Wed Apr 12 11:42:50 2017 -0700
@@ -409,7 +409,7 @@
      * @param section set of elements
      * @return true if there are elements to be displayed
      */
-    public boolean display(SortedSet<? extends Element> section) {
+    public boolean display(Set<? extends Element> section) {
         return section != null && !section.isEmpty();
     }
 
@@ -423,6 +423,25 @@
         return section != null && !section.isEmpty();
     }
 
+    /*
+     * Returns true, in API mode, if at least one type element in
+     * the typeElements set is referenced by a javadoc tag in tagsMap.
+     */
+    private boolean displayServices(Set<TypeElement> typeElements,
+                                    Map<TypeElement, Content> tagsMap) {
+        return typeElements != null &&
+                typeElements.stream().anyMatch((v) -> displayServiceDirective(v, tagsMap));
+    }
+
+    /*
+     * Returns true, in API mode, if the type element is referenced
+     * from a javadoc tag in tagsMap.
+     */
+    private boolean displayServiceDirective(TypeElement typeElement,
+                                            Map<TypeElement, Content> tagsMap) {
+        return moduleMode == ModuleMode.ALL || tagsMap.containsKey(typeElement);
+    }
+
     /**
      * Add the summary header.
      *
@@ -768,14 +787,18 @@
      * {@inheritDoc}
      */
     public void addServicesSummary(Content summaryContentTree) {
-        if (display(uses) || display(provides)) {
+
+        boolean haveUses = displayServices(uses, usesTrees);
+        boolean haveProvides = displayServices(provides.keySet(), providesTrees);
+
+        if (haveProvides || haveUses) {
             HtmlTree li = new HtmlTree(HtmlTag.LI);
             li.addStyle(HtmlStyle.blockList);
             addSummaryHeader(HtmlConstants.START_OF_SERVICES_SUMMARY, SectionName.SERVICES,
                     contents.navServices, li);
             String text;
             String tableSummary;
-            if (display(provides)) {
+            if (haveProvides) {
                 text = configuration.getText("doclet.Provides_Summary");
                 tableSummary = configuration.getText("doclet.Member_Table_Summary",
                         configuration.getText("doclet.Provides_Summary"),
@@ -788,7 +811,7 @@
                     li.addContent(table);
                 }
             }
-            if (display(uses)) {
+            if (haveUses){
                 text = configuration.getText("doclet.Uses_Summary");
                 tableSummary = configuration.getText("doclet.Member_Table_Summary",
                         configuration.getText("doclet.Uses_Summary"),
@@ -818,17 +841,13 @@
         HtmlTree tdSummary;
         Content description;
         for (TypeElement t : uses) {
-            // For each uses directive in the module declaration, if we are in the "api" mode and
-            // if there are service types listed using @uses javadoc tag, check if the service type in
-            // the uses directive is specified using the @uses tag. If not, we do not display the
-            // service type in the "api" mode.
-            if (moduleMode == ModuleMode.API && display(usesTrees) && !usesTrees.containsKey(t)) {
+            if (!displayServiceDirective(t, usesTrees)) {
                 continue;
             }
             typeLinkContent = getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.PACKAGE, t));
             thType = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst, typeLinkContent);
             tdSummary = new HtmlTree(HtmlTag.TD);
-        tdSummary.addStyle(HtmlStyle.colLast);
+            tdSummary.addStyle(HtmlStyle.colLast);
             if (display(usesTrees)) {
                 description = usesTrees.get(t);
                 if (description != null) {
@@ -837,9 +856,9 @@
             }
             addSummaryComment(t, tdSummary);
             HtmlTree tr = HtmlTree.TR(thType);
-        tr.addContent(tdSummary);
-        tr.addStyle(altColor ? HtmlStyle.altColor : HtmlStyle.rowColor);
-        tbody.addContent(tr);
+            tr.addContent(tdSummary);
+            tr.addStyle(altColor ? HtmlStyle.altColor : HtmlStyle.rowColor);
+            tbody.addContent(tr);
             altColor = !altColor;
         }
     }
@@ -851,18 +870,13 @@
      */
     public void addProvidesList(Content tbody) {
         boolean altColor = true;
-        TypeElement srv;
         SortedSet<TypeElement> implSet;
         Content description;
         for (Map.Entry<TypeElement, SortedSet<TypeElement>> entry : provides.entrySet()) {
-            srv = entry.getKey();
-            // For each provides directive in the module declaration, if we are in the "api" mode and
-            // if there are service types listed using @provides javadoc tag, check if the service type in
-            // the provides directive is specified using the @provides tag. If not, we do not display the
-            // service type in the "api" mode.
-            if (moduleMode == ModuleMode.API && display(providesTrees) && !providesTrees.containsKey(srv)) {
+            TypeElement srv = entry.getKey();
+            if (!displayServiceDirective(srv, providesTrees)) {
                 continue;
-    }
+            }
             implSet = entry.getValue();
             Content srvLinkContent = getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.PACKAGE, srv));
             HtmlTree thType = HtmlTree.TH_ROW_SCOPE(HtmlStyle.colFirst, srvLinkContent);