src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1997, 2014, 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. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1997, 2016, 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. Oracle designates this
*** 21,41 ****
* 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 com.sun.tools.doclets.formats.html;
import java.io.*;
import java.util.*;
! import com.sun.javadoc.*;
! import com.sun.tools.javac.jvm.Profile;
! import com.sun.tools.doclets.internal.toolkit.*;
! import com.sun.tools.doclets.internal.toolkit.builders.*;
! import com.sun.tools.doclets.internal.toolkit.util.*;
/**
* The class with "start" method, calls individual Writers.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
--- 21,51 ----
* 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 jdk.javadoc.internal.doclets.formats.html;
import java.io.*;
import java.util.*;
! import javax.lang.model.element.PackageElement;
! import javax.lang.model.element.TypeElement;
+ import jdk.javadoc.doclet.Doclet.Option;
+ import jdk.javadoc.doclet.DocletEnvironment;
+ import jdk.javadoc.doclet.Reporter;
+ import jdk.javadoc.internal.doclets.toolkit.AbstractDoclet;
+ import jdk.javadoc.internal.doclets.toolkit.Configuration;
+ 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.DocPath;
+ import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
+ import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException;
+ import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder;
+
/**
* The class with "start" method, calls individual Writers.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
*** 46,57 ****
* @author Robert Field
* @author Jamie Ho
*
*/
public class HtmlDoclet extends AbstractDoclet {
- // An instance will be created by validOptions, and used by start.
- private static HtmlDoclet docletToStart = null;
public HtmlDoclet() {
configuration = new ConfigurationImpl();
}
--- 56,65 ----
*** 58,86 ****
/**
* The global configuration information for this run.
*/
public final ConfigurationImpl configuration;
/**
* The "start" method as required by Javadoc.
*
* @param root the root of the documentation tree.
! * @see com.sun.javadoc.RootDoc
* @return true if the doclet ran without encountering any errors.
*/
! public static boolean start(RootDoc root) {
! // In typical use, options will have been set up by calling validOptions,
! // which will create an HtmlDoclet for use here.
! HtmlDoclet doclet;
! if (docletToStart != null) {
! doclet = docletToStart;
! docletToStart = null;
! } else {
! doclet = new HtmlDoclet();
}
- return doclet.startDoclet(root);
- }
/**
* Create the configuration instance.
* Override this method to use a different
* configuration.
--- 66,90 ----
/**
* The global configuration information for this run.
*/
public final ConfigurationImpl configuration;
+ public void init(Locale locale, Reporter reporter) {
+ configuration.reporter = reporter;
+ configuration.locale = locale;
+ }
+
/**
* The "start" method as required by Javadoc.
*
* @param root the root of the documentation tree.
! * @see jdk.doclet.DocletEnvironment
* @return true if the doclet ran without encountering any errors.
*/
! public boolean run(DocletEnvironment root) {
! return startDoclet(root);
}
/**
* Create the configuration instance.
* Override this method to use a different
* configuration.
*** 95,107 ****
* TreeWriter generation first to ensure the Class Hierarchy is built
* first and then can be used in the later generation.
*
* For new format.
*
! * @see com.sun.javadoc.RootDoc
*/
! protected void generateOtherFiles(RootDoc root, ClassTree classtree)
throws Exception {
super.generateOtherFiles(root, classtree);
if (configuration.linksource) {
SourceToHTMLConverter.convertRoot(configuration,
root, DocPaths.SOURCE_OUTPUT);
--- 99,111 ----
* TreeWriter generation first to ensure the Class Hierarchy is built
* first and then can be used in the later generation.
*
* For new format.
*
! * @see jdk.doclet.RootDoc
*/
! protected void generateOtherFiles(DocletEnvironment root, ClassTree classtree)
throws Exception {
super.generateOtherFiles(root, classtree);
if (configuration.linksource) {
SourceToHTMLConverter.convertRoot(configuration,
root, DocPaths.SOURCE_OUTPUT);
*** 158,172 ****
}
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(DocPaths.RESOURCES.resolve(DocPaths.SEARCH_JS), true, true);
f = DocFile.createFileForOutput(configuration, DocPaths.RESOURCES.resolve(DocPaths.GLASS_IMG));
! f.copyResource(DocPaths.RESOURCES.resolve(DocPaths.GLASS_IMG), true, false);
f = DocFile.createFileForOutput(configuration, DocPaths.RESOURCES.resolve(DocPaths.X_IMG));
! f.copyResource(DocPaths.RESOURCES.resolve(DocPaths.X_IMG), true, false);
copyJqueryFiles();
}
}
protected void copyJqueryFiles() {
--- 162,178 ----
}
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(DocPaths.RESOURCES_IN_FORMATS_HTML.resolve(DocPaths.SEARCH_JS), true, true);
!
f = DocFile.createFileForOutput(configuration, DocPaths.RESOURCES.resolve(DocPaths.GLASS_IMG));
! f.copyResource(DocPaths.RESOURCES_IN_FORMATS_HTML.resolve(DocPaths.GLASS_IMG), true, false);
!
f = DocFile.createFileForOutput(configuration, DocPaths.RESOURCES.resolve(DocPaths.X_IMG));
! f.copyResource(DocPaths.RESOURCES_IN_FORMATS_HTML.resolve(DocPaths.X_IMG), true, false);
copyJqueryFiles();
}
}
protected void copyJqueryFiles() {
*** 200,240 ****
"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(DocPaths.RESOURCES.resolve(filePath), true, false);
}
}
/**
* {@inheritDoc}
*/
! protected void generateClassFiles(ClassDoc[] arr, ClassTree classtree) {
! Arrays.sort(arr);
! for(int i = 0; i < arr.length; i++) {
! if (!(configuration.isGeneratedDoc(arr[i]) && arr[i].isIncluded())) {
continue;
}
- ClassDoc prev = (i == 0)?
- null:
- arr[i-1];
- ClassDoc curr = arr[i];
- ClassDoc next = (i+1 == arr.length)?
- null:
- arr[i+1];
try {
! if (curr.isAnnotationType()) {
AbstractBuilder annotationTypeBuilder =
configuration.getBuilderFactory()
! .getAnnotationTypeBuilder((AnnotationTypeDoc) curr,
! prev, next);
annotationTypeBuilder.build();
} else {
AbstractBuilder classBuilder =
! configuration.getBuilderFactory()
! .getClassBuilder(curr, prev, next, classtree);
classBuilder.build();
}
} catch (IOException e) {
throw new DocletAbortException(e);
} catch (DocletAbortException de) {
--- 206,246 ----
"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(DocPaths.RESOURCES_IN_FORMATS_HTML.resolve(filePath), true, false);
}
}
/**
* {@inheritDoc}
*/
! protected void generateClassFiles(SortedSet<TypeElement> arr, ClassTree classtree) {
! 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 (!(configuration.isGeneratedDoc(klass) && utils.isIncluded(klass))) {
continue;
}
try {
! 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();
}
} catch (IOException e) {
throw new DocletAbortException(e);
} catch (DocletAbortException de) {
*** 244,374 ****
throw new DocletAbortException(e);
}
}
}
- /**
- * {@inheritDoc}
- */
- protected void generateProfileFiles() throws Exception {
- if (configuration.showProfiles && configuration.profilePackages.size() > 0) {
- ProfileIndexFrameWriter.generate(configuration);
- Profile prevProfile = null, nextProfile;
- String profileName;
- for (int i = 1; i < configuration.profiles.getProfileCount(); i++) {
- profileName = Profile.lookup(i).name;
- // Generate profile package pages only if there are any packages
- // in a profile to be documented. The profilePackages map will not
- // contain an entry for the profile if there are no packages to be documented.
- if (!configuration.shouldDocumentProfile(profileName))
- continue;
- ProfilePackageIndexFrameWriter.generate(configuration, profileName);
- List<PackageDoc> packages = configuration.profilePackages.get(
- profileName);
- PackageDoc prev = null, next;
- for (int j = 0; j < packages.size(); j++) {
- // if -nodeprecated option is set and the package is marked as
- // deprecated, do not generate the profilename-package-summary.html
- // and profilename-package-frame.html pages for that package.
- PackageDoc pkg = packages.get(j);
- if (!(configuration.nodeprecated && utils.isDeprecated(pkg))) {
- ProfilePackageFrameWriter.generate(configuration, pkg, i);
- next = getNamedPackage(packages, j + 1);
- AbstractBuilder profilePackageSummaryBuilder =
- configuration.getBuilderFactory().getProfilePackageSummaryBuilder(
- pkg, prev, next, Profile.lookup(i));
- profilePackageSummaryBuilder.build();
- prev = pkg;
- }
- }
- nextProfile = (i + 1 < configuration.profiles.getProfileCount()) ?
- Profile.lookup(i + 1) : null;
- AbstractBuilder profileSummaryBuilder =
- configuration.getBuilderFactory().getProfileSummaryBuilder(
- Profile.lookup(i), prevProfile, nextProfile);
- profileSummaryBuilder.build();
- prevProfile = Profile.lookup(i);
- }
- }
- }
- PackageDoc getNamedPackage(List<PackageDoc> list, int idx) {
- if (idx < list.size()) {
- PackageDoc pkg = list.get(idx);
- if (!pkg.name().isEmpty()) {
- return pkg;
- }
- }
- return null;
- }
-
/**
* {@inheritDoc}
*/
protected void generatePackageFiles(ClassTree classtree) throws Exception {
! Set<PackageDoc> packages = configuration.packages;
if (packages.size() > 1) {
PackageIndexFrameWriter.generate(configuration);
}
! List<PackageDoc> pList = new ArrayList<>(configuration.packages);
! PackageDoc prev = null, next;
! for (int i = 0; i < pList.size(); i++) {
// if -nodeprecated option is set and the package is marked as
// deprecated, do not generate the package-summary.html, package-frame.html
// and package-tree.html pages for that package.
! PackageDoc pkg = pList.get(i);
if (!(configuration.nodeprecated && utils.isDeprecated(pkg))) {
PackageFrameWriter.generate(configuration, pkg);
! next = getNamedPackage(pList, i + 1);
! //If the next package is unnamed package, skip 2 ahead if possible
! if (next == null)
! next = getNamedPackage(pList, i + 2);
AbstractBuilder packageSummaryBuilder =
configuration.getBuilderFactory().getPackageSummaryBuilder(
pkg, prev, next);
packageSummaryBuilder.build();
if (configuration.createtree) {
! PackageTreeWriter.generate(configuration,
! pkg, prev, next,
configuration.nodeprecated);
}
prev = pkg;
}
}
}
! public static final ConfigurationImpl sharedInstanceForOptions =
! new ConfigurationImpl();
!
! /**
! * Check for doclet added options here.
! *
! * @return number of arguments to option. Zero return means
! * option not known. Negative value means error occurred.
! */
! public static int optionLength(String option) {
! // Construct temporary configuration for check
! return sharedInstanceForOptions.optionLength(option);
}
- /**
- * Check that options have the correct arguments here.
- * <P>
- * This method is not required and will default gracefully
- * (to true) if absent.
- * <P>
- * Printing option related error messages (using the provided
- * DocErrorReporter) is the responsibility of this method.
- *
- * @return true if the options are valid.
- */
- public static boolean validOptions(String options[][],
- DocErrorReporter reporter) {
- docletToStart = new HtmlDoclet();
- return docletToStart.configuration.validOptions(options, reporter);
- }
-
private void performCopy(String filename) {
if (filename.isEmpty())
return;
try {
--- 250,303 ----
throw new DocletAbortException(e);
}
}
}
/**
* {@inheritDoc}
*/
protected void generatePackageFiles(ClassTree classtree) throws Exception {
! Set<PackageElement> packages = configuration.packages;
if (packages.size() > 1) {
PackageIndexFrameWriter.generate(configuration);
}
! List<PackageElement> pList = new ArrayList<>(packages);
! PackageElement prev = null;
! for (int i = 0 ; i < pList.size() ; i++) {
// if -nodeprecated option is set and the package is marked as
// deprecated, do not generate the package-summary.html, package-frame.html
// and package-tree.html pages for that package.
! PackageElement pkg = pList.get(i);
if (!(configuration.nodeprecated && utils.isDeprecated(pkg))) {
PackageFrameWriter.generate(configuration, pkg);
! int nexti = i + 1;
! PackageElement next = null;
! if (nexti < pList.size()) {
! next = pList.get(nexti);
! // If the next package is unnamed package, skip 2 ahead if possible
! 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;
}
}
}
! public Set<Option> getSupportedOptions() {
! return configuration.getSupportedOptions();
}
private void performCopy(String filename) {
if (filename.isEmpty())
return;
try {
*** 376,392 ****
DocPath path = DocPath.create(fromfile.getName());
DocFile toFile = DocFile.createFileForOutput(configuration, path);
if (toFile.isSameFile(fromfile))
return;
! configuration.message.notice((SourcePosition) null,
! "doclet.Copying_File_0_To_File_1",
fromfile.toString(), path.getPath());
toFile.copyFile(fromfile);
} catch (IOException exc) {
! configuration.message.error((SourcePosition) null,
! "doclet.perform_copy_exception_encountered",
exc.toString());
throw new DocletAbortException(exc);
}
}
}
--- 305,319 ----
DocPath path = DocPath.create(fromfile.getName());
DocFile toFile = DocFile.createFileForOutput(configuration, path);
if (toFile.isSameFile(fromfile))
return;
! configuration.message.notice("doclet.Copying_File_0_To_File_1",
fromfile.toString(), path.getPath());
toFile.copyFile(fromfile);
} catch (IOException exc) {
! configuration.message.error("doclet.perform_copy_exception_encountered",
exc.toString());
throw new DocletAbortException(exc);
}
}
}