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

Sun, 24 Feb 2013 11:36:58 -0800

author
jjg
date
Sun, 24 Feb 2013 11:36:58 -0800
changeset 1606
ccbe7ffdd867
parent 1468
690c41cdab55
child 1858
27bd6a2302f6
permissions
-rw-r--r--

7112427: The doclet needs to be able to generate JavaFX documentation.
Reviewed-by: jjg
Contributed-by: jan.valenta@oracle.com

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

mercurial