8220497: Improve Javadoc search feature and add test coverage

Reviewed-by: jjg
This commit is contained in:
Hannes Wallnöfer 2019-04-25 09:12:40 +02:00
parent 80240eb399
commit 8322ce2e6b
12 changed files with 938 additions and 104 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2019, 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
@ -30,20 +30,16 @@ var catTypes = "Types";
var catMembers = "Members";
var catSearchTags = "SearchTags";
var highlight = "<span class=\"resultHighlight\">$&</span>";
var camelCaseRegexp = "";
var secondaryMatcher = "";
var searchPattern = "";
var RANKING_THRESHOLD = 2;
var NO_MATCH = 0xffff;
var MAX_RESULTS_PER_CATEGORY = 500;
function escapeHtml(str) {
return str.replace(/</g, "&lt;").replace(/>/g, "&gt;");
}
function getHighlightedText(item) {
var ccMatcher = new RegExp(escapeHtml(camelCaseRegexp));
function getHighlightedText(item, matcher) {
var escapedItem = escapeHtml(item);
var label = escapedItem.replace(ccMatcher, highlight);
if (label === escapedItem) {
var secMatcher = new RegExp(escapeHtml(secondaryMatcher.source), "i");
label = escapedItem.replace(secMatcher, highlight);
}
return label;
return escapedItem.replace(matcher, highlight);
}
function getURLPrefix(ui) {
var urlPrefix="";
@ -64,6 +60,33 @@ function getURLPrefix(ui) {
}
return urlPrefix;
}
function makeCamelCaseRegex(term) {
var pattern = "";
var isWordToken = false;
term.replace(/,\s*/g, ", ").trim().split(/\s+/).forEach(function(w, index) {
if (index > 0) {
// whitespace between identifiers is significant
pattern += (isWordToken && /^\w/.test(w)) ? "\\s+" : "\\s*";
}
var tokens = w.split(/(?=[A-Z,.()<>[\/])/);
for (var i = 0; i < tokens.length; i++) {
var s = tokens[i];
if (s === "") {
continue;
}
pattern += $.ui.autocomplete.escapeRegex(s);
isWordToken = /\w$/.test(s);
if (isWordToken) {
pattern += "([a-z0-9_$<>\\[\\]]*?)";
}
}
});
return pattern;
}
function createMatcher(pattern, flags) {
var isCamelCase = /[A-Z]/.test(pattern);
return new RegExp(pattern, flags + (isCamelCase ? "" : "i"));
}
var watermark = 'Search';
$(function() {
$("#search").val('');
@ -93,8 +116,8 @@ $.widget("custom.catcomplete", $.ui.autocomplete, {
this.widget().menu("option", "items", "> :not(.ui-autocomplete-category)");
},
_renderMenu: function(ul, items) {
var rMenu = this,
currentCategory = "";
var rMenu = this;
var currentCategory = "";
rMenu.menu.bindings = $();
$.each(items, function(index, item) {
var li;
@ -114,20 +137,21 @@ $.widget("custom.catcomplete", $.ui.autocomplete, {
},
_renderItem: function(ul, item) {
var label = "";
var matcher = createMatcher(escapeHtml(searchPattern), "g");
if (item.category === catModules) {
label = getHighlightedText(item.l);
label = getHighlightedText(item.l, matcher);
} else if (item.category === catPackages) {
label = (item.m)
? getHighlightedText(item.m + "/" + item.l)
: getHighlightedText(item.l);
? getHighlightedText(item.m + "/" + item.l, matcher)
: getHighlightedText(item.l, matcher);
} else if (item.category === catTypes) {
label = (item.p)
? getHighlightedText(item.p + "." + item.l)
: getHighlightedText(item.l);
? getHighlightedText(item.p + "." + item.l, matcher)
: getHighlightedText(item.l, matcher);
} else if (item.category === catMembers) {
label = getHighlightedText(item.p + "." + (item.c + "." + item.l));
label = getHighlightedText(item.p + "." + (item.c + "." + item.l), matcher);
} else if (item.category === catSearchTags) {
label = getHighlightedText(item.l);
label = getHighlightedText(item.l, matcher);
} else {
label = item.l;
}
@ -146,128 +170,137 @@ $.widget("custom.catcomplete", $.ui.autocomplete, {
return li;
}
});
function rankMatch(match, category) {
if (!match) {
return NO_MATCH;
}
var index = match.index;
var input = match.input;
var leftBoundaryMatch = 2;
var periferalMatch = 0;
var delta = 0;
// make sure match is anchored on a left word boundary
if (index === 0 || /\W/.test(input[index - 1]) || "_" === input[index - 1] || "_" === input[index]) {
leftBoundaryMatch = 0;
} else if (input[index] === input[index].toUpperCase() && !/^[A-Z0-9_$]+$/.test(input)) {
leftBoundaryMatch = 1;
}
var matchEnd = index + match[0].length;
var leftParen = input.indexOf("(");
// exclude peripheral matches
if (category !== catModules && category !== catSearchTags) {
var endOfName = leftParen > -1 ? leftParen : input.length;
var delim = category === catPackages ? "/" : ".";
if (leftParen > -1 && leftParen < index) {
periferalMatch += 2;
} else if (input.lastIndexOf(delim, endOfName) >= matchEnd) {
periferalMatch += 2;
}
}
for (var i = 1; i < match.length; i++) {
// lower ranking if parts of the name are missing
if (match[i])
delta += match[i].length;
}
if (category === catTypes) {
// lower ranking if a type name contains unmatched camel-case parts
if (/[A-Z]/.test(input.substring(matchEnd)))
delta += 5;
if (/[A-Z]/.test(input.substring(0, index)))
delta += 5;
}
return leftBoundaryMatch + periferalMatch + (delta / 200);
}
$(function() {
$("#search").catcomplete({
minLength: 1,
delay: 300,
source: function(request, response) {
var result = new Array();
var presult = new Array();
var tresult = new Array();
var mresult = new Array();
var tgresult = new Array();
var secondaryresult = new Array();
var displayCount = 0;
var exactMatcher = new RegExp("^" + $.ui.autocomplete.escapeRegex(request.term) + "$", "i");
camelCaseRegexp = ($.ui.autocomplete.escapeRegex(request.term)).split(/(?=[A-Z])/).join("([a-z0-9_$]*?)");
var camelCaseMatcher = new RegExp("^" + camelCaseRegexp);
secondaryMatcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
var result = [];
var newResults = [];
// Return the nested innermost name from the specified object
function nestedName(e) {
return e.l.substring(e.l.lastIndexOf(".") + 1);
searchPattern = makeCamelCaseRegex(request.term);
if (searchPattern === "") {
return this.close();
}
var camelCaseMatcher = createMatcher(searchPattern, "");
var boundaryMatcher = createMatcher("\\b" + searchPattern, "");
function concatResults(a1, a2) {
a1 = a1.concat(a2);
a2.sort(function(e1, e2) {
return e1.ranking - e2.ranking;
});
a1 = a1.concat(a2.map(function(e) { return e.item; }));
a2.length = 0;
return a1;
}
if (moduleSearchIndex) {
var mdleCount = 0;
$.each(moduleSearchIndex, function(index, item) {
item.category = catModules;
if (exactMatcher.test(item.l)) {
result.push(item);
mdleCount++;
} else if (camelCaseMatcher.test(item.l)) {
result.push(item);
} else if (secondaryMatcher.test(item.l)) {
secondaryresult.push(item);
var ranking = rankMatch(boundaryMatcher.exec(item.l), catModules);
if (ranking < RANKING_THRESHOLD) {
newResults.push({ ranking: ranking, item: item });
}
return newResults.length < MAX_RESULTS_PER_CATEGORY;
});
displayCount = mdleCount;
result = concatResults(result, secondaryresult);
result = concatResults(result, newResults);
}
if (packageSearchIndex) {
var pCount = 0;
var pkg = "";
$.each(packageSearchIndex, function(index, item) {
item.category = catPackages;
pkg = (item.m)
var name = (item.m && request.term.indexOf("/") > -1)
? (item.m + "/" + item.l)
: item.l;
if (exactMatcher.test(item.l)) {
presult.push(item);
pCount++;
} else if (camelCaseMatcher.test(pkg)) {
presult.push(item);
} else if (secondaryMatcher.test(pkg)) {
secondaryresult.push(item);
var ranking = rankMatch(boundaryMatcher.exec(name), catPackages);
if (ranking < RANKING_THRESHOLD) {
newResults.push({ ranking: ranking, item: item });
}
return newResults.length < MAX_RESULTS_PER_CATEGORY;
});
result = result.concat(concatResults(presult, secondaryresult));
displayCount = (pCount > displayCount) ? pCount : displayCount;
result = concatResults(result, newResults);
}
if (typeSearchIndex) {
var tCount = 0;
$.each(typeSearchIndex, function(index, item) {
item.category = catTypes;
var s = nestedName(item);
if (exactMatcher.test(s)) {
tresult.push(item);
tCount++;
} else if (camelCaseMatcher.test(s)) {
tresult.push(item);
} else if (secondaryMatcher.test(item.p + "." + item.l)) {
secondaryresult.push(item);
var name = request.term.indexOf(".") > -1
? item.p + "." + item.l
: item.l;
var ranking = rankMatch(camelCaseMatcher.exec(name), catTypes);
if (ranking < RANKING_THRESHOLD) {
newResults.push({ ranking: ranking, item: item });
}
return newResults.length < MAX_RESULTS_PER_CATEGORY;
});
result = result.concat(concatResults(tresult, secondaryresult));
displayCount = (tCount > displayCount) ? tCount : displayCount;
result = concatResults(result, newResults);
}
if (memberSearchIndex) {
var mCount = 0;
$.each(memberSearchIndex, function(index, item) {
item.category = catMembers;
var s = nestedName(item);
if (exactMatcher.test(s)) {
mresult.push(item);
mCount++;
} else if (camelCaseMatcher.test(s)) {
mresult.push(item);
} else if (secondaryMatcher.test(item.c + "." + item.l)) {
secondaryresult.push(item);
var name = request.term.indexOf(".") > -1
? item.p + "." + item.c + "." + item.l
: item.l;
var ranking = rankMatch(camelCaseMatcher.exec(name), catMembers);
if (ranking < RANKING_THRESHOLD) {
newResults.push({ ranking: ranking, item: item });
}
return newResults.length < MAX_RESULTS_PER_CATEGORY;
});
result = result.concat(concatResults(mresult, secondaryresult));
displayCount = (mCount > displayCount) ? mCount : displayCount;
result = concatResults(result, newResults);
}
if (tagSearchIndex) {
var tgCount = 0;
$.each(tagSearchIndex, function(index, item) {
item.category = catSearchTags;
if (exactMatcher.test(item.l)) {
tgresult.push(item);
tgCount++;
} else if (secondaryMatcher.test(item.l)) {
secondaryresult.push(item);
var ranking = rankMatch(boundaryMatcher.exec(item.l), catSearchTags);
if (ranking < RANKING_THRESHOLD) {
newResults.push({ ranking: ranking, item: item });
}
return newResults.length < MAX_RESULTS_PER_CATEGORY;
});
result = result.concat(concatResults(tgresult, secondaryresult));
displayCount = (tgCount > displayCount) ? tgCount : displayCount;
result = concatResults(result, newResults);
}
displayCount = (displayCount > 500) ? displayCount : 500;
var counter = function() {
var count = {Modules: 0, Packages: 0, Types: 0, Members: 0, SearchTags: 0};
var f = function(item) {
count[item.category] += 1;
return (count[item.category] <= displayCount);
};
return f;
}();
response(result.filter(counter));
response(result);
},
response: function(event, ui) {
if (!ui.content.length) {

View File

@ -600,14 +600,7 @@ public class TestSearch extends JavadocTester {
void checkSearchJS() {
checkOutput("search.js", true,
"camelCaseRegexp = ($.ui.autocomplete.escapeRegex(request.term)).split(/(?=[A-Z])/).join(\"([a-z0-9_$]*?)\");",
"var camelCaseMatcher = new RegExp(\"^\" + camelCaseRegexp);",
"camelCaseMatcher.test(item.l)",
"var secondaryresult = new Array();",
"function nestedName(e) {",
"function concatResults(a1, a2) {",
"if (exactMatcher.test(item.l)) {\n"
+ " presult.push(item);",
"$(\"#search\").on('click keydown paste', function() {\n"
+ " if ($(this).val() == watermark) {\n"
+ " $(this).val('').removeClass('watermark');\n"

View File

@ -0,0 +1,312 @@
/*
* Copyright (c) 2019, 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.
*
* 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.
*/
/*
* @test
* @bug 8178982 8220497 8210683
* @summary Test the search feature of javadoc.
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @run main TestSearchScript
*/
import javadoc.tester.JavadocTester;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
/*
* Tests for the search feature using Nashorn JavaScript engine.
*/
public class TestSearchScript extends JavadocTester {
public static void main(String... args) throws Exception {
TestSearchScript tester = new TestSearchScript();
tester.runTests();
}
private Invocable getEngine() throws ScriptException, IOException, NoSuchMethodException {
ScriptEngineManager engineManager = new ScriptEngineManager();
ScriptEngine engine = engineManager.getEngineByName("nashorn");
engine.eval(new BufferedReader(new FileReader(new File(testSrc, "javadoc-search.js"))));
Invocable inv = (Invocable) engine;
inv.invokeFunction("loadIndexFiles", outputDir.getAbsolutePath());
return inv;
}
@Test
public void testModuleSearch() throws ScriptException, IOException, NoSuchMethodException {
javadoc("-d", "out-full",
"-Xdoclint:none",
"-use",
"--module-source-path", testSrc,
"--module", "mapmodule",
"mappkg", "mappkg.impl");
checkExit(Exit.OK);
Invocable inv = getEngine();
// exact match, case sensitivity
checkSearch(inv, "mapmodule", List.of("mapmodule"));
checkSearch(inv, "mappkg", List.of("mapmodule/mappkg", "mapmodule/mappkg.impl", "mappkg.system.property"));
checkSearch(inv, "Mapmodule", List.of());
checkSearch(inv, "Mappkg", List.of());
checkSearch(inv, "mymap", List.of("mappkg.impl.MyMap", "mappkg.impl.MyMap.MyMap()", "mappkg.impl.MyMap.MyMap(Map)"));
checkSearch(inv, "MyMap", List.of("mappkg.impl.MyMap", "mappkg.impl.MyMap.MyMap()", "mappkg.impl.MyMap.MyMap(Map)"));
checkSearch(inv, "mymap(", List.of("mappkg.impl.MyMap.MyMap()", "mappkg.impl.MyMap.MyMap(Map)"));
checkSearch(inv, "MyMap(", List.of("mappkg.impl.MyMap.MyMap()", "mappkg.impl.MyMap.MyMap(Map)"));
checkSearch(inv, "mymap()", List.of("mappkg.impl.MyMap.MyMap()"));
checkSearch(inv, "MyMap()", List.of("mappkg.impl.MyMap.MyMap()"));
checkSearch(inv, "Mymap", List.of());
checkSearch(inv, "Mymap()", List.of());
// left boundaries, ranking
checkSearch(inv, "map", List.of("mapmodule", "mapmodule/mappkg", "mapmodule/mappkg.impl", "mappkg.Map", "mappkg.impl.MyMap",
"mappkg.impl.MyMap.MyMap()", "mappkg.impl.MyMap.MyMap(Map)", "mappkg.system.property"));
checkSearch(inv, "Map", List.of("mappkg.Map", "mappkg.impl.MyMap", "mappkg.impl.MyMap.MyMap()",
"mappkg.impl.MyMap.MyMap(Map)"));
checkSearch(inv, "MAP", List.of());
checkSearch(inv, "value", List.of("mappkg.impl.MyMap.OTHER_VALUE", "mappkg.impl.MyMap.some_value"));
checkSearch(inv, "VALUE", List.of("mappkg.impl.MyMap.OTHER_VALUE"));
checkSearch(inv, "map.other", List.of("mappkg.impl.MyMap.OTHER_VALUE"));
checkSearch(inv, "Map.some_", List.of("mappkg.impl.MyMap.some_value"));
checkSearch(inv, "Mm", List.of());
checkSearch(inv, "mym", List.of("mappkg.impl.MyMap", "mappkg.impl.MyMap.MyMap()", "mappkg.impl.MyMap.MyMap(Map)"));
checkSearch(inv, "imp.mym.mym(", List.of("mappkg.impl.MyMap.MyMap()", "mappkg.impl.MyMap.MyMap(Map)"));
checkSearch(inv, "imp.mym.mym(m", List.of("mappkg.impl.MyMap.MyMap(Map)"));
// camel case
checkSearch(inv, "MM", List.of("mappkg.impl.MyMap", "mappkg.impl.MyMap.MyMap()", "mappkg.impl.MyMap.MyMap(Map)"));
checkSearch(inv, "MyM", List.of("mappkg.impl.MyMap", "mappkg.impl.MyMap.MyMap()", "mappkg.impl.MyMap.MyMap(Map)"));
checkSearch(inv, "Mym", List.of());
checkSearch(inv, "i.MyM.MyM(", List.of("mappkg.impl.MyMap.MyMap()", "mappkg.impl.MyMap.MyMap(Map)"));
checkSearch(inv, "i.MMa.MMa(", List.of("mappkg.impl.MyMap.MyMap()", "mappkg.impl.MyMap.MyMap(Map)"));
checkSearch(inv, "i.MyM.MyM(Ma", List.of("mappkg.impl.MyMap.MyMap(Map)"));
checkSearch(inv, "i.MMa.MMa(M", List.of("mappkg.impl.MyMap.MyMap(Map)"));
checkSearch(inv, "i.Mym.MyM(", List.of());
checkSearch(inv, "i.Mym.Ma(", List.of());
checkSearch(inv, "mapm", List.of("mapmodule"));
// child entity listing
checkSearch(inv, "mapmodule/", List.of("mapmodule/mappkg", "mapmodule/mappkg.impl"));
checkSearch(inv, "mapmod/", List.of("mapmodule/mappkg", "mapmodule/mappkg.impl"));
checkSearch(inv, "module/", List.of());
checkSearch(inv, "le/", List.of());
checkSearch(inv, "mapmodule.", List.of());
checkSearch(inv, "mapmod.", List.of());
checkSearch(inv, "mappkg.", List.of("mapmodule/mappkg.impl", "mappkg.Map", "mappkg.system.property"));
checkSearch(inv, "mappkg.", List.of("mapmodule/mappkg.impl", "mappkg.Map", "mappkg.system.property"));
checkSearch(inv, "Map.", List.of("mappkg.Map.contains(Object)", "mappkg.Map.get(Object)", "mappkg.Map.iterate()",
"mappkg.Map.put(Object, Object)", "mappkg.Map.remove(Object)",
"mappkg.impl.MyMap.contains(Object)", "mappkg.impl.MyMap.get(Object)",
"mappkg.impl.MyMap.iterate()", "mappkg.impl.MyMap.MyMap()",
"mappkg.impl.MyMap.MyMap(Map)", "mappkg.impl.MyMap.OTHER_VALUE",
"mappkg.impl.MyMap.put(Object, Object)", "mappkg.impl.MyMap.remove(Object)",
"mappkg.impl.MyMap.some_value"));
checkSearch(inv, "mym.", List.of("mappkg.impl.MyMap.contains(Object)", "mappkg.impl.MyMap.get(Object)",
"mappkg.impl.MyMap.iterate()", "mappkg.impl.MyMap.MyMap()",
"mappkg.impl.MyMap.MyMap(Map)", "mappkg.impl.MyMap.OTHER_VALUE",
"mappkg.impl.MyMap.put(Object, Object)", "mappkg.impl.MyMap.remove(Object)",
"mappkg.impl.MyMap.some_value"));
checkSearch(inv, "MyMap.i", List.of("mappkg.impl.MyMap.iterate()"));
// system properties
checkSearch(inv, "mappkg.system.property", List.of("mappkg.system.property"));
checkSearch(inv, "system.property", List.of("mappkg.system.property"));
checkSearch(inv, "property", List.of("mappkg.system.property"));
checkSearch(inv, "sys.prop", List.of("mappkg.system.property"));
checkSearch(inv, "m.s.p", List.of("mappkg.system.property"));
checkSearch(inv, "operty", List.of());
// search tag
checkSearch(inv, "search tag", List.of("search tag"));
checkSearch(inv, "search tag", List.of("search tag"));
checkSearch(inv, "search ", List.of("search tag"));
checkSearch(inv, "tag", List.of("search tag"));
checkSearch(inv, "sea", List.of("search tag"));
checkSearch(inv, "ear", List.of());
}
@Test
public void testPackageSource() throws ScriptException, IOException, NoSuchMethodException {
javadoc("-d", "out-overload",
"-Xdoclint:none",
"-use",
"-sourcepath", testSrc,
"listpkg");
checkExit(Exit.OK);
Invocable inv = getEngine();
// exact match, case sensitvity, left boundaries
checkSearch(inv, "list", List.of("listpkg", "listpkg.List", "listpkg.ListProvider", "listpkg.MyList",
"listpkg.MyListFactory", "listpkg.ListProvider.ListProvider()",
"listpkg.MyListFactory.createList(ListProvider, MyListFactory)",
"listpkg.ListProvider.makeNewList()",
"listpkg.MyList.MyList()", "listpkg.MyListFactory.MyListFactory()"));
checkSearch(inv, "List", List.of("listpkg.List", "listpkg.ListProvider", "listpkg.MyList",
"listpkg.MyListFactory", "listpkg.ListProvider.ListProvider()",
"listpkg.MyListFactory.createList(ListProvider, MyListFactory)",
"listpkg.ListProvider.makeNewList()",
"listpkg.MyList.MyList()", "listpkg.MyListFactory.MyListFactory()"));
// partial match
checkSearch(inv, "fact", List.of("listpkg.MyListFactory", "listpkg.MyListFactory.MyListFactory()"));
checkSearch(inv, "pro", List.of("listpkg.ListProvider", "listpkg.ListProvider.ListProvider()"));
checkSearch(inv, "listpro", List.of("listpkg.ListProvider", "listpkg.ListProvider.ListProvider()"));
// camel case
checkSearch(inv, "l.MLF.cL(LP, MLF)", List.of("listpkg.MyListFactory.createList(ListProvider, MyListFactory)"));
checkSearch(inv, "Fact.creaLi(LiPro,MLiFact)", List.of("listpkg.MyListFactory.createList(ListProvider, MyListFactory)"));
checkSearch(inv, "(LP,ML", List.of("listpkg.MyListFactory.createList(ListProvider, MyListFactory)"));
// ranking of overloaded methods JDK-8210683
checkSearch(inv, "list.of",
List.of("listpkg.List.of()", "listpkg.List.of(E)", "listpkg.List.of(E, E)",
"listpkg.List.of(E, E, E)", "listpkg.List.of(E, E, E, E)",
"listpkg.List.of(E, E, E, E, E)", "listpkg.List.of(E...)"));
checkSearch(inv, "Li.of",
List.of("listpkg.List.of()", "listpkg.List.of(E)", "listpkg.List.of(E, E)",
"listpkg.List.of(E, E, E)", "listpkg.List.of(E, E, E, E)",
"listpkg.List.of(E, E, E, E, E)", "listpkg.List.of(E...)"));
checkSearch(inv, "li.Li.o",
List.of("listpkg.List.of()", "listpkg.List.of(E)", "listpkg.List.of(E, E)",
"listpkg.List.of(E, E, E)", "listpkg.List.of(E, E, E, E)",
"listpkg.List.of(E, E, E, E, E)", "listpkg.List.of(E...)"));
checkSearch(inv, "l.l.o",
List.of("listpkg.List.of()", "listpkg.List.of(E)", "listpkg.List.of(E, E)",
"listpkg.List.of(E, E, E)", "listpkg.List.of(E, E, E, E)",
"listpkg.List.of(E, E, E, E, E)", "listpkg.List.of(E...)"));
checkSearch(inv, "L.l.o", List.of());
// whitespace
checkSearch(inv, "(e,e,e",
List.of("listpkg.List.of(E, E, E)", "listpkg.List.of(E, E, E, E)",
"listpkg.List.of(E, E, E, E, E)"));
checkSearch(inv, "(e, e,e",
List.of("listpkg.List.of(E, E, E)", "listpkg.List.of(E, E, E, E)",
"listpkg.List.of(E, E, E, E, E)"));
checkSearch(inv, "(e, e, e",
List.of("listpkg.List.of(E, E, E)", "listpkg.List.of(E, E, E, E)",
"listpkg.List.of(E, E, E, E, E)"));
checkSearch(inv, "(e, e, e",
List.of("listpkg.List.of(E, E, E)", "listpkg.List.of(E, E, E, E)",
"listpkg.List.of(E, E, E, E, E)"));
checkSearch(inv, "(e, e, e ,",
List.of("listpkg.List.of(E, E, E, E)", "listpkg.List.of(E, E, E, E, E)"));
checkSearch(inv, "(e , e, e,",
List.of("listpkg.List.of(E, E, E, E)", "listpkg.List.of(E, E, E, E, E)"));
checkSearch(inv, " listpkg .list .of ",
List.of("listpkg.List.of()", "listpkg.List.of(E)", "listpkg.List.of(E, E)",
"listpkg.List.of(E, E, E)", "listpkg.List.of(E, E, E, E)",
"listpkg.List.of(E, E, E, E, E)", "listpkg.List.of(E...)"));
checkSearch(inv, " l. l. o",
List.of("listpkg.List.of()", "listpkg.List.of(E)", "listpkg.List.of(E, E)",
"listpkg.List.of(E, E, E)", "listpkg.List.of(E, E, E, E)",
"listpkg.List.of(E, E, E, E, E)", "listpkg.List.of(E...)"));
checkSearch(inv, "list . of",
List.of("listpkg.List.of()", "listpkg.List.of(E)", "listpkg.List.of(E, E)",
"listpkg.List.of(E, E, E)", "listpkg.List.of(E, E, E, E)",
"listpkg.List.of(E, E, E, E, E)", "listpkg.List.of(E...)"));
checkSearch(inv, "lis t.of", List.of());
checkSearch(inv, "list . of(e,e,e,",
List.of("listpkg.List.of(E, E, E, E)", "listpkg.List.of(E, E, E, E, E)"));
checkSearch(inv, "l . o (e,e,e,",
List.of("listpkg.List.of(E, E, E, E)", "listpkg.List.of(E, E, E, E, E)"));
checkSearch(inv, "search \tt", List.of("search tag"));
checkSearch(inv, "sear ch", List.of());
checkSearch(inv, "( e ..", List.of("listpkg.List.of(E...)"));
checkSearch(inv, "( i [ ]", List.of("listpkg.Nolist.withArrayArg(int[])"));
// empty/white space search should not trigger results
checkNullSearch(inv, "");
checkNullSearch(inv, " ");
checkNullSearch(inv, " ");
checkNullSearch(inv, " \t\t ");
// _ word boundaries and case sensitivity
checkSearch(inv, "some", List.of("listpkg.Nolist.SOME_INT_CONSTANT"));
checkSearch(inv, "SOME", List.of("listpkg.Nolist.SOME_INT_CONSTANT"));
checkSearch(inv, "Some", List.of());
checkSearch(inv, "int", List.of("listpkg.Nolist.SOME_INT_CONSTANT"));
checkSearch(inv, "INT", List.of("listpkg.Nolist.SOME_INT_CONSTANT"));
checkSearch(inv, "Int", List.of());
checkSearch(inv, "int_con", List.of("listpkg.Nolist.SOME_INT_CONSTANT"));
checkSearch(inv, "INT_CON", List.of("listpkg.Nolist.SOME_INT_CONSTANT"));
checkSearch(inv, "NT", List.of());
checkSearch(inv, "NT_", List.of());
checkSearch(inv, "_const", List.of("listpkg.Nolist.SOME_INT_CONSTANT"));
checkSearch(inv, "_CONST", List.of("listpkg.Nolist.SOME_INT_CONSTANT"));
// Test for all packages, all classes links
checkSearch(inv, "all", List.of("All Packages", "All Classes"));
checkSearch(inv, "All", List.of("All Packages", "All Classes"));
checkSearch(inv, "ALL", List.of());
// test for generic types, var-arg and array args
checkSearch(inv, "(map<string, ? ext collection>)",
List.of("listpkg.Nolist.withTypeParams(Map<String, ? extends Collection>)"));
checkSearch(inv, "(m<str,? ext coll>",
List.of("listpkg.Nolist.withTypeParams(Map<String, ? extends Collection>)"));
checkSearch(inv, "(object...", List.of("listpkg.Nolist.withVarArgs(Object...)"));
checkSearch(inv, "(obj...", List.of("listpkg.Nolist.withVarArgs(Object...)"));
checkSearch(inv, "(e..", List.of("listpkg.List.of(E...)"));
checkSearch(inv, "(int[]", List.of("listpkg.Nolist.withArrayArg(int[])"));
checkSearch(inv, "(i[]", List.of("listpkg.Nolist.withArrayArg(int[])"));
}
void checkSearch(Invocable inv, String query, List<String> results) throws ScriptException, NoSuchMethodException {
checkList((List) inv.invokeFunction("search", query), results);
}
void checkList(List<?> result, List<?> expected) {
checking("Checking list: " + result);
if (!expected.equals(result)) {
failed("Expected: " + expected + ", got: " + result);
} else {
passed("List matches expected result");
}
}
void checkNullSearch(Invocable inv, String query) throws ScriptException, NoSuchMethodException {
Object result = inv.invokeFunction("search", query);
checking("Checking null result");
if (result == null) {
passed("Result is null as expected");
} else {
failed("Expected: null, got: " + result);
}
}
}

View File

@ -0,0 +1,164 @@
/*
* Copyright (c) 2019, 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.
*
* 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.
*/
var moduleSearchIndex;
var packageSearchIndex;
var typeSearchIndex;
var memberSearchIndex;
var tagSearchIndex;
var clargs = arguments;
var search;
function loadIndexFiles(docsPath) {
tryLoad(docsPath, "module-search-index.js");
tryLoad(docsPath, "package-search-index.js");
tryLoad(docsPath, "type-search-index.js");
tryLoad(docsPath, "member-search-index.js");
tryLoad(docsPath, "tag-search-index.js");
load(docsPath + "/search.js");
}
function tryLoad(docsPath, file) {
try {
load(docsPath + "/" + file);
} catch (e) {
print(e);
}
}
var $ = function(f) {
if (typeof f === "function") {
f();
} else {
return {
val: function() {
return this;
},
prop: function() {
return this;
},
addClass: function() {
return this;
},
removeClass: function() {
return this;
},
on: function() {
return this;
},
focus: function() {
return this;
},
blur: function() {
return this;
},
click: function() {
return this;
},
catcomplete: function(o) {
o.close = function() {};
search = function(term) {
var resultList = null;
o.source({
term: term
},
function(result) {
resultList = renderMenu(result);
}
);
return resultList;
};
for (var i = 0; i < clargs.length; i++) {
search(clargs[i]);
}
},
"0": {
setSelectionRange: function() {
return this;
}
}
}
}
};
$.each = function(arr, f) {
for (var i = 0; i < arr.length; i++) {
f(i, arr[i]);
}
};
$.widget = function(a, b, c) {
};
$.ui = {
autocomplete: {
escapeRegex: function(re) {
return re.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}
}
};
var console = {
log: function() {
print.apply(this, arguments);
}
};
var renderMenu = function(items) {
var result = new java.util.ArrayList();
var currentCategory = "";
$.each(items, function(index, item) {
var li;
if (item.l !== noResult.l && item.category !== currentCategory) {
// print(item.category);
currentCategory = item.category;
}
result.add(renderItem(item));
});
return result;
};
var renderItem = function(item) {
var label;
if (item.category === catModules) {
label = item.l;
} else if (item.category === catPackages) {
label = (item.m)
? item.m + "/" + item.l
: item.l;
} else if (item.category === catTypes) {
label = (item.p)
? item.p + "." + item.l
: item.l;
} else if (item.category === catMembers) {
label = item.p + "." + item.c + "." + item.l;
} else if (item.category === catSearchTags) {
label = item.l;
} else {
label = item.l;
}
return label;
};

View File

@ -0,0 +1,59 @@
/*
* Copyright (c) 2019, 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.
*
* 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 listpkg;
/**
* Example class containing "list" matching full name.
*/
public interface List<E> {
List add(E e);
void remove(int i);
int size();
static <E> List<E> of() {
return null;
}
static <E> List<E> of(E e1) {
return null;
}
static <E> List<E> of(E e1, E e2) {
return null;
}
static <E> List<E> of(E e1, E e2, E e3) {
return null;
}
static <E> List<E> of(E e1, E e2, E e3, E e4) {
return null;
}
static <E> List<E> of(E e1, E e2, E e3, E e4, E e5) {
return null;
}
static <E> List<E> of(E... elements) {
return null;
}
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2019, 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.
*
* 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 listpkg;
/**
* Example class containing "list" matching at beginning of name.
*/
public class ListProvider {
public ListProvider() {}
public List makeNewList() {
return null;
}
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2019, 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.
*
* 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 listpkg;
public class MyList implements List {
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2019, 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.
*
* 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 listpkg;
/**
* Example class containing "list" matching at camel case word boundaries.
*/
public class MyListFactory {
public static List createList(ListProvider provider, MyListFactory factory) {
return null;
}
}

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2019, 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.
*
* 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 listpkg;
import java.util.Collection;
import java.util.Map;
/**
* Example class containing "list" but not matching at any word boundary.
*
* {@index "search tag"}.
*/
public class Nolist {
public final int SOME_INT_CONSTANT = 0;
public Nolist() {}
public void nolist() {}
public static List withTypeParams(Map<String, ? extends Collection> map) {
return null;
}
public static List withVarArgs(Object... args) {
return null;
}
public static List withArrayArg(int[] args) {
return null;
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2019, 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.
*
* 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 mappkg;
import java.util.Iterator;
public interface Map {
public void put(Object key, Object value);
public boolean contains(Object key);
public Object get(Object key);
public void remove(Object key);
public Iterator<Object> iterate();
}

View File

@ -0,0 +1,62 @@
/*
* Copyright (c) 2019, 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.
*
* 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 mappkg.impl;
import mappkg.Map;
import java.util.Iterator;
/**
* {@index "search tag"}
*/
public class MyMap implements Map {
/** {@systemProperty mappkg.system.property} */
public int some_value;
public int OTHER_VALUE;
public MyMap() {}
public MyMap(Map map) {}
@Override
public void put(Object key, Object value) {}
@Override
public boolean contains(Object key) {
return false;
}
@Override
public Object get(Object key) {
return null;
}
@Override
public void remove(Object key) {}
@Override
public Iterator<Object> iterate() {
return null;
}
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2019, 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.
*
* 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.
*/
module mapmodule {
exports mappkg;
exports mappkg.impl;
}