FileDocCategorySizeDatePackage
ClassWriter.javaAPI DocExample14079Wed Apr 19 11:17:10 BST 2000com.sun.tools.doclets.standard

ClassWriter

public class ClassWriter extends SubWriterHolderWriter
Generate the Class Information Page.
see
com.sun.javadoc.ClassDoc
see
java.util.Collections
see
java.util.List
see
java.util.ArrayList
see
java.util.HashMap
author
Atul M Dambalkar
author
Robert Field

Fields Summary
protected ClassDoc
classdoc
protected ClassTree
classtree
protected ClassDoc
prev
protected ClassDoc
next
protected boolean
nopackage
protected MethodSubWriter
methodSubWriter
protected ConstructorSubWriter
constrSubWriter
protected FieldSubWriter
fieldSubWriter
protected ClassSubWriter
innerSubWriter
Constructors Summary
public ClassWriter(String path, String filename, ClassDoc classdoc, ClassDoc prev, ClassDoc next, ClassTree classtree, boolean nopackage)

        super(path, filename, 
         DirectoryManager.getRelativePath(classdoc.containingPackage().name()));
        this.classdoc = classdoc;
        HtmlStandardWriter.currentcd = classdoc;
        this.classtree = classtree;
        this.prev = prev;
        this.next = next;
        this.nopackage = nopackage;
        methodSubWriter = new MethodSubWriter(this, classdoc);
        constrSubWriter = new ConstructorSubWriter(this, classdoc);
        fieldSubWriter = new FieldSubWriter(this, classdoc);
        innerSubWriter = new ClassSubWriter(this, classdoc);
    
Methods Summary
public static voidgenerate(com.sun.javadoc.ClassDoc classdoc, com.sun.javadoc.ClassDoc prev, com.sun.javadoc.ClassDoc next, ClassTree classtree, boolean nopackage)
Generate a class page.

param
prev the previous class to generated, or null if no previous.
param
classdoc the class to generate.
param
next the next class to be generated, or null if no next.

            ClassWriter clsgen;
            String path = 
               DirectoryManager.getDirectoryPath(classdoc.containingPackage());
            String filename = classdoc.name() + ".html";
            try {
                clsgen = new ClassWriter(path, filename, classdoc, 
                                         prev, next, classtree, nopackage);
                clsgen.generateClassFile();
                clsgen.close();
            } catch (IOException exc) {
                Standard.configuration().standardmessage.
                    error("doclet.exception_encountered",
                           exc.toString(), filename);
                throw new DocletAbortException();
            }
    
public voidgenerateClassFile()
Generate the class file contents.

        String cltype = getText(classdoc.isInterface()? 
                                    "doclet.Interface": 
                                    "doclet.Class") + " ";
        PackageDoc pkg = classdoc.containingPackage();
        String pkgname = (pkg != null)? pkg.name(): "";
        String clname = classdoc.name();
        String label = cltype + ' " + clname;

        printHeader(getText("doclet.Window_ClassFile_label", 
                            Standard.configuration().windowtitle, label));
        navLinks(true);
        hr();
        println("<!-- ======== START OF CLASS DATA ======== -->");
        h2();
        if (pkgname.length() > 0) {
            font("-1"); print(pkgname); fontEnd(); br();
        }
        print(label);
        h2End();

        // if this is a class (not an interface) then generate 
        // the super class tree.
        if (classdoc.isClass()) {
            pre();
            printTreeForClass(classdoc);
            preEnd();
        }
        
        printSuperImplementedInterfacesInfo();

        printSubClassInterfaceInfo();
        
        if (classdoc.isInterface()) {
            printImplementingClasses();
        }

        printEnclosingClassInfo();

        hr();

        printDeprecated();

        printClassDescription();
        p();
        // generate documentation for the class.
        if (classdoc.inlineTags().length > 0) {
            printInlineComment(classdoc);
            p();
        }
        // Print Information about all the tags here
        generateTagInfo(classdoc);
        hr();
        p();

	printAllMembers();

        println("<!-- ========= END OF CLASS DATA ========= -->");
        hr();
        navLinks(false);
        printBottom();
        printBodyHtmlEnd();
    
