205 addDescription(e, dl, si);
206 configuration.typeSearchIndex.add(si);
207 return null;
208 }
209
210 @Override
211 protected Void defaultAction(Element e, Void p) {
212 addDescription(e, dl, si);
213 configuration.memberSearchIndex.add(si);
214 return null;
215 }
216
217 }.visit(element);
218 }
219
220 /**
221 * Add one line summary comment for the module.
222 *
223 * @param mdle the module to be documented
224 * @param dlTree the content tree to which the description will be added
225 */
226 protected void addDescription(ModuleElement mdle, Content dlTree, SearchIndexItem si) {
227 String moduleName = utils.getFullyQualifiedName(mdle);
228 Content link = getModuleLink(mdle, new StringContent(moduleName));
229 si.setLabel(moduleName);
230 si.setCategory(resources.getText("doclet.Modules"));
231 Content dt = HtmlTree.DT(link);
232 dt.addContent(" - ");
233 dt.addContent(contents.module_);
234 dt.addContent(" " + moduleName);
235 dlTree.addContent(dt);
236 Content dd = new HtmlTree(HtmlTag.DD);
237 addSummaryComment(mdle, dd);
238 dlTree.addContent(dd);
239 }
240
241 /**
242 * Add one line summary comment for the package.
243 *
244 * @param pkg the package to be documented
299 ));
300 }
301
302 /**
303 * Add description for Class, Field, Method or Constructor.
304 *
305 * @param member the member of the Class Kind
306 * @param dlTree the content tree to which the description will be added
307 * @param si search index item
308 */
309 protected void addDescription(Element member, Content dlTree, SearchIndexItem si) {
310
311 si.setContainingPackage(utils.getPackageName(utils.containingPackage(member)));
312 si.setContainingClass(utils.getSimpleName(utils.getEnclosingTypeElement(member)));
313 String name = utils.getSimpleName(member);
314 if (utils.isExecutableElement(member)) {
315 ExecutableElement ee = (ExecutableElement)member;
316 name = name + utils.flatSignature(ee);
317 si.setLabel(name);
318 if (!((utils.signature(ee)).equals(utils.flatSignature(ee)))) {
319 si.setUrl(getName(getAnchor(ee)));
320 }
321
322 } else {
323 si.setLabel(name);
324 }
325 si.setCategory(resources.getText("doclet.Members"));
326 Content span = HtmlTree.SPAN(HtmlStyle.memberNameLink,
327 getDocLink(LinkInfoImpl.Kind.INDEX, member, name));
328 Content dt = HtmlTree.DT(span);
329 dt.addContent(" - ");
330 addMemberDesc(member, dt);
331 dlTree.addContent(dt);
332 Content dd = new HtmlTree(HtmlTag.DD);
333 addComment(member, dd);
334 dlTree.addContent(dd);
335 }
336
337 protected void addDescription(SearchIndexItem sii, Content dlTree) {
338 String siiPath = pathToRoot.isEmpty() ? "" : pathToRoot.getPath() + "/";
339 siiPath += sii.getUrl();
403 } else if (utils.isConstructor(member)) {
404 contentTree.addContent(
405 contents.getContent("doclet.Constructor_for", classdesc));
406 } else if (utils.isMethod(member)) {
407 Content resource = contents.getContent(utils.isStatic(member)
408 ? "doclet.Static_method_in"
409 : "doclet.Method_in", classdesc);
410 contentTree.addContent(resource);
411 }
412 addPreQualifiedClassLink(LinkInfoImpl.Kind.INDEX, containing,
413 false, contentTree);
414 }
415
416 /**
417 * Get the marker anchor which will be added to the index documentation tree.
418 *
419 * @param anchorNameForIndex the anchor name attribute for index page
420 * @return a content tree for the marker anchor
421 */
422 public Content getMarkerAnchorForIndex(String anchorNameForIndex) {
423 return getMarkerAnchor(getNameForIndex(anchorNameForIndex), null);
424 }
425
426 /**
427 * Generate a valid HTML name for member index page.
428 *
429 * @param unicode the string that needs to be converted to valid HTML name.
430 * @return a valid HTML name string.
431 */
432 public String getNameForIndex(String unicode) {
433 return "I:" + getName(unicode);
434 }
435
436 /**
437 * @throws DocFileIOException if there is a problem creating any of the search index files
438 */
439 protected void createSearchIndexFiles() throws DocFileIOException {
440 if (configuration.showModules) {
441 createSearchIndexFile(DocPaths.MODULE_SEARCH_INDEX_JSON, DocPaths.MODULE_SEARCH_INDEX_ZIP,
442 DocPaths.MODULE_SEARCH_INDEX_JS, configuration.moduleSearchIndex, "moduleSearchIndex");
443 }
444 createSearchIndexFile(DocPaths.PACKAGE_SEARCH_INDEX_JSON, DocPaths.PACKAGE_SEARCH_INDEX_ZIP,
445 DocPaths.PACKAGE_SEARCH_INDEX_JS, configuration.packageSearchIndex, "packageSearchIndex");
446 createSearchIndexFile(DocPaths.TYPE_SEARCH_INDEX_JSON, DocPaths.TYPE_SEARCH_INDEX_ZIP,
447 DocPaths.TYPE_SEARCH_INDEX_JS, configuration.typeSearchIndex, "typeSearchIndex");
448 createSearchIndexFile(DocPaths.MEMBER_SEARCH_INDEX_JSON, DocPaths.MEMBER_SEARCH_INDEX_ZIP,
449 DocPaths.MEMBER_SEARCH_INDEX_JS, configuration.memberSearchIndex, "memberSearchIndex");
450 createSearchIndexFile(DocPaths.TAG_SEARCH_INDEX_JSON, DocPaths.TAG_SEARCH_INDEX_ZIP,
451 DocPaths.TAG_SEARCH_INDEX_JS, configuration.tagSearchIndex, "tagSearchIndex");
452 }
453
454 /**
455 * @throws DocFileIOException if there is a problem creating the search index file
456 */
457 protected void createSearchIndexFile(DocPath searchIndexFile, DocPath searchIndexZip,
458 DocPath searchIndexJS, Collection<SearchIndexItem> searchIndex, String varName) throws DocFileIOException {
459 if (!searchIndex.isEmpty()) {
460 StringBuilder searchVar = new StringBuilder("[");
461 boolean first = true;
462 for (SearchIndexItem item : searchIndex) {
463 if (first) {
464 searchVar.append(item.toString());
465 first = false;
466 } else {
467 searchVar.append(",").append(item.toString());
468 }
469 }
470 searchVar.append("]");
471 DocFile jsFile = DocFile.createFileForOutput(configuration, searchIndexJS);
472 try (Writer wr = jsFile.openWriter()) {
473 wr.write(varName);
474 wr.write(" = ");
|
205 addDescription(e, dl, si);
206 configuration.typeSearchIndex.add(si);
207 return null;
208 }
209
210 @Override
211 protected Void defaultAction(Element e, Void p) {
212 addDescription(e, dl, si);
213 configuration.memberSearchIndex.add(si);
214 return null;
215 }
216
217 }.visit(element);
218 }
219
220 /**
221 * Add one line summary comment for the module.
222 *
223 * @param mdle the module to be documented
224 * @param dlTree the content tree to which the description will be added
225 * @param si the search index item
226 */
227 protected void addDescription(ModuleElement mdle, Content dlTree, SearchIndexItem si) {
228 String moduleName = utils.getFullyQualifiedName(mdle);
229 Content link = getModuleLink(mdle, new StringContent(moduleName));
230 si.setLabel(moduleName);
231 si.setCategory(resources.getText("doclet.Modules"));
232 Content dt = HtmlTree.DT(link);
233 dt.addContent(" - ");
234 dt.addContent(contents.module_);
235 dt.addContent(" " + moduleName);
236 dlTree.addContent(dt);
237 Content dd = new HtmlTree(HtmlTag.DD);
238 addSummaryComment(mdle, dd);
239 dlTree.addContent(dd);
240 }
241
242 /**
243 * Add one line summary comment for the package.
244 *
245 * @param pkg the package to be documented
300 ));
301 }
302
303 /**
304 * Add description for Class, Field, Method or Constructor.
305 *
306 * @param member the member of the Class Kind
307 * @param dlTree the content tree to which the description will be added
308 * @param si search index item
309 */
310 protected void addDescription(Element member, Content dlTree, SearchIndexItem si) {
311
312 si.setContainingPackage(utils.getPackageName(utils.containingPackage(member)));
313 si.setContainingClass(utils.getSimpleName(utils.getEnclosingTypeElement(member)));
314 String name = utils.getSimpleName(member);
315 if (utils.isExecutableElement(member)) {
316 ExecutableElement ee = (ExecutableElement)member;
317 name = name + utils.flatSignature(ee);
318 si.setLabel(name);
319 if (!((utils.signature(ee)).equals(utils.flatSignature(ee)))) {
320 si.setUrl(links.getName(getAnchor(ee)));
321 }
322
323 } else {
324 si.setLabel(name);
325 }
326 si.setCategory(resources.getText("doclet.Members"));
327 Content span = HtmlTree.SPAN(HtmlStyle.memberNameLink,
328 getDocLink(LinkInfoImpl.Kind.INDEX, member, name));
329 Content dt = HtmlTree.DT(span);
330 dt.addContent(" - ");
331 addMemberDesc(member, dt);
332 dlTree.addContent(dt);
333 Content dd = new HtmlTree(HtmlTag.DD);
334 addComment(member, dd);
335 dlTree.addContent(dd);
336 }
337
338 protected void addDescription(SearchIndexItem sii, Content dlTree) {
339 String siiPath = pathToRoot.isEmpty() ? "" : pathToRoot.getPath() + "/";
340 siiPath += sii.getUrl();
404 } else if (utils.isConstructor(member)) {
405 contentTree.addContent(
406 contents.getContent("doclet.Constructor_for", classdesc));
407 } else if (utils.isMethod(member)) {
408 Content resource = contents.getContent(utils.isStatic(member)
409 ? "doclet.Static_method_in"
410 : "doclet.Method_in", classdesc);
411 contentTree.addContent(resource);
412 }
413 addPreQualifiedClassLink(LinkInfoImpl.Kind.INDEX, containing,
414 false, contentTree);
415 }
416
417 /**
418 * Get the marker anchor which will be added to the index documentation tree.
419 *
420 * @param anchorNameForIndex the anchor name attribute for index page
421 * @return a content tree for the marker anchor
422 */
423 public Content getMarkerAnchorForIndex(String anchorNameForIndex) {
424 return links.createAnchor(getNameForIndex(anchorNameForIndex), null);
425 }
426
427 /**
428 * Generate a valid HTML name for member index page.
429 *
430 * @param unicode the string that needs to be converted to valid HTML name.
431 * @return a valid HTML name string.
432 */
433 public String getNameForIndex(String unicode) {
434 return "I:" + links.getName(unicode);
435 }
436
437 /**
438 * @throws DocFileIOException if there is a problem creating any of the search index files
439 */
440 protected void createSearchIndexFiles() throws DocFileIOException {
441 if (configuration.showModules) {
442 createSearchIndexFile(DocPaths.MODULE_SEARCH_INDEX_JSON, DocPaths.MODULE_SEARCH_INDEX_ZIP,
443 DocPaths.MODULE_SEARCH_INDEX_JS, configuration.moduleSearchIndex, "moduleSearchIndex");
444 }
445 createSearchIndexFile(DocPaths.PACKAGE_SEARCH_INDEX_JSON, DocPaths.PACKAGE_SEARCH_INDEX_ZIP,
446 DocPaths.PACKAGE_SEARCH_INDEX_JS, configuration.packageSearchIndex, "packageSearchIndex");
447 createSearchIndexFile(DocPaths.TYPE_SEARCH_INDEX_JSON, DocPaths.TYPE_SEARCH_INDEX_ZIP,
448 DocPaths.TYPE_SEARCH_INDEX_JS, configuration.typeSearchIndex, "typeSearchIndex");
449 createSearchIndexFile(DocPaths.MEMBER_SEARCH_INDEX_JSON, DocPaths.MEMBER_SEARCH_INDEX_ZIP,
450 DocPaths.MEMBER_SEARCH_INDEX_JS, configuration.memberSearchIndex, "memberSearchIndex");
451 createSearchIndexFile(DocPaths.TAG_SEARCH_INDEX_JSON, DocPaths.TAG_SEARCH_INDEX_ZIP,
452 DocPaths.TAG_SEARCH_INDEX_JS, configuration.tagSearchIndex, "tagSearchIndex");
453 }
454
455 /**
456 * Creates a search index file.
457 *
458 * @param searchIndexFile the file to be generated
459 * @param searchIndexZip the zip file to be generated
460 * @param searchIndexJS the file for the JavaScript to be generated
461 * @param searchIndex the search index items
462 * @param varName the variable name to write in the JavaScript file
463 * @throws DocFileIOException if there is a problem creating the search index file
464 */
465 protected void createSearchIndexFile(DocPath searchIndexFile, DocPath searchIndexZip,
466 DocPath searchIndexJS, Collection<SearchIndexItem> searchIndex, String varName) throws DocFileIOException {
467 if (!searchIndex.isEmpty()) {
468 StringBuilder searchVar = new StringBuilder("[");
469 boolean first = true;
470 for (SearchIndexItem item : searchIndex) {
471 if (first) {
472 searchVar.append(item.toString());
473 first = false;
474 } else {
475 searchVar.append(",").append(item.toString());
476 }
477 }
478 searchVar.append("]");
479 DocFile jsFile = DocFile.createFileForOutput(configuration, searchIndexJS);
480 try (Writer wr = jsFile.openWriter()) {
481 wr.write(varName);
482 wr.write(" = ");
|