Tue, 03 Dec 2013 14:21:45 -0800
8025416: doclet not substituting {@docRoot} in some cases
Reviewed-by: jjg
duke@1 | 1 | /* |
jjg@1521 | 2 | * Copyright (c) 1997, 2013, 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@1606 | 63 | VisibleMemberMap.CONSTRUCTORS, configuration); |
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@2101 | 100 | constructorDetailsTree.addContent(writer.getMarkerAnchor( |
bpatel@2101 | 101 | SectionName.CONSTRUCTOR_DETAIL)); |
bpatel@766 | 102 | Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING, |
bpatel@766 | 103 | writer.constructorDetailsLabel); |
bpatel@766 | 104 | constructorDetailsTree.addContent(heading); |
bpatel@766 | 105 | return constructorDetailsTree; |
duke@1 | 106 | } |
duke@1 | 107 | |
duke@1 | 108 | /** |
bpatel@766 | 109 | * {@inheritDoc} |
duke@1 | 110 | */ |
bpatel@766 | 111 | public Content getConstructorDocTreeHeader(ConstructorDoc constructor, |
bpatel@766 | 112 | Content constructorDetailsTree) { |
bpatel@766 | 113 | String erasureAnchor; |
bpatel@766 | 114 | if ((erasureAnchor = getErasureAnchor(constructor)) != null) { |
bpatel@766 | 115 | constructorDetailsTree.addContent(writer.getMarkerAnchor((erasureAnchor))); |
bpatel@766 | 116 | } |
bpatel@766 | 117 | constructorDetailsTree.addContent( |
bpatel@766 | 118 | writer.getMarkerAnchor(writer.getAnchor(constructor))); |
bpatel@766 | 119 | Content constructorDocTree = writer.getMemberTreeHeader(); |
bpatel@766 | 120 | Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING); |
bpatel@766 | 121 | heading.addContent(constructor.name()); |
bpatel@766 | 122 | constructorDocTree.addContent(heading); |
bpatel@766 | 123 | return constructorDocTree; |
duke@1 | 124 | } |
duke@1 | 125 | |
duke@1 | 126 | /** |
bpatel@766 | 127 | * {@inheritDoc} |
duke@1 | 128 | */ |
bpatel@766 | 129 | public Content getSignature(ConstructorDoc constructor) { |
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 | } |
jjg@1741 | 139 | int indent = pre.charCount(); |
jjg@1741 | 140 | addParameters(constructor, pre, indent); |
jjg@1741 | 141 | addExceptions(constructor, pre, indent); |
bpatel@766 | 142 | return pre; |
duke@1 | 143 | } |
duke@1 | 144 | |
duke@1 | 145 | /** |
bpatel@766 | 146 | * {@inheritDoc} |
duke@1 | 147 | */ |
bpatel@766 | 148 | @Override |
bpatel@766 | 149 | public void setSummaryColumnStyle(HtmlTree tdTree) { |
bpatel@766 | 150 | if (foundNonPubConstructor) |
bpatel@766 | 151 | tdTree.addStyle(HtmlStyle.colLast); |
bpatel@766 | 152 | else |
bpatel@766 | 153 | tdTree.addStyle(HtmlStyle.colOne); |
duke@1 | 154 | } |
duke@1 | 155 | |
duke@1 | 156 | /** |
bpatel@766 | 157 | * {@inheritDoc} |
duke@1 | 158 | */ |
bpatel@766 | 159 | public void addDeprecated(ConstructorDoc constructor, Content constructorDocTree) { |
bpatel@766 | 160 | addDeprecatedInfo(constructor, constructorDocTree); |
duke@1 | 161 | } |
duke@1 | 162 | |
duke@1 | 163 | /** |
bpatel@766 | 164 | * {@inheritDoc} |
duke@1 | 165 | */ |
bpatel@766 | 166 | public void addComments(ConstructorDoc constructor, Content constructorDocTree) { |
bpatel@766 | 167 | addComment(constructor, constructorDocTree); |
duke@1 | 168 | } |
duke@1 | 169 | |
duke@1 | 170 | /** |
bpatel@766 | 171 | * {@inheritDoc} |
duke@1 | 172 | */ |
bpatel@766 | 173 | public void addTags(ConstructorDoc constructor, Content constructorDocTree) { |
bpatel@766 | 174 | writer.addTagsInfo(constructor, constructorDocTree); |
duke@1 | 175 | } |
duke@1 | 176 | |
duke@1 | 177 | /** |
bpatel@766 | 178 | * {@inheritDoc} |
duke@1 | 179 | */ |
bpatel@766 | 180 | public Content getConstructorDetails(Content constructorDetailsTree) { |
bpatel@766 | 181 | return getMemberTree(constructorDetailsTree); |
duke@1 | 182 | } |
duke@1 | 183 | |
duke@1 | 184 | /** |
bpatel@766 | 185 | * {@inheritDoc} |
duke@1 | 186 | */ |
bpatel@766 | 187 | public Content getConstructorDoc(Content constructorDocTree, |
bpatel@766 | 188 | boolean isLastContent) { |
bpatel@766 | 189 | return getMemberTree(constructorDocTree, isLastContent); |
duke@1 | 190 | } |
duke@1 | 191 | |
duke@1 | 192 | /** |
duke@1 | 193 | * Close the writer. |
duke@1 | 194 | */ |
duke@1 | 195 | public void close() throws IOException { |
duke@1 | 196 | writer.close(); |
duke@1 | 197 | } |
duke@1 | 198 | |
duke@1 | 199 | /** |
duke@1 | 200 | * Let the writer know whether a non public constructor was found. |
duke@1 | 201 | * |
duke@1 | 202 | * @param foundNonPubConstructor true if we found a non public constructor. |
duke@1 | 203 | */ |
duke@1 | 204 | public void setFoundNonPubConstructor(boolean foundNonPubConstructor) { |
duke@1 | 205 | this.foundNonPubConstructor = foundNonPubConstructor; |
duke@1 | 206 | } |
duke@1 | 207 | |
bpatel@766 | 208 | /** |
bpatel@766 | 209 | * {@inheritDoc} |
bpatel@766 | 210 | */ |
bpatel@766 | 211 | public void addSummaryLabel(Content memberTree) { |
bpatel@766 | 212 | Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, |
bpatel@766 | 213 | writer.getResource("doclet.Constructor_Summary")); |
bpatel@766 | 214 | memberTree.addContent(label); |
bpatel@243 | 215 | } |
bpatel@243 | 216 | |
bpatel@766 | 217 | /** |
bpatel@766 | 218 | * {@inheritDoc} |
bpatel@766 | 219 | */ |
bpatel@766 | 220 | public String getTableSummary() { |
jjg@1410 | 221 | return configuration.getText("doclet.Member_Table_Summary", |
jjg@1410 | 222 | configuration.getText("doclet.Constructor_Summary"), |
jjg@1410 | 223 | configuration.getText("doclet.constructors")); |
bpatel@243 | 224 | } |
bpatel@243 | 225 | |
bpatel@766 | 226 | /** |
bpatel@766 | 227 | * {@inheritDoc} |
bpatel@766 | 228 | */ |
jjg@1747 | 229 | public Content getCaption() { |
jjg@1747 | 230 | return configuration.getResource("doclet.Constructors"); |
bpatel@766 | 231 | } |
bpatel@766 | 232 | |
bpatel@766 | 233 | /** |
bpatel@766 | 234 | * {@inheritDoc} |
bpatel@766 | 235 | */ |
bpatel@766 | 236 | public String[] getSummaryTableHeader(ProgramElementDoc member) { |
bpatel@243 | 237 | String[] header; |
bpatel@243 | 238 | if (foundNonPubConstructor) { |
bpatel@243 | 239 | header = new String[] { |
jjg@1410 | 240 | configuration.getText("doclet.Modifier"), |
jjg@1410 | 241 | configuration.getText("doclet.0_and_1", |
jjg@1410 | 242 | configuration.getText("doclet.Constructor"), |
jjg@1410 | 243 | configuration.getText("doclet.Description")) |
bpatel@243 | 244 | }; |
bpatel@243 | 245 | } |
bpatel@243 | 246 | else { |
bpatel@243 | 247 | header = new String[] { |
jjg@1410 | 248 | configuration.getText("doclet.0_and_1", |
jjg@1410 | 249 | configuration.getText("doclet.Constructor"), |
jjg@1410 | 250 | configuration.getText("doclet.Description")) |
bpatel@243 | 251 | }; |
bpatel@243 | 252 | } |
bpatel@766 | 253 | return header; |
duke@1 | 254 | } |
duke@1 | 255 | |
bpatel@766 | 256 | /** |
bpatel@766 | 257 | * {@inheritDoc} |
bpatel@766 | 258 | */ |
bpatel@766 | 259 | public void addSummaryAnchor(ClassDoc cd, Content memberTree) { |
bpatel@2101 | 260 | memberTree.addContent(writer.getMarkerAnchor( |
bpatel@2101 | 261 | SectionName.CONSTRUCTOR_SUMMARY)); |
duke@1 | 262 | } |
duke@1 | 263 | |
bpatel@766 | 264 | /** |
bpatel@766 | 265 | * {@inheritDoc} |
bpatel@766 | 266 | */ |
bpatel@766 | 267 | public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) { |
bpatel@766 | 268 | } |
duke@1 | 269 | |
bpatel@766 | 270 | /** |
bpatel@766 | 271 | * {@inheritDoc} |
bpatel@766 | 272 | */ |
bpatel@766 | 273 | public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) { |
duke@1 | 274 | } |
duke@1 | 275 | |
duke@1 | 276 | public int getMemberKind() { |
duke@1 | 277 | return VisibleMemberMap.CONSTRUCTORS; |
duke@1 | 278 | } |
duke@1 | 279 | |
bpatel@766 | 280 | /** |
bpatel@766 | 281 | * {@inheritDoc} |
bpatel@766 | 282 | */ |
bpatel@766 | 283 | protected Content getNavSummaryLink(ClassDoc cd, boolean link) { |
duke@1 | 284 | if (link) { |
bpatel@2101 | 285 | return writer.getHyperLink(SectionName.CONSTRUCTOR_SUMMARY, |
bpatel@766 | 286 | writer.getResource("doclet.navConstructor")); |
duke@1 | 287 | } else { |
bpatel@766 | 288 | return writer.getResource("doclet.navConstructor"); |
duke@1 | 289 | } |
duke@1 | 290 | } |
duke@1 | 291 | |
duke@1 | 292 | /** |
duke@1 | 293 | * {@inheritDoc} |
duke@1 | 294 | */ |
bpatel@766 | 295 | protected void addNavDetailLink(boolean link, Content liNav) { |
bpatel@766 | 296 | if (link) { |
bpatel@2101 | 297 | liNav.addContent(writer.getHyperLink( |
bpatel@2101 | 298 | SectionName.CONSTRUCTOR_DETAIL, |
bpatel@766 | 299 | writer.getResource("doclet.navConstructor"))); |
bpatel@766 | 300 | } else { |
bpatel@766 | 301 | liNav.addContent(writer.getResource("doclet.navConstructor")); |
bpatel@766 | 302 | } |
bpatel@766 | 303 | } |
duke@1 | 304 | |
duke@1 | 305 | /** |
bpatel@766 | 306 | * {@inheritDoc} |
duke@1 | 307 | */ |
bpatel@766 | 308 | protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) { |
bpatel@766 | 309 | if (foundNonPubConstructor) { |
bpatel@766 | 310 | Content code = new HtmlTree(HtmlTag.CODE); |
bpatel@766 | 311 | if (member.isProtected()) { |
bpatel@766 | 312 | code.addContent("protected "); |
bpatel@766 | 313 | } else if (member.isPrivate()) { |
bpatel@766 | 314 | code.addContent("private "); |
bpatel@766 | 315 | } else if (member.isPublic()) { |
bpatel@766 | 316 | code.addContent(writer.getSpace()); |
bpatel@766 | 317 | } else { |
bpatel@766 | 318 | code.addContent( |
jjg@1410 | 319 | configuration.getText("doclet.Package_private")); |
bpatel@766 | 320 | } |
bpatel@766 | 321 | tdSummaryType.addContent(code); |
bpatel@766 | 322 | } |
bpatel@766 | 323 | } |
duke@1 | 324 | } |