langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java Wed Jul 05 22:07:34 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SourceToHTMLConverter.java Mon Aug 22 16:32:40 2016 -0700
@@ -42,10 +42,11 @@
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.Messages;
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.DocletAbortException;
import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants;
+import jdk.javadoc.internal.doclets.toolkit.util.SimpleDocletException;
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
/**
@@ -79,7 +80,7 @@
private final DocletEnvironment docEnv;
- private DocPath outputdir;
+ private final DocPath outputdir;
/**
* Relative path from the documentation root to the file that is being
@@ -102,13 +103,15 @@
* @param configuration the configuration.
* @param docEnv the DocletEnvironment to convert.
* @param outputdir the name of the directory to output to.
+ * @throws DocFileIOException if there is a problem generating an output file
+ * @throws SimpleDocletException if there is a problem reading a source file
*/
public static void convertRoot(ConfigurationImpl configuration, DocletEnvironment docEnv,
- DocPath outputdir) {
+ DocPath outputdir) throws DocFileIOException, SimpleDocletException {
new SourceToHTMLConverter(configuration, docEnv, outputdir).generate();
}
- void generate() {
+ void generate() throws DocFileIOException, SimpleDocletException {
if (docEnv == null || outputdir == null) {
return;
}
@@ -129,12 +132,15 @@
}
/**
- * Convert the Classes in the given Package to an HTML.
+ * Convert the Classes in the given Package to an HTML file.
*
* @param pkg the Package to convert.
* @param outputdir the name of the directory to output to.
+ * @throws DocFileIOException if there is a problem generating an output file
+ * @throws SimpleDocletException if there is a problem reading a source file
*/
- public void convertPackage(PackageElement pkg, DocPath outputdir) {
+ public void convertPackage(PackageElement pkg, DocPath outputdir)
+ throws DocFileIOException, SimpleDocletException {
if (pkg == null) {
return;
}
@@ -152,16 +158,20 @@
* Convert the given Class to an HTML.
*
* @param te the class to convert.
- * @param outputdir the name of the directory to output to.
+ * @param outputdir the name of the directory to output to
+ * @throws DocFileIOException if there is a problem generating the output file
+ * @throws SimpleDocletException if there is a problem reading the source file
*/
- public void convertClass(TypeElement te, DocPath outputdir) {
+ public void convertClass(TypeElement te, DocPath outputdir)
+ throws DocFileIOException, SimpleDocletException {
if (te == null) {
return;
}
+ FileObject fo = utils.getFileObject(te);
+ if (fo == null)
+ return;
+
try {
- FileObject fo = utils.getFileObject(te);
- if (fo == null)
- return;
Reader r = fo.openReader(true);
int lineno = 1;
String line;
@@ -182,7 +192,8 @@
body.addContent((configuration.allowTag(HtmlTag.MAIN)) ? HtmlTree.MAIN(div) : div);
writeToFile(body, outputdir.resolve(DocPath.forClass(utils, te)));
} catch (IOException e) {
- throw new DocletAbortException(e);
+ String message = configuration.resources.getText("doclet.exception.read.file", fo.getName());
+ throw new SimpleDocletException(message, e);
}
}
@@ -192,7 +203,7 @@
* @param body the documentation content to be written to the file.
* @param path the path for the file.
*/
- private void writeToFile(Content body, DocPath path) throws IOException {
+ private void writeToFile(Content body, DocPath path) throws DocFileIOException {
Content htmlDocType = configuration.isOutputHtml5()
? DocType.HTML5
: DocType.TRANSITIONAL;
@@ -207,6 +218,8 @@
DocFile df = DocFile.createFileForOutput(configuration, path);
try (Writer w = df.openWriter()) {
htmlDocument.write(w, true);
+ } catch (IOException e) {
+ throw new DocFileIOException(df, DocFileIOException.Mode.WRITE, e);
}
}
@@ -287,9 +300,10 @@
}
/**
- * Given a <code>Doc</code>, return an anchor name for it.
+ * Given an element, return an anchor name for it.
*
- * @param d the <code>Doc</code> to check.
+ * @param utils the utility class, used to get the line number of the element
+ * @param e the element to check.
* @return the name of the anchor.
*/
public static String getAnchorName(Utils utils, Element e) {