author | jjg |
Fri, 27 May 2016 13:06:58 -0700 | |
changeset 38617 | d93a7f64e231 |
parent 29957 | 7740f9657f56 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
2 |
* Copyright (c) 1998, 2015, 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 |
||
26 |
package com.sun.tools.doclets.formats.html; |
|
27 |
||
28 |
import java.io.*; |
|
29 |
import java.util.*; |
|
14258 | 30 |
|
31 |
import com.sun.javadoc.*; |
|
32 |
import com.sun.tools.doclets.formats.html.markup.*; |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
33 |
import com.sun.tools.doclets.internal.toolkit.*; |
14258 | 34 |
import com.sun.tools.doclets.internal.toolkit.util.*; |
10 | 35 |
|
36 |
/** |
|
37 |
* Abstract class to print the class hierarchy page for all the Classes. This |
|
38 |
* is sub-classed by {@link PackageTreeWriter} and {@link TreeWriter} to |
|
39 |
* generate the Package Tree and global Tree(for all the classes and packages) |
|
40 |
* pages. |
|
41 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
42 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
43 |
* If you write code that depends on this, you do so at your own risk. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
44 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
45 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
46 |
* |
10 | 47 |
* @author Atul M Dambalkar |
48 |
*/ |
|
38617 | 49 |
@Deprecated |
10 | 50 |
public abstract class AbstractTreeWriter extends HtmlDocletWriter { |
51 |
||
52 |
/** |
|
53 |
* The class and interface tree built by using {@link ClassTree} |
|
54 |
*/ |
|
55 |
protected final ClassTree classtree; |
|
56 |
||
57 |
/** |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
58 |
* Constructor initializes classtree variable. This constructor will be used |
10 | 59 |
* while generating global tree file "overview-tree.html". |
60 |
* |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
61 |
* @param configuration The current configuration |
10 | 62 |
* @param filename File to be generated. |
63 |
* @param classtree Tree built by {@link ClassTree}. |
|
64 |
* @throws IOException |
|
65 |
* @throws DocletAbortException |
|
66 |
*/ |
|
67 |
protected AbstractTreeWriter(ConfigurationImpl configuration, |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
68 |
DocPath filename, ClassTree classtree) |
10 | 69 |
throws IOException { |
70 |
super(configuration, filename); |
|
71 |
this.classtree = classtree; |
|
72 |
} |
|
73 |
||
74 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
75 |
* Add each level of the class tree. For each sub-class or |
10 | 76 |
* sub-interface indents the next level information. |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
77 |
* Recurses itself to add subclasses info. |
10 | 78 |
* |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
79 |
* @param parent the superclass or superinterface of the list |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
80 |
* @param list list of the sub-classes at this level |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
81 |
* @param isEnum true if we are generating a tree for enums |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
82 |
* @param contentTree the content tree to which the level information will be added |
10 | 83 |
*/ |
26270
a3635e6d3d78
8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents:
25874
diff
changeset
|
84 |
protected void addLevelInfo(ClassDoc parent, Collection<ClassDoc> list, |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
85 |
boolean isEnum, Content contentTree) { |
26270
a3635e6d3d78
8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents:
25874
diff
changeset
|
86 |
if (!list.isEmpty()) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
87 |
Content ul = new HtmlTree(HtmlTag.UL); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17558
diff
changeset
|
88 |
for (ClassDoc local : list) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
89 |
HtmlTree li = new HtmlTree(HtmlTag.LI); |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
90 |
li.addStyle(HtmlStyle.circle); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
91 |
addPartialInfo(local, li); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
92 |
addExtendsImplements(parent, local, li); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
93 |
addLevelInfo(local, classtree.subs(local, isEnum), |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17558
diff
changeset
|
94 |
isEnum, li); // Recurse |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
95 |
ul.addContent(li); |
10 | 96 |
} |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
97 |
contentTree.addContent(ul); |
10 | 98 |
} |
99 |
} |
|
100 |
||
101 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
102 |
* Add the heading for the tree depending upon tree type if it's a |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
103 |
* Class Tree or Interface tree. |
10 | 104 |
* |
105 |
* @param list List of classes which are at the most base level, all the |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
106 |
* other classes in this run will derive from these classes |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
107 |
* @param heading heading for the tree |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
108 |
* @param div the content tree to which the tree will be added |
10 | 109 |
*/ |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
110 |
protected void addTree(SortedSet<ClassDoc> list, String heading, HtmlTree div) { |
26270
a3635e6d3d78
8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents:
25874
diff
changeset
|
111 |
if (!list.isEmpty()) { |
a3635e6d3d78
8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents:
25874
diff
changeset
|
112 |
ClassDoc firstClassDoc = list.first(); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
113 |
Content headingContent = getResource(heading); |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
114 |
Content sectionHeading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true, |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
115 |
headingContent); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
116 |
HtmlTree htmlTree; |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
117 |
if (configuration.allowTag(HtmlTag.SECTION)) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
118 |
htmlTree = HtmlTree.SECTION(sectionHeading); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
119 |
} else { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
120 |
div.addContent(sectionHeading); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
121 |
htmlTree = div; |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
122 |
} |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
123 |
addLevelInfo(!firstClassDoc.isInterface()? firstClassDoc : null, |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
124 |
list, list == classtree.baseEnums(), htmlTree); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
125 |
if (configuration.allowTag(HtmlTag.SECTION)) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
126 |
div.addContent(htmlTree); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
26270
diff
changeset
|
127 |
} |
10 | 128 |
} |
129 |
} |
|
130 |
||
131 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
132 |
* Add information regarding the classes which this class extends or |
10 | 133 |
* implements. |
134 |
* |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
135 |
* @param parent the parent class of the class being documented |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
136 |
* @param cd the classdoc under consideration |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
137 |
* @param contentTree the content tree to which the information will be added |
10 | 138 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
139 |
protected void addExtendsImplements(ClassDoc parent, ClassDoc cd, |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
140 |
Content contentTree) { |
10 | 141 |
ClassDoc[] interfaces = cd.interfaces(); |
142 |
if (interfaces.length > (cd.isInterface()? 1 : 0)) { |
|
143 |
Arrays.sort(interfaces); |
|
144 |
int counter = 0; |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17558
diff
changeset
|
145 |
for (ClassDoc intf : interfaces) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17558
diff
changeset
|
146 |
if (parent != intf) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17558
diff
changeset
|
147 |
if (!(intf.isPublic() || |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
148 |
utils.isLinkable(intf, configuration))) { |
10 | 149 |
continue; |
150 |
} |
|
151 |
if (counter == 0) { |
|
152 |
if (cd.isInterface()) { |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
153 |
contentTree.addContent(" ("); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
154 |
contentTree.addContent(getResource("doclet.also")); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
155 |
contentTree.addContent(" extends "); |
10 | 156 |
} else { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
157 |
contentTree.addContent(" (implements "); |
10 | 158 |
} |
159 |
} else { |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
160 |
contentTree.addContent(", "); |
10 | 161 |
} |
17558
eee4ccf66cfd
8010440: Replace int constants in LinkInfoImpl with enum
jjg
parents:
14542
diff
changeset
|
162 |
addPreQualifiedClassLink(LinkInfoImpl.Kind.TREE, |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17558
diff
changeset
|
163 |
intf, contentTree); |
10 | 164 |
counter++; |
165 |
} |
|
166 |
} |
|
167 |
if (counter > 0) { |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
168 |
contentTree.addContent(")"); |
10 | 169 |
} |
170 |
} |
|
171 |
} |
|
172 |
||
173 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
174 |
* Add information about the class kind, if it's a "class" or "interface". |
10 | 175 |
* |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
176 |
* @param cd the class being documented |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
177 |
* @param contentTree the content tree to which the information will be added |
10 | 178 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
179 |
protected void addPartialInfo(ClassDoc cd, Content contentTree) { |
17558
eee4ccf66cfd
8010440: Replace int constants in LinkInfoImpl with enum
jjg
parents:
14542
diff
changeset
|
180 |
addPreQualifiedStrongClassLink(LinkInfoImpl.Kind.TREE, cd, contentTree); |
10 | 181 |
} |
182 |
||
183 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
184 |
* Get the tree label for the navigation bar. |
10 | 185 |
* |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
186 |
* @return a content tree for the tree label |
10 | 187 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
188 |
protected Content getNavLinkTree() { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
189 |
Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, treeLabel); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
190 |
return li; |
10 | 191 |
} |
192 |
} |