author | ksrini |
Sat, 28 Nov 2015 18:52:17 -0800 | |
changeset 35426 | 374342e56a56 |
parent 29957 | langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ConstantsSummaryBuilder.java@7740f9657f56 |
child 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
2 |
* Copyright (c) 2003, 2016, 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:
29957
diff
changeset
|
26 |
package jdk.javadoc.internal.doclets.toolkit.builders; |
10 | 27 |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
28 |
import java.io.*; |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
29 |
import java.util.*; |
14258 | 30 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
31 |
import javax.lang.model.element.Element; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
32 |
import javax.lang.model.element.PackageElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
33 |
import javax.lang.model.element.TypeElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
34 |
import javax.lang.model.element.VariableElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
35 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
36 |
import jdk.javadoc.internal.doclets.toolkit.ConstantsSummaryWriter; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
37 |
import jdk.javadoc.internal.doclets.toolkit.Content; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
38 |
import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
39 |
|
10 | 40 |
|
41 |
/** |
|
42 |
* Builds the Constants Summary Page. |
|
43 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
44 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
45 |
* 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:
14259
diff
changeset
|
46 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
47 |
* deletion without notice.</b> |
10 | 48 |
* |
49 |
* @author Jamie Ho |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
50 |
* @author Bhavesh Patel (Modified) |
10 | 51 |
*/ |
52 |
public class ConstantsSummaryBuilder extends AbstractBuilder { |
|
53 |
||
54 |
/** |
|
55 |
* The root element of the constant summary XML is {@value}. |
|
56 |
*/ |
|
57 |
public static final String ROOT = "ConstantSummary"; |
|
58 |
||
59 |
/** |
|
60 |
* The maximum number of package directories shown in the constant |
|
61 |
* value index. |
|
62 |
*/ |
|
63 |
public static final int MAX_CONSTANT_VALUE_INDEX_LENGTH = 2; |
|
64 |
||
65 |
/** |
|
66 |
* The writer used to write the results. |
|
67 |
*/ |
|
14542 | 68 |
protected final ConstantsSummaryWriter writer; |
10 | 69 |
|
70 |
/** |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
71 |
* The set of TypeElements that have constant fields. |
10 | 72 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
73 |
protected final Set<TypeElement> typeElementsWithConstFields; |
10 | 74 |
|
75 |
/** |
|
76 |
* The set of printed package headers. |
|
77 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
78 |
protected final Set<PackageElement> printedPackageHeaders; |
10 | 79 |
|
80 |
/** |
|
81 |
* The current package being documented. |
|
82 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
83 |
private PackageElement currentPackage; |
10 | 84 |
|
85 |
/** |
|
86 |
* The current class being documented. |
|
87 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
88 |
private TypeElement currentClass; |
10 | 89 |
|
90 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
91 |
* The content tree for the constant summary documentation. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
92 |
*/ |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
93 |
private Content contentTree; |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
94 |
|
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
95 |
/** |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
96 |
* True if first package is listed. |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
97 |
*/ |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
98 |
private boolean first = true; |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
99 |
|
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
100 |
/** |
10 | 101 |
* Construct a new ConstantsSummaryBuilder. |
102 |
* |
|
14542 | 103 |
* @param context the build context. |
104 |
* @param writer the writer for the summary. |
|
10 | 105 |
*/ |
14542 | 106 |
private ConstantsSummaryBuilder(Context context, |
107 |
ConstantsSummaryWriter writer) { |
|
108 |
super(context); |
|
109 |
this.writer = writer; |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
110 |
this.typeElementsWithConstFields = new HashSet<>(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
111 |
this.printedPackageHeaders = new TreeSet<>(utils.makePackageComparator()); |
10 | 112 |
} |
113 |
||
114 |
/** |
|
115 |
* Construct a ConstantsSummaryBuilder. |
|
116 |
* |
|
14542 | 117 |
* @param context the build context. |
10 | 118 |
* @param writer the writer for the summary. |
119 |
*/ |
|
14542 | 120 |
public static ConstantsSummaryBuilder getInstance(Context context, |
121 |
ConstantsSummaryWriter writer) { |
|
122 |
return new ConstantsSummaryBuilder(context, writer); |
|
10 | 123 |
} |
124 |
||
125 |
/** |
|
126 |
* {@inheritDoc} |
|
127 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
128 |
@Override |
10 | 129 |
public void build() throws IOException { |
130 |
if (writer == null) { |
|
131 |
//Doclet does not support this output. |
|
132 |
return; |
|
133 |
} |
|
14542 | 134 |
build(layoutParser.parseXML(ROOT), contentTree); |
10 | 135 |
} |
136 |
||
137 |
/** |
|
138 |
* {@inheritDoc} |
|
139 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
140 |
@Override |
10 | 141 |
public String getName() { |
142 |
return ROOT; |
|
143 |
} |
|
144 |
||
145 |
/** |
|
146 |
* Build the constant summary. |
|
147 |
* |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
148 |
* @param node the XML element that specifies which components to document |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
149 |
* @param contentTree the content tree to which the documentation will be added |
10 | 150 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
151 |
public void buildConstantSummary(XMLNode node, Content contentTree) throws Exception { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
152 |
contentTree = writer.getHeader(); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
153 |
buildChildren(node, contentTree); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
154 |
writer.addFooter(contentTree); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
155 |
writer.printDocument(contentTree); |
10 | 156 |
writer.close(); |
157 |
} |
|
158 |
||
159 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
160 |
* Build the list of packages. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
161 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
162 |
* @param node the XML element that specifies which components to document |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
163 |
* @param contentTree the content tree to which the content list will be added |
10 | 164 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
165 |
public void buildContents(XMLNode node, Content contentTree) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
166 |
Content contentListTree = writer.getContentsHeader(); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
167 |
printedPackageHeaders.clear(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
168 |
for (PackageElement pkg : configuration.packages) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
169 |
if (hasConstantField(pkg) && !hasPrintedPackageIndex(pkg)) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
170 |
writer.addLinkToPackageContent(pkg, printedPackageHeaders, contentListTree); |
10 | 171 |
} |
172 |
} |
|
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
173 |
writer.addContentsList(contentTree, contentListTree); |
10 | 174 |
} |
175 |
||
176 |
/** |
|
177 |
* Build the summary for each documented package. |
|
178 |
* |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
179 |
* @param node the XML element that specifies which components to document |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
180 |
* @param contentTree the tree to which the summaries will be added |
10 | 181 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
182 |
public void buildConstantSummaries(XMLNode node, Content contentTree) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
183 |
printedPackageHeaders.clear(); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
184 |
Content summariesTree = writer.getConstantSummaries(); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
185 |
for (PackageElement aPackage : configuration.packages) { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
186 |
if (hasConstantField(aPackage)) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
187 |
currentPackage = aPackage; |
10 | 188 |
//Build the documentation for the current package. |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
189 |
buildChildren(node, summariesTree); |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
190 |
first = false; |
10 | 191 |
} |
192 |
} |
|
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
193 |
writer.addConstantSummaries(contentTree, summariesTree); |
10 | 194 |
} |
195 |
||
196 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
197 |
* Build the header for the given package. |
10 | 198 |
* |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
199 |
* @param node the XML element that specifies which components to document |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
200 |
* @param summariesTree the tree to which the package header will be added |
10 | 201 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
202 |
public void buildPackageHeader(XMLNode node, Content summariesTree) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
203 |
String parsedPackageName = utils.parsePackageName(currentPackage); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
204 |
PackageElement p = utils.elementUtils.getPackageElement(parsedPackageName); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
205 |
if (!printedPackageHeaders.contains(p)) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
206 |
writer.addPackageName(currentPackage, summariesTree, first); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
207 |
printedPackageHeaders.add(p); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
208 |
} |
10 | 209 |
} |
210 |
||
211 |
/** |
|
212 |
* Build the summary for the current class. |
|
213 |
* |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
214 |
* @param node the XML element that specifies which components to document |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
215 |
* @param summariesTree the tree to which the class constant summary will be added |
10 | 216 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
217 |
public void buildClassConstantSummary(XMLNode node, Content summariesTree) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
218 |
SortedSet<TypeElement> classes = !currentPackage.isUnnamed() |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
219 |
? utils.getAllClasses(currentPackage) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
220 |
: configuration.typeElementCatalog.allUnnamedClasses(); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
221 |
Content classConstantTree = writer.getClassConstantHeader(); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
222 |
for (TypeElement te : classes) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
223 |
if (!typeElementsWithConstFields.contains(te) || |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
224 |
!utils.isIncluded(te)) { |
10 | 225 |
continue; |
226 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
227 |
currentClass = te; |
10 | 228 |
//Build the documentation for the current class. |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
229 |
buildChildren(node, classConstantTree); |
10 | 230 |
} |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
231 |
writer.addClassConstant(summariesTree, classConstantTree); |
10 | 232 |
} |
233 |
||
234 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
235 |
* Build the summary of constant members in the class. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
236 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
237 |
* @param node the XML element that specifies which components to document |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
238 |
* @param classConstantTree the tree to which the constant members table |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
239 |
* will be added |
10 | 240 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
241 |
public void buildConstantMembers(XMLNode node, Content classConstantTree) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
242 |
new ConstantFieldBuilder(currentClass).buildMembersSummary(node, classConstantTree); |
10 | 243 |
} |
244 |
||
245 |
/** |
|
246 |
* Return true if the given package has constant fields to document. |
|
247 |
* |
|
248 |
* @param pkg the package being checked. |
|
249 |
* @return true if the given package has constant fields to document. |
|
250 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
251 |
private boolean hasConstantField(PackageElement pkg) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
252 |
SortedSet<TypeElement> classes = !pkg.isUnnamed() |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
253 |
? utils.getAllClasses(pkg) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
254 |
: configuration.typeElementCatalog.allUnnamedClasses(); |
10 | 255 |
boolean found = false; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
256 |
for (TypeElement te : classes) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
257 |
if (utils.isIncluded(te) && hasConstantField(te)) { |
10 | 258 |
found = true; |
259 |
} |
|
260 |
} |
|
261 |
return found; |
|
262 |
} |
|
263 |
||
264 |
/** |
|
265 |
* Return true if the given class has constant fields to document. |
|
266 |
* |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
267 |
* @param typeElement the class being checked. |
10 | 268 |
* @return true if the given package has constant fields to document. |
269 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
270 |
private boolean hasConstantField (TypeElement typeElement) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
271 |
VisibleMemberMap visibleMemberMapFields = new VisibleMemberMap(typeElement, |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
272 |
VisibleMemberMap.Kind.FIELDS, configuration); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
273 |
SortedSet<Element> fields = visibleMemberMapFields.getLeafClassMembers(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
274 |
for (Element f : fields) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
275 |
VariableElement field = (VariableElement)f; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
276 |
if (field.getConstantValue() != null) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
277 |
typeElementsWithConstFields.add(typeElement); |
10 | 278 |
return true; |
279 |
} |
|
280 |
} |
|
281 |
return false; |
|
282 |
} |
|
283 |
||
284 |
/** |
|
285 |
* Return true if the given package name has been printed. Also |
|
286 |
* return true if the root of this package has been printed. |
|
287 |
* |
|
288 |
* @param pkgname the name of the package to check. |
|
289 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
290 |
private boolean hasPrintedPackageIndex(PackageElement pkg) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
291 |
for (PackageElement printedPkg : printedPackageHeaders) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
292 |
if (utils.getPackageName(pkg).startsWith(utils.parsePackageName(printedPkg))) { |
10 | 293 |
return true; |
294 |
} |
|
295 |
} |
|
296 |
return false; |
|
297 |
} |
|
298 |
||
299 |
/** |
|
300 |
* Print the table of constants. |
|
301 |
* |
|
302 |
* @author Jamie Ho |
|
303 |
*/ |
|
304 |
private class ConstantFieldBuilder { |
|
305 |
||
306 |
/** |
|
307 |
* The map used to get the visible variables. |
|
308 |
*/ |
|
309 |
protected VisibleMemberMap visibleMemberMapFields = null; |
|
310 |
||
311 |
/** |
|
312 |
* The map used to get the visible variables. |
|
313 |
*/ |
|
314 |
protected VisibleMemberMap visibleMemberMapEnumConst = null; |
|
315 |
||
316 |
/** |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
317 |
* The typeElement that we are examining constants for. |
10 | 318 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
319 |
protected TypeElement typeElement; |
10 | 320 |
|
321 |
/** |
|
322 |
* Construct a ConstantFieldSubWriter. |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
323 |
* @param typeElement the typeElement that we are examining constants for. |
10 | 324 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
325 |
public ConstantFieldBuilder(TypeElement typeElement) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
326 |
this.typeElement = typeElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
327 |
visibleMemberMapFields = new VisibleMemberMap(typeElement, |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
328 |
VisibleMemberMap.Kind.FIELDS, configuration); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
329 |
visibleMemberMapEnumConst = new VisibleMemberMap(typeElement, |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
330 |
VisibleMemberMap.Kind.ENUM_CONSTANTS, configuration); |
10 | 331 |
} |
332 |
||
333 |
/** |
|
334 |
* Builds the table of constants for a given class. |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
335 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
336 |
* @param node the XML element that specifies which components to document |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
337 |
* @param classConstantTree the tree to which the class constants table |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
338 |
* will be added |
10 | 339 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
340 |
protected void buildMembersSummary(XMLNode node, Content classConstantTree) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
341 |
SortedSet<VariableElement> members = members(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
342 |
if (!members.isEmpty()) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
343 |
writer.addConstantMembers(typeElement, members, classConstantTree); |
10 | 344 |
} |
345 |
} |
|
346 |
||
347 |
/** |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
348 |
* Return the list of visible constant fields for the given TypeElement. |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
349 |
* @return the list of visible constant fields for the given TypeElement. |
10 | 350 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
351 |
protected SortedSet<VariableElement> members() { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
352 |
SortedSet<Element> list = visibleMemberMapFields.getLeafClassMembers(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
353 |
list.addAll(visibleMemberMapEnumConst.getLeafClassMembers()); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
354 |
SortedSet<VariableElement> inclList = |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
355 |
new TreeSet<>(utils.makeGeneralPurposeComparator()); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
356 |
for (Element element : list) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
357 |
VariableElement member = (VariableElement)element; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
358 |
if (member.getConstantValue() != null) { |
10 | 359 |
inclList.add(member); |
360 |
} |
|
361 |
} |
|
362 |
return inclList; |
|
363 |
} |
|
364 |
} |
|
365 |
} |