package jdk.javadoc.internal.doclets.formats.html;
import java.util.*;
import javax.lang.model.element.ModuleElement;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import jdk.javadoc.doclet.DocletEnvironment;
import jdk.javadoc.doclet.Reporter;
import jdk.javadoc.internal.doclets.toolkit.AbstractDoclet;
import jdk.javadoc.internal.doclets.toolkit.DocletException;
import jdk.javadoc.internal.doclets.toolkit.Messages;
import jdk.javadoc.internal.doclets.toolkit.builders.AbstractBuilder;
import jdk.javadoc.internal.doclets.toolkit.util.ClassTree;
import jdk.javadoc.internal.doclets.toolkit.util.DocFile;
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;
public class HtmlDoclet extends AbstractDoclet {
public HtmlDoclet() {
configuration = new HtmlConfiguration(this);
}
@Override
public String getName() {
return "Html";
}
private final HtmlConfiguration configuration;
private Messages messages;
private static final DocPath DOCLET_RESOURCES = DocPath
.create("/jdk/javadoc/internal/doclets/formats/html/resources");
@Override
public void init(Locale locale, Reporter reporter) {
configuration.reporter = reporter;
configuration.locale = locale;
messages = configuration.getMessages();
}
@Override
public HtmlConfiguration getConfiguration() {
return configuration;
}
@Override
protected void generateOtherFiles(DocletEnvironment docEnv, ClassTree classtree)
throws DocletException {
super.generateOtherFiles(docEnv, classtree);
if (configuration.linksource) {
SourceToHTMLConverter.convertRoot(configuration,
docEnv, DocPaths.SOURCE_OUTPUT);
}
if (configuration.getSpecifiedModuleElements().isEmpty() &&
configuration.topFile.isEmpty()) {
messages.error("doclet.No_Non_Deprecated_Classes_To_Document");
return;
}
boolean nodeprecated = configuration.nodeprecated;
performCopy(configuration.helpfile);
performCopy(configuration.stylesheetfile);
for (String stylesheet : configuration.additionalStylesheets) {
performCopy(stylesheet);
}
if (configuration.classuse) {
ClassUseWriter.generate(configuration, classtree);
}
IndexBuilder indexbuilder = new IndexBuilder(configuration, nodeprecated);
if (configuration.createtree) {
TreeWriter.generate(configuration, classtree);
}
if (configuration.createindex) {
configuration.buildSearchTagIndex();
if (configuration.splitindex) {
SplitIndexWriter.generate(configuration, indexbuilder);
} else {
SingleIndexWriter.generate(configuration, indexbuilder);
}
}
if (!(configuration.nodeprecatedlist || nodeprecated)) {
DeprecatedListWriter.generate(configuration);
}
AllClassesFrameWriter.generate(configuration,
new IndexBuilder(configuration, nodeprecated, true));
if (configuration.frames) {
FrameOutputWriter.generate(configuration);
}
if (configuration.createoverview) {
if (configuration.showModules) {
ModuleIndexWriter.generate(configuration);
} else {
PackageIndexWriter.generate(configuration);
}
}
if (!configuration.frames && !configuration.createoverview) {
IndexRedirectWriter.generate(configuration);
}
if (configuration.helpfile.isEmpty() && !configuration.nohelp) {
HelpWriter.generate(configuration);
}
DocFile f;
if (configuration.stylesheetfile.length() == 0) {
f = DocFile.createFileForOutput(configuration, DocPaths.STYLESHEET);
f.copyResource(DocPaths.RESOURCES.resolve(DocPaths.STYLESHEET), false, true);
}
f = DocFile.createFileForOutput(configuration, DocPaths.JAVASCRIPT);
f.copyResource(DocPaths.RESOURCES.resolve(DocPaths.JAVASCRIPT), true, true);
if (configuration.createindex) {
f = DocFile.createFileForOutput(configuration, DocPaths.SEARCH_JS);
f.copyResource(DOCLET_RESOURCES.resolve(DocPaths.SEARCH_JS), true, true);
f = DocFile.createFileForOutput(configuration, DocPaths.RESOURCES.resolve(DocPaths.GLASS_IMG));
f.copyResource(DOCLET_RESOURCES.resolve(DocPaths.GLASS_IMG), true, false);
f = DocFile.createFileForOutput(configuration, DocPaths.RESOURCES.resolve(DocPaths.X_IMG));
f.copyResource(DOCLET_RESOURCES.resolve(DocPaths.X_IMG), true, false);
copyJqueryFiles();
}
}
protected void copyJqueryFiles() throws DocletException {
List<String> files = Arrays.asList(
"jquery-1.10.2.js",
"jquery-ui.js",
"jquery-ui.css",
"jquery-ui.min.js",
"jquery-ui.min.css",
"jquery-ui.structure.min.css",
"jquery-ui.structure.css",
"external/jquery/jquery.js",
"jszip/dist/jszip.js",
"jszip/dist/jszip.min.js",
"jszip-utils/dist/jszip-utils.js",
"jszip-utils/dist/jszip-utils.min.js",
"jszip-utils/dist/jszip-utils-ie.js",
"jszip-utils/dist/jszip-utils-ie.min.js",
"images/ui-bg_flat_0_aaaaaa_40x100.png",
"images/ui-icons_454545_256x240.png",
"images/ui-bg_glass_95_fef1ec_1x400.png",
"images/ui-bg_glass_75_dadada_1x400.png",
"images/ui-bg_highlight-soft_75_cccccc_1x100.png",
"images/ui-icons_888888_256x240.png",
"images/ui-icons_2e83ff_256x240.png",
"images/ui-bg_glass_65_ffffff_1x400.png",
"images/ui-icons_cd0a0a_256x240.png",
"images/ui-bg_glass_55_fbf9ee_1x400.png",
"images/ui-icons_222222_256x240.png",
"images/ui-bg_glass_75_e6e6e6_1x400.png",
"images/ui-bg_flat_75_ffffff_40x100.png");
DocFile f;
for (String file : files) {
DocPath filePath = DocPaths.JQUERY_FILES.resolve(file);
f = DocFile.createFileForOutput(configuration, filePath);
f.copyResource(DOCLET_RESOURCES.resolve(filePath), true, false);
}
}
@Override
protected void generateClassFiles(SortedSet<TypeElement> arr, ClassTree classtree)
throws DocletException {
List<TypeElement> list = new ArrayList<>(arr);
ListIterator<TypeElement> iterator = list.listIterator();
TypeElement klass = null;
while (iterator.hasNext()) {
TypeElement prev = iterator.hasPrevious() ? klass : null;
klass = iterator.next();
TypeElement next = iterator.nextIndex() == list.size()
? null : list.get(iterator.nextIndex());
if (utils.isHidden(klass) ||
!(configuration.isGeneratedDoc(klass) && utils.isIncluded(klass))) {
continue;
}
if (utils.isAnnotationType(klass)) {
AbstractBuilder annotationTypeBuilder =
configuration.getBuilderFactory()
.getAnnotationTypeBuilder(klass,
prev == null ? null : prev.asType(),
next == null ? null : next.asType());
annotationTypeBuilder.build();
} else {
AbstractBuilder classBuilder =
configuration.getBuilderFactory().getClassBuilder(klass,
prev, next, classtree);
classBuilder.build();
}
}
}
@Override
protected void generateModuleFiles() throws DocletException {
if (configuration.showModules) {
if (configuration.frames && configuration.modules.size() > 1) {
ModuleIndexFrameWriter.generate(configuration);
}
ModuleElement prevModule = null, nextModule;
List<ModuleElement> mdles = new ArrayList<>(configuration.modulePackages.keySet());
int i = 0;
for (ModuleElement mdle : mdles) {
if (configuration.frames && configuration.modules.size() > 1) {
ModulePackageIndexFrameWriter.generate(configuration, mdle);
ModuleFrameWriter.generate(configuration, mdle);
}
nextModule = (i + 1 < mdles.size()) ? mdles.get(i + 1) : null;
AbstractBuilder moduleSummaryBuilder =
configuration.getBuilderFactory().getModuleSummaryBuilder(
mdle, prevModule, nextModule);
moduleSummaryBuilder.build();
prevModule = mdle;
i++;
}
}
}
PackageElement getNamedPackage(List<PackageElement> list, int idx) {
if (idx < list.size()) {
PackageElement pkg = list.get(idx);
if (pkg != null && !pkg.isUnnamed()) {
return pkg;
}
}
return null;
}
@Override
protected void generatePackageFiles(ClassTree classtree) throws DocletException {
Set<PackageElement> packages = configuration.packages;
if (packages.size() > 1 && configuration.frames) {
PackageIndexFrameWriter.generate(configuration);
}
List<PackageElement> pList = new ArrayList<>(packages);
PackageElement prev = null;
for (int i = 0 ; i < pList.size() ; i++) {
PackageElement pkg = pList.get(i);
if (!(configuration.nodeprecated && utils.isDeprecated(pkg))) {
if (configuration.frames) {
PackageFrameWriter.generate(configuration, pkg);
}
int nexti = i + 1;
PackageElement next = null;
if (nexti < pList.size()) {
next = pList.get(nexti);
if (next.isUnnamed() && ++nexti < pList.size()) {
next = pList.get(nexti);
}
}
AbstractBuilder packageSummaryBuilder =
configuration.getBuilderFactory().getPackageSummaryBuilder(
pkg, prev, next);
packageSummaryBuilder.build();
if (configuration.createtree) {
PackageTreeWriter.generate(configuration, pkg, prev, next,
configuration.nodeprecated);
}
prev = pkg;
}
}
}
@Override
public Set<Option> getSupportedOptions() {
return configuration.getSupportedOptions();
}
private void performCopy(String filename) throws DocFileIOException {
if (filename.isEmpty())
return;
DocFile fromfile = DocFile.createFileForInput(configuration, filename);
DocPath path = DocPath.create(fromfile.getName());
DocFile toFile = DocFile.createFileForOutput(configuration, path);
if (toFile.isSameFile(fromfile))
return;
messages.notice("doclet.Copying_File_0_To_File_1",
fromfile.toString(), path.getPath());
toFile.copyFile(fromfile);
}
}