src/share/classes/com/sun/tools/doclets/formats/html/ConstructorWriterImpl.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 1359
25e14ad23cef
permissions
-rw-r--r--

6962318: Update copyright year
Reviewed-by: xdono

     1 /*
     2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.doclets.formats.html;
    28 import java.io.*;
    29 import java.util.*;
    31 import com.sun.javadoc.*;
    32 import com.sun.tools.doclets.formats.html.markup.*;
    33 import com.sun.tools.doclets.internal.toolkit.*;
    34 import com.sun.tools.doclets.internal.toolkit.util.*;
    36 /**
    37  * Writes constructor documentation.
    38  *
    39  * @author Robert Field
    40  * @author Atul M Dambalkar
    41  * @author Bhavesh Patel (Modified)
    42  */
    43 public class ConstructorWriterImpl extends AbstractExecutableMemberWriter
    44     implements ConstructorWriter, MemberSummaryWriter {
    46     private boolean foundNonPubConstructor = false;
    48     /**
    49      * Construct a new ConstructorWriterImpl.
    50      *
    51      * @param writer The writer for the class that the constructors belong to.
    52      * @param classDoc the class being documented.
    53      */
    54     public ConstructorWriterImpl(SubWriterHolderWriter writer,
    55             ClassDoc classDoc) {
    56         super(writer, classDoc);
    57         VisibleMemberMap visibleMemberMap = new VisibleMemberMap(classDoc,
    58             VisibleMemberMap.CONSTRUCTORS, configuration().nodeprecated);
    59         List<ProgramElementDoc> constructors = new ArrayList<ProgramElementDoc>(visibleMemberMap.getMembersFor(classDoc));
    60         for (int i = 0; i < constructors.size(); i++) {
    61             if ((constructors.get(i)).isProtected() ||
    62                 (constructors.get(i)).isPrivate()) {
    63                 setFoundNonPubConstructor(true);
    64             }
    65         }
    66     }
    68     /**
    69      * Construct a new ConstructorWriterImpl.
    70      *
    71      * @param writer The writer for the class that the constructors belong to.
    72      */
    73     public ConstructorWriterImpl(SubWriterHolderWriter writer) {
    74         super(writer);
    75     }
    77     /**
    78      * {@inheritDoc}
    79      */
    80     public Content getMemberSummaryHeader(ClassDoc classDoc,
    81             Content memberSummaryTree) {
    82         memberSummaryTree.addContent(HtmlConstants.START_OF_CONSTRUCTOR_SUMMARY);
    83         Content memberTree = writer.getMemberTreeHeader();
    84         writer.addSummaryHeader(this, classDoc, memberTree);
    85         return memberTree;
    86     }
    88     /**
    89      * {@inheritDoc}
    90      */
    91     public Content getConstructorDetailsTreeHeader(ClassDoc classDoc,
    92             Content memberDetailsTree) {
    93         memberDetailsTree.addContent(HtmlConstants.START_OF_CONSTRUCTOR_DETAILS);
    94         Content constructorDetailsTree = writer.getMemberTreeHeader();
    95         constructorDetailsTree.addContent(writer.getMarkerAnchor("constructor_detail"));
    96         Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
    97                 writer.constructorDetailsLabel);
    98         constructorDetailsTree.addContent(heading);
    99         return constructorDetailsTree;
   100     }
   102     /**
   103      * {@inheritDoc}
   104      */
   105     public Content getConstructorDocTreeHeader(ConstructorDoc constructor,
   106             Content constructorDetailsTree) {
   107         String erasureAnchor;
   108         if ((erasureAnchor = getErasureAnchor(constructor)) != null) {
   109             constructorDetailsTree.addContent(writer.getMarkerAnchor((erasureAnchor)));
   110         }
   111         constructorDetailsTree.addContent(
   112                 writer.getMarkerAnchor(writer.getAnchor(constructor)));
   113         Content constructorDocTree = writer.getMemberTreeHeader();
   114         Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
   115         heading.addContent(constructor.name());
   116         constructorDocTree.addContent(heading);
   117         return constructorDocTree;
   118     }
   120     /**
   121      * {@inheritDoc}
   122      */
   123     public Content getSignature(ConstructorDoc constructor) {
   124         writer.displayLength = 0;
   125         Content pre = new HtmlTree(HtmlTag.PRE);
   126         writer.addAnnotationInfo(constructor, pre);
   127         addModifiers(constructor, pre);
   128         if (configuration().linksource) {
   129             Content constructorName = new StringContent(constructor.name());
   130             writer.addSrcLink(constructor, constructorName, pre);
   131         } else {
   132             addName(constructor.name(), pre);
   133         }
   134         addParameters(constructor, pre);
   135         addExceptions(constructor, pre);
   136         return pre;
   137     }
   139     /**
   140      * {@inheritDoc}
   141      */
   142     @Override
   143     public void setSummaryColumnStyle(HtmlTree tdTree) {
   144         if (foundNonPubConstructor)
   145             tdTree.addStyle(HtmlStyle.colLast);
   146         else
   147             tdTree.addStyle(HtmlStyle.colOne);
   148     }
   150     /**
   151      * {@inheritDoc}
   152      */
   153     public void addDeprecated(ConstructorDoc constructor, Content constructorDocTree) {
   154         addDeprecatedInfo(constructor, constructorDocTree);
   155     }
   157     /**
   158      * {@inheritDoc}
   159      */
   160     public void addComments(ConstructorDoc constructor, Content constructorDocTree) {
   161         addComment(constructor, constructorDocTree);
   162     }
   164     /**
   165      * {@inheritDoc}
   166      */
   167     public void addTags(ConstructorDoc constructor, Content constructorDocTree) {
   168         writer.addTagsInfo(constructor, constructorDocTree);
   169     }
   171     /**
   172      * {@inheritDoc}
   173      */
   174     public Content getConstructorDetails(Content constructorDetailsTree) {
   175         return getMemberTree(constructorDetailsTree);
   176     }
   178     /**
   179      * {@inheritDoc}
   180      */
   181     public Content getConstructorDoc(Content constructorDocTree,
   182             boolean isLastContent) {
   183         return getMemberTree(constructorDocTree, isLastContent);
   184     }
   186     /**
   187      * Close the writer.
   188      */
   189     public void close() throws IOException {
   190         writer.close();
   191     }
   193     /**
   194      * Let the writer know whether a non public constructor was found.
   195      *
   196      * @param foundNonPubConstructor true if we found a non public constructor.
   197      */
   198     public void setFoundNonPubConstructor(boolean foundNonPubConstructor) {
   199         this.foundNonPubConstructor = foundNonPubConstructor;
   200     }
   202     /**
   203      * {@inheritDoc}
   204      */
   205     public void addSummaryLabel(Content memberTree) {
   206         Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
   207                 writer.getResource("doclet.Constructor_Summary"));
   208         memberTree.addContent(label);
   209     }
   211     /**
   212      * {@inheritDoc}
   213      */
   214     public String getTableSummary() {
   215         return configuration().getText("doclet.Member_Table_Summary",
   216                 configuration().getText("doclet.Constructor_Summary"),
   217                 configuration().getText("doclet.constructors"));
   218     }
   220     /**
   221      * {@inheritDoc}
   222      */
   223     public String getCaption() {
   224         return configuration().getText("doclet.Constructors");
   225     }
   227     /**
   228      * {@inheritDoc}
   229      */
   230     public String[] getSummaryTableHeader(ProgramElementDoc member) {
   231         String[] header;
   232         if (foundNonPubConstructor) {
   233             header = new String[] {
   234                 configuration().getText("doclet.Modifier"),
   235                 configuration().getText("doclet.0_and_1",
   236                         configuration().getText("doclet.Constructor"),
   237                         configuration().getText("doclet.Description"))
   238             };
   239         }
   240         else {
   241             header = new String[] {
   242                 configuration().getText("doclet.0_and_1",
   243                         configuration().getText("doclet.Constructor"),
   244                         configuration().getText("doclet.Description"))
   245             };
   246         }
   247         return header;
   248     }
   250     /**
   251      * {@inheritDoc}
   252      */
   253     public void addSummaryAnchor(ClassDoc cd, Content memberTree) {
   254         memberTree.addContent(writer.getMarkerAnchor("constructor_summary"));
   255     }
   257     /**
   258      * {@inheritDoc}
   259      */
   260     public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) {
   261     }
   263     /**
   264      * {@inheritDoc}
   265      */
   266     public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
   267     }
   269     public int getMemberKind() {
   270         return VisibleMemberMap.CONSTRUCTORS;
   271     }
   273     /**
   274      * {@inheritDoc}
   275      */
   276     protected Content getNavSummaryLink(ClassDoc cd, boolean link) {
   277         if (link) {
   278             return writer.getHyperLink("", "constructor_summary",
   279                     writer.getResource("doclet.navConstructor"));
   280         } else {
   281             return writer.getResource("doclet.navConstructor");
   282         }
   283     }
   285     /**
   286      * {@inheritDoc}
   287      */
   288     protected void addNavDetailLink(boolean link, Content liNav) {
   289         if (link) {
   290             liNav.addContent(writer.getHyperLink("", "constructor_detail",
   291                     writer.getResource("doclet.navConstructor")));
   292         } else {
   293             liNav.addContent(writer.getResource("doclet.navConstructor"));
   294         }
   295     }
   297     /**
   298      * {@inheritDoc}
   299      */
   300     protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) {
   301         if (foundNonPubConstructor) {
   302             Content code = new HtmlTree(HtmlTag.CODE);
   303             if (member.isProtected()) {
   304                 code.addContent("protected ");
   305             } else if (member.isPrivate()) {
   306                 code.addContent("private ");
   307             } else if (member.isPublic()) {
   308                 code.addContent(writer.getSpace());
   309             } else {
   310                 code.addContent(
   311                         configuration().getText("doclet.Package_private"));
   312             }
   313             tdSummaryType.addContent(code);
   314         }
   315     }
   316 }

mercurial