8254627: Cleanup {Abstract,Single,Split}IndexWriter classes

Reviewed-by: hannesw
This commit is contained in:
Jonathan Gibbons 2020-10-13 16:22:52 +00:00
parent 02d9c29185
commit 3fb2e822be
15 changed files with 456 additions and 646 deletions

View File

@ -1,274 +0,0 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.javadoc.internal.doclets.formats.html;
import java.util.List;
import java.util.SortedSet;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ModuleElement;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import com.sun.source.doctree.DocTree;
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.TagName;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder;
import jdk.javadoc.internal.doclets.toolkit.util.IndexItem;
/**
* Generate Index for all the Member Names with Indexing in
* Unicode Order. This class is a base class for {@link SingleIndexWriter} and
* {@link SplitIndexWriter}. It uses the functionality from
* {@link HtmlDocletWriter} to generate the Index Contents.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*
* @see IndexBuilder
*/
public class AbstractIndexWriter extends HtmlDocletWriter {
protected final IndexBuilder mainIndex;
protected final Navigation navBar;
/**
* Initializes the common data for writers that can generate index files
* based on the information in {@code configuration.mainIndex}.
*
* @param configuration the current configuration
* @param path path to the file which is getting generated.
*/
protected AbstractIndexWriter(HtmlConfiguration configuration,
DocPath path) {
super(configuration, path);
this.mainIndex = configuration.mainIndex;
this.navBar = new Navigation(null, configuration, PageMode.INDEX, path);
}
protected void addContents(Character uc, SortedSet<IndexItem> memberlist,
Content contentTree) {
addHeading(uc, contentTree);
HtmlTree dl = HtmlTree.DL(HtmlStyle.index);
for (IndexItem item : memberlist) {
addDescription(item, dl);
}
contentTree.add(dl);
}
protected void addHeading(Character uc, Content contentTree) {
String unicode = uc.toString();
Content headContent = new StringContent(unicode);
HtmlTree heading = HtmlTree.HEADING(Headings.CONTENT_HEADING,
HtmlStyle.title, headContent);
heading.setId(getNameForIndex(unicode));
contentTree.add(heading);
}
protected void addDescription(IndexItem indexItem, Content dl) {
if (indexItem.isTagItem()) {
addTagDescription(indexItem, dl);
} else if (indexItem.isElementItem()) {
addElementDescription(indexItem, dl);
}
}
/**
* Add one line summary comment for the element.
*
* @param item the element to be documented
* @param dlTree the content tree to which the description will be added
*/
protected void addElementDescription(IndexItem item, Content dlTree) {
Content dt;
Element element = item.getElement();
String label = item.getLabel();
switch (element.getKind()) {
case MODULE:
dt = HtmlTree.DT(getModuleLink((ModuleElement) element, new StringContent(label)));
dt.add(" - ").add(contents.module_).add(" " + label);
break;
case PACKAGE:
dt = HtmlTree.DT(getPackageLink((PackageElement) element, new StringContent(label)));
if (configuration.showModules) {
item.setContainingModule(utils.getFullyQualifiedName(utils.containingModule(element)));
}
dt.add(" - ").add(contents.package_).add(" " + label);
break;
case CLASS:
case ENUM:
case RECORD:
case ANNOTATION_TYPE:
case INTERFACE:
dt = HtmlTree.DT(getLink(new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.INDEX, (TypeElement) element).strong(true)));
dt.add(" - ");
addClassInfo((TypeElement) element, dt);
break;
case CONSTRUCTOR:
case METHOD:
case FIELD:
case ENUM_CONSTANT:
TypeElement containingType = item.getContainingTypeElement();
dt = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.memberNameLink,
getDocLink(LinkInfoImpl.Kind.INDEX, containingType, element, new StringContent(label))));
dt.add(" - ");
addMemberDesc(element, containingType, dt);
break;
default:
throw new Error();
}
dlTree.add(dt);
Content dd = new HtmlTree(TagName.DD);
if (element.getKind() == ElementKind.MODULE || element.getKind() == ElementKind.PACKAGE) {
addSummaryComment(element, dd);
} else {
addComment(element, dd);
}
dlTree.add(dd);
}
/**
* Add the classkind (class, interface, exception), error of the class
* passed.
*
* @param te the class being documented
* @param contentTree the content tree to which the class info will be added
*/
protected void addClassInfo(TypeElement te, Content contentTree) {
contentTree.add(contents.getContent("doclet.in",
utils.getTypeElementName(te, false),
getPackageLink(utils.containingPackage(te),
utils.getPackageName(utils.containingPackage(te)))
));
}
protected void addTagDescription(IndexItem item, Content dlTree) {
String itemPath = pathToRoot.isEmpty() ? "" : pathToRoot.getPath() + "/";
itemPath += item.getUrl();
HtmlTree labelLink = HtmlTree.A(itemPath, new StringContent(item.getLabel()));
Content dt = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.searchTagLink, labelLink));
dt.add(" - ");
dt.add(contents.getContent("doclet.Search_tag_in", item.getHolder()));
dlTree.add(dt);
Content dd = new HtmlTree(TagName.DD);
if (item.getDescription().isEmpty()) {
dd.add(Entity.NO_BREAK_SPACE);
} else {
dd.add(item.getDescription());
}
dlTree.add(dd);
}
/**
* Add comment for each element in the index. If the element is deprecated
* and it has a @deprecated tag, use that comment. Else if the containing
* class for this element is deprecated, then add the word "Deprecated." at
* the start and then print the normal comment.
*
* @param element Index element
* @param contentTree the content tree to which the comment will be added
*/
protected void addComment(Element element, Content contentTree) {
List<? extends DocTree> tags;
Content span = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, getDeprecatedPhrase(element));
HtmlTree div = new HtmlTree(TagName.DIV);
div.setStyle(HtmlStyle.deprecationBlock);
if (utils.isDeprecated(element)) {
div.add(span);
tags = utils.getBlockTags(element, DocTree.Kind.DEPRECATED);
if (!tags.isEmpty())
addInlineDeprecatedComment(element, tags.get(0), div);
contentTree.add(div);
} else {
TypeElement encl = utils.getEnclosingTypeElement(element);
while (encl != null) {
if (utils.isDeprecated(encl)) {
div.add(span);
contentTree.add(div);
break;
}
encl = utils.getEnclosingTypeElement(encl);
}
addSummaryComment(element, contentTree);
}
}
/**
* Add description about the Static Variable/Method/Constructor for a
* member.
*
* @param member element for the member
* @param enclosing the enclosing type element
* @param contentTree the content tree to which the member description will be added
*/
protected void addMemberDesc(Element member, TypeElement enclosing, Content contentTree) {
String classdesc = utils.getTypeElementName(enclosing, true) + " ";
if (utils.isField(member)) {
Content resource = contents.getContent(utils.isStatic(member)
? "doclet.Static_variable_in"
: "doclet.Variable_in", classdesc);
contentTree.add(resource);
} else if (utils.isConstructor(member)) {
contentTree.add(
contents.getContent("doclet.Constructor_for", classdesc));
} else if (utils.isMethod(member)) {
Content resource = contents.getContent(utils.isStatic(member)
? "doclet.Static_method_in"
: "doclet.Method_in", classdesc);
contentTree.add(resource);
}
addPreQualifiedClassLink(LinkInfoImpl.Kind.INDEX, enclosing,
false, contentTree);
}
/**
* Generate a valid HTML name for member index page.
*
* @param unicode the string that needs to be converted to valid HTML name.
* @return a valid HTML name string.
*/
public String getNameForIndex(String unicode) {
return "I:" + links.getName(unicode);
}
}