protected voidnavDetailLinks()

        printText("doclet.Detail");
        print(" ");
        fieldSubWriter.navDetailLink();
        navGap();
        constrSubWriter.navDetailLink();
        navGap();
        methodSubWriter.navDetailLink();
    
protected voidnavGap()

        space();
        print('|");
        space();
    
protected voidnavLinkClass()
Print class page indicator

        navCellRevStart();
        fontStyle("NavBarFont1Rev");
        boldText("doclet.Class");
        fontEnd();
        navCellEnd();
    
protected voidnavLinkClassUse()
Print class use link

        navCellStart();
        printHyperLink("class-use/" + filename, "", 
                       getText("doclet.navClassUse"), true, "NavBarFont1");
        navCellEnd();
    
protected voidnavLinkNext()
Print next package link

        if (next == null) {
            printText("doclet.Next_Class"); 
        } else {
            printClassLink(next, getText("doclet.Next_Class"), true);
        }
    
protected voidnavLinkPackage()
Print this package link

        navCellStart();
        printHyperLink("package-summary.html", "", getText("doclet.Package"),
                       true, "NavBarFont1");
        navCellEnd();
    
protected voidnavLinkPrevious()
Print previous package link

        if (prev == null) {
            printText("doclet.Prev_Class"); 
        } else {
            printClassLink(prev, getText("doclet.Prev_Class"), true);
        }
    
protected voidnavLinkTree()

        navCellStart();
        if (nopackage) {
            printHyperLink(relativepath + "overview-tree.html", "",
                           getText("doclet.Tree"), true, "NavBarFont1");
        } else {
            printHyperLink("package-tree.html", "", getText("doclet.Tree"),
                           true, "NavBarFont1");
        }
        navCellEnd();
    
protected voidnavSummaryLinks()

        printText("doclet.Summary");
        print(" ");
        innerSubWriter.navSummaryLink();
        navGap();
        fieldSubWriter.navSummaryLink();
        navGap();
        constrSubWriter.navSummaryLink();
        navGap();
        methodSubWriter.navSummaryLink();
    
protected voidprintAllMembers()
Print summary and detail information for the specified members in the class.

        println("<!-- ======== INNER CLASS SUMMARY ======== -->"); println();
	innerSubWriter.printMembersSummary();
	innerSubWriter.printInheritedMembersSummary();
        println(); 
        println("<!-- =========== FIELD SUMMARY =========== -->"); println();
	fieldSubWriter.printMembersSummary();
	fieldSubWriter.printInheritedMembersSummary();
        println(); 
        println("<!-- ======== CONSTRUCTOR SUMMARY ======== -->"); println();
	constrSubWriter.printMembersSummary();
        println(); 
        println("<!-- ========== METHOD SUMMARY =========== -->"); println();
	methodSubWriter.printMembersSummary();
        methodSubWriter.printInheritedMembersSummary();

        p();

        println(); 
        println("<!-- ============ FIELD DETAIL =========== -->"); println();
	fieldSubWriter.printMembers();
        println(); 
        println("<!-- ========= CONSTRUCTOR DETAIL ======== -->"); println();
	constrSubWriter.printMembers();
        println(); 
        println("<!-- ============ METHOD DETAIL ========== -->"); println();
	methodSubWriter.printMembers();
    
protected voidprintClassDescription()
Print the class description regarding iterfaces implemented, classes inheritted.

        boolean isInterface = classdoc.isInterface();
        dl();
        dt();

        print(classdoc.modifiers() + " ");  

        if (!isInterface) {
            print("class ");
        }
        bold(classdoc.name());

        if (!isInterface) {
            ClassDoc superclass = classdoc.superclass();
            if (superclass != null) {
                dt();
                print("extends ");
                printClassLink(superclass); 
            }
        }

        ClassDoc[] implIntfacs = classdoc.interfaces();
        if (implIntfacs != null && implIntfacs.length > 0) {
            dt();
            print(isInterface? "extends " : "implements ");
            printClassLink(implIntfacs[0]);
            for (int i = 1; i < implIntfacs.length; i++) {
                print(", ");
                printClassLink(implIntfacs[i]);
            }
        }
        dlEnd();
    
protected voidprintDeprecated()
Mark the class as deprecated if it is.

        Tag[] deprs = classdoc.tags("deprecated");
        if (deprs.length > 0) {
            Tag[] commentTags = deprs[0].inlineTags();
            if (commentTags.length > 0) {
                boldText("doclet.Deprecated");
                space();
                printInlineDeprecatedComment(deprs[0]);
            }
            p();
        }
    
protected voidprintEnclosingClassInfo()

        ClassDoc outerClass = classdoc.containingClass(); 
        if (outerClass != null) {
            printInfoHeader();
            boldText("doclet.Enclosing_Class");
            dd();
            printClassLink(outerClass);            
            ddEnd();
            dlEnd();
        }
    
protected voidprintImplementingClasses()
If this is the interface which are the classes, that implement this?

        if (classdoc.qualifiedName().equals("java.lang.Cloneable") || 
                classdoc.qualifiedName().equals("java.io.Serializable")) {
            return;   // Don't generate the list, too big
        }
        List implcl = classtree.implementingclasses(classdoc);
        if (implcl.size() > 0) {
            printInfoHeader();
            boldText("doclet.Implementing_Classes");
            printSubClassLinkInfo(implcl);
        }
    
protected voidprintInfoHeader()

        dl();
        dt();
    
protected voidprintStep(int indent)
Generate the step like diagram for the class hierarchy.

        String spc = spaces(6 * indent - 4);
        print(spc);
        println("|");
        print(spc);
        print("+--");
    
protected voidprintSubClassInterfaceInfo()
Which are the sub-classes or sub-interfaces for this class?

        // Before using TreeBuilder.getSubClassList
        // make sure that tree.html is generated prior.
        if (classdoc.qualifiedName().equals("java.lang.Object") ||
               classdoc.qualifiedName().equals("org.omg.CORBA.Object")) {
            return;    // Don't generate the list, too huge
        }
        List subclasses = classdoc.isClass()? 
                             classtree.subs(classdoc): // it's a class
                             classtree.allSubs(classdoc); // it's an interface
        if (subclasses.size() > 0) {
            printInfoHeader();
            if (classdoc.isClass()) {
                boldText("doclet.Subclasses");
            } else { // this is an interface
                boldText("doclet.Subinterfaces");
            }
            printSubClassLinkInfo(subclasses);
        }
    
protected voidprintSubClassLinkInfo(java.util.List list)
Generate a link for the sub-classes.

        int i = 0;
        print(' ");
        dd();
        for (; i < list.size() - 1; i++) {
            printClassLink((ClassDoc)(list.get(i)));
            print(", ");
        }
        printClassLink((ClassDoc)(list.get(i)));
        ddEnd();
        dlEnd();
    
protected voidprintSummaryDetailLinks()

        tr();
        tdVAlignClass("top", "NavBarCell3");
        font("-2");
        print("  ");
        navSummaryLinks();
        fontEnd();
        tdEnd();
        
        tdVAlignClass("top", "NavBarCell3");
        font("-2");
        navDetailLinks();
        fontEnd();
        tdEnd();
        trEnd();
    
protected voidprintSuperImplementedInterfacesInfo()

        ProgramElementDoc[] intarr = Util.getAllInterfaces(classdoc);
        Arrays.sort(intarr);
        if (intarr.length > 0) {
            printInfoHeader();
            boldText(classdoc.isClass()?
		         "doclet.All_Implemented_Interfaces":
                         "doclet.All_Superinterfaces");
            printSubClassLinkInfo(Arrays.asList(intarr));
        }
    
protected intprintTreeForClass(com.sun.javadoc.ClassDoc cd)
Print the class hierarchy tree for this class only.

        ClassDoc sup = cd.superclass();
        int indent = 0;
        if (sup != null) {
            indent = printTreeForClass(sup);
            printStep(indent);
        }
        if (cd.equals(classdoc)) {
            bold(cd.qualifiedName());
        } else {
            printQualifiedClassLink(cd);
        }
        println();
        return indent + 1;