Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8239487: Better links generation for system properties found in HTML …
…files

8239485: Define behavior of the System Properties page when no system properties are available

Reviewed-by: jjg
  • Loading branch information
pavelrappo committed Mar 11, 2020
1 parent 5b323a8 commit 8c6649dea0c6bed166974eab81467565f64de80d
Showing with 504 additions and 161 deletions.
  1. +30 −29 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java
  2. +2 −32 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DocFilesHandlerImpl.java
  3. +17 −7 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SearchIndexItem.java
  4. +78 −17 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SearchIndexItems.java
  5. +2 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SingleIndexWriter.java
  6. +10 −7 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SplitIndexWriter.java
  7. +60 −33 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SystemPropertiesWriter.java
  8. +4 −2 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TagletWriterImpl.java
  9. +3 −3 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/DocFileElement.java
  10. +37 −0 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java
  11. +2 −2 test/langtools/jdk/javadoc/doclet/testMetadata/TestMetadata.java
  12. +42 −25 test/langtools/jdk/javadoc/doclet/testSystemPropertyPage/TestSystemPropertyPage.java
  13. +32 −0 test/langtools/jdk/javadoc/doclet/testSystemPropertyPage/src1/overview.html
  14. +29 −0 test/langtools/jdk/javadoc/doclet/testSystemPropertyPage/src1/pkg1/A.java
  15. +32 −0 test/langtools/jdk/javadoc/doclet/testSystemPropertyPage/src1/pkg1/doc-files/WithEmptyTitle.html
  16. +33 −0 test/langtools/jdk/javadoc/doclet/testSystemPropertyPage/src1/pkg1/doc-files/WithTitle.html
  17. +31 −0 test/langtools/jdk/javadoc/doclet/testSystemPropertyPage/src1/pkg1/doc-files/WithoutTitle.html
  18. +29 −0 test/langtools/jdk/javadoc/doclet/testSystemPropertyPage/src1/pkg2/B.java
  19. +29 −0 test/langtools/jdk/javadoc/doclet/testSystemPropertyPage/src2/pkg1/A.java
  20. +2 −2 test/langtools/jdk/javadoc/doclet/testSystemPropertyTaglet/TestSystemPropertyTaglet.java
  21. +0 −1 test/langtools/jdk/javadoc/tool/api/basic/APITest.java
@@ -27,11 +27,12 @@

import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
@@ -41,6 +42,7 @@
import javax.lang.model.util.SimpleElementVisitor14;

import com.sun.source.doctree.DocTree;
import jdk.javadoc.internal.doclets.formats.html.SearchIndexItem.Category;
import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
@@ -92,8 +94,9 @@ protected AbstractIndexWriter(HtmlConfiguration configuration,
super(configuration, path);
this.indexBuilder = indexBuilder;
this.navBar = new Navigation(null, configuration, PageMode.INDEX, path);
Collection<SearchIndexItem> items =
searchItems.get(SearchIndexItem.Category.SEARCH_TAGS);
Stream<SearchIndexItem> items =
searchItems.itemsOfCategories(Category.INDEX, Category.SYSTEM_PROPERTY)
.sorted(utils.makeGenericSearchIndexComparator());
this.tagSearchIndexMap = buildSearchTagIndex(items);
}