View File

@ -171,11 +171,7 @@ public class HtmlDoclet extends AbstractDoclet {
if (options.createIndex()) {
SystemPropertiesWriter.generate(configuration);
configuration.mainIndex.addElements();
if (options.splitIndex()) {
SplitIndexWriter.generate(configuration);
} else {
SingleIndexWriter.generate(configuration);
}
IndexWriter.generate(configuration);
IndexBuilder allClassesIndex = new IndexBuilder(configuration, nodeprecated, true);
allClassesIndex.addElements();
AllClassesIndexWriter.generate(configuration, allClassesIndex);

View File

@ -0,0 +1,400 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.javadoc.internal.doclets.formats.html;
import java.util.List;
import java.util.ListIterator;
import java.util.SortedSet;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ModuleElement;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import com.sun.source.doctree.DocTree;
import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
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.TagName;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder;
import jdk.javadoc.internal.doclets.toolkit.util.IndexItem;
/**
* Generator for either a single index or split index for all
* documented elements, terms defined in some documentation comments,
* and summary pages.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*
* @see IndexBuilder
*/
public class IndexWriter extends HtmlDocletWriter {
protected final IndexBuilder mainIndex;
protected final boolean splitIndex;
/**
* Generates the main index of all documented elements, terms defined in some documentation
* comments, and summary pages.
*
* If {@link HtmlOptions#splitIndex()} is true, a separate page is generated for each
* initial letter; otherwise, a single page is generated for all items in the index.
*
* @param configuration the configuration
* @throws DocFileIOException if an error occurs while writing the files
*/
public static void generate(HtmlConfiguration configuration) throws DocFileIOException {
IndexBuilder mainIndex = configuration.mainIndex;
List<Character> firstCharacters = mainIndex.getFirstCharacters();
if (configuration.getOptions().splitIndex()) {
ListIterator<Character> iter = firstCharacters.listIterator();
while (iter.hasNext()) {
Character ch = iter.next();
DocPath file = DocPaths.INDEX_FILES.resolve(DocPaths.indexN(iter.nextIndex()));
IndexWriter writer = new IndexWriter(configuration, file);
writer.generateIndexFile(firstCharacters, List.of(ch));
}
} else {
IndexWriter writer = new IndexWriter(configuration, DocPaths.INDEX_ALL);
writer.generateIndexFile(firstCharacters, firstCharacters);
}
}
/**
* Creates a writer that can write a page containing some or all of the overall index.
*
* @param configuration the current configuration
* @param path the file to be generated
*/
protected IndexWriter(HtmlConfiguration configuration, DocPath path) {
super(configuration, path);
this.mainIndex = configuration.mainIndex;
this.splitIndex = configuration.getOptions().splitIndex();
}
/**
* Generates a page containing some or all of the overall index.
*
* @param allFirstCharacters the initial characters of all index items
* @param displayFirstCharacters the initial characters of the index items to appear on this page
* @throws DocFileIOException if an error occurs while writing the page
*/
protected void generateIndexFile(List<Character> allFirstCharacters,
List<Character> displayFirstCharacters) throws DocFileIOException {
String title = splitIndex
? resources.getText("doclet.Window_Split_Index", displayFirstCharacters.get(0))
: resources.getText("doclet.Window_Single_Index");
HtmlTree body = getBody(getWindowTitle(title));
Content headerContent = new ContentBuilder();
addTop(headerContent);
Navigation navBar = new Navigation(null, configuration, PageMode.INDEX, path);
navBar.setUserHeader(getUserHeaderFooter(true));
headerContent.add(navBar.getContent(Navigation.Position.TOP));
Content mainContent = new ContentBuilder();
addLinksForIndexes(allFirstCharacters, mainContent);
for (Character ch : displayFirstCharacters) {
addContents(ch, mainIndex.getItems(ch), mainContent);
}
addLinksForIndexes(allFirstCharacters, mainContent);
HtmlTree footer = HtmlTree.FOOTER();
navBar.setUserFooter(getUserHeaderFooter(false));
footer.add(navBar.getContent(Navigation.Position.BOTTOM));
addBottom(footer);
body.add(new BodyContents()
.setHeader(headerContent)
.addMainContent(HtmlTree.DIV(HtmlStyle.header,
HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING,
contents.getContent("doclet.Index"))))
.addMainContent(mainContent)
.setFooter(footer));
String description = splitIndex ? "index: " + displayFirstCharacters.get(0) : "index";
printHtmlDocument(null, description, body);
}
/**
* Adds a set of items to the page.
*
* @param ch the first character of the names of the items
* @param items the items
* @param contentTree the tree to which to add the items
*/
protected void addContents(char ch, SortedSet<IndexItem> items, Content contentTree) {
addHeading(ch, contentTree);
HtmlTree dl = HtmlTree.DL(HtmlStyle.index);
for (IndexItem item : items) {
addDescription(item, dl);
}
contentTree.add(dl);
}
/**
* Adds a heading containing the first character for a set of items.
*
* @param ch the first character of the names of the items
* @param contentTree the tree to which to add the items
*/
protected void addHeading(char ch, Content contentTree) {
Content headContent = new StringContent(String.valueOf(ch));
HtmlTree heading = HtmlTree.HEADING(Headings.CONTENT_HEADING, HtmlStyle.title, headContent)
.setId(getNameForIndex(ch));
contentTree.add(heading);
}
/**
* Adds the description for an index item into a list.
*
* @param indexItem the item
* @param dl the list
*/
protected void addDescription(IndexItem indexItem, Content dl) {
if (indexItem.isTagItem()) {
addTagDescription(indexItem, dl);
} else if (indexItem.isElementItem()) {
addElementDescription(indexItem, dl);
}
}
/**
* Add one line summary comment for the item.
*
* @param item the item to be documented
* @param dlTree the content tree to which the description will be added
*/
protected void addElementDescription(IndexItem item, Content dlTree) {
Content dt;
Element element = item.getElement();
String label = item.getLabel();
switch (element.getKind()) {
case MODULE:
dt = HtmlTree.DT(getModuleLink((ModuleElement) element, new StringContent(label)));
dt.add(" - ").add(contents.module_).add(" " + label);
break;
case PACKAGE:
dt = HtmlTree.DT(getPackageLink((PackageElement) element, new StringContent(label)));
if (configuration.showModules) {
item.setContainingModule(utils.getFullyQualifiedName(utils.containingModule(element)));
}
dt.add(" - ").add(contents.package_).add(" " + label);
break;
case CLASS:
case ENUM:
case RECORD:
case ANNOTATION_TYPE:
case INTERFACE:
dt = HtmlTree.DT(getLink(new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.INDEX, (TypeElement) element).strong(true)));
dt.add(" - ");
addClassInfo((TypeElement) element, dt);
break;
case CONSTRUCTOR:
case METHOD:
case FIELD:
case ENUM_CONSTANT:
TypeElement containingType = item.getContainingTypeElement();
dt = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.memberNameLink,
getDocLink(LinkInfoImpl.Kind.INDEX, containingType, element, new StringContent(label))));
dt.add(" - ");
addMemberDesc(element, containingType, dt);
break;
default:
throw new Error();
}
dlTree.add(dt);
Content dd = new HtmlTree(TagName.DD);
if (element.getKind() == ElementKind.MODULE || element.getKind() == ElementKind.PACKAGE) {
addSummaryComment(element, dd);
} else {
addComment(element, dd);
}
dlTree.add(dd);
}
/**
* Adds information for the given type element.
*
* @param te the element
* @param contentTree the content tree to which the class info will be added
*/
protected void addClassInfo(TypeElement te, Content contentTree) {
contentTree.add(contents.getContent("doclet.in",
utils.getTypeElementKindName(te, false),
getPackageLink(utils.containingPackage(te),
utils.getPackageName(utils.containingPackage(te)))
));
}
/**
* Adds a description for an item found in a documentation comment.
*
* @param item the item
* @param dlTree the list to which to add the description
*/
protected void addTagDescription(IndexItem item, Content dlTree) {
String itemPath = pathToRoot.isEmpty() ? "" : pathToRoot.getPath() + "/";
itemPath += item.getUrl();
HtmlTree labelLink = HtmlTree.A(itemPath, new StringContent(item.getLabel()));
Content dt = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.searchTagLink, labelLink));
dt.add(" - ");
dt.add(contents.getContent("doclet.Search_tag_in", item.getHolder()));
dlTree.add(dt);
Content dd = new HtmlTree(TagName.DD);
if (item.getDescription().isEmpty()) {
dd.add(Entity.NO_BREAK_SPACE);
} else {
dd.add(item.getDescription());
}
dlTree.add(dd);
}
/**
* Adds a comment for an element in the index. If the element is deprecated
* and it has a @deprecated tag, use that comment; otherwise, if the containing
* class for this element is deprecated, then add the word "Deprecated." at
* the start and then print the normal comment.
*
* @param element the element
* @param contentTree the content tree to which the comment will be added
*/
protected void addComment(Element element, Content contentTree) {
List<? extends DocTree> tags;
Content span = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, getDeprecatedPhrase(element));
HtmlTree div = new HtmlTree(TagName.DIV);
div.setStyle(HtmlStyle.deprecationBlock);
if (utils.isDeprecated(element)) {
div.add(span);
tags = utils.getBlockTags(element, DocTree.Kind.DEPRECATED);
if (!tags.isEmpty())
addInlineDeprecatedComment(element, tags.get(0), div);
contentTree.add(div);
} else {
TypeElement encl = utils.getEnclosingTypeElement(element);
while (encl != null) {
if (utils.isDeprecated(encl)) {
div.add(span);
contentTree.add(div);
break;
}
encl = utils.getEnclosingTypeElement(encl);
}
addSummaryComment(element, contentTree);
}
}
/**
* Adds a description for a member element.
*
* @param member the element
* @param enclosing the enclosing type element
* @param contentTree the content tree to which the member description will be added
*/
protected void addMemberDesc(Element member, TypeElement enclosing, Content contentTree) {
String kindName = utils.getTypeElementKindName(enclosing, true);
String resource = switch (member.getKind()) {
case ENUM_CONSTANT ->
"doclet.Enum_constant_in";
case FIELD ->
utils.isStatic(member) ? "doclet.Static_variable_in" : "doclet.Variable_in";
case CONSTRUCTOR ->
"doclet.Constructor_for";
case METHOD ->
utils.isAnnotationType(enclosing) ? "doclet.Element_in"
: utils.isStatic(member) ? "doclet.Static_method_in" : "doclet.Method_in";
case RECORD_COMPONENT ->
"doclet.Record_component_in";
default -> throw new IllegalArgumentException(member.getKind().toString());
};
contentTree.add(contents.getContent(resource, kindName)).add(" ");
addPreQualifiedClassLink(LinkInfoImpl.Kind.INDEX, enclosing,
false, contentTree);
}
/**
* Add links for all the index files, based on the first character of the names of the items.
*
* @param allFirstCharacters the list of all first characters to be linked
* @param contentTree the content tree to which the links for indexes will be added
*/
protected void addLinksForIndexes(List<Character> allFirstCharacters, Content contentTree) {
ListIterator<Character> iter = allFirstCharacters.listIterator();
while (iter.hasNext()) {
char ch = iter.next();
Content label = new StringContent(Character.toString(ch));
Content link = splitIndex
? links.createLink(DocPaths.indexN(iter.nextIndex()), label)
: links.createLink(getNameForIndex(ch), label);
contentTree.add(link);
contentTree.add(Entity.NO_BREAK_SPACE);
}
contentTree.add(new HtmlTree(TagName.BR));
contentTree.add(links.createLink(pathToRoot.resolve(DocPaths.ALLCLASSES_INDEX),
contents.allClassesLabel));
if (!configuration.packages.isEmpty()) {
contentTree.add(getVerticalSeparator());
contentTree.add(links.createLink(pathToRoot.resolve(DocPaths.ALLPACKAGES_INDEX),
contents.allPackagesLabel));
}
boolean anySystemProperties = !mainIndex.getItems(DocTree.Kind.SYSTEM_PROPERTY).isEmpty();
if (anySystemProperties) {
contentTree.add(getVerticalSeparator());
contentTree.add(links.createLink(pathToRoot.resolve(DocPaths.SYSTEM_PROPERTIES),
contents.systemPropertiesLabel));
}
}
/**
* Returns the anchor name for a first character of names in the index.
*
* @param firstCharacter the character
* @return a name
*/
protected String getNameForIndex(char firstCharacter) {
return "I:" + links.getName(Character.toString(firstCharacter));
}
}

