author | jjg |
Mon, 22 Aug 2016 16:32:40 -0700 | |
changeset 40587 | 1c355ea550ed |
parent 40303 | 96a1226aca18 |
child 42000 | 8b7412f7eecd |
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.util.*; |
14258 | 29 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
30 |
import javax.lang.model.element.Element; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
31 |
import javax.lang.model.element.PackageElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
32 |
import javax.lang.model.element.TypeElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
33 |
import javax.lang.model.element.VariableElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
34 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
35 |
import jdk.javadoc.internal.doclets.toolkit.ConstantsSummaryWriter; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
36 |
import jdk.javadoc.internal.doclets.toolkit.Content; |
40587 | 37 |
import jdk.javadoc.internal.doclets.toolkit.DocletException; |
35426
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. |
40587 | 119 |
* @return the new ConstantsSummaryBuilder |
10 | 120 |
*/ |
14542 | 121 |
public static ConstantsSummaryBuilder getInstance(Context context, |
122 |
ConstantsSummaryWriter writer) { |
|
123 |
return new ConstantsSummaryBuilder(context, writer); |
|
10 | 124 |
} |
125 |
||
126 |
/** |
|
127 |
* {@inheritDoc} |
|
40587 | 128 |
* @throws DocletException if there is a problem while building the documentation |
10 | 129 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
130 |
@Override |
40587 | 131 |
public void build() throws DocletException { |
10 | 132 |
if (writer == null) { |
133 |
//Doclet does not support this output. |
|
134 |
return; |
|
135 |
} |
|
14542 | 136 |
build(layoutParser.parseXML(ROOT), contentTree); |
10 | 137 |
} |
138 |
||
139 |
/** |
|
140 |
* {@inheritDoc} |
|
141 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
142 |
@Override |
10 | 143 |
public String getName() { |
144 |
return ROOT; |
|
145 |
} |
|
146 |
||
147 |
/** |
|
148 |
* Build the constant summary. |
|
149 |
* |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
150 |
* @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
|
151 |
* @param contentTree the content tree to which the documentation will be added |
40587 | 152 |
* @throws DocletException if there is a problem while building the documentation |
10 | 153 |
*/ |
40587 | 154 |
public void buildConstantSummary(XMLNode node, Content contentTree) throws DocletException { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
155 |
contentTree = writer.getHeader(); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
156 |
buildChildren(node, contentTree); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
157 |
writer.addFooter(contentTree); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
158 |
writer.printDocument(contentTree); |
10 | 159 |
} |
160 |
||
161 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
162 |
* Build the list of packages. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
163 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
164 |
* @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
|
165 |
* @param contentTree the content tree to which the content list will be added |
10 | 166 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
167 |
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
|
168 |
Content contentListTree = writer.getContentsHeader(); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
169 |
printedPackageHeaders.clear(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
170 |
for (PackageElement pkg : configuration.packages) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
171 |
if (hasConstantField(pkg) && !hasPrintedPackageIndex(pkg)) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
172 |
writer.addLinkToPackageContent(pkg, printedPackageHeaders, contentListTree); |
10 | 173 |
} |
174 |
} |
|
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
175 |
writer.addContentsList(contentTree, contentListTree); |
10 | 176 |
} |
177 |
||
178 |
/** |
|
179 |
* Build the summary for each documented package. |
|
180 |
* |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
181 |
* @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
|
182 |
* @param contentTree the tree to which the summaries will be added |
40587 | 183 |
* @throws DocletException if there is a problem while building the documentation |
10 | 184 |
*/ |
40587 | 185 |
public void buildConstantSummaries(XMLNode node, Content contentTree) throws DocletException { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
186 |
printedPackageHeaders.clear(); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
187 |
Content summariesTree = writer.getConstantSummaries(); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
188 |
for (PackageElement aPackage : configuration.packages) { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
189 |
if (hasConstantField(aPackage)) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
190 |
currentPackage = aPackage; |
10 | 191 |
//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
|
192 |
buildChildren(node, summariesTree); |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
193 |
first = false; |
10 | 194 |
} |
195 |
} |
|
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
196 |
writer.addConstantSummaries(contentTree, summariesTree); |
10 | 197 |
} |
198 |
||
199 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
200 |
* Build the header for the given package. |
10 | 201 |
* |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
202 |
* @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
|
203 |
* @param summariesTree the tree to which the package header will be added |
10 | 204 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
205 |
public void buildPackageHeader(XMLNode node, Content summariesTree) { |
36526 | 206 |
PackageElement abbrevPkg = configuration.workArounds.getAbbreviatedPackageElement(currentPackage); |
207 |
if (!printedPackageHeaders.contains(abbrevPkg)) { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
208 |
writer.addPackageName(currentPackage, summariesTree, first); |
36526 | 209 |
printedPackageHeaders.add(abbrevPkg); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
210 |
} |
10 | 211 |
} |
212 |
||
213 |
/** |
|
214 |
* Build the summary for the current class. |
|
215 |
* |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
216 |
* @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
|
217 |
* @param summariesTree the tree to which the class constant summary will be added |
40587 | 218 |
* @throws DocletException if there is a problem while building the documentation |
219 |
* |
|
10 | 220 |
*/ |
40587 | 221 |
public void buildClassConstantSummary(XMLNode node, Content summariesTree) |
222 |
throws DocletException { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
223 |
SortedSet<TypeElement> classes = !currentPackage.isUnnamed() |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
224 |
? utils.getAllClasses(currentPackage) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
225 |
: configuration.typeElementCatalog.allUnnamedClasses(); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
226 |
Content classConstantTree = writer.getClassConstantHeader(); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
227 |
for (TypeElement te : classes) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
228 |
if (!typeElementsWithConstFields.contains(te) || |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
229 |
!utils.isIncluded(te)) { |
10 | 230 |
continue; |
231 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
232 |
currentClass = te; |
10 | 233 |
//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
|
234 |
buildChildren(node, classConstantTree); |
10 | 235 |
} |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
236 |
writer.addClassConstant(summariesTree, classConstantTree); |
10 | 237 |
} |
238 |
||
239 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
240 |
* 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
|
241 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
242 |
* @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
|
243 |
* @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
|
244 |
* will be added |
10 | 245 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
246 |
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
|
247 |
new ConstantFieldBuilder(currentClass).buildMembersSummary(node, classConstantTree); |
10 | 248 |
} |
249 |
||
250 |
/** |
|
251 |
* Return true if the given package has constant fields to document. |
|
252 |
* |
|
253 |
* @param pkg the package being checked. |
|
254 |
* @return true if the given package has constant fields to document. |
|
255 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
256 |
private boolean hasConstantField(PackageElement pkg) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
257 |
SortedSet<TypeElement> classes = !pkg.isUnnamed() |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
258 |
? utils.getAllClasses(pkg) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
259 |
: configuration.typeElementCatalog.allUnnamedClasses(); |
10 | 260 |
boolean found = false; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
261 |
for (TypeElement te : classes) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
262 |
if (utils.isIncluded(te) && hasConstantField(te)) { |
10 | 263 |
found = true; |
264 |
} |
|
265 |
} |
|
266 |
return found; |
|
267 |
} |
|
268 |
||
269 |
/** |
|
270 |
* Return true if the given class has constant fields to document. |
|
271 |
* |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
272 |
* @param typeElement the class being checked. |
10 | 273 |
* @return true if the given package has constant fields to document. |
274 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
275 |
private boolean hasConstantField (TypeElement typeElement) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
276 |
VisibleMemberMap visibleMemberMapFields = new VisibleMemberMap(typeElement, |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
277 |
VisibleMemberMap.Kind.FIELDS, configuration); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
278 |
SortedSet<Element> fields = visibleMemberMapFields.getLeafClassMembers(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
279 |
for (Element f : fields) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
280 |
VariableElement field = (VariableElement)f; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
281 |
if (field.getConstantValue() != null) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
282 |
typeElementsWithConstFields.add(typeElement); |
10 | 283 |
return true; |
284 |
} |
|
285 |
} |
|
286 |
return false; |
|
287 |
} |
|
288 |
||
289 |
/** |
|
290 |
* Return true if the given package name has been printed. Also |
|
291 |
* return true if the root of this package has been printed. |
|
292 |
* |
|
293 |
* @param pkgname the name of the package to check. |
|
294 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
295 |
private boolean hasPrintedPackageIndex(PackageElement pkg) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
296 |
for (PackageElement printedPkg : printedPackageHeaders) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
297 |
if (utils.getPackageName(pkg).startsWith(utils.parsePackageName(printedPkg))) { |
10 | 298 |
return true; |
299 |
} |
|
300 |
} |
|
301 |
return false; |
|
302 |
} |
|
303 |
||
304 |
/** |
|
305 |
* Print the table of constants. |
|
306 |
* |
|
307 |
* @author Jamie Ho |
|
308 |
*/ |
|
309 |
private class ConstantFieldBuilder { |
|
310 |
||
311 |
/** |
|
312 |
* The map used to get the visible variables. |
|
313 |
*/ |
|
314 |
protected VisibleMemberMap visibleMemberMapFields = null; |
|
315 |
||
316 |
/** |
|
317 |
* The map used to get the visible variables. |
|
318 |
*/ |
|
319 |
protected VisibleMemberMap visibleMemberMapEnumConst = null; |
|
320 |
||
321 |
/** |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
322 |
* The typeElement that we are examining constants for. |
10 | 323 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
324 |
protected TypeElement typeElement; |
10 | 325 |
|
326 |
/** |
|
327 |
* Construct a ConstantFieldSubWriter. |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
328 |
* @param typeElement the typeElement that we are examining constants for. |
10 | 329 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
330 |
public ConstantFieldBuilder(TypeElement typeElement) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
331 |
this.typeElement = typeElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
332 |
visibleMemberMapFields = new VisibleMemberMap(typeElement, |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
333 |
VisibleMemberMap.Kind.FIELDS, configuration); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
334 |
visibleMemberMapEnumConst = new VisibleMemberMap(typeElement, |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
335 |
VisibleMemberMap.Kind.ENUM_CONSTANTS, configuration); |
10 | 336 |
} |
337 |
||
338 |
/** |
|
339 |
* 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
|
340 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
341 |
* @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
|
342 |
* @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
|
343 |
* will be added |
10 | 344 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
345 |
protected void buildMembersSummary(XMLNode node, Content classConstantTree) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
346 |
SortedSet<VariableElement> members = members(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
347 |
if (!members.isEmpty()) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
348 |
writer.addConstantMembers(typeElement, members, classConstantTree); |
10 | 349 |
} |
350 |
} |
|
351 |
||
352 |
/** |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
353 |
* Return the list of visible constant fields for the given TypeElement. |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
354 |
* @return the list of visible constant fields for the given TypeElement. |
10 | 355 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
356 |
protected SortedSet<VariableElement> members() { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
357 |
SortedSet<Element> list = visibleMemberMapFields.getLeafClassMembers(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
358 |
list.addAll(visibleMemberMapEnumConst.getLeafClassMembers()); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
359 |
SortedSet<VariableElement> inclList = |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
360 |
new TreeSet<>(utils.makeGeneralPurposeComparator()); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
361 |
for (Element element : list) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
362 |
VariableElement member = (VariableElement)element; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
363 |
if (member.getConstantValue() != null) { |
10 | 364 |
inclList.add(member); |
365 |
} |
|
366 |
} |
|
367 |
return inclList; |
|
368 |
} |
|
369 |
} |
|
370 |
} |