src/share/classes/com/sun/tools/doclets/formats/html/ConstructorWriterImpl.java

Thu, 15 Nov 2012 09:18:36 -0800

author
jjg
date
Thu, 15 Nov 2012 09:18:36 -0800
changeset 1410
bfec2a1cc869
parent 1372
78962d89f283
child 1521
71f35e4b93a5
permissions
-rw-r--r--

8000800: javadoc uses static non-final fields
Reviewed-by: bpatel

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

mercurial