View File

@ -1,143 +0,0 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.javadoc.internal.doclets.formats.html;
import java.util.Set;
import java.util.TreeSet;
import com.sun.source.doctree.DocTree;
import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
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.TagName;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder;
import jdk.javadoc.internal.doclets.toolkit.util.IndexItem.Category;
/**
* Generate only one index file for all the Member Names with Indexing in
* Unicode Order. The name of the generated file is "index-all.html" and it is
* generated in current or the destination directory.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*
* @see java.lang.Character
*/
public class SingleIndexWriter extends AbstractIndexWriter {
private Set<Character> firstCharacters;
/**
* Construct the SingleIndexWriter with filename "index-all.html" and the
* {@link IndexBuilder}
*
* @param configuration the configuration for this doclet
*/
public SingleIndexWriter(HtmlConfiguration configuration) {
super(configuration, DocPaths.INDEX_ALL);
}
/**
* Generate single index file, for all Unicode characters.
*
* @param configuration the configuration for this doclet
* @throws DocFileIOException if there is a problem generating the index
*/
public static void generate(HtmlConfiguration configuration) throws DocFileIOException {
SingleIndexWriter indexgen = new SingleIndexWriter(configuration);
indexgen.generateIndexFile();
}
/**
* Generate the contents of each index file, with Header, Footer,
* Member Field, Method and Constructor Description.
* @throws DocFileIOException if there is a problem generating the index
*/
protected void generateIndexFile() throws DocFileIOException {
String title = resources.getText("doclet.Window_Single_Index");
HtmlTree body = getBody(getWindowTitle(title));
Content headerContent = new ContentBuilder();
addTop(headerContent);
navBar.setUserHeader(getUserHeaderFooter(true));
headerContent.add(navBar.getContent(Navigation.Position.TOP));
Content mainContent = new ContentBuilder();
firstCharacters = new TreeSet<>(mainIndex.getFirstCharacters());
addLinksForIndexes(mainContent);
for (Character ch : firstCharacters) {
addContents(ch, mainIndex.getItems(ch), mainContent);
}
addLinksForIndexes(mainContent);
HtmlTree footer = HtmlTree.FOOTER();
navBar.setUserFooter(getUserHeaderFooter(false));
footer.add(navBar.getContent(Navigation.Position.BOTTOM));
addBottom(footer);
body.add(new BodyContents()
.setHeader(headerContent)
.addMainContent(HtmlTree.DIV(HtmlStyle.header,
HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING,
contents.getContent("doclet.Index"))))
.addMainContent(mainContent)
.setFooter(footer));
printHtmlDocument(null, "index", body);
}
/**
* Add links for all the Index Files per unicode character.
*
* @param contentTree the content tree to which the links for indexes will be added
*/
protected void addLinksForIndexes(Content contentTree) {
for (Character ch : firstCharacters) {
String unicode = ch.toString();
contentTree.add(
links.createLink(getNameForIndex(unicode),
new StringContent(unicode)));
contentTree.add(Entity.NO_BREAK_SPACE);
}
contentTree.add(new HtmlTree(TagName.BR));
contentTree.add(links.createLink(DocPaths.ALLCLASSES_INDEX,
contents.allClassesLabel));
if (!configuration.packages.isEmpty()) {
contentTree.add(getVerticalSeparator());
contentTree.add(links.createLink(DocPaths.ALLPACKAGES_INDEX,
contents.allPackagesLabel));
}
boolean anySystemProperties = !mainIndex.getItems(DocTree.Kind.SYSTEM_PROPERTY).isEmpty();
if (anySystemProperties) {
contentTree.add(getVerticalSeparator());
contentTree.add(links.createLink(DocPaths.SYSTEM_PROPERTIES, contents.systemPropertiesLabel));
}
}
}

