8198705: Javadoc search needs a fix to handle duplicate package names in different modules
Reviewed-by: jjg
This commit is contained in:
parent
226e852831
commit
ffbee17d8a
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets
formats/html
toolkit/util
test/langtools/jdk/javadoc/doclet
@ -27,6 +27,7 @@ package jdk.javadoc.internal.doclets.formats.html;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -105,8 +106,12 @@ public class AbstractIndexWriter extends HtmlDocletWriter {
|
||||
addHeading(uc, contentTree);
|
||||
|
||||
HtmlTree dl = HtmlTree.DL(HtmlStyle.index);
|
||||
Map<String,Integer> duplicateLabelCheck = new HashMap<>();
|
||||
memberlist.forEach(e -> duplicateLabelCheck.compute(e.getFullyQualifiedLabel(utils),
|
||||
(k, v) -> v == null ? 1 : v + 1));
|
||||
for (IndexItem indexItem : memberlist) {
|
||||
addDescription(indexItem, dl);
|
||||
addDescription(indexItem, dl,
|
||||
duplicateLabelCheck.get(indexItem.getFullyQualifiedLabel(utils)) > 1);
|
||||
}
|
||||
contentTree.add(dl);
|
||||
}
|
||||
@ -120,14 +125,14 @@ public class AbstractIndexWriter extends HtmlDocletWriter {
|
||||
contentTree.add(heading);
|
||||
}
|
||||
|
||||
protected void addDescription(IndexItem indexItem, Content dl) {
|
||||
protected void addDescription(IndexItem indexItem, Content dl, boolean addModuleInfo) {
|
||||
SearchIndexItem si = indexItem.getSearchTag();
|
||||
if (si != null) {
|
||||
addDescription(si, dl);
|
||||
} else {
|
||||
si = new SearchIndexItem();
|
||||
si.setLabel(indexItem.getLabel());
|
||||
addElementDescription(indexItem, dl, si);
|
||||
addElementDescription(indexItem, dl, si, addModuleInfo);
|
||||
searchItems.add(si);
|
||||
}
|
||||
}
|
||||
@ -138,8 +143,10 @@ public class AbstractIndexWriter extends HtmlDocletWriter {
|
||||
* @param indexItem the element to be documented
|
||||
* @param dlTree the content tree to which the description will be added
|
||||
* @param si the search index item
|
||||
* @param addModuleInfo whether to include module information
|
||||
*/
|
||||
protected void addElementDescription(IndexItem indexItem, Content dlTree, SearchIndexItem si) {
|
||||
protected void addElementDescription(IndexItem indexItem, Content dlTree, SearchIndexItem si,
|
||||
boolean addModuleInfo) {
|
||||
Content dt;
|
||||
Element element = indexItem.getElement();
|
||||
String label = indexItem.getLabel();
|
||||
@ -165,6 +172,9 @@ public class AbstractIndexWriter extends HtmlDocletWriter {
|
||||
dt = HtmlTree.DT(getLink(new LinkInfoImpl(configuration,
|
||||
LinkInfoImpl.Kind.INDEX, (TypeElement)element).strong(true)));
|
||||
si.setContainingPackage(utils.getPackageName(utils.containingPackage(element)));
|
||||
if (configuration.showModules && addModuleInfo) {
|
||||
si.setContainingModule(utils.getFullyQualifiedName(utils.containingModule(element)));
|
||||
}
|
||||
si.setCategory(Category.TYPES);
|
||||
dt.add(" - ");
|
||||
addClassInfo((TypeElement)element, dt);
|
||||
@ -175,6 +185,9 @@ public class AbstractIndexWriter extends HtmlDocletWriter {
|
||||
getDocLink(LinkInfoImpl.Kind.INDEX, containingType, element, new StringContent(label))));
|
||||
si.setContainingPackage(utils.getPackageName(utils.containingPackage(element)));
|
||||
si.setContainingClass(utils.getSimpleName(containingType));
|
||||
if (configuration.showModules && addModuleInfo) {
|
||||
si.setContainingModule(utils.getFullyQualifiedName(utils.containingModule(element)));
|
||||
}
|
||||
if (utils.isExecutableElement(element)) {
|
||||
String url = HtmlTree.encodeURL(links.getName(getAnchor((ExecutableElement)element)));
|
||||
if (!label.equals(url)) {
|
||||
|
@ -148,6 +148,9 @@ public class SearchIndexItem {
|
||||
if (!containingPackage.isEmpty()) {
|
||||
item.append("\"p\":\"").append(containingPackage).append("\",");
|
||||
}
|
||||
if (!containingModule.isEmpty()) {
|
||||
item.append("\"m\":\"").append(containingModule).append("\",");
|
||||
}
|
||||
item.append("\"l\":\"").append(label).append("\"");
|
||||
if (!url.isEmpty()) {
|
||||
item.append(",\"u\":\"").append(url).append("\"");
|
||||
@ -155,8 +158,11 @@ public class SearchIndexItem {
|
||||
item.append("}");
|
||||
break;
|
||||
case MEMBERS:
|
||||
item.append("{")
|
||||
.append("\"p\":\"").append(containingPackage).append("\",")
|
||||
item.append("{");
|
||||
if (!containingModule.isEmpty()) {
|
||||
item.append("\"m\":\"").append(containingModule).append("\",");
|
||||
}
|
||||
item.append("\"p\":\"").append(containingPackage).append("\",")
|
||||
.append("\"c\":\"").append(containingClass).append("\",")
|
||||
.append("\"l\":\"").append(label).append("\"");
|
||||
if (!url.isEmpty()) {
|
||||
|
@ -34,6 +34,7 @@ var searchPattern = "";
|
||||
var RANKING_THRESHOLD = 2;
|
||||
var NO_MATCH = 0xffff;
|
||||
var MAX_RESULTS_PER_CATEGORY = 500;
|
||||
var UNNAMED = "<Unnamed>";
|
||||
function escapeHtml(str) {
|
||||
return str.replace(/</g, "<").replace(/>/g, ">");
|
||||
}
|
||||
@ -48,14 +49,16 @@ function getURLPrefix(ui) {
|
||||
return ui.item.l + slash;
|
||||
} else if (ui.item.category === catPackages && ui.item.m) {
|
||||
return ui.item.m + slash;
|
||||
} else if ((ui.item.category === catTypes && ui.item.p) || ui.item.category === catMembers) {
|
||||
$.each(packageSearchIndex, function(index, item) {
|
||||
if (item.m && ui.item.p == item.l) {
|
||||
urlPrefix = item.m + slash;
|
||||
}
|
||||
});
|
||||
return urlPrefix;
|
||||
} else {
|
||||
} else if (ui.item.category === catTypes || ui.item.category === catMembers) {
|
||||
if (ui.item.m) {
|
||||
urlPrefix = ui.item.m + slash;
|
||||
} else {
|
||||
$.each(packageSearchIndex, function(index, item) {
|
||||
if (item.m && ui.item.p === item.l) {
|
||||
urlPrefix = item.m + slash;
|
||||
}
|
||||
});
|
||||
}
|
||||
return urlPrefix;
|
||||
}
|
||||
return urlPrefix;
|
||||
@ -121,7 +124,7 @@ $.widget("custom.catcomplete", $.ui.autocomplete, {
|
||||
rMenu.menu.bindings = $();
|
||||
$.each(items, function(index, item) {
|
||||
var li;
|
||||
if (item.l !== noResult.l && item.category !== currentCategory) {
|
||||
if (item.category && item.category !== currentCategory) {
|
||||
ul.append("<li class=\"ui-autocomplete-category\">" + item.category + "</li>");
|
||||
currentCategory = item.category;
|
||||
}
|
||||
@ -141,15 +144,15 @@ $.widget("custom.catcomplete", $.ui.autocomplete, {
|
||||
if (item.category === catModules) {
|
||||
label = getHighlightedText(item.l, matcher);
|
||||
} else if (item.category === catPackages) {
|
||||
label = (item.m)
|
||||
? getHighlightedText(item.m + "/" + item.l, matcher)
|
||||
: getHighlightedText(item.l, matcher);
|
||||
label = getHighlightedText(item.l, matcher);
|
||||
} else if (item.category === catTypes) {
|
||||
label = (item.p)
|
||||
label = (item.p && item.p !== UNNAMED)
|
||||
? getHighlightedText(item.p + "." + item.l, matcher)
|
||||
: getHighlightedText(item.l, matcher);
|
||||
} else if (item.category === catMembers) {
|
||||
label = getHighlightedText(item.p + "." + (item.c + "." + item.l), matcher);
|
||||
label = (item.p && item.p !== UNNAMED)
|
||||
? getHighlightedText(item.p + "." + item.c + "." + item.l, matcher)
|
||||
: getHighlightedText(item.c + "." + item.l, matcher);
|
||||
} else if (item.category === catSearchTags) {
|
||||
label = getHighlightedText(item.l, matcher);
|
||||
} else {
|
||||
@ -165,7 +168,11 @@ $.widget("custom.catcomplete", $.ui.autocomplete, {
|
||||
div.html(label + "<span class=\"search-tag-holder-result\"> (" + item.h + ")</span>");
|
||||
}
|
||||
} else {
|
||||
div.html(label);
|
||||
if (item.m) {
|
||||
div.html(item.m + "/" + label);
|
||||
} else {
|
||||
div.html(label);
|
||||
}
|
||||
}
|
||||
return li;
|
||||
}
|
||||
@ -317,7 +324,7 @@ $(function() {
|
||||
collision: "flip"
|
||||
},
|
||||
select: function(event, ui) {
|
||||
if (ui.item.l !== noResult.l) {
|
||||
if (ui.item.category) {
|
||||
var url = getURLPrefix(ui);
|
||||
if (ui.item.category === catModules) {
|
||||
url += "module-summary.html";
|
||||
@ -330,13 +337,13 @@ $(function() {
|
||||
} else if (ui.item.category === catTypes) {
|
||||
if (ui.item.u) {
|
||||
url = ui.item.u;
|
||||
} else if (ui.item.p === "<Unnamed>") {
|
||||
} else if (ui.item.p === UNNAMED) {
|
||||
url += ui.item.l + ".html";
|
||||
} else {
|
||||
url += ui.item.p.replace(/\./g, '/') + "/" + ui.item.l + ".html";
|
||||
}
|
||||
} else if (ui.item.category === catMembers) {
|
||||
if (ui.item.p === "<Unnamed>") {
|
||||
if (ui.item.p === UNNAMED) {
|
||||
url += ui.item.c + ".html" + "#";
|
||||
} else {
|
||||
url += ui.item.p.replace(/\./g, '/') + "/" + ui.item.c + ".html" + "#";
|
||||
|
@ -26,7 +26,6 @@
|
||||
package jdk.javadoc.internal.doclets.toolkit.util;
|
||||
|
||||
import jdk.javadoc.internal.doclets.formats.html.SearchIndexItem;
|
||||
import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
@ -90,6 +89,16 @@ public class IndexItem {
|
||||
return label;
|
||||
}
|
||||
|
||||
public String getFullyQualifiedLabel(Utils utils) {
|
||||
if (typeElement != null) {
|
||||
return utils.getFullyQualifiedName(typeElement) + "." + label;
|
||||
} else if (element != null) {
|
||||
return utils.getFullyQualifiedName(element);
|
||||
} else {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
public Element getElement() {
|
||||
return element;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8178070 8196201 8184205 8246429
|
||||
* @bug 8178070 8196201 8184205 8246429 8198705
|
||||
* @summary Test packages table in module summary pages
|
||||
* @library /tools/lib ../../lib
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
@ -167,6 +167,14 @@ public class TestModulePackages extends JavadocTester {
|
||||
<div class="sub-title"><span class="module-label-in-type">Module</span> <a href="../module-summary.html">o</a></div>
|
||||
<div class="sub-title"><span class="package-label-in-type">Package</span> <a href="package-summary.html">p</a></div>
|
||||
""");
|
||||
checkOutput("type-search-index.js", true,
|
||||
"""
|
||||
{"p":"p","m":"m","l":"C"},{"p":"p","m":"o","l":"C"}""");
|
||||
checkOutput("member-search-index.js", true,
|
||||
"""
|
||||
{"m":"m","p":"p","c":"C","l":"C()","u":"%3Cinit%3E()"}""",
|
||||
"""
|
||||
{"m":"o","p":"p","c":"C","l":"C()","u":"%3Cinit%3E()"}""");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -726,14 +726,16 @@ public class TestSearch extends JavadocTester {
|
||||
return ui.item.l + slash;
|
||||
} else if (ui.item.category === catPackages && ui.item.m) {
|
||||
return ui.item.m + slash;
|
||||
} else if ((ui.item.category === catTypes && ui.item.p) || ui.item.category === catMembers) {
|
||||
$.each(packageSearchIndex, function(index, item) {
|
||||
if (item.m && ui.item.p == item.l) {
|
||||
urlPrefix = item.m + slash;
|
||||
}
|
||||
});
|
||||
return urlPrefix;
|
||||
} else {
|
||||
} else if (ui.item.category === catTypes || ui.item.category === catMembers) {
|
||||
if (ui.item.m) {
|
||||
urlPrefix = ui.item.m + slash;
|
||||
} else {
|
||||
$.each(packageSearchIndex, function(index, item) {
|
||||
if (item.m && ui.item.p === item.l) {
|
||||
urlPrefix = item.m + slash;
|
||||
}
|
||||
});
|
||||
}
|
||||
return urlPrefix;
|
||||
}
|
||||
return urlPrefix;
|
||||
|
Loading…
x
Reference in New Issue
Block a user