001    /*
002     * Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
003     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004     *
005     * This code is free software; you can redistribute it and/or modify it
006     * under the terms of the GNU General Public License version 2 only, as
007     * published by the Free Software Foundation.  Sun designates this
008     * particular file as subject to the "Classpath" exception as provided
009     * by Sun in the LICENSE file that accompanied this code.
010     *
011     * This code is distributed in the hope that it will be useful, but WITHOUT
012     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014     * version 2 for more details (a copy is included in the LICENSE file that
015     * accompanied this code).
016     *
017     * You should have received a copy of the GNU General Public License version
018     * 2 along with this work; if not, write to the Free Software Foundation,
019     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020     *
021     * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022     * CA 95054 USA or visit www.sun.com if you need additional information or
023     * have any questions.
024     */
025    
026    package com.sun.tools.doclets.formats.html;
027    
028    import com.sun.tools.doclets.internal.toolkit.*;
029    import com.sun.tools.doclets.internal.toolkit.taglets.*;
030    import com.sun.tools.doclets.internal.toolkit.util.*;
031    import com.sun.javadoc.*;
032    
033    import java.io.*;
034    
035    /**
036     * Writes enum constant documentation in HTML format.
037     *
038     * @author Jamie Ho
039     */
040    public class EnumConstantWriterImpl extends AbstractMemberWriter
041        implements EnumConstantWriter, MemberSummaryWriter {
042    
043        private boolean printedSummaryHeader = false;
044    
045        public EnumConstantWriterImpl(SubWriterHolderWriter writer,
046            ClassDoc classdoc) {
047            super(writer, classdoc);
048        }
049    
050        public EnumConstantWriterImpl(SubWriterHolderWriter writer) {
051            super(writer);
052        }
053    
054        /**
055         * Write the enum constant summary header for the given class.
056         *
057         * @param classDoc the class the summary belongs to.
058         */
059        public void writeMemberSummaryHeader(ClassDoc classDoc) {
060            printedSummaryHeader = true;
061            writer.println("<!-- =========== ENUM CONSTANT SUMMARY =========== -->");
062            writer.println();
063            writer.printSummaryHeader(this, classDoc);
064        }
065    
066        /**
067         * Write the enum constant summary footer for the given class.
068         *
069         * @param classDoc the class the summary belongs to.
070         */
071        public void writeMemberSummaryFooter(ClassDoc classDoc) {
072            writer.printSummaryFooter(this, classDoc);
073        }
074    
075        /**
076         * Write the inherited enum constant summary header for the given class.
077         *
078         * @param classDoc the class the summary belongs to.
079         */
080        public void writeInheritedMemberSummaryHeader(ClassDoc classDoc) {
081            if(! printedSummaryHeader){
082                //We don't want inherited summary to not be under heading.
083                writeMemberSummaryHeader(classDoc);
084                writeMemberSummaryFooter(classDoc);
085                printedSummaryHeader = true;
086            }
087            writer.printInheritedSummaryHeader(this, classDoc);
088        }
089    
090        /**
091         * {@inheritDoc}
092         */
093        public void writeInheritedMemberSummary(ClassDoc classDoc,
094            ProgramElementDoc enumConstant, boolean isFirst, boolean isLast) {
095            writer.printInheritedSummaryMember(this, classDoc, enumConstant, isFirst);
096        }
097    
098        /**
099         * Write the inherited enum constant summary footer for the given class.
100         *
101         * @param classDoc the class the summary belongs to.
102         */
103        public void writeInheritedMemberSummaryFooter(ClassDoc classDoc) {
104            writer.printInheritedSummaryFooter(this, classDoc);
105        }
106    
107        /**
108         * {@inheritDoc}
109         */
110        public void writeHeader(ClassDoc classDoc, String header) {
111            writer.println();
112            writer.println("<!-- ============ ENUM CONSTANT DETAIL =========== -->");
113            writer.println();
114            writer.anchor("enum_constant_detail");
115            writer.printTableHeadingBackground(header);
116            writer.println();
117        }
118    
119        /**
120         * {@inheritDoc}
121         */
122        public void writeEnumConstantHeader(FieldDoc enumConstant, boolean isFirst) {
123            if (! isFirst) {
124                writer.printMemberHeader();
125                writer.println("");
126            }
127            writer.anchor(enumConstant.name());
128            writer.h3();
129            writer.print(enumConstant.name());
130            writer.h3End();
131        }
132    
133        /**
134         * {@inheritDoc}
135         */
136        public void writeSignature(FieldDoc enumConstant) {
137            writer.pre();
138            writer.writeAnnotationInfo(enumConstant);
139            printModifiers(enumConstant);
140            writer.printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER,
141                enumConstant.type()));
142            print(' ');
143            if (configuration().linksource) {
144                writer.printSrcLink(enumConstant, enumConstant.name());
145            } else {
146                strong(enumConstant.name());
147            }
148            writer.preEnd();
149            writer.dl();
150        }
151    
152        /**
153         * {@inheritDoc}
154         */
155        public void writeDeprecated(FieldDoc enumConstant) {
156            print(((TagletOutputImpl)
157                (new DeprecatedTaglet()).getTagletOutput(enumConstant,
158                writer.getTagletWriterInstance(false))).toString());
159        }
160    
161        /**
162         * {@inheritDoc}
163         */
164        public void writeComments(FieldDoc enumConstant) {
165            if (enumConstant.inlineTags().length > 0) {
166                writer.dd();
167                writer.printInlineComment(enumConstant);
168            }
169        }
170    
171        /**
172         * {@inheritDoc}
173         */
174        public void writeTags(FieldDoc enumConstant) {
175            writer.printTags(enumConstant);
176        }
177    
178        /**
179         * {@inheritDoc}
180         */
181        public void writeEnumConstantFooter() {
182            writer.dlEnd();
183        }
184    
185        /**
186         * {@inheritDoc}
187         */
188        public void writeFooter(ClassDoc classDoc) {
189            //No footer to write for enum constant documentation
190        }
191    
192        /**
193         * {@inheritDoc}
194         */
195        public void close() throws IOException {
196            writer.close();
197        }
198    
199        public int getMemberKind() {
200            return VisibleMemberMap.ENUM_CONSTANTS;
201        }
202    
203        public void printSummaryLabel(ClassDoc cd) {
204            writer.strongText("doclet.Enum_Constant_Summary");
205        }
206    
207        public void printSummaryAnchor(ClassDoc cd) {
208            writer.anchor("enum_constant_summary");
209        }
210    
211        public void printInheritedSummaryAnchor(ClassDoc cd) {
212        }   // no such
213    
214        public void printInheritedSummaryLabel(ClassDoc cd) {
215            // no such
216        }
217    
218        protected void writeSummaryLink(int context, ClassDoc cd, ProgramElementDoc member) {
219            writer.strong();
220            writer.printDocLink(context, (MemberDoc) member, member.name(), false);
221            writer.strongEnd();
222        }
223    
224        protected void writeInheritedSummaryLink(ClassDoc cd,
225                ProgramElementDoc member) {
226            writer.printDocLink(LinkInfoImpl.CONTEXT_MEMBER, (MemberDoc)member,
227                member.name(), false);
228        }
229    
230        protected void printSummaryType(ProgramElementDoc member) {
231            //Not applicable.
232        }
233    
234        protected void writeDeprecatedLink(ProgramElementDoc member) {
235            writer.printDocLink(LinkInfoImpl.CONTEXT_MEMBER,
236                (MemberDoc) member, ((FieldDoc)member).qualifiedName(), false);
237        }
238    
239        protected void printNavSummaryLink(ClassDoc cd, boolean link) {
240            if (link) {
241                writer.printHyperLink("", (cd == null)?
242                            "enum_constant_summary":
243                            "enum_constants_inherited_from_class_" +
244                            configuration().getClassName(cd),
245                        configuration().getText("doclet.navEnum"));
246            } else {
247                writer.printText("doclet.navEnum");
248            }
249        }
250    
251        protected void printNavDetailLink(boolean link) {
252            if (link) {
253                writer.printHyperLink("", "enum_constant_detail",
254                    configuration().getText("doclet.navEnum"));
255            } else {
256                writer.printText("doclet.navEnum");
257            }
258        }
259    }