duke@1: /*
jjg@1359: * Copyright (c) 1997, 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.formats.html;
duke@1:
bpatel@233: import java.io.*;
bpatel@233: import java.util.*;
bpatel@233:
bpatel@233: import com.sun.javadoc.*;
bpatel@766: import com.sun.tools.doclets.formats.html.markup.*;
duke@1: import com.sun.tools.doclets.internal.toolkit.*;
duke@1: import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1:
duke@1: /**
duke@1: * Writes constructor documentation.
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.
jjg@1359: *
duke@1: * @author Robert Field
duke@1: * @author Atul M Dambalkar
bpatel@243: * @author Bhavesh Patel (Modified)
duke@1: */
duke@1: public class ConstructorWriterImpl extends AbstractExecutableMemberWriter
duke@1: implements ConstructorWriter, MemberSummaryWriter {
duke@1:
duke@1: private boolean foundNonPubConstructor = false;
duke@1:
duke@1: /**
duke@1: * Construct a new ConstructorWriterImpl.
duke@1: *
duke@1: * @param writer The writer for the class that the constructors belong to.
duke@1: * @param classDoc the class being documented.
duke@1: */
duke@1: public ConstructorWriterImpl(SubWriterHolderWriter writer,
duke@1: ClassDoc classDoc) {
duke@1: super(writer, classDoc);
duke@1: VisibleMemberMap visibleMemberMap = new VisibleMemberMap(classDoc,
jjg@1410: VisibleMemberMap.CONSTRUCTORS, configuration.nodeprecated);
jjg@74: List constructors = new ArrayList(visibleMemberMap.getMembersFor(classDoc));
duke@1: for (int i = 0; i < constructors.size(); i++) {
jjg@74: if ((constructors.get(i)).isProtected() ||
jjg@74: (constructors.get(i)).isPrivate()) {
duke@1: setFoundNonPubConstructor(true);
duke@1: }
duke@1: }
duke@1: }
duke@1:
duke@1: /**
duke@1: * Construct a new ConstructorWriterImpl.
duke@1: *
duke@1: * @param writer The writer for the class that the constructors belong to.
duke@1: */
duke@1: public ConstructorWriterImpl(SubWriterHolderWriter writer) {
duke@1: super(writer);
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * {@inheritDoc}
duke@1: */
bpatel@766: public Content getMemberSummaryHeader(ClassDoc classDoc,
bpatel@766: Content memberSummaryTree) {
bpatel@766: memberSummaryTree.addContent(HtmlConstants.START_OF_CONSTRUCTOR_SUMMARY);
bpatel@766: Content memberTree = writer.getMemberTreeHeader();
bpatel@766: writer.addSummaryHeader(this, classDoc, memberTree);
bpatel@766: return memberTree;
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * {@inheritDoc}
duke@1: */
bpatel@766: public Content getConstructorDetailsTreeHeader(ClassDoc classDoc,
bpatel@766: Content memberDetailsTree) {
bpatel@766: memberDetailsTree.addContent(HtmlConstants.START_OF_CONSTRUCTOR_DETAILS);
bpatel@766: Content constructorDetailsTree = writer.getMemberTreeHeader();
bpatel@766: constructorDetailsTree.addContent(writer.getMarkerAnchor("constructor_detail"));
bpatel@766: Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
bpatel@766: writer.constructorDetailsLabel);
bpatel@766: constructorDetailsTree.addContent(heading);
bpatel@766: return constructorDetailsTree;
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * {@inheritDoc}
duke@1: */
bpatel@766: public Content getConstructorDocTreeHeader(ConstructorDoc constructor,
bpatel@766: Content constructorDetailsTree) {
bpatel@766: String erasureAnchor;
bpatel@766: if ((erasureAnchor = getErasureAnchor(constructor)) != null) {
bpatel@766: constructorDetailsTree.addContent(writer.getMarkerAnchor((erasureAnchor)));
bpatel@766: }
bpatel@766: constructorDetailsTree.addContent(
bpatel@766: writer.getMarkerAnchor(writer.getAnchor(constructor)));
bpatel@766: Content constructorDocTree = writer.getMemberTreeHeader();
bpatel@766: Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
bpatel@766: heading.addContent(constructor.name());
bpatel@766: constructorDocTree.addContent(heading);
bpatel@766: return constructorDocTree;
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * {@inheritDoc}
duke@1: */
bpatel@766: public Content getSignature(ConstructorDoc constructor) {
bpatel@766: writer.displayLength = 0;
bpatel@766: Content pre = new HtmlTree(HtmlTag.PRE);
bpatel@766: writer.addAnnotationInfo(constructor, pre);
bpatel@766: addModifiers(constructor, pre);
jjg@1410: if (configuration.linksource) {
bpatel@766: Content constructorName = new StringContent(constructor.name());
bpatel@766: writer.addSrcLink(constructor, constructorName, pre);
bpatel@766: } else {
bpatel@766: addName(constructor.name(), pre);
duke@1: }
bpatel@766: addParameters(constructor, pre);
bpatel@766: addExceptions(constructor, pre);
bpatel@766: return pre;
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * {@inheritDoc}
duke@1: */
bpatel@766: @Override
bpatel@766: public void setSummaryColumnStyle(HtmlTree tdTree) {
bpatel@766: if (foundNonPubConstructor)
bpatel@766: tdTree.addStyle(HtmlStyle.colLast);
bpatel@766: else
bpatel@766: tdTree.addStyle(HtmlStyle.colOne);
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * {@inheritDoc}
duke@1: */
bpatel@766: public void addDeprecated(ConstructorDoc constructor, Content constructorDocTree) {
bpatel@766: addDeprecatedInfo(constructor, constructorDocTree);
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * {@inheritDoc}
duke@1: */
bpatel@766: public void addComments(ConstructorDoc constructor, Content constructorDocTree) {
bpatel@766: addComment(constructor, constructorDocTree);
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * {@inheritDoc}
duke@1: */
bpatel@766: public void addTags(ConstructorDoc constructor, Content constructorDocTree) {
bpatel@766: writer.addTagsInfo(constructor, constructorDocTree);
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * {@inheritDoc}
duke@1: */
bpatel@766: public Content getConstructorDetails(Content constructorDetailsTree) {
bpatel@766: return getMemberTree(constructorDetailsTree);
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * {@inheritDoc}
duke@1: */
bpatel@766: public Content getConstructorDoc(Content constructorDocTree,
bpatel@766: boolean isLastContent) {
bpatel@766: return getMemberTree(constructorDocTree, isLastContent);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Close the writer.
duke@1: */
duke@1: public void close() throws IOException {
duke@1: writer.close();
duke@1: }
duke@1:
duke@1: /**
duke@1: * Let the writer know whether a non public constructor was found.
duke@1: *
duke@1: * @param foundNonPubConstructor true if we found a non public constructor.
duke@1: */
duke@1: public void setFoundNonPubConstructor(boolean foundNonPubConstructor) {
duke@1: this.foundNonPubConstructor = foundNonPubConstructor;
duke@1: }
duke@1:
bpatel@766: /**
bpatel@766: * {@inheritDoc}
bpatel@766: */
bpatel@766: public void addSummaryLabel(Content memberTree) {
bpatel@766: Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
bpatel@766: writer.getResource("doclet.Constructor_Summary"));
bpatel@766: memberTree.addContent(label);
bpatel@243: }
bpatel@243:
bpatel@766: /**
bpatel@766: * {@inheritDoc}
bpatel@766: */
bpatel@766: public String getTableSummary() {
jjg@1410: return configuration.getText("doclet.Member_Table_Summary",
jjg@1410: configuration.getText("doclet.Constructor_Summary"),
jjg@1410: configuration.getText("doclet.constructors"));
bpatel@243: }
bpatel@243:
bpatel@766: /**
bpatel@766: * {@inheritDoc}
bpatel@766: */
bpatel@766: public String getCaption() {
jjg@1410: return configuration.getText("doclet.Constructors");
bpatel@766: }
bpatel@766:
bpatel@766: /**
bpatel@766: * {@inheritDoc}
bpatel@766: */
bpatel@766: public String[] getSummaryTableHeader(ProgramElementDoc member) {
bpatel@243: String[] header;
bpatel@243: if (foundNonPubConstructor) {
bpatel@243: header = new String[] {
jjg@1410: configuration.getText("doclet.Modifier"),
jjg@1410: configuration.getText("doclet.0_and_1",
jjg@1410: configuration.getText("doclet.Constructor"),
jjg@1410: configuration.getText("doclet.Description"))
bpatel@243: };
bpatel@243: }
bpatel@243: else {
bpatel@243: header = new String[] {
jjg@1410: configuration.getText("doclet.0_and_1",
jjg@1410: configuration.getText("doclet.Constructor"),
jjg@1410: configuration.getText("doclet.Description"))
bpatel@243: };
bpatel@243: }
bpatel@766: return header;
duke@1: }
duke@1:
bpatel@766: /**
bpatel@766: * {@inheritDoc}
bpatel@766: */
bpatel@766: public void addSummaryAnchor(ClassDoc cd, Content memberTree) {
bpatel@766: memberTree.addContent(writer.getMarkerAnchor("constructor_summary"));
duke@1: }
duke@1:
bpatel@766: /**
bpatel@766: * {@inheritDoc}
bpatel@766: */
bpatel@766: public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) {
bpatel@766: }
duke@1:
bpatel@766: /**
bpatel@766: * {@inheritDoc}
bpatel@766: */
bpatel@766: public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
duke@1: }
duke@1:
duke@1: public int getMemberKind() {
duke@1: return VisibleMemberMap.CONSTRUCTORS;
duke@1: }
duke@1:
bpatel@766: /**
bpatel@766: * {@inheritDoc}
bpatel@766: */
bpatel@766: protected Content getNavSummaryLink(ClassDoc cd, boolean link) {
duke@1: if (link) {
jjg@1372: return writer.getHyperLink("constructor_summary",
bpatel@766: writer.getResource("doclet.navConstructor"));
duke@1: } else {
bpatel@766: return writer.getResource("doclet.navConstructor");
duke@1: }
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc}
duke@1: */
bpatel@766: protected void addNavDetailLink(boolean link, Content liNav) {
bpatel@766: if (link) {
jjg@1372: liNav.addContent(writer.getHyperLink("constructor_detail",
bpatel@766: writer.getResource("doclet.navConstructor")));
bpatel@766: } else {
bpatel@766: liNav.addContent(writer.getResource("doclet.navConstructor"));
bpatel@766: }
bpatel@766: }
duke@1:
duke@1: /**
bpatel@766: * {@inheritDoc}
duke@1: */
bpatel@766: protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) {
bpatel@766: if (foundNonPubConstructor) {
bpatel@766: Content code = new HtmlTree(HtmlTag.CODE);
bpatel@766: if (member.isProtected()) {
bpatel@766: code.addContent("protected ");
bpatel@766: } else if (member.isPrivate()) {
bpatel@766: code.addContent("private ");
bpatel@766: } else if (member.isPublic()) {
bpatel@766: code.addContent(writer.getSpace());
bpatel@766: } else {
bpatel@766: code.addContent(
jjg@1410: configuration.getText("doclet.Package_private"));
bpatel@766: }
bpatel@766: tdSummaryType.addContent(code);
bpatel@766: }
bpatel@766: }
duke@1: }