View File

@ -1,166 +0,0 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.javadoc.internal.doclets.formats.html;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.ListIterator;
import java.util.SortedSet;
import java.util.TreeSet;
import com.sun.source.doctree.DocTree;
import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
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.TagName;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder;
import jdk.javadoc.internal.doclets.toolkit.util.IndexItem.Category;
/**
* Generate Separate Index Files for all the member names with Indexing in
* Unicode Order. This will create "index-files" directory in the current or
* destination directory and will generate separate file for each unicode index.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*
* @see java.lang.Character
*/
public class SplitIndexWriter extends AbstractIndexWriter {
private final List<Character> indexElements;
/**
* Construct the SplitIndexWriter. Uses path to this file and relative path
* from this file.
*
* @param configuration the configuration for this doclet
* @param path Path to the file which is getting generated.
* @param elements the collection of characters for which to generate index files
*/
public SplitIndexWriter(HtmlConfiguration configuration,
DocPath path,
Collection<Character> elements) {
super(configuration, path);
this.indexElements = new ArrayList<>(elements);
}
/**
* Generate separate index files, for each Unicode character, listing all
* the members starting with the particular unicode character.
*
* @param configuration the configuration for this doclet
* @throws DocFileIOException if there is a problem generating the index files
*/
public static void generate(HtmlConfiguration configuration) throws DocFileIOException {
DocPath path = DocPaths.INDEX_FILES;
IndexBuilder mainIndex = configuration.mainIndex;
SortedSet<Character> keys = new TreeSet<>(mainIndex.getFirstCharacters());
ListIterator<Character> li = new ArrayList<>(keys).listIterator();
while (li.hasNext()) {
Character ch = li.next();
DocPath filename = DocPaths.indexN(li.nextIndex());
SplitIndexWriter indexgen = new SplitIndexWriter(configuration,
path.resolve(filename), keys);
indexgen.generateIndexFile(ch);
}
}
/**
* Generate the contents of each index file, with Header, Footer,
* Member Field, Method and Constructor Description.
*
* @param unicode Unicode character referring to the character for the
* index.
* @throws DocFileIOException if there is a problem generating an index file
*/
protected void generateIndexFile(Character unicode) throws DocFileIOException {
String title = resources.getText("doclet.Window_Split_Index",
unicode.toString());
HtmlTree body = getBody(getWindowTitle(title));
Content headerContent = new ContentBuilder();
addTop(headerContent);
navBar.setUserHeader(getUserHeaderFooter(true));
headerContent.add(navBar.getContent(Navigation.Position.TOP));
Content main = new ContentBuilder();
main.add(HtmlTree.DIV(HtmlStyle.header,
HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING,
contents.getContent("doclet.Index"))));
Content mainContent = new ContentBuilder();
addLinksForIndexes(mainContent);
addContents(unicode, mainIndex.getItems(unicode), mainContent);
addLinksForIndexes(mainContent);
main.add(mainContent);
HtmlTree footer = HtmlTree.FOOTER();
navBar.setUserFooter(getUserHeaderFooter(false));
footer.add(navBar.getContent(Navigation.Position.BOTTOM));
addBottom(footer);
body.add(new BodyContents()
.setHeader(headerContent)
.addMainContent(main)
.setFooter(footer));
String description = "index: " + unicode;
printHtmlDocument(null, description, body);
}
/**
* Add links for all the Index Files per unicode character.
*
* @param contentTree the content tree to which the links for indexes will be added
*/
protected void addLinksForIndexes(Content contentTree) {
for (int i = 0; i < indexElements.size(); i++) {
int j = i + 1;
contentTree.add(links.createLink(DocPaths.indexN(j),
new StringContent(indexElements.get(i).toString())));
contentTree.add(Entity.NO_BREAK_SPACE);
}
contentTree.add(new HtmlTree(TagName.BR));
contentTree.add(links.createLink(pathToRoot.resolve(DocPaths.ALLCLASSES_INDEX),
contents.allClassesLabel));
if (!configuration.packages.isEmpty()) {
contentTree.add(getVerticalSeparator());
contentTree.add(links.createLink(pathToRoot.resolve(DocPaths.ALLPACKAGES_INDEX),
contents.allPackagesLabel));
}
boolean anySystemProperties = !mainIndex.getItems(DocTree.Kind.SYSTEM_PROPERTY).isEmpty();
if (anySystemProperties) {
contentTree.add(getVerticalSeparator());
contentTree.add(links.createLink(pathToRoot.resolve(DocPaths.SYSTEM_PROPERTIES),
contents.systemPropertiesLabel));
}
}
}