@@ -229,7 +232,7 @@ protected void addDescription(ModuleElement mdle, Content dlTree, SearchIndexIte
String moduleName = utils.getFullyQualifiedName(mdle);
Content link = getModuleLink(mdle, new StringContent(moduleName));
si.setLabel(moduleName);
si.setCategory(SearchIndexItem.Category.MODULES);
si.setCategory(Category.MODULES);
Content dt = HtmlTree.DT(link);
dt.add(" - ");
dt.add(contents.module_);
@@ -253,7 +256,7 @@ protected void addDescription(PackageElement pkg, Content dlTree, SearchIndexIte
si.setContainingModule(utils.getFullyQualifiedName(utils.containingModule(pkg)));
}
si.setLabel(utils.getPackageName(pkg));
si.setCategory(SearchIndexItem.Category.PACKAGES);
si.setCategory(Category.PACKAGES);
Content dt = HtmlTree.DT(link);
dt.add(" - ");
dt.add(contents.package_);
@@ -276,7 +279,7 @@ protected void addDescription(TypeElement typeElement, Content dlTree, SearchInd
LinkInfoImpl.Kind.INDEX, typeElement).strong(true));
si.setContainingPackage(utils.getPackageName(utils.containingPackage(typeElement)));
si.setLabel(utils.getSimpleName(typeElement));
si.setCategory(SearchIndexItem.Category.TYPES);
si.setCategory(Category.TYPES);
Content dt = HtmlTree.DT(link);
dt.add(" - ");
addClassInfo(typeElement, dt);
@@ -324,7 +327,7 @@ protected void addDescription(Element member, Content dlTree, SearchIndexItem si
} else {
si.setLabel(name);
}
si.setCategory(SearchIndexItem.Category.MEMBERS);
si.setCategory(Category.MEMBERS);
Content span = HtmlTree.SPAN(HtmlStyle.memberNameLink,
getDocLink(LinkInfoImpl.Kind.INDEX, member, name));
Content dt = HtmlTree.DT(span);
@@ -431,32 +434,32 @@ public String getNameForIndex(String unicode) {
protected void createSearchIndexFiles() throws DocFileIOException {
if (configuration.showModules) {
createSearchIndexFile(DocPaths.MODULE_SEARCH_INDEX_JS,
searchItems.get(SearchIndexItem.Category.MODULES),
searchItems.itemsOfCategories(Category.MODULES),
"moduleSearchIndex");
}
if (!configuration.packages.isEmpty()) {
SearchIndexItem si = new SearchIndexItem();
si.setCategory(SearchIndexItem.Category.PACKAGES);
si.setCategory(Category.PACKAGES);
si.setLabel(resources.getText("doclet.All_Packages"));
si.setUrl(DocPaths.ALLPACKAGES_INDEX.getPath());
searchItems.add(si);
}
createSearchIndexFile(DocPaths.PACKAGE_SEARCH_INDEX_JS,
searchItems.get(SearchIndexItem.Category.PACKAGES),
searchItems.itemsOfCategories(Category.PACKAGES),
"packageSearchIndex");
SearchIndexItem si = new SearchIndexItem();
si.setCategory(SearchIndexItem.Category.TYPES);
si.setCategory(Category.TYPES);
si.setLabel(resources.getText("doclet.All_Classes"));
si.setUrl(DocPaths.ALLCLASSES_INDEX.getPath());
searchItems.add(si);
createSearchIndexFile(DocPaths.TYPE_SEARCH_INDEX_JS,
searchItems.get(SearchIndexItem.Category.TYPES),
searchItems.itemsOfCategories(Category.TYPES),
"typeSearchIndex");
createSearchIndexFile(DocPaths.MEMBER_SEARCH_INDEX_JS,
searchItems.get(SearchIndexItem.Category.MEMBERS),
searchItems.itemsOfCategories(Category.MEMBERS),
"memberSearchIndex");
createSearchIndexFile(DocPaths.TAG_SEARCH_INDEX_JS,
searchItems.get(SearchIndexItem.Category.SEARCH_TAGS),
searchItems.itemsOfCategories(Category.INDEX, Category.SYSTEM_PROPERTY),
"tagSearchIndex");
}

@@ -469,16 +472,18 @@ protected void createSearchIndexFiles() throws DocFileIOException {
* @throws DocFileIOException if there is a problem creating the search index file
*/
protected void createSearchIndexFile(DocPath searchIndexJS,
Collection<SearchIndexItem> searchIndex,
Stream<SearchIndexItem> searchIndex,
String varName)
throws DocFileIOException
{
// The file needs to be created even if there are no searchIndex items
// File could be written straight-through, without an intermediate StringBuilder
if (!searchIndex.isEmpty()) {
Iterator<SearchIndexItem> index = searchIndex.iterator();
if (index.hasNext()) {
StringBuilder searchVar = new StringBuilder("[");
boolean first = true;
for (SearchIndexItem item : searchIndex) {
while (index.hasNext()) {
SearchIndexItem item = index.next();
if (first) {
searchVar.append(item.toString());
first = false;
@@ -498,17 +503,13 @@ protected void createSearchIndexFile(DocPath searchIndexJS,
}
}

protected static Map<Character, List<SearchIndexItem>> buildSearchTagIndex(
Collection<? extends SearchIndexItem> searchItems)
private static Map<Character, List<SearchIndexItem>> buildSearchTagIndex(
Stream<? extends SearchIndexItem> searchItems)
{
Map<Character, List<SearchIndexItem>> map = new HashMap<>();
for (SearchIndexItem sii : searchItems) {
String tagLabel = sii.getLabel();
Character unicode = (tagLabel.length() == 0)
? '*'
: Character.toUpperCase(tagLabel.charAt(0));
map.computeIfAbsent(unicode, k -> new ArrayList<>()).add(sii);
}
return map;
return searchItems.collect(Collectors.groupingBy(i -> keyCharacter(i.getLabel())));
}

protected static Character keyCharacter(String s) {
return s.isEmpty() ? '*' : Character.toUpperCase(s.charAt(0));
}
}
@@ -28,7 +28,6 @@
import com.sun.source.doctree.DocTree;
import com.sun.source.doctree.EndElementTree;
import com.sun.source.doctree.StartElementTree;
import com.sun.source.doctree.TextTree;
import com.sun.source.util.DocTreeFactory;
import com.sun.tools.doclint.HtmlTag;
import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents;
@@ -266,37 +265,8 @@ private List<? extends DocTree> getLocalHeaderTags(List<? extends DocTree> dtree
}

private String getWindowTitle(HtmlDocletWriter docletWriter, Element element) {
List<? extends DocTree> preamble = configuration.utils.getPreamble(element);
StringBuilder sb = new StringBuilder();
boolean titleFound = false;
loop:
for (DocTree dt : preamble) {
switch (dt.getKind()) {
case START_ELEMENT:
StartElementTree nodeStart = (StartElementTree)dt;
if (Utils.toLowerCase(nodeStart.getName().toString()).equals("title")) {
titleFound = true;
}
break;

case END_ELEMENT:
EndElementTree nodeEnd = (EndElementTree)dt;
if (Utils.toLowerCase(nodeEnd.getName().toString()).equals("title")) {
break loop;
}
break;

case TEXT:
TextTree nodeText = (TextTree)dt;
if (titleFound)
sb.append(nodeText.getBody());
break;

default:
// do nothing
}
}
return docletWriter.getWindowTitle(sb.toString().trim());
String t = configuration.utils.getHTMLTitle(element);
return docletWriter.getWindowTitle(t);
}

private static class DocFileWriter extends HtmlDocletWriter {
@@ -25,6 +25,8 @@

package jdk.javadoc.internal.doclets.formats.html;

import javax.lang.model.element.Element;

/**
* Index item for search.
*
@@ -40,7 +42,14 @@ enum Category {
PACKAGES,
TYPES,
MEMBERS,
SEARCH_TAGS
/**
* The category of items corresponding to {@code {@index}} tags.
*/
INDEX,
/**
* The category of items corresponding to {@code {@systemProperty}} tags.
*/
SYSTEM_PROPERTY
}

private Category category;
@@ -51,7 +60,7 @@ enum Category {
private String containingClass = "";
private String holder = "";
private String description = "";
private boolean systemProperty;
private Element element;

public void setLabel(String l) {
label = l;
@@ -105,12 +114,12 @@ protected Category getCategory() {
return category;
}

public void setSystemProperty(boolean value) {
systemProperty = value;
public void setElement(Element element) {
this.element = element;
}

public boolean isSystemProperty() {
return systemProperty;
public Element getElement() {
return element;
}

@Override
@@ -155,7 +164,8 @@ public String toString() {
}
item.append("}");
break;
case SEARCH_TAGS:
case INDEX:
case SYSTEM_PROPERTY:
item.append("{")
.append("\"l\":\"").append(label).append("\",")
.append("\"h\":\"").append(holder).append("\",");

0 comments on commit 8c6649d

Please sign in to comment.