src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ClassBuilder.java

Tue, 28 Dec 2010 15:54:52 -0800

author
ohair
date
Tue, 28 Dec 2010 15:54:52 -0800
changeset 798
4868a36f6fd8
parent 766
90af8d87741f
child 1326
30c36e23f154
permissions
-rw-r--r--

6962318: Update copyright year
Reviewed-by: xdono

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

mercurial