Skip to content
This repository was archived by the owner on Mar 2, 2019. It is now read-only.

Commit 3d7b273

Browse files
author
hannesw
committed
8190876: javadoc search on "java.se" shows "java.se" the last one among other modules
Reviewed-by: jjg
1 parent 5ad4f19 commit 3d7b273

File tree

6 files changed

+92
-59
lines changed

6 files changed

+92
-59
lines changed

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,15 @@ public class HtmlConfiguration extends BaseConfiguration {
232232
*/
233233
public TypeElement currentTypeElement = null; // Set this TypeElement in the ClassWriter.
234234

235-
protected List<SearchIndexItem> memberSearchIndex = new ArrayList<>();
235+
protected SortedSet<SearchIndexItem> memberSearchIndex;
236236

237-
protected List<SearchIndexItem> moduleSearchIndex = new ArrayList<>();
237+
protected SortedSet<SearchIndexItem> moduleSearchIndex;
238238

239-
protected List<SearchIndexItem> packageSearchIndex = new ArrayList<>();
239+
protected SortedSet<SearchIndexItem> packageSearchIndex;
240240

241-
protected SortedSet<SearchIndexItem> tagSearchIndex = new TreeSet<>(makeSearchTagComparator());
241+
protected SortedSet<SearchIndexItem> tagSearchIndex;
242242

243-
protected List<SearchIndexItem> typeSearchIndex = new ArrayList<>();
243+
protected SortedSet<SearchIndexItem> typeSearchIndex;
244244

245245
protected Map<Character,List<SearchIndexItem>> tagSearchIndexMap = new HashMap<>();
246246

@@ -385,16 +385,6 @@ public boolean allowTag(HtmlTag htmlTag) {
385385
return htmlTag.allowTag(this.htmlVersion);
386386
}
387387

388-
public Comparator<SearchIndexItem> makeSearchTagComparator() {
389-
return (SearchIndexItem sii1, SearchIndexItem sii2) -> {
390-
int result = (sii1.getLabel()).compareTo(sii2.getLabel());
391-
if (result == 0) {
392-
result = (sii1.getHolder()).compareTo(sii2.getHolder());
393-
}
394-
return result;
395-
};
396-
}
397-
398388
/**
399389
* Decide the page which will appear first in the right-hand frame. It will
400390
* be "overview-summary.html" if "-overview" option is used or no
@@ -883,4 +873,14 @@ protected boolean finishOptionSettings0() throws DocletException {
883873
}
884874
return super.finishOptionSettings0();
885875
}
876+
877+
@Override
878+
protected void initConfiguration(DocletEnvironment docEnv) {
879+
super.initConfiguration(docEnv);
880+
memberSearchIndex = new TreeSet<>(utils.makeGenericSearchIndexComparator());
881+
moduleSearchIndex = new TreeSet<>(utils.makeGenericSearchIndexComparator());
882+
packageSearchIndex = new TreeSet<>(utils.makeGenericSearchIndexComparator());
883+
tagSearchIndex = new TreeSet<>(utils.makeGenericSearchIndexComparator());
884+
typeSearchIndex = new TreeSet<>(utils.makeTypeSearchIndexComparator());
885+
}
886886
}

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SearchIndexItem.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,13 @@ public String toString() {
139139
}
140140
return item.toString();
141141
}
142+
143+
/**
144+
* Get the part of the label after the last dot, or whole label if no dots.
145+
*
146+
* @return the simple name
147+
*/
148+
public String getSimpleName() {
149+
return label.substring(label.lastIndexOf('.') + 1);
150+
}
142151
}

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/search.js

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525

