Tue, 09 Oct 2012 19:10:00 -0700
8000663: clean up langtools imports
Reviewed-by: darcy
duke@1 | 1 | /* |
jjg@1326 | 2 | * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.doclets.internal.toolkit.builders; |
duke@1 | 27 | |
bpatel@766 | 28 | import java.io.*; |
bpatel@766 | 29 | import java.util.*; |
jjg@1357 | 30 | |
jjg@1357 | 31 | import com.sun.javadoc.*; |
jjg@1357 | 32 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 33 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 34 | |
duke@1 | 35 | /** |
duke@1 | 36 | * Builds the summary for a given class. |
duke@1 | 37 | * |
duke@1 | 38 | * This code is not part of an API. |
duke@1 | 39 | * It is implementation that is subject to change. |
duke@1 | 40 | * Do not use it as an API |
duke@1 | 41 | * |
duke@1 | 42 | * @author Jamie Ho |
bpatel@766 | 43 | * @author Bhavesh Patel (Modified) |
duke@1 | 44 | * @since 1.5 |
duke@1 | 45 | */ |
duke@1 | 46 | public class ClassBuilder extends AbstractBuilder { |
duke@1 | 47 | |
duke@1 | 48 | /** |
duke@1 | 49 | * The root element of the class XML is {@value}. |
duke@1 | 50 | */ |
duke@1 | 51 | public static final String ROOT = "ClassDoc"; |
duke@1 | 52 | |
duke@1 | 53 | /** |
duke@1 | 54 | * The class being documented. |
duke@1 | 55 | */ |
duke@1 | 56 | private ClassDoc classDoc; |
duke@1 | 57 | |
duke@1 | 58 | /** |
duke@1 | 59 | * The doclet specific writer. |
duke@1 | 60 | */ |
duke@1 | 61 | private ClassWriter writer; |
duke@1 | 62 | |
duke@1 | 63 | /** |
duke@1 | 64 | * Keep track of whether or not this classdoc is an interface. |
duke@1 | 65 | */ |
duke@1 | 66 | private boolean isInterface = false; |
duke@1 | 67 | |
duke@1 | 68 | /** |
duke@1 | 69 | * Keep track of whether or not this classdoc is an enum. |
duke@1 | 70 | */ |
duke@1 | 71 | private boolean isEnum = false; |
duke@1 | 72 | |
duke@1 | 73 | /** |
bpatel@766 | 74 | * The content tree for the class documentation. |
bpatel@766 | 75 | */ |
bpatel@766 | 76 | private Content contentTree; |
bpatel@766 | 77 | |
bpatel@766 | 78 | /** |
duke@1 | 79 | * Construct a new ClassBuilder. |
duke@1 | 80 | * |
duke@1 | 81 | * @param configuration the current configuration of the |
duke@1 | 82 | * doclet. |
duke@1 | 83 | */ |
duke@1 | 84 | private ClassBuilder(Configuration configuration) { |
duke@1 | 85 | super(configuration); |
duke@1 | 86 | } |
duke@1 | 87 | |
duke@1 | 88 | /** |
duke@1 | 89 | * Construct a new ClassBuilder. |
duke@1 | 90 | * |
duke@1 | 91 | * @param configuration the current configuration of the doclet. |
duke@1 | 92 | * @param classDoc the class being documented. |
duke@1 | 93 | * @param writer the doclet specific writer. |
duke@1 | 94 | */ |
duke@1 | 95 | public static ClassBuilder getInstance(Configuration configuration, |
duke@1 | 96 | ClassDoc classDoc, ClassWriter writer) |
duke@1 | 97 | throws Exception { |
duke@1 | 98 | ClassBuilder builder = new ClassBuilder(configuration); |
duke@1 | 99 | builder.configuration = configuration; |
duke@1 | 100 | builder.classDoc = classDoc; |
duke@1 | 101 | builder.writer = writer; |
duke@1 | 102 | if (classDoc.isInterface()) { |
duke@1 | 103 | builder.isInterface = true; |
duke@1 | 104 | } else if (classDoc.isEnum()) { |
duke@1 | 105 | builder.isEnum = true; |
duke@1 | 106 | Util.setEnumDocumentation(configuration, classDoc); |
duke@1 | 107 | } |
duke@1 | 108 | if(containingPackagesSeen == null) { |
jjg@74 | 109 | containingPackagesSeen = new HashSet<String>(); |
duke@1 | 110 | } |
duke@1 | 111 | return builder; |
duke@1 | 112 | } |
duke@1 | 113 | |
duke@1 | 114 | /** |
duke@1 | 115 | * {@inheritDoc} |
duke@1 | 116 | */ |
duke@1 | 117 | public void build() throws IOException { |
bpatel@766 | 118 | build(LayoutParser.getInstance(configuration).parseXML(ROOT), contentTree); |
duke@1 | 119 | } |
duke@1 | 120 | |
duke@1 | 121 | /** |
duke@1 | 122 | * {@inheritDoc} |
duke@1 | 123 | */ |
duke@1 | 124 | public String getName() { |
duke@1 | 125 | return ROOT; |
duke@1 | 126 | } |
duke@1 | 127 | |
duke@1 | 128 | /** |
jjg@1326 | 129 | * Handles the {@literal <ClassDoc>} tag. |
duke@1 | 130 | * |
bpatel@766 | 131 | * @param node the XML element that specifies which components to document |
bpatel@766 | 132 | * @param contentTree the content tree to which the documentation will be added |
duke@1 | 133 | */ |
bpatel@766 | 134 | public void buildClassDoc(XMLNode node, Content contentTree) throws Exception { |
bpatel@766 | 135 | String key; |
bpatel@766 | 136 | if (isInterface) { |
bpatel@766 | 137 | key = "doclet.Interface"; |
bpatel@766 | 138 | } else if (isEnum) { |
bpatel@766 | 139 | key = "doclet.Enum"; |
bpatel@766 | 140 | } else { |
bpatel@766 | 141 | key = "doclet.Class"; |
bpatel@766 | 142 | } |
bpatel@766 | 143 | contentTree = writer.getHeader(configuration.getText(key) + " " + |
bpatel@766 | 144 | classDoc.name()); |
bpatel@766 | 145 | Content classContentTree = writer.getClassContentHeader(); |
bpatel@766 | 146 | buildChildren(node, classContentTree); |
bpatel@766 | 147 | contentTree.addContent(classContentTree); |
bpatel@766 | 148 | writer.addFooter(contentTree); |
bpatel@766 | 149 | writer.printDocument(contentTree); |
bpatel@766 | 150 | writer.close(); |
bpatel@766 | 151 | copyDocFiles(); |
duke@1 | 152 | } |
duke@1 | 153 | |
bpatel@766 | 154 | /** |
bpatel@766 | 155 | * Build the class tree documentation. |
bpatel@766 | 156 | * |
bpatel@766 | 157 | * @param node the XML element that specifies which components to document |
bpatel@766 | 158 | * @param classContentTree the content tree to which the documentation will be added |
bpatel@766 | 159 | */ |
bpatel@766 | 160 | public void buildClassTree(XMLNode node, Content classContentTree) { |
bpatel@766 | 161 | writer.addClassTree(classContentTree); |
bpatel@766 | 162 | } |
duke@1 | 163 | |
bpatel@766 | 164 | /** |
bpatel@766 | 165 | * Build the class information tree documentation. |
bpatel@766 | 166 | * |
bpatel@766 | 167 | * @param node the XML element that specifies which components to document |
bpatel@766 | 168 | * @param classContentTree the content tree to which the documentation will be added |
bpatel@766 | 169 | */ |
bpatel@766 | 170 | public void buildClassInfo(XMLNode node, Content classContentTree) { |
bpatel@766 | 171 | Content classInfoTree = writer.getClassInfoTreeHeader(); |
bpatel@766 | 172 | buildChildren(node, classInfoTree); |
bpatel@766 | 173 | classContentTree.addContent(writer.getClassInfo(classInfoTree)); |
bpatel@766 | 174 | } |
bpatel@766 | 175 | |
bpatel@766 | 176 | /** |
bpatel@766 | 177 | * Build the typeparameters of this class. |
bpatel@766 | 178 | * |
bpatel@766 | 179 | * @param node the XML element that specifies which components to document |
bpatel@766 | 180 | * @param classInfoTree the content tree to which the documentation will be added |
bpatel@766 | 181 | */ |
bpatel@766 | 182 | public void buildTypeParamInfo(XMLNode node, Content classInfoTree) { |
bpatel@766 | 183 | writer.addTypeParamInfo(classInfoTree); |
bpatel@766 | 184 | } |
bpatel@766 | 185 | |
bpatel@766 | 186 | /** |
bpatel@766 | 187 | * If this is an interface, list all super interfaces. |
bpatel@766 | 188 | * |
bpatel@766 | 189 | * @param node the XML element that specifies which components to document |
bpatel@766 | 190 | * @param classInfoTree the content tree to which the documentation will be added |
bpatel@766 | 191 | */ |
bpatel@766 | 192 | public void buildSuperInterfacesInfo(XMLNode node, Content classInfoTree) { |
bpatel@766 | 193 | writer.addSuperInterfacesInfo(classInfoTree); |
bpatel@766 | 194 | } |
bpatel@766 | 195 | |
bpatel@766 | 196 | /** |
bpatel@766 | 197 | * If this is a class, list all interfaces implemented by this class. |
bpatel@766 | 198 | * |
bpatel@766 | 199 | * @param node the XML element that specifies which components to document |
bpatel@766 | 200 | * @param classInfoTree the content tree to which the documentation will be added |
bpatel@766 | 201 | */ |
bpatel@766 | 202 | public void buildImplementedInterfacesInfo(XMLNode node, Content classInfoTree) { |
bpatel@766 | 203 | writer.addImplementedInterfacesInfo(classInfoTree); |
bpatel@766 | 204 | } |
bpatel@766 | 205 | |
bpatel@766 | 206 | /** |
bpatel@766 | 207 | * List all the classes extend this one. |
bpatel@766 | 208 | * |
bpatel@766 | 209 | * @param node the XML element that specifies which components to document |
bpatel@766 | 210 | * @param classInfoTree the content tree to which the documentation will be added |
bpatel@766 | 211 | */ |
bpatel@766 | 212 | public void buildSubClassInfo(XMLNode node, Content classInfoTree) { |
bpatel@766 | 213 | writer.addSubClassInfo(classInfoTree); |
bpatel@766 | 214 | } |
bpatel@766 | 215 | |
bpatel@766 | 216 | /** |
bpatel@766 | 217 | * List all the interfaces that extend this one. |
bpatel@766 | 218 | * |
bpatel@766 | 219 | * @param node the XML element that specifies which components to document |
bpatel@766 | 220 | * @param classInfoTree the content tree to which the documentation will be added |
bpatel@766 | 221 | */ |
bpatel@766 | 222 | public void buildSubInterfacesInfo(XMLNode node, Content classInfoTree) { |
bpatel@766 | 223 | writer.addSubInterfacesInfo(classInfoTree); |
bpatel@766 | 224 | } |
bpatel@766 | 225 | |
bpatel@766 | 226 | /** |
bpatel@766 | 227 | * If this is an interface, list all classes that implement this interface. |
bpatel@766 | 228 | * |
bpatel@766 | 229 | * @param node the XML element that specifies which components to document |
bpatel@766 | 230 | * @param classInfoTree the content tree to which the documentation will be added |
bpatel@766 | 231 | */ |
bpatel@766 | 232 | public void buildInterfaceUsageInfo(XMLNode node, Content classInfoTree) { |
bpatel@766 | 233 | writer.addInterfaceUsageInfo(classInfoTree); |
bpatel@766 | 234 | } |
bpatel@766 | 235 | |
bpatel@766 | 236 | /** |
bpatel@766 | 237 | * If this class is deprecated, build the appropriate information. |
bpatel@766 | 238 | * |
bpatel@766 | 239 | * @param node the XML element that specifies which components to document |
bpatel@766 | 240 | * @param classInfoTree the content tree to which the documentation will be added |
bpatel@766 | 241 | */ |
bpatel@766 | 242 | public void buildDeprecationInfo (XMLNode node, Content classInfoTree) { |
bpatel@766 | 243 | writer.addClassDeprecationInfo(classInfoTree); |
bpatel@766 | 244 | } |
bpatel@766 | 245 | |
bpatel@766 | 246 | /** |
bpatel@766 | 247 | * If this is an inner class or interface, list the enclosing class or interface. |
bpatel@766 | 248 | * |
bpatel@766 | 249 | * @param node the XML element that specifies which components to document |
bpatel@766 | 250 | * @param classInfoTree the content tree to which the documentation will be added |
bpatel@766 | 251 | */ |
bpatel@766 | 252 | public void buildNestedClassInfo (XMLNode node, Content classInfoTree) { |
bpatel@766 | 253 | writer.addNestedClassInfo(classInfoTree); |
bpatel@766 | 254 | } |
bpatel@766 | 255 | |
bpatel@766 | 256 | /** |
bpatel@766 | 257 | * Copy the doc files for the current ClassDoc if necessary. |
bpatel@766 | 258 | */ |
duke@1 | 259 | private void copyDocFiles() { |
duke@1 | 260 | PackageDoc containingPackage = classDoc.containingPackage(); |
duke@1 | 261 | if((configuration.packages == null || |
duke@1 | 262 | Arrays.binarySearch(configuration.packages, |
bpatel@766 | 263 | containingPackage) < 0) && |
bpatel@766 | 264 | ! containingPackagesSeen.contains(containingPackage.name())){ |
duke@1 | 265 | //Only copy doc files dir if the containing package is not |
duke@1 | 266 | //documented AND if we have not documented a class from the same |
duke@1 | 267 | //package already. Otherwise, we are making duplicate copies. |
duke@1 | 268 | Util.copyDocFiles(configuration, |
bpatel@766 | 269 | Util.getPackageSourcePath(configuration, |
duke@1 | 270 | classDoc.containingPackage()) + |
bpatel@766 | 271 | DirectoryManager.getDirectoryPath(classDoc.containingPackage()) |
duke@1 | 272 | + File.separator, DocletConstants.DOC_FILES_DIR_NAME, true); |
duke@1 | 273 | containingPackagesSeen.add(containingPackage.name()); |
duke@1 | 274 | } |
duke@1 | 275 | } |
duke@1 | 276 | |
duke@1 | 277 | /** |
bpatel@766 | 278 | * Build the signature of the current class. |
bpatel@766 | 279 | * |
bpatel@766 | 280 | * @param node the XML element that specifies which components to document |
bpatel@766 | 281 | * @param classInfoTree the content tree to which the documentation will be added |
duke@1 | 282 | */ |
bpatel@766 | 283 | public void buildClassSignature(XMLNode node, Content classInfoTree) { |
duke@1 | 284 | StringBuffer modifiers = new StringBuffer(classDoc.modifiers() + " "); |
duke@1 | 285 | if (isEnum) { |
duke@1 | 286 | modifiers.append("enum "); |
duke@1 | 287 | int index; |
duke@1 | 288 | if ((index = modifiers.indexOf("abstract")) >= 0) { |
duke@1 | 289 | modifiers.delete(index, index + (new String("abstract")).length()); |
duke@1 | 290 | modifiers = new StringBuffer( |
bpatel@766 | 291 | Util.replaceText(modifiers.toString(), " ", " ")); |
duke@1 | 292 | } |
duke@1 | 293 | if ((index = modifiers.indexOf("final")) >= 0) { |
duke@1 | 294 | modifiers.delete(index, index + (new String("final")).length()); |
duke@1 | 295 | modifiers = new StringBuffer( |
bpatel@766 | 296 | Util.replaceText(modifiers.toString(), " ", " ")); |
duke@1 | 297 | } |
duke@1 | 298 | //} else if (classDoc.isAnnotationType()) { |
duke@1 | 299 | //modifiers.append("@interface "); |
duke@1 | 300 | } else if (! isInterface) { |
duke@1 | 301 | modifiers.append("class "); |
duke@1 | 302 | } |
bpatel@766 | 303 | writer.addClassSignature(modifiers.toString(), classInfoTree); |
duke@1 | 304 | } |
duke@1 | 305 | |
duke@1 | 306 | /** |
duke@1 | 307 | * Build the class description. |
bpatel@766 | 308 | * |
bpatel@766 | 309 | * @param node the XML element that specifies which components to document |
bpatel@766 | 310 | * @param classInfoTree the content tree to which the documentation will be added |
duke@1 | 311 | */ |
bpatel@766 | 312 | public void buildClassDescription(XMLNode node, Content classInfoTree) { |
bpatel@766 | 313 | writer.addClassDescription(classInfoTree); |
duke@1 | 314 | } |
duke@1 | 315 | |
duke@1 | 316 | /** |
duke@1 | 317 | * Build the tag information for the current class. |
bpatel@766 | 318 | * |
bpatel@766 | 319 | * @param node the XML element that specifies which components to document |
bpatel@766 | 320 | * @param classInfoTree the content tree to which the documentation will be added |
duke@1 | 321 | */ |
bpatel@766 | 322 | public void buildClassTagInfo(XMLNode node, Content classInfoTree) { |
bpatel@766 | 323 | writer.addClassTagInfo(classInfoTree); |
duke@1 | 324 | } |
duke@1 | 325 | |
duke@1 | 326 | /** |
bpatel@766 | 327 | * Build the member summary contents of the page. |
duke@1 | 328 | * |
bpatel@766 | 329 | * @param node the XML element that specifies which components to document |
bpatel@766 | 330 | * @param classContentTree the content tree to which the documentation will be added |
duke@1 | 331 | */ |
bpatel@766 | 332 | public void buildMemberSummary(XMLNode node, Content classContentTree) throws Exception { |
bpatel@766 | 333 | Content memberSummaryTree = writer.getMemberTreeHeader(); |
duke@1 | 334 | configuration.getBuilderFactory(). |
bpatel@766 | 335 | getMemberSummaryBuilder(writer).buildChildren(node, memberSummaryTree); |
bpatel@766 | 336 | classContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree)); |
bpatel@766 | 337 | } |
bpatel@766 | 338 | |
bpatel@766 | 339 | /** |
bpatel@766 | 340 | * Build the member details contents of the page. |
bpatel@766 | 341 | * |
bpatel@766 | 342 | * @param node the XML element that specifies which components to document |
bpatel@766 | 343 | * @param classContentTree the content tree to which the documentation will be added |
bpatel@766 | 344 | */ |
bpatel@766 | 345 | public void buildMemberDetails(XMLNode node, Content classContentTree) { |
bpatel@766 | 346 | Content memberDetailsTree = writer.getMemberTreeHeader(); |
bpatel@766 | 347 | buildChildren(node, memberDetailsTree); |
bpatel@766 | 348 | classContentTree.addContent(writer.getMemberDetailsTree(memberDetailsTree)); |
duke@1 | 349 | } |
duke@1 | 350 | |
duke@1 | 351 | /** |
duke@1 | 352 | * Build the enum constants documentation. |
duke@1 | 353 | * |
bpatel@766 | 354 | * @param node the XML element that specifies which components to document |
bpatel@766 | 355 | * @param memberDetailsTree the content tree to which the documentation will be added |
duke@1 | 356 | */ |
bpatel@766 | 357 | public void buildEnumConstantsDetails(XMLNode node, |
bpatel@766 | 358 | Content memberDetailsTree) throws Exception { |
duke@1 | 359 | configuration.getBuilderFactory(). |
bpatel@766 | 360 | getEnumConstantsBuilder(writer).buildChildren(node, memberDetailsTree); |
duke@1 | 361 | } |
duke@1 | 362 | |
duke@1 | 363 | /** |
duke@1 | 364 | * Build the field documentation. |
duke@1 | 365 | * |
bpatel@766 | 366 | * @param node the XML element that specifies which components to document |
bpatel@766 | 367 | * @param memberDetailsTree the content tree to which the documentation will be added |
duke@1 | 368 | */ |
bpatel@766 | 369 | public void buildFieldDetails(XMLNode node, |
bpatel@766 | 370 | Content memberDetailsTree) throws Exception { |
duke@1 | 371 | configuration.getBuilderFactory(). |
bpatel@766 | 372 | getFieldBuilder(writer).buildChildren(node, memberDetailsTree); |
duke@1 | 373 | } |
duke@1 | 374 | |
duke@1 | 375 | /** |
duke@1 | 376 | * Build the constructor documentation. |
duke@1 | 377 | * |
bpatel@766 | 378 | * @param node the XML element that specifies which components to document |
bpatel@766 | 379 | * @param memberDetailsTree the content tree to which the documentation will be added |
duke@1 | 380 | */ |
bpatel@766 | 381 | public void buildConstructorDetails(XMLNode node, |
bpatel@766 | 382 | Content memberDetailsTree) throws Exception { |
duke@1 | 383 | configuration.getBuilderFactory(). |
bpatel@766 | 384 | getConstructorBuilder(writer).buildChildren(node, memberDetailsTree); |
duke@1 | 385 | } |
duke@1 | 386 | |
duke@1 | 387 | /** |
duke@1 | 388 | * Build the method documentation. |
duke@1 | 389 | * |
bpatel@766 | 390 | * @param node the XML element that specifies which components to document |
bpatel@766 | 391 | * @param memberDetailsTree the content tree to which the documentation will be added |
duke@1 | 392 | */ |
bpatel@766 | 393 | public void buildMethodDetails(XMLNode node, |
bpatel@766 | 394 | Content memberDetailsTree) throws Exception { |
duke@1 | 395 | configuration.getBuilderFactory(). |
bpatel@766 | 396 | getMethodBuilder(writer).buildChildren(node, memberDetailsTree); |
duke@1 | 397 | } |
duke@1 | 398 | } |