author | jjg |
Wed, 20 Feb 2019 16:15:02 -0800 | |
changeset 53863 | d001808c57e8 |
parent 53562 | 0d9dee001667 |
child 54002 | fb9541185457 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
53863
d001808c57e8
8218998: Add metadata to generated API documentation files
jjg
parents:
53562
diff
changeset
|
2 |
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
26 |
package jdk.javadoc.internal.doclets.formats.html; |
10 | 27 |
|
47849 | 28 |
import jdk.javadoc.internal.doclets.formats.html.markup.Head; |
29 |
||
10 | 30 |
import java.io.*; |
47748
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
31 |
import java.util.List; |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
32 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
33 |
import javax.lang.model.element.Element; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
34 |
import javax.lang.model.element.PackageElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
35 |
import javax.lang.model.element.TypeElement; |
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
36 |
import javax.tools.FileObject; |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
37 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
38 |
import jdk.javadoc.doclet.DocletEnvironment; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
39 |
import jdk.javadoc.internal.doclets.formats.html.markup.DocType; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
40 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlDocument; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
41 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
42 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
43 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
44 |
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
45 |
import jdk.javadoc.internal.doclets.toolkit.Content; |
40303 | 46 |
import jdk.javadoc.internal.doclets.toolkit.Messages; |
47847 | 47 |
import jdk.javadoc.internal.doclets.toolkit.Resources; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
48 |
import jdk.javadoc.internal.doclets.toolkit.util.DocFile; |
40587 | 49 |
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
50 |
import jdk.javadoc.internal.doclets.toolkit.util.DocPath; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
51 |
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
52 |
import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants; |
40587 | 53 |
import jdk.javadoc.internal.doclets.toolkit.util.SimpleDocletException; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
54 |
import jdk.javadoc.internal.doclets.toolkit.util.Utils; |
10 | 55 |
|
56 |
/** |
|
57 |
* Converts Java Source Code to HTML. |
|
58 |
* |
|
14260 | 59 |
* <p><b>This is NOT part of any supported API. |
60 |
* If you write code that depends on this, you do so at your own risk. |
|
61 |
* This code and its internal interfaces are subject to change or |
|
62 |
* deletion without notice.</b> |
|
10 | 63 |
* |
64 |
* @author Jamie Ho |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
65 |
* @author Bhavesh Patel (Modified) |
10 | 66 |
*/ |
67 |
public class SourceToHTMLConverter { |
|
68 |
||
69 |
/** |
|
70 |
* The number of trailing blank lines at the end of the page. |
|
71 |
* This is inserted so that anchors at the bottom of small pages |
|
72 |
* can be reached. |
|
73 |
*/ |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
74 |
private static final int NUM_BLANK_LINES = 60; |
10 | 75 |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
76 |
/** |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
77 |
* New line to be added to the documentation. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
78 |
*/ |
17560 | 79 |
private static final String NEW_LINE = DocletConstants.NL; |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
80 |
|
45417 | 81 |
private final HtmlConfiguration configuration; |
40303 | 82 |
private final Messages messages; |
47847 | 83 |
private final Resources resources; |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
84 |
private final Utils utils; |
14542 | 85 |
|
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
35426
diff
changeset
|
86 |
private final DocletEnvironment docEnv; |
14542 | 87 |
|
40587 | 88 |
private final DocPath outputdir; |
14542 | 89 |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
90 |
/** |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
91 |
* Relative path from the documentation root to the file that is being |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
92 |
* generated. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
93 |
*/ |
14542 | 94 |
private DocPath relativePath = DocPath.empty; |
10 | 95 |
|
45417 | 96 |
private SourceToHTMLConverter(HtmlConfiguration configuration, DocletEnvironment rd, |
97 |
DocPath outputdir) { |
|
14542 | 98 |
this.configuration = configuration; |
40303 | 99 |
this.messages = configuration.getMessages(); |
47847 | 100 |
this.resources = configuration.resources; |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
101 |
this.utils = configuration.utils; |
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
35426
diff
changeset
|
102 |
this.docEnv = rd; |
14542 | 103 |
this.outputdir = outputdir; |
104 |
} |
|
10 | 105 |
|
106 |
/** |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
107 |
* Translate the TypeElements in the given DocletEnvironment to HTML representation. |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
108 |
* |
10 | 109 |
* @param configuration the configuration. |
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
35426
diff
changeset
|
110 |
* @param docEnv the DocletEnvironment to convert. |
10 | 111 |
* @param outputdir the name of the directory to output to. |
40587 | 112 |
* @throws DocFileIOException if there is a problem generating an output file |
113 |
* @throws SimpleDocletException if there is a problem reading a source file |
|
10 | 114 |
*/ |
45417 | 115 |
public static void convertRoot(HtmlConfiguration configuration, DocletEnvironment docEnv, |
116 |
DocPath outputdir) throws DocFileIOException, SimpleDocletException { |
|
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
35426
diff
changeset
|
117 |
new SourceToHTMLConverter(configuration, docEnv, outputdir).generate(); |
14542 | 118 |
} |
119 |
||
40587 | 120 |
void generate() throws DocFileIOException, SimpleDocletException { |
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
35426
diff
changeset
|
121 |
if (docEnv == null || outputdir == null) { |
10 | 122 |
return; |
123 |
} |
|
42277 | 124 |
for (PackageElement pkg : configuration.getSpecifiedPackageElements()) { |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
125 |
// If -nodeprecated option is set and the package is marked as deprecated, |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
126 |
// do not convert the package files to HTML. |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
127 |
if (!(configuration.nodeprecated && utils.isDeprecated(pkg))) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
128 |
convertPackage(pkg, outputdir); |
10 | 129 |
} |
42277 | 130 |
for (TypeElement te : configuration.getSpecifiedTypeElements()) { |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
131 |
// If -nodeprecated option is set and the class is marked as deprecated |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
132 |
// or the containing package is deprecated, do not convert the |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
133 |
// package files to HTML. |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
134 |
if (!(configuration.nodeprecated && |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
135 |
(utils.isDeprecated(te) || utils.isDeprecated(utils.containingPackage(te))))) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
136 |
convertClass(te, outputdir); |
10 | 137 |
} |
138 |
} |
|
139 |
||
140 |
/** |
|
40587 | 141 |
* Convert the Classes in the given Package to an HTML file. |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
142 |
* |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
143 |
* @param pkg the Package to convert. |
10 | 144 |
* @param outputdir the name of the directory to output to. |
40587 | 145 |
* @throws DocFileIOException if there is a problem generating an output file |
146 |
* @throws SimpleDocletException if there is a problem reading a source file |
|
10 | 147 |
*/ |
40587 | 148 |
public void convertPackage(PackageElement pkg, DocPath outputdir) |
149 |
throws DocFileIOException, SimpleDocletException { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
150 |
if (pkg == null) { |
10 | 151 |
return; |
152 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
153 |
for (Element te : utils.getAllClasses(pkg)) { |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
154 |
// If -nodeprecated option is set and the class is marked as deprecated, |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
155 |
// do not convert the package files to HTML. We do not check for |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
156 |
// containing package deprecation since it is already check in |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
157 |
// the calling method above. |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
158 |
if (!(configuration.nodeprecated && utils.isDeprecated(te))) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
159 |
convertClass((TypeElement)te, outputdir); |
10 | 160 |
} |
161 |
} |
|
162 |
||
163 |
/** |
|
164 |
* Convert the given Class to an HTML. |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
165 |
* |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
166 |
* @param te the class to convert. |
40587 | 167 |
* @param outputdir the name of the directory to output to |
168 |
* @throws DocFileIOException if there is a problem generating the output file |
|
169 |
* @throws SimpleDocletException if there is a problem reading the source file |
|
10 | 170 |
*/ |
40587 | 171 |
public void convertClass(TypeElement te, DocPath outputdir) |
172 |
throws DocFileIOException, SimpleDocletException { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
173 |
if (te == null) { |
10 | 174 |
return; |
175 |
} |
|
40587 | 176 |
FileObject fo = utils.getFileObject(te); |
177 |
if (fo == null) |
|
178 |
return; |
|
179 |
||
10 | 180 |
try { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
181 |
Reader r = fo.openReader(true); |
10 | 182 |
int lineno = 1; |
183 |
String line; |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
184 |
relativePath = DocPaths.SOURCE_OUTPUT |
48759
ffa68af7da87
8195795: Organize output files by module/package, not just package
jjg
parents:
47849
diff
changeset
|
185 |
.resolve(configuration.docPaths.forPackage(te)) |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
186 |
.invert(); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
187 |
Content body = getHeader(); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
188 |
Content pre = new HtmlTree(HtmlTag.PRE); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17571
diff
changeset
|
189 |
try (LineNumberReader reader = new LineNumberReader(r)) { |
10 | 190 |
while ((line = reader.readLine()) != null) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
191 |
addLineNo(pre, lineno); |
14542 | 192 |
addLine(pre, line, lineno); |
10 | 193 |
lineno++; |
194 |
} |
|
195 |
} |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
196 |
addBlankLines(pre); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
197 |
Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre); |
53562 | 198 |
body.addContent(HtmlTree.MAIN(div)); |
53863
d001808c57e8
8218998: Add metadata to generated API documentation files
jjg
parents:
53562
diff
changeset
|
199 |
writeToFile(body, outputdir.resolve(configuration.docPaths.forClass(te)), te); |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
200 |
} catch (IOException e) { |
47847 | 201 |
String message = resources.getText("doclet.exception.read.file", fo.getName()); |
40587 | 202 |
throw new SimpleDocletException(message, e); |
10 | 203 |
} |
204 |
} |
|
205 |
||
206 |
/** |
|
207 |
* Write the output to the file. |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
208 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
209 |
* @param body the documentation content to be written to the file. |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
210 |
* @param path the path for the file. |
10 | 211 |
*/ |
53863
d001808c57e8
8218998: Add metadata to generated API documentation files
jjg
parents:
53562
diff
changeset
|
212 |
private void writeToFile(Content body, DocPath path, TypeElement te) throws DocFileIOException { |
53562 | 213 |
Head head = new Head(path, configuration.docletVersion) |
47849 | 214 |
// .setTimestamp(!configuration.notimestamp) // temporary: compatibility! |
215 |
.setTitle(resources.getText("doclet.Window_Source_title")) |
|
216 |
// .setCharset(configuration.charset) // temporary: compatibility! |
|
53863
d001808c57e8
8218998: Add metadata to generated API documentation files
jjg
parents:
53562
diff
changeset
|
217 |
.setDescription(HtmlDocletWriter.getDescription("source", te)) |
d001808c57e8
8218998: Add metadata to generated API documentation files
jjg
parents:
53562
diff
changeset
|
218 |
.setGenerator(HtmlDocletWriter.getGenerator(getClass())) |
47849 | 219 |
.addDefaultScript(false) |
220 |
.setStylesheets(configuration.getMainStylesheet(), configuration.getAdditionalStylesheets()); |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
221 |
Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(), |
47849 | 222 |
head.toContent(), body); |
53562 | 223 |
HtmlDocument htmlDocument = new HtmlDocument(htmlTree); |
40303 | 224 |
messages.notice("doclet.Generating_0", path.getPath()); |
47848 | 225 |
htmlDocument.write(DocFile.createFileForOutput(configuration, path)); |
10 | 226 |
} |
227 |
||
228 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
229 |
* Returns a link to the stylesheet file. |
10 | 230 |
* |
47748
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
231 |
* @param head an HtmlTree to which the stylesheet links will be added |
10 | 232 |
*/ |
47748
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
233 |
public void addStyleSheetProperties(Content head) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
234 |
String filename = configuration.stylesheetfile; |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
235 |
DocPath stylesheet; |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
236 |
if (filename.length() > 0) { |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
237 |
DocFile file = DocFile.createFileForInput(configuration, filename); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
238 |
stylesheet = DocPath.create(file.getName()); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
239 |
} else { |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
240 |
stylesheet = DocPaths.STYLESHEET; |
10 | 241 |
} |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
242 |
DocPath p = relativePath.resolve(stylesheet); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
243 |
HtmlTree link = HtmlTree.LINK("stylesheet", "text/css", p.getPath(), "Style"); |
47748
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
244 |
head.addContent(link); |
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
245 |
addStylesheets(head); |
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
246 |
} |
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
247 |
|
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
248 |
protected void addStylesheets(Content tree) { |
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
249 |
List<String> stylesheets = configuration.additionalStylesheets; |
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
250 |
if (!stylesheets.isEmpty()) { |
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
251 |
stylesheets.forEach((ssheet) -> { |
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
252 |
DocFile file = DocFile.createFileForInput(configuration, ssheet); |
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
253 |
DocPath ssheetPath = DocPath.create(file.getName()); |
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
254 |
HtmlTree slink = HtmlTree.LINK("stylesheet", "text/css", relativePath.resolve(ssheetPath).getPath(), |
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
255 |
"Style"); |
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
256 |
tree.addContent(slink); |
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
257 |
}); |
dfc709c80775
8185371: Support for multiple stylesheets in javadoc
bpatel
parents:
47216
diff
changeset
|
258 |
} |
10 | 259 |
} |
260 |
||
261 |
/** |
|
262 |
* Get the header. |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
263 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
264 |
* @return the header content for the HTML file |
10 | 265 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
266 |
private static Content getHeader() { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
267 |
return new HtmlTree(HtmlTag.BODY); |
10 | 268 |
} |
269 |
||
270 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
271 |
* Add the line numbers for the source code. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
272 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
273 |
* @param pre the content tree to which the line number will be added |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
274 |
* @param lineno The line number |
10 | 275 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
276 |
private static void addLineNo(Content pre, int lineno) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
277 |
HtmlTree span = new HtmlTree(HtmlTag.SPAN); |
47846 | 278 |
span.setStyle(HtmlStyle.sourceLineNo); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
279 |
if (lineno < 10) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
280 |
span.addContent("00" + Integer.toString(lineno)); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
281 |
} else if (lineno < 100) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
282 |
span.addContent("0" + Integer.toString(lineno)); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
283 |
} else { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
284 |
span.addContent(Integer.toString(lineno)); |
10 | 285 |
} |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
286 |
pre.addContent(span); |
10 | 287 |
} |
288 |
||
289 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
290 |
* Add a line from source to the HTML file that is generated. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
291 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
292 |
* @param pre the content tree to which the line will be added. |
10 | 293 |
* @param line the string to format. |
294 |
* @param currentLineNo the current number. |
|
295 |
*/ |
|
14542 | 296 |
private void addLine(Content pre, String line, int currentLineNo) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
297 |
if (line != null) { |
53562 | 298 |
Content anchor = HtmlTree.A_ID( |
31297
86fe1414f12c
8081854: Javadoc should generate named anchors for HTML4 output
bpatel
parents:
29957
diff
changeset
|
299 |
"line." + Integer.toString(currentLineNo), |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
300 |
new StringContent(utils.replaceTabs(line))); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
301 |
pre.addContent(anchor); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
302 |
pre.addContent(NEW_LINE); |
10 | 303 |
} |
304 |
} |
|
305 |
||
306 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
307 |
* Add trailing blank lines at the end of the page. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
308 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
309 |
* @param pre the content tree to which the blank lines will be added. |
10 | 310 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
311 |
private static void addBlankLines(Content pre) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
312 |
for (int i = 0; i < NUM_BLANK_LINES; i++) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
313 |
pre.addContent(NEW_LINE); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
314 |
} |
10 | 315 |
} |
316 |
||
317 |
/** |
|
40587 | 318 |
* Given an element, return an anchor name for it. |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
319 |
* |
40587 | 320 |
* @param utils the utility class, used to get the line number of the element |
321 |
* @param e the element to check. |
|
10 | 322 |
* @return the name of the anchor. |
323 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
324 |
public static String getAnchorName(Utils utils, Element e) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
325 |
return "line." + utils.getLineNumber(e); |
10 | 326 |
} |
327 |
} |