Tue, 03 Dec 2013 14:21:45 -0800
8025416: doclet not substituting {@docRoot} in some cases
Reviewed-by: jjg
duke@1 | 1 | /* |
jjg@1735 | 2 | * Copyright (c) 1998, 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.*; |
duke@1 | 30 | |
duke@1 | 31 | import com.sun.javadoc.*; |
bpatel@766 | 32 | import com.sun.tools.doclets.formats.html.markup.*; |
bpatel@766 | 33 | import com.sun.tools.doclets.internal.toolkit.*; |
jjg@1357 | 34 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 35 | |
duke@1 | 36 | /** |
duke@1 | 37 | * Generate Index for all the Member Names with Indexing in |
duke@1 | 38 | * Unicode Order. This class is a base class for {@link SingleIndexWriter} and |
duke@1 | 39 | * {@link SplitIndexWriter}. It uses the functionality from |
duke@1 | 40 | * {@link HtmlDocletWriter} to generate the Index Contents. |
duke@1 | 41 | * |
jjg@1359 | 42 | * <p><b>This is NOT part of any supported API. |
jjg@1359 | 43 | * If you write code that depends on this, you do so at your own risk. |
jjg@1359 | 44 | * This code and its internal interfaces are subject to change or |
jjg@1359 | 45 | * deletion without notice.</b> |
jjg@1359 | 46 | * |
duke@1 | 47 | * @see IndexBuilder |
duke@1 | 48 | * @author Atul M Dambalkar |
bpatel@766 | 49 | * @author Bhavesh Patel (Modified) |
duke@1 | 50 | */ |
duke@1 | 51 | public class AbstractIndexWriter extends HtmlDocletWriter { |
duke@1 | 52 | |
duke@1 | 53 | /** |
duke@1 | 54 | * The index of all the members with unicode character. |
duke@1 | 55 | */ |
duke@1 | 56 | protected IndexBuilder indexbuilder; |
duke@1 | 57 | |
duke@1 | 58 | /** |
jjg@1372 | 59 | * This constructor will be used by {@link SplitIndexWriter}. Initializes |
duke@1 | 60 | * path to this file and relative path from this file. |
duke@1 | 61 | * |
jjg@1372 | 62 | * @param configuration The current configuration |
duke@1 | 63 | * @param path Path to the file which is getting generated. |
duke@1 | 64 | * @param indexbuilder Unicode based Index from {@link IndexBuilder} |
duke@1 | 65 | */ |
duke@1 | 66 | protected AbstractIndexWriter(ConfigurationImpl configuration, |
jjg@1372 | 67 | DocPath path, |
jjg@1372 | 68 | IndexBuilder indexbuilder) |
duke@1 | 69 | throws IOException { |
jjg@1372 | 70 | super(configuration, path); |
duke@1 | 71 | this.indexbuilder = indexbuilder; |
duke@1 | 72 | } |
duke@1 | 73 | |
duke@1 | 74 | /** |
bpatel@766 | 75 | * Get the index label for navigation bar. |
bpatel@766 | 76 | * |
bpatel@766 | 77 | * @return a content tree for the tree label |
duke@1 | 78 | */ |
bpatel@766 | 79 | protected Content getNavLinkIndex() { |
bpatel@766 | 80 | Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, indexLabel); |
bpatel@766 | 81 | return li; |
duke@1 | 82 | } |
duke@1 | 83 | |
duke@1 | 84 | /** |
bpatel@766 | 85 | * Add the member information for the unicode character along with the |
duke@1 | 86 | * list of the members. |
duke@1 | 87 | * |
bpatel@766 | 88 | * @param unicode Unicode for which member list information to be generated |
bpatel@766 | 89 | * @param memberlist List of members for the unicode character |
bpatel@766 | 90 | * @param contentTree the content tree to which the information will be added |
duke@1 | 91 | */ |
bpatel@2101 | 92 | protected void addContents(Character uc, List<? extends Doc> memberlist, |
bpatel@766 | 93 | Content contentTree) { |
bpatel@2101 | 94 | String unicode = uc.toString(); |
bpatel@2101 | 95 | contentTree.addContent(getMarkerAnchorForIndex(unicode)); |
bpatel@2101 | 96 | Content headContent = new StringContent(unicode); |
bpatel@766 | 97 | Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, false, |
bpatel@766 | 98 | HtmlStyle.title, headContent); |
bpatel@766 | 99 | contentTree.addContent(heading); |
bpatel@233 | 100 | int memberListSize = memberlist.size(); |
bpatel@233 | 101 | // Display the list only if there are elements to be displayed. |
bpatel@233 | 102 | if (memberListSize > 0) { |
bpatel@766 | 103 | Content dl = new HtmlTree(HtmlTag.DL); |
bpatel@233 | 104 | for (int i = 0; i < memberListSize; i++) { |
bpatel@233 | 105 | Doc element = memberlist.get(i); |
bpatel@233 | 106 | if (element instanceof MemberDoc) { |
bpatel@766 | 107 | addDescription((MemberDoc)element, dl); |
bpatel@233 | 108 | } else if (element instanceof ClassDoc) { |
bpatel@766 | 109 | addDescription((ClassDoc)element, dl); |
bpatel@233 | 110 | } else if (element instanceof PackageDoc) { |
bpatel@766 | 111 | addDescription((PackageDoc)element, dl); |
bpatel@233 | 112 | } |
duke@1 | 113 | } |
bpatel@766 | 114 | contentTree.addContent(dl); |
duke@1 | 115 | } |
duke@1 | 116 | } |
duke@1 | 117 | |
duke@1 | 118 | /** |
bpatel@766 | 119 | * Add one line summary comment for the package. |
duke@1 | 120 | * |
bpatel@766 | 121 | * @param pkg the package to be documented |
bpatel@766 | 122 | * @param dlTree the content tree to which the description will be added |
duke@1 | 123 | */ |
bpatel@766 | 124 | protected void addDescription(PackageDoc pkg, Content dlTree) { |
bpatel@766 | 125 | Content link = getPackageLink(pkg, new StringContent(Util.getPackageName(pkg))); |
bpatel@766 | 126 | Content dt = HtmlTree.DT(link); |
bpatel@766 | 127 | dt.addContent(" - "); |
bpatel@766 | 128 | dt.addContent(getResource("doclet.package")); |
bpatel@766 | 129 | dt.addContent(" " + pkg.name()); |
bpatel@766 | 130 | dlTree.addContent(dt); |
bpatel@766 | 131 | Content dd = new HtmlTree(HtmlTag.DD); |
bpatel@766 | 132 | addSummaryComment(pkg, dd); |
bpatel@766 | 133 | dlTree.addContent(dd); |
duke@1 | 134 | } |
duke@1 | 135 | |
duke@1 | 136 | /** |
bpatel@766 | 137 | * Add one line summary comment for the class. |
bpatel@766 | 138 | * |
bpatel@766 | 139 | * @param cd the class being documented |
bpatel@766 | 140 | * @param dlTree the content tree to which the description will be added |
bpatel@766 | 141 | */ |
bpatel@766 | 142 | protected void addDescription(ClassDoc cd, Content dlTree) { |
jjg@1736 | 143 | Content link = getLink(new LinkInfoImpl(configuration, |
jjg@1738 | 144 | LinkInfoImpl.Kind.INDEX, cd).strong(true)); |
bpatel@766 | 145 | Content dt = HtmlTree.DT(link); |
bpatel@766 | 146 | dt.addContent(" - "); |
bpatel@766 | 147 | addClassInfo(cd, dt); |
bpatel@766 | 148 | dlTree.addContent(dt); |
bpatel@766 | 149 | Content dd = new HtmlTree(HtmlTag.DD); |
bpatel@766 | 150 | addComment(cd, dd); |
bpatel@766 | 151 | dlTree.addContent(dd); |
bpatel@766 | 152 | } |
bpatel@766 | 153 | |
bpatel@766 | 154 | /** |
jjg@1735 | 155 | * Add the classkind (class, interface, exception), error of the class |
duke@1 | 156 | * passed. |
duke@1 | 157 | * |
bpatel@766 | 158 | * @param cd the class being documented |
bpatel@766 | 159 | * @param contentTree the content tree to which the class info will be added |
duke@1 | 160 | */ |
bpatel@766 | 161 | protected void addClassInfo(ClassDoc cd, Content contentTree) { |
bpatel@766 | 162 | contentTree.addContent(getResource("doclet.in", |
bpatel@766 | 163 | Util.getTypeName(configuration, cd, false), |
jjg@1740 | 164 | getPackageLink(cd.containingPackage(), |
jjg@1740 | 165 | Util.getPackageName(cd.containingPackage())) |
jjg@1740 | 166 | )); |
duke@1 | 167 | } |
duke@1 | 168 | |
duke@1 | 169 | /** |
bpatel@766 | 170 | * Add description for Class, Field, Method or Constructor. |
duke@1 | 171 | * |
bpatel@766 | 172 | * @param member MemberDoc for the member of the Class Kind |
bpatel@766 | 173 | * @param dlTree the content tree to which the description will be added |
duke@1 | 174 | */ |
bpatel@766 | 175 | protected void addDescription(MemberDoc member, Content dlTree) { |
duke@1 | 176 | String name = (member instanceof ExecutableMemberDoc)? |
duke@1 | 177 | member.name() + ((ExecutableMemberDoc)member).flatSignature() : |
duke@1 | 178 | member.name(); |
bpatel@2147 | 179 | Content span = HtmlTree.SPAN(HtmlStyle.memberNameLink, |
jjg@1735 | 180 | getDocLink(LinkInfoImpl.Kind.INDEX, member, name)); |
bpatel@766 | 181 | Content dt = HtmlTree.DT(span); |
bpatel@766 | 182 | dt.addContent(" - "); |
bpatel@766 | 183 | addMemberDesc(member, dt); |
bpatel@766 | 184 | dlTree.addContent(dt); |
bpatel@766 | 185 | Content dd = new HtmlTree(HtmlTag.DD); |
bpatel@766 | 186 | addComment(member, dd); |
bpatel@766 | 187 | dlTree.addContent(dd); |
duke@1 | 188 | } |
duke@1 | 189 | |
duke@1 | 190 | /** |
bpatel@766 | 191 | * Add comment for each element in the index. If the element is deprecated |
duke@1 | 192 | * and it has a @deprecated tag, use that comment. Else if the containing |
duke@1 | 193 | * class for this element is deprecated, then add the word "Deprecated." at |
duke@1 | 194 | * the start and then print the normal comment. |
duke@1 | 195 | * |
bpatel@766 | 196 | * @param element Index element |
bpatel@766 | 197 | * @param contentTree the content tree to which the comment will be added |
duke@1 | 198 | */ |
bpatel@766 | 199 | protected void addComment(ProgramElementDoc element, Content contentTree) { |
duke@1 | 200 | Tag[] tags; |
bpatel@2147 | 201 | Content span = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, deprecatedPhrase); |
bpatel@766 | 202 | HtmlTree div = new HtmlTree(HtmlTag.DIV); |
bpatel@766 | 203 | div.addStyle(HtmlStyle.block); |
duke@1 | 204 | if (Util.isDeprecated(element)) { |
bpatel@766 | 205 | div.addContent(span); |
duke@1 | 206 | if ((tags = element.tags("deprecated")).length > 0) |
bpatel@766 | 207 | addInlineDeprecatedComment(element, tags[0], div); |
bpatel@766 | 208 | contentTree.addContent(div); |
duke@1 | 209 | } else { |
duke@1 | 210 | ClassDoc cont = element.containingClass(); |
duke@1 | 211 | while (cont != null) { |
duke@1 | 212 | if (Util.isDeprecated(cont)) { |
bpatel@766 | 213 | div.addContent(span); |
bpatel@766 | 214 | contentTree.addContent(div); |
duke@1 | 215 | break; |
duke@1 | 216 | } |
duke@1 | 217 | cont = cont.containingClass(); |
duke@1 | 218 | } |
bpatel@766 | 219 | addSummaryComment(element, contentTree); |
duke@1 | 220 | } |
duke@1 | 221 | } |
duke@1 | 222 | |
duke@1 | 223 | /** |
bpatel@766 | 224 | * Add description about the Static Varible/Method/Constructor for a |
duke@1 | 225 | * member. |
duke@1 | 226 | * |
bpatel@766 | 227 | * @param member MemberDoc for the member within the Class Kind |
bpatel@766 | 228 | * @param contentTree the content tree to which the member description will be added |
duke@1 | 229 | */ |
bpatel@766 | 230 | protected void addMemberDesc(MemberDoc member, Content contentTree) { |
duke@1 | 231 | ClassDoc containing = member.containingClass(); |
bpatel@766 | 232 | String classdesc = Util.getTypeName( |
bpatel@766 | 233 | configuration, containing, true) + " "; |
duke@1 | 234 | if (member.isField()) { |
duke@1 | 235 | if (member.isStatic()) { |
bpatel@766 | 236 | contentTree.addContent( |
bpatel@766 | 237 | getResource("doclet.Static_variable_in", classdesc)); |
duke@1 | 238 | } else { |
bpatel@766 | 239 | contentTree.addContent( |
bpatel@766 | 240 | getResource("doclet.Variable_in", classdesc)); |
duke@1 | 241 | } |
duke@1 | 242 | } else if (member.isConstructor()) { |
bpatel@766 | 243 | contentTree.addContent( |
bpatel@766 | 244 | getResource("doclet.Constructor_for", classdesc)); |
duke@1 | 245 | } else if (member.isMethod()) { |
duke@1 | 246 | if (member.isStatic()) { |
bpatel@766 | 247 | contentTree.addContent( |
bpatel@766 | 248 | getResource("doclet.Static_method_in", classdesc)); |
duke@1 | 249 | } else { |
bpatel@766 | 250 | contentTree.addContent( |
bpatel@766 | 251 | getResource("doclet.Method_in", classdesc)); |
duke@1 | 252 | } |
duke@1 | 253 | } |
jjg@1735 | 254 | addPreQualifiedClassLink(LinkInfoImpl.Kind.INDEX, containing, |
bpatel@766 | 255 | false, contentTree); |
duke@1 | 256 | } |
bpatel@2101 | 257 | |
bpatel@2101 | 258 | /** |
bpatel@2101 | 259 | * Get the marker anchor which will be added to the index documentation tree. |
bpatel@2101 | 260 | * |
bpatel@2101 | 261 | * @param anchorNameForIndex the anchor name attribute for index page |
bpatel@2101 | 262 | * @return a content tree for the marker anchor |
bpatel@2101 | 263 | */ |
bpatel@2101 | 264 | public Content getMarkerAnchorForIndex(String anchorNameForIndex) { |
bpatel@2101 | 265 | return getMarkerAnchor(getNameForIndex(anchorNameForIndex), null); |
bpatel@2101 | 266 | } |
bpatel@2101 | 267 | |
bpatel@2101 | 268 | /** |
bpatel@2101 | 269 | * Generate a valid HTML name for member index page. |
bpatel@2101 | 270 | * |
bpatel@2101 | 271 | * @param unicode the string that needs to be converted to valid HTML name. |
bpatel@2101 | 272 | * @return a valid HTML name string. |
bpatel@2101 | 273 | */ |
bpatel@2101 | 274 | public String getNameForIndex(String unicode) { |
bpatel@2101 | 275 | return "I:" + getName(unicode); |
bpatel@2101 | 276 | } |
duke@1 | 277 | } |