2626
var noResult = {l: "No results found"};
27-
var category = "category";
2827
var catModules = "Modules";
2928
var catPackages = "Packages";
3029
var catTypes = "Types";
@@ -170,25 +169,7 @@ $(function() {
170169
return e.l.substring(e.l.lastIndexOf(".") + 1);
171170
}
172171

173-
// Sort array items by short name (as opposed to fully qualified name).
174-
// Additionally, sort by the nested type name, when present,
175-
// as opposed to top level short name.
176-
function sortAndConcatResults(a1, a2) {
177-
var sortingKey;
178-
var sortArray = function(e1, e2) {
179-
var l = sortingKey(e1);
180-
var m = sortingKey(e2);
181-
if (l < m)
182-
return -1;
183-
if (l > m)
184-
return 1;
185-
return 0;
186-
};
187-
sortingKey = function(e) {
188-
return nestedName(e).toUpperCase();
189-
};
190-
a1.sort(sortArray);
191-
a2.sort(sortArray);
172+
function concatResults(a1, a2) {
192173
a1 = a1.concat(a2);
193174
a2.length = 0;
194175
return a1;
@@ -197,85 +178,85 @@ $(function() {
197178
if (moduleSearchIndex) {
198179
var mdleCount = 0;
199180
$.each(moduleSearchIndex, function(index, item) {
200-
item[category] = catModules;
181+
item.category = catModules;
201182
if (exactMatcher.test(item.l)) {
202-
result.unshift(item);
183+
result.push(item);
203184
mdleCount++;
204185
} else if (camelCaseMatcher.test(item.l)) {
205-
result.unshift(item);
186+
result.push(item);
206187
} else if (secondaryMatcher.test(item.l)) {
207188
secondaryresult.push(item);
208189
}
209190
});
210191
displayCount = mdleCount;
211-
result = sortAndConcatResults(result, secondaryresult);
192+
result = concatResults(result, secondaryresult);
212193
}
213194
if (packageSearchIndex) {
214195
var pCount = 0;
215196
var pkg = "";
216197
$.each(packageSearchIndex, function(index, item) {
217-
item[category] = catPackages;
198+
item.category = catPackages;
218199
pkg = (item.m)
219200
? (item.m + "/" + item.l)
220201
: item.l;
221202
if (exactMatcher.test(item.l)) {
222-
presult.unshift(item);
203+
presult.push(item);
223204
pCount++;
224205
} else if (camelCaseMatcher.test(pkg)) {
225-
presult.unshift(item);
206+
presult.push(item);
226207
} else if (secondaryMatcher.test(pkg)) {
227208
secondaryresult.push(item);
228209
}
229210
});
230-
result = result.concat(sortAndConcatResults(presult, secondaryresult));
211+
result = result.concat(concatResults(presult, secondaryresult));
231212
displayCount = (pCount > displayCount) ? pCount : displayCount;
232213
}
233214
if (typeSearchIndex) {
234215
var tCount = 0;
235216
$.each(typeSearchIndex, function(index, item) {
236-
item[category] = catTypes;
217+
item.category = catTypes;
237218
var s = nestedName(item);
238219
if (exactMatcher.test(s)) {
239-
tresult.unshift(item);
220+
tresult.push(item);
240221
tCount++;
241222
} else if (camelCaseMatcher.test(s)) {
242-
tresult.unshift(item);
223+
tresult.push(item);
243224
} else if (secondaryMatcher.test(item.p + "." + item.l)) {
244225
secondaryresult.push(item);
245226
}
246227
});
247-
result = result.concat(sortAndConcatResults(tresult, secondaryresult));
228+
result = result.concat(concatResults(tresult, secondaryresult));
248229
displayCount = (tCount > displayCount) ? tCount : displayCount;
249230
}
250231
if (memberSearchIndex) {
251232
var mCount = 0;
252233
$.each(memberSearchIndex, function(index, item) {
253-
item[category] = catMembers;
234+
item.category = catMembers;
254235
var s = nestedName(item);
255236
if (exactMatcher.test(s)) {
256-
mresult.unshift(item);
237+
mresult.push(item);
257238
mCount++;
258239
} else if (camelCaseMatcher.test(s)) {
259-
mresult.unshift(item);
240+
mresult.push(item);
260241
} else if (secondaryMatcher.test(item.c + "." + item.l)) {
261242
secondaryresult.push(item);
262243
}
263244
});
264-
result = result.concat(sortAndConcatResults(mresult, secondaryresult));
245+
result = result.concat(concatResults(mresult, secondaryresult));
265246
displayCount = (mCount > displayCount) ? mCount : displayCount;
266247
}
267248
if (tagSearchIndex) {
268249
var tgCount = 0;
269250
$.each(tagSearchIndex, function(index, item) {
270-
item[category] = catSearchTags;
251+
item.category = catSearchTags;
271252
if (exactMatcher.test(item.l)) {
272-
tgresult.unshift(item);
253+
tgresult.push(item);
273254
tgCount++;
274255
} else if (secondaryMatcher.test(item.l)) {
275256
secondaryresult.push(item);
276257
}
277258
});
278-
result = result.concat(sortAndConcatResults(tgresult, secondaryresult));
259+
result = result.concat(concatResults(tgresult, secondaryresult));
279260
displayCount = (tgCount > displayCount) ? tgCount : displayCount;
280261
}
281262
displayCount = (displayCount > 500) ? displayCount : 500;

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
import com.sun.source.util.DocTrees;
8181
import com.sun.source.util.TreePath;
8282
import com.sun.tools.javac.model.JavacTypes;
83+
import jdk.javadoc.internal.doclets.formats.html.SearchIndexItem;
8384
import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
8485
import jdk.javadoc.internal.doclets.toolkit.CommentUtils.DocCommentDuo;
8586
import jdk.javadoc.internal.doclets.toolkit.Messages;
@@ -2079,6 +2080,48 @@ protected String defaultAction(Element e, Void p) {
20792080
}
20802081
}
20812082

2083+
/**
2084+
* Returns a Comparator for SearchIndexItems representing types. Items are
2085+
* compared by short name, or full string representation if names are equal.
2086+
*
2087+
* @return a Comparator
2088+
*/
2089+
public Comparator<SearchIndexItem> makeTypeSearchIndexComparator() {
2090+
return (SearchIndexItem sii1, SearchIndexItem sii2) -> {
2091+
int result = compareStrings(sii1.getSimpleName(), sii2.getSimpleName());
2092+
if (result == 0) {
2093+
// TreeSet needs this to be consistent with equal so we do
2094+
// a plain comparison of string representations as fallback.
2095+
result = sii1.toString().compareTo(sii2.toString());
2096+
}
2097+
return result;
2098+
};
2099+
}
2100+
2101+
private Comparator<SearchIndexItem> genericSearchIndexComparator = null;
2102+
/**
2103+
* Returns a Comparator for SearchIndexItems representing modules, packages, or members.
2104+
* Items are compared by label (member name plus signature for members, package name for
2105+
* packages, and module name for modules). If labels are equal then full string
2106+
* representation is compared.
2107+
*
2108+
* @return a Comparator
2109+
*/
2110+
public Comparator<SearchIndexItem> makeGenericSearchIndexComparator() {
2111+
if (genericSearchIndexComparator == null) {
2112+
genericSearchIndexComparator = (SearchIndexItem sii1, SearchIndexItem sii2) -> {
2113+
int result = compareStrings(sii1.getLabel(), sii2.getLabel());
2114+
if (result == 0) {
2115+
// TreeSet needs this to be consistent with equal so we do
2116+
// a plain comparison of string representations as fallback.
2117+
result = sii1.toString().compareTo(sii2.toString());
2118+
}
2119+
return result;
2120+
};
2121+
}
2122+
return genericSearchIndexComparator;
2123+
}
2124+
20822125
public Iterable<TypeElement> getEnclosedTypeElements(PackageElement pkg) {
20832126
List<TypeElement> out = getInterfaces(pkg);
20842127
out.addAll(getClasses(pkg));

test/langtools/jdk/javadoc/doclet/testModules/TestModules.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,12 +1171,12 @@ void checkModulesInSearch(boolean found) {
11711171
+ "</dd>\n"
11721172
+ "</dl>",
11731173
"<dl>\n"
1174-
+ "<dt><span class=\"searchTagLink\"><a href=\"moduleA/module-summary.html#searchphrase\">"
1175-
+ "search phrase</a></span> - Search tag in moduleA</dt>\n"
1176-
+ "<dd>with description</dd>\n"
11771174
+ "<dt><span class=\"searchTagLink\"><a href=\"moduleB/module-summary.html#search_word\">"
11781175
+ "search_word</a></span> - Search tag in moduleB</dt>\n"
11791176
+ "<dd>&nbsp;</dd>\n"
1177+
+ "<dt><span class=\"searchTagLink\"><a href=\"moduleA/module-summary.html#searchphrase\">"
1178+
+ "search phrase</a></span> - Search tag in moduleA</dt>\n"
1179+
+ "<dd>with description</dd>\n"
11801180
+ "</dl>");
11811181
checkOutput("index-all.html", false,
11821182
"<dt><span class=\"searchTagLink\"><a href=\"moduleA/module-summary.html#searchphrase\">"

test/langtools/jdk/javadoc/doclet/testSearch/TestSearch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,9 @@ void checkSearchJS() {
631631
"camelCaseMatcher.test(item.l)",
632632
"var secondaryresult = new Array();",
633633
"function nestedName(e) {",
634-
"function sortAndConcatResults(a1, a2) {",
634+
"function concatResults(a1, a2) {",
635635
"if (exactMatcher.test(item.l)) {\n"
636-
+ " presult.unshift(item);",
636+
+ " presult.push(item);",
637637
"$(\"#search\").on('click keydown', function() {\n"
638638
+ " if ($(this).val() == watermark) {\n"
639639
+ " $(this).val('').removeClass('watermark');\n"

0 commit comments

Comments
 (0)