duke@1: /* jjg@1326: * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.internal.toolkit.builders; duke@1: bpatel@766: import java.io.*; bpatel@766: import java.util.*; jjg@1357: jjg@1357: import com.sun.javadoc.*; jjg@1357: import com.sun.tools.doclets.internal.toolkit.*; duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: duke@1: /** duke@1: * Builds the summary for a given class. duke@1: * jjg@1359: *

This is NOT part of any supported API. jjg@1359: * If you write code that depends on this, you do so at your own risk. jjg@1359: * This code and its internal interfaces are subject to change or jjg@1359: * deletion without notice. duke@1: * duke@1: * @author Jamie Ho bpatel@766: * @author Bhavesh Patel (Modified) duke@1: * @since 1.5 duke@1: */ duke@1: public class ClassBuilder extends AbstractBuilder { duke@1: duke@1: /** duke@1: * The root element of the class XML is {@value}. duke@1: */ duke@1: public static final String ROOT = "ClassDoc"; duke@1: duke@1: /** duke@1: * The class being documented. duke@1: */ jjg@1410: private final ClassDoc classDoc; duke@1: duke@1: /** duke@1: * The doclet specific writer. duke@1: */ jjg@1410: private final ClassWriter writer; duke@1: duke@1: /** duke@1: * Keep track of whether or not this classdoc is an interface. duke@1: */ jjg@1410: private final boolean isInterface; duke@1: duke@1: /** duke@1: * Keep track of whether or not this classdoc is an enum. duke@1: */ jjg@1410: private final boolean isEnum; duke@1: duke@1: /** bpatel@766: * The content tree for the class documentation. bpatel@766: */ bpatel@766: private Content contentTree; bpatel@766: bpatel@766: /** duke@1: * Construct a new ClassBuilder. duke@1: * jjg@1410: * @param context the build context jjg@1410: * @param classDoc the class being documented. jjg@1410: * @param writer the doclet specific writer. duke@1: */ jjg@1410: private ClassBuilder(Context context, jjg@1410: ClassDoc classDoc, ClassWriter writer) { jjg@1410: super(context); jjg@1410: this.classDoc = classDoc; jjg@1410: this.writer = writer; jjg@1410: if (classDoc.isInterface()) { jjg@1410: isInterface = true; jjg@1410: isEnum = false; jjg@1410: } else if (classDoc.isEnum()) { jjg@1410: isInterface = false; jjg@1410: isEnum = true; jjg@1410: Util.setEnumDocumentation(configuration, classDoc); jjg@1410: } else { jjg@1410: isInterface = false; jjg@1410: isEnum = false; jjg@1410: } duke@1: } duke@1: duke@1: /** duke@1: * Construct a new ClassBuilder. duke@1: * jjg@1410: * @param context the build context duke@1: * @param classDoc the class being documented. duke@1: * @param writer the doclet specific writer. duke@1: */ jjg@1410: public static ClassBuilder getInstance(Context context, jjg@1410: ClassDoc classDoc, ClassWriter writer) { jjg@1410: return new ClassBuilder(context, classDoc, writer); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public void build() throws IOException { jjg@1410: build(layoutParser.parseXML(ROOT), contentTree); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public String getName() { duke@1: return ROOT; duke@1: } duke@1: duke@1: /** jjg@1326: * Handles the {@literal } tag. duke@1: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param contentTree the content tree to which the documentation will be added duke@1: */ bpatel@766: public void buildClassDoc(XMLNode node, Content contentTree) throws Exception { bpatel@766: String key; bpatel@766: if (isInterface) { bpatel@766: key = "doclet.Interface"; bpatel@766: } else if (isEnum) { bpatel@766: key = "doclet.Enum"; bpatel@766: } else { bpatel@766: key = "doclet.Class"; bpatel@766: } bpatel@766: contentTree = writer.getHeader(configuration.getText(key) + " " + bpatel@766: classDoc.name()); bpatel@766: Content classContentTree = writer.getClassContentHeader(); bpatel@766: buildChildren(node, classContentTree); bpatel@766: contentTree.addContent(classContentTree); bpatel@766: writer.addFooter(contentTree); bpatel@766: writer.printDocument(contentTree); bpatel@766: writer.close(); bpatel@766: copyDocFiles(); duke@1: } duke@1: bpatel@766: /** bpatel@766: * Build the class tree documentation. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param classContentTree the content tree to which the documentation will be added bpatel@766: */ bpatel@766: public void buildClassTree(XMLNode node, Content classContentTree) { bpatel@766: writer.addClassTree(classContentTree); bpatel@766: } duke@1: bpatel@766: /** bpatel@766: * Build the class information tree documentation. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param classContentTree the content tree to which the documentation will be added bpatel@766: */ bpatel@766: public void buildClassInfo(XMLNode node, Content classContentTree) { bpatel@766: Content classInfoTree = writer.getClassInfoTreeHeader(); bpatel@766: buildChildren(node, classInfoTree); bpatel@766: classContentTree.addContent(writer.getClassInfo(classInfoTree)); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Build the typeparameters of this class. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param classInfoTree the content tree to which the documentation will be added bpatel@766: */ bpatel@766: public void buildTypeParamInfo(XMLNode node, Content classInfoTree) { bpatel@766: writer.addTypeParamInfo(classInfoTree); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * If this is an interface, list all super interfaces. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param classInfoTree the content tree to which the documentation will be added bpatel@766: */ bpatel@766: public void buildSuperInterfacesInfo(XMLNode node, Content classInfoTree) { bpatel@766: writer.addSuperInterfacesInfo(classInfoTree); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * If this is a class, list all interfaces implemented by this class. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param classInfoTree the content tree to which the documentation will be added bpatel@766: */ bpatel@766: public void buildImplementedInterfacesInfo(XMLNode node, Content classInfoTree) { bpatel@766: writer.addImplementedInterfacesInfo(classInfoTree); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * List all the classes extend this one. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param classInfoTree the content tree to which the documentation will be added bpatel@766: */ bpatel@766: public void buildSubClassInfo(XMLNode node, Content classInfoTree) { bpatel@766: writer.addSubClassInfo(classInfoTree); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * List all the interfaces that extend this one. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param classInfoTree the content tree to which the documentation will be added bpatel@766: */ bpatel@766: public void buildSubInterfacesInfo(XMLNode node, Content classInfoTree) { bpatel@766: writer.addSubInterfacesInfo(classInfoTree); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * If this is an interface, list all classes that implement this interface. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param classInfoTree the content tree to which the documentation will be added bpatel@766: */ bpatel@766: public void buildInterfaceUsageInfo(XMLNode node, Content classInfoTree) { bpatel@766: writer.addInterfaceUsageInfo(classInfoTree); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * If this class is deprecated, build the appropriate information. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param classInfoTree the content tree to which the documentation will be added bpatel@766: */ bpatel@766: public void buildDeprecationInfo (XMLNode node, Content classInfoTree) { bpatel@766: writer.addClassDeprecationInfo(classInfoTree); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * If this is an inner class or interface, list the enclosing class or interface. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param classInfoTree the content tree to which the documentation will be added bpatel@766: */ bpatel@766: public void buildNestedClassInfo (XMLNode node, Content classInfoTree) { bpatel@766: writer.addNestedClassInfo(classInfoTree); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Copy the doc files for the current ClassDoc if necessary. bpatel@766: */ duke@1: private void copyDocFiles() { duke@1: PackageDoc containingPackage = classDoc.containingPackage(); duke@1: if((configuration.packages == null || duke@1: Arrays.binarySearch(configuration.packages, bpatel@766: containingPackage) < 0) && bpatel@766: ! containingPackagesSeen.contains(containingPackage.name())){ duke@1: //Only copy doc files dir if the containing package is not duke@1: //documented AND if we have not documented a class from the same duke@1: //package already. Otherwise, we are making duplicate copies. jjg@1383: Util.copyDocFiles(configuration, containingPackage); duke@1: containingPackagesSeen.add(containingPackage.name()); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Build the signature of the current class. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param classInfoTree the content tree to which the documentation will be added duke@1: */ bpatel@766: public void buildClassSignature(XMLNode node, Content classInfoTree) { jjg@1362: StringBuilder modifiers = new StringBuilder(classDoc.modifiers() + " "); duke@1: if (isEnum) { duke@1: modifiers.append("enum "); duke@1: int index; duke@1: if ((index = modifiers.indexOf("abstract")) >= 0) { jjg@1362: modifiers.delete(index, index + "abstract".length()); jjg@1362: modifiers = new StringBuilder( bpatel@766: Util.replaceText(modifiers.toString(), " ", " ")); duke@1: } duke@1: if ((index = modifiers.indexOf("final")) >= 0) { jjg@1362: modifiers.delete(index, index + "final".length()); jjg@1362: modifiers = new StringBuilder( bpatel@766: Util.replaceText(modifiers.toString(), " ", " ")); duke@1: } duke@1: //} else if (classDoc.isAnnotationType()) { duke@1: //modifiers.append("@interface "); duke@1: } else if (! isInterface) { duke@1: modifiers.append("class "); duke@1: } bpatel@766: writer.addClassSignature(modifiers.toString(), classInfoTree); duke@1: } duke@1: duke@1: /** duke@1: * Build the class description. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param classInfoTree the content tree to which the documentation will be added duke@1: */ bpatel@766: public void buildClassDescription(XMLNode node, Content classInfoTree) { bpatel@766: writer.addClassDescription(classInfoTree); duke@1: } duke@1: duke@1: /** duke@1: * Build the tag information for the current class. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param classInfoTree the content tree to which the documentation will be added duke@1: */ bpatel@766: public void buildClassTagInfo(XMLNode node, Content classInfoTree) { bpatel@766: writer.addClassTagInfo(classInfoTree); duke@1: } duke@1: duke@1: /** bpatel@766: * Build the member summary contents of the page. duke@1: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param classContentTree the content tree to which the documentation will be added duke@1: */ bpatel@766: public void buildMemberSummary(XMLNode node, Content classContentTree) throws Exception { bpatel@766: Content memberSummaryTree = writer.getMemberTreeHeader(); duke@1: configuration.getBuilderFactory(). bpatel@766: getMemberSummaryBuilder(writer).buildChildren(node, memberSummaryTree); bpatel@766: classContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree)); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Build the member details contents of the page. bpatel@766: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param classContentTree the content tree to which the documentation will be added bpatel@766: */ bpatel@766: public void buildMemberDetails(XMLNode node, Content classContentTree) { bpatel@766: Content memberDetailsTree = writer.getMemberTreeHeader(); bpatel@766: buildChildren(node, memberDetailsTree); bpatel@766: classContentTree.addContent(writer.getMemberDetailsTree(memberDetailsTree)); duke@1: } duke@1: duke@1: /** duke@1: * Build the enum constants documentation. duke@1: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param memberDetailsTree the content tree to which the documentation will be added duke@1: */ bpatel@766: public void buildEnumConstantsDetails(XMLNode node, bpatel@766: Content memberDetailsTree) throws Exception { duke@1: configuration.getBuilderFactory(). bpatel@766: getEnumConstantsBuilder(writer).buildChildren(node, memberDetailsTree); duke@1: } duke@1: duke@1: /** duke@1: * Build the field documentation. duke@1: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param memberDetailsTree the content tree to which the documentation will be added duke@1: */ bpatel@766: public void buildFieldDetails(XMLNode node, bpatel@766: Content memberDetailsTree) throws Exception { duke@1: configuration.getBuilderFactory(). bpatel@766: getFieldBuilder(writer).buildChildren(node, memberDetailsTree); duke@1: } duke@1: duke@1: /** duke@1: * Build the constructor documentation. duke@1: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param memberDetailsTree the content tree to which the documentation will be added duke@1: */ bpatel@766: public void buildConstructorDetails(XMLNode node, bpatel@766: Content memberDetailsTree) throws Exception { duke@1: configuration.getBuilderFactory(). bpatel@766: getConstructorBuilder(writer).buildChildren(node, memberDetailsTree); duke@1: } duke@1: duke@1: /** duke@1: * Build the method documentation. duke@1: * bpatel@766: * @param node the XML element that specifies which components to document bpatel@766: * @param memberDetailsTree the content tree to which the documentation will be added duke@1: */ bpatel@766: public void buildMethodDetails(XMLNode node, bpatel@766: Content memberDetailsTree) throws Exception { duke@1: configuration.getBuilderFactory(). bpatel@766: getMethodBuilder(writer).buildChildren(node, memberDetailsTree); duke@1: } duke@1: }