View File

@ -395,7 +395,7 @@ public class TagletWriterImpl extends TagletWriter {
@Override
public String visitType(TypeElement e, Void p) {
return utils.getTypeElementName(e, true)
return utils.getTypeElementKindName(e, true)
+ " " + utils.getFullyQualifiedName(e);
}

View File

@ -484,7 +484,6 @@ public enum HtmlStyle {
/**
* The class of the element used to present the documentation comment for a module element,
* excluding block tags.
* The content of the block tags will be in a sibling element with class {@link #moduleTags}.
*/
moduleDescription,
@ -630,6 +629,11 @@ public enum HtmlStyle {
*/
helpPage,
/**
* The class of the {@code body} element for a page in either the "single" or "split index".
*/
indexPage,
/**
* The class of the {@code body} element for the top-level redirect page.
*/
@ -670,21 +674,11 @@ public enum HtmlStyle {
*/
serializedFormPage,
/**
* The class of the {@code body} element for the full single index page.
*/
singleIndexPage,
/**
* The class of the {@code body} element for a page with the source code for a class.
*/
sourcePage,
/**
* The class of the {@code body} element for a page in a "split index".
*/
splitIndexPage,
/**
* The class of the {@code body} element for the system-properties page.
*/

View File

@ -74,9 +74,12 @@ doclet.navDeprecated=Deprecated
doclet.Window_Deprecated_List=Deprecated List
doclet.Overrides=Overrides:
doclet.in_class=in class
doclet.Element_in=Element in {0}
doclet.Enum_constant_in=Enum constant in {0}
doclet.Static_variable_in=Static variable in {0}
doclet.Variable_in=Variable in {0}
doclet.Constructor_for=Constructor for {0}
doclet.Record_component_in=Record component of {0}
doclet.Static_method_in=Static method in {0}
doclet.Search_tag_in=Search tag in {0}
doclet.Method_in=Method in {0}

View File

@ -163,6 +163,7 @@ doclet.interfaces=interfaces
doclet.class=class
doclet.classes=classes
doclet.Record=Record
doclet.record=record
doclet.Error=Error
doclet.error=error
doclet.errors=errors

View File

@ -61,7 +61,7 @@ public class DocPaths {
/** The name of the file for constant values. */
public static final DocPath CONSTANT_VALUES = DocPath.create("constant-values.html");
/** The name of the fie for deprecated elements. */
/** The name of the file for deprecated elements. */
public static final DocPath DEPRECATED_LIST = DocPath.create("deprecated-list.html");
/** The name of the subdirectory for user-provided additional documentation files. */

View File

@ -184,7 +184,7 @@ public class IndexBuilder {
}
/**
* Returns a list of index keys.
* Returns a sorted list of the first characters of the labels of index items.
*/
public List<Character> getFirstCharacters() {
return new ArrayList<>(itemsByFirstChar.keySet());

View File

@ -1337,33 +1337,35 @@ public class Utils {
}
/**
* Given a TypeElement, return the name of its type (Class, Interface, etc.).
* Returns the name of the kind of a type element (Class, Interface, etc.).
*
* @param te the TypeElement to check.
* @param lowerCaseOnly true if you want the name returned in lower case.
* If false, the first letter of the name is capitalized.
* @return
* @param te the type element
* @param lowerCaseOnly true if you want the name returned in lower case;
* if false, the first letter of the name is capitalized
* @return the name
*/
public String getTypeElementName(TypeElement te, boolean lowerCaseOnly) {
String typeName = "";
if (isInterface(te)) {
typeName = "doclet.Interface";
} else if (isException(te)) {
typeName = "doclet.Exception";
} else if (isError(te)) {
typeName = "doclet.Error";
} else if (isAnnotationType(te)) {
typeName = "doclet.AnnotationType";
} else if (isEnum(te)) {
typeName = "doclet.Enum";
} else if (isOrdinaryClass(te)) {
typeName = "doclet.Class";
}
typeName = lowerCaseOnly ? toLowerCase(typeName) : typeName;
return typeNameMap.computeIfAbsent(typeName, resources::getText);
public String getTypeElementKindName(TypeElement te, boolean lowerCaseOnly) {
String kindName = switch (te.getKind()) {
case ANNOTATION_TYPE ->
"doclet.AnnotationType";
case ENUM ->
"doclet.Enum";
case INTERFACE ->
"doclet.Interface";
case RECORD ->
"doclet.Record";
case CLASS ->
isException(te) ? "doclet.Exception"
: isError(te) ? "doclet.Error"
: "doclet.Class";
default ->
throw new IllegalArgumentException(te.getKind().toString());
};
kindName = lowerCaseOnly ? toLowerCase(kindName) : kindName;
return kindNameMap.computeIfAbsent(kindName, resources::getText);
}
private final Map<String, String> typeNameMap = new HashMap<>();
private final Map<String, String> kindNameMap = new HashMap<>();
public String getTypeName(TypeMirror t, boolean fullyQualified) {
return new SimpleTypeVisitor9<String, Void>() {

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 8218998 8219946 8219060 8241190 8242056
* @bug 8218998 8219946 8219060 8241190 8242056 8254627
* @summary Add metadata to generated API documentation files
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
@ -150,6 +150,7 @@ public class TestMetadata extends JavadocTester {
"deprecated-list-page",
"doc-file-page",
"help-page",
"index-page",
"index-redirect-page",
"module-declaration-page",
"module-index-page",
@ -158,9 +159,7 @@ public class TestMetadata extends JavadocTester {
"package-tree-page",
"package-use-page",
"serialized-form-page",
"single-index-page",
"source-page",
"split-index-page",
"system-properties-page",
"tree-page"
);
@ -218,6 +217,7 @@ public class TestMetadata extends JavadocTester {
"DocFileWriter",
"HelpWriter",
"IndexRedirectWriter",
"IndexWriter",
"ModuleIndexWriter",
"ModuleWriterImpl",
"PackageIndexWriter",
@ -225,9 +225,7 @@ public class TestMetadata extends JavadocTester {
"PackageUseWriter",
"PackageWriterImpl",
"SerializedFormWriterImpl",
"SingleIndexWriter",
"SourceToHTMLConverter",
"SplitIndexWriter",
"SystemPropertiesWriter",
"TreeWriter"
);
@ -353,6 +351,10 @@ public class TestMetadata extends JavadocTester {
check(generator, content, content.contains("redirect"));
break;
case "IndexWriter":
check(generator, content, content.startsWith("index"));
break;
case "PackageTreeWriter":
case "TreeWriter":
check(generator, content, content.contains("tree"));
@ -362,11 +364,6 @@ public class TestMetadata extends JavadocTester {
check(generator, content, content.contains("serialized"));
break;
case "SingleIndexWriter":
case "SplitIndexWriter":
check(generator, content, content.startsWith("index"));
break;
case "SourceToHTMLConverter":
check(generator, content, content.startsWith("source:"));
break;

View File

@ -25,7 +25,7 @@
* @test
* @bug 8141492 8071982 8141636 8147890 8166175 8168965 8176794 8175218 8147881
* 8181622 8182263 8074407 8187521 8198522 8182765 8199278 8196201 8196202
* 8184205 8214468 8222548 8223378 8234746 8241219
* 8184205 8214468 8222548 8223378 8234746 8241219 8254627
* @summary Test the search feature of javadoc.
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
@ -487,14 +487,14 @@ public class TestSearch extends JavadocTester {
/a></span> - Search tag in pkg.AnotherClass.CONSTANT1</dt>""",
"""
<dt><span class="member-name-link"><a href="pkg2/TestEnum.html#ONE">ONE</a></spa\
n> - pkg2.<a href="pkg2/TestEnum.html" title="enum in pkg2">TestEnum</a></dt>""",
n> - Enum constant in enum pkg2.<a href="pkg2/TestEnum.html" title="enum in pkg2">TestEnum</a></dt>""",
"""
<dt><span class="member-name-link"><a href="pkg2/TestEnum.html#THREE">THREE</a><\
/span> - pkg2.<a href="pkg2/TestEnum.html" title="enum in pkg2">TestEnum</a></dt\
/span> - Enum constant in enum pkg2.<a href="pkg2/TestEnum.html" title="enum in pkg2">TestEnum</a></dt\
>""",
"""
<dt><span class="member-name-link"><a href="pkg2/TestEnum.html#TWO">TWO</a></spa\
n> - pkg2.<a href="pkg2/TestEnum.html" title="enum in pkg2">TestEnum</a></dt>""");
n> - Enum constant in enum pkg2.<a href="pkg2/TestEnum.html" title="enum in pkg2">TestEnum</a></dt>""");
checkOutput("index-all.html", true,
"""
<div class="deprecation-comment">class_test1 passes. Search tag <span id="Search\
@ -575,16 +575,16 @@ public class TestSearch extends JavadocTester {
checkOutput("index-files/index-9.html", true,
"""
<dt><span class="member-name-link"><a href="../pkg2/TestEnum.html#ONE">ONE</a></\
span> - pkg2.<a href="../pkg2/TestEnum.html" title="enum in pkg2">TestEnum</a></\
span> - Enum constant in enum pkg2.<a href="../pkg2/TestEnum.html" title="enum in pkg2">TestEnum</a></\
dt>""");
checkOutput("index-files/index-14.html", true,
"""
<dt><span class="member-name-link"><a href="../pkg2/TestEnum.html#THREE">THREE</\
a></span> - pkg2.<a href="../pkg2/TestEnum.html" title="enum in pkg2">TestEnum</\
a></span> - Enum constant in enum pkg2.<a href="../pkg2/TestEnum.html" title="enum in pkg2">TestEnum</\
a></dt>""",
"""
<dt><span class="member-name-link"><a href="../pkg2/TestEnum.html#TWO">TWO</a></\
span> - pkg2.<a href="../pkg2/TestEnum.html" title="enum in pkg2">TestEnum</a></\
span> - Enum constant in enum pkg2.<a href="../pkg2/TestEnum.html" title="enum in pkg2">TestEnum</a></\
dt>""");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/*
* @test
* @bug 8000612
* @bug 8000612 8254627
* @summary need test program to validate javadoc resource bundles
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.resources:open
@ -201,9 +201,9 @@ public class CheckResourceKeys {
}
// special handling for code strings synthesized in
// com.sun.tools.doclets.internal.toolkit.util.Util.getTypeName
// jdk.javadoc.internal.doclets.toolkit.util.Utils.getTypeName
String[] extras = {
"AnnotationType", "Class", "Enum", "Error", "Exception", "Interface"
"AnnotationType", "Class", "Enum", "Error", "Exception", "Interface", "Record"
};
for (String s: extras) {
if (results.contains("doclet." + s))