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

Wed, 10 Oct 2012 16:48:21 -0700

author
jjg
date
Wed, 10 Oct 2012 16:48:21 -0700
changeset 1359
25e14ad23cef
parent 1357
c75be5bc5283
child 1372
78962d89f283
permissions
-rw-r--r--

8000665: fix "internal API" comments on javadoc files
Reviewed-by: darcy

duke@1 1 /*
jjg@1357 2 * Copyright (c) 1998, 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.*;
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 /**
duke@1 59 * This constructor will be used by {@link SplitIndexWriter}. Initialises
duke@1 60 * path to this file and relative path from this file.
duke@1 61 *
duke@1 62 * @param path Path to the file which is getting generated.
duke@1 63 * @param filename Name of the file which is getting genrated.
duke@1 64 * @param relpath Relative path from this file to the current directory.
duke@1 65 * @param indexbuilder Unicode based Index from {@link IndexBuilder}
duke@1 66 */
duke@1 67 protected AbstractIndexWriter(ConfigurationImpl configuration,
duke@1 68 String path, String filename,
duke@1 69 String relpath, IndexBuilder indexbuilder)
duke@1 70 throws IOException {
duke@1 71 super(configuration, path, filename, relpath);
duke@1 72 this.indexbuilder = indexbuilder;
duke@1 73 }
duke@1 74
duke@1 75 /**
duke@1 76 * This Constructor will be used by {@link SingleIndexWriter}.
duke@1 77 *
duke@1 78 * @param filename Name of the file which is getting genrated.
duke@1 79 * @param indexbuilder Unicode based Index form {@link IndexBuilder}
duke@1 80 */
duke@1 81 protected AbstractIndexWriter(ConfigurationImpl configuration,
duke@1 82 String filename, IndexBuilder indexbuilder)
duke@1 83 throws IOException {
duke@1 84 super(configuration, filename);
duke@1 85 this.indexbuilder = indexbuilder;
duke@1 86 }
duke@1 87
duke@1 88 /**
bpatel@766 89 * Get the index label for navigation bar.
bpatel@766 90 *
bpatel@766 91 * @return a content tree for the tree label
duke@1 92 */
bpatel@766 93 protected Content getNavLinkIndex() {
bpatel@766 94 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, indexLabel);
bpatel@766 95 return li;
duke@1 96 }
duke@1 97
duke@1 98 /**
bpatel@766 99 * Add the member information for the unicode character along with the
duke@1 100 * list of the members.
duke@1 101 *
bpatel@766 102 * @param unicode Unicode for which member list information to be generated
bpatel@766 103 * @param memberlist List of members for the unicode character
bpatel@766 104 * @param contentTree the content tree to which the information will be added
duke@1 105 */
bpatel@766 106 protected void addContents(Character unicode, List<? extends Doc> memberlist,
bpatel@766 107 Content contentTree) {
bpatel@766 108 contentTree.addContent(getMarkerAnchor("_" + unicode + "_"));
bpatel@766 109 Content headContent = new StringContent(unicode.toString());
bpatel@766 110 Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, false,
bpatel@766 111 HtmlStyle.title, headContent);
bpatel@766 112 contentTree.addContent(heading);
bpatel@233 113 int memberListSize = memberlist.size();
bpatel@233 114 // Display the list only if there are elements to be displayed.
bpatel@233 115 if (memberListSize > 0) {
bpatel@766 116 Content dl = new HtmlTree(HtmlTag.DL);
bpatel@233 117 for (int i = 0; i < memberListSize; i++) {
bpatel@233 118 Doc element = memberlist.get(i);
bpatel@233 119 if (element instanceof MemberDoc) {
bpatel@766 120 addDescription((MemberDoc)element, dl);
bpatel@233 121 } else if (element instanceof ClassDoc) {
bpatel@766 122 addDescription((ClassDoc)element, dl);
bpatel@233 123 } else if (element instanceof PackageDoc) {
bpatel@766 124 addDescription((PackageDoc)element, dl);
bpatel@233 125 }
duke@1 126 }
bpatel@766 127 contentTree.addContent(dl);
duke@1 128 }
duke@1 129 }
duke@1 130
duke@1 131 /**
bpatel@766 132 * Add one line summary comment for the package.
duke@1 133 *
bpatel@766 134 * @param pkg the package to be documented
bpatel@766 135 * @param dlTree the content tree to which the description will be added
duke@1 136 */
bpatel@766 137 protected void addDescription(PackageDoc pkg, Content dlTree) {
bpatel@766 138 Content link = getPackageLink(pkg, new StringContent(Util.getPackageName(pkg)));
bpatel@766 139 Content dt = HtmlTree.DT(link);
bpatel@766 140 dt.addContent(" - ");
bpatel@766 141 dt.addContent(getResource("doclet.package"));
bpatel@766 142 dt.addContent(" " + pkg.name());
bpatel@766 143 dlTree.addContent(dt);
bpatel@766 144 Content dd = new HtmlTree(HtmlTag.DD);
bpatel@766 145 addSummaryComment(pkg, dd);
bpatel@766 146 dlTree.addContent(dd);
duke@1 147 }
duke@1 148
duke@1 149 /**
bpatel@766 150 * Add one line summary comment for the class.
bpatel@766 151 *
bpatel@766 152 * @param cd the class being documented
bpatel@766 153 * @param dlTree the content tree to which the description will be added
bpatel@766 154 */
bpatel@766 155 protected void addDescription(ClassDoc cd, Content dlTree) {
bpatel@766 156 Content link = new RawHtml(
bpatel@766 157 getLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_INDEX, cd, true)));
bpatel@766 158 Content dt = HtmlTree.DT(link);
bpatel@766 159 dt.addContent(" - ");
bpatel@766 160 addClassInfo(cd, dt);
bpatel@766 161 dlTree.addContent(dt);
bpatel@766 162 Content dd = new HtmlTree(HtmlTag.DD);
bpatel@766 163 addComment(cd, dd);
bpatel@766 164 dlTree.addContent(dd);
bpatel@766 165 }
bpatel@766 166
bpatel@766 167 /**
bpatel@766 168 * Add the classkind(class, interface, exception, error of the class
duke@1 169 * passed.
duke@1 170 *
bpatel@766 171 * @param cd the class being documented
bpatel@766 172 * @param contentTree the content tree to which the class info will be added
duke@1 173 */
bpatel@766 174 protected void addClassInfo(ClassDoc cd, Content contentTree) {
bpatel@766 175 contentTree.addContent(getResource("doclet.in",
bpatel@766 176 Util.getTypeName(configuration, cd, false),
bpatel@766 177 getPackageLinkString(cd.containingPackage(),
duke@1 178 Util.getPackageName(cd.containingPackage()), false)));
duke@1 179 }
duke@1 180
duke@1 181 /**
bpatel@766 182 * Add description for Class, Field, Method or Constructor.
duke@1 183 *
bpatel@766 184 * @param member MemberDoc for the member of the Class Kind
bpatel@766 185 * @param dlTree the content tree to which the description will be added
duke@1 186 */
bpatel@766 187 protected void addDescription(MemberDoc member, Content dlTree) {
duke@1 188 String name = (member instanceof ExecutableMemberDoc)?
duke@1 189 member.name() + ((ExecutableMemberDoc)member).flatSignature() :
duke@1 190 member.name();
duke@1 191 if (name.indexOf("<") != -1 || name.indexOf(">") != -1) {
duke@1 192 name = Util.escapeHtmlChars(name);
duke@1 193 }
bpatel@766 194 Content span = HtmlTree.SPAN(HtmlStyle.strong,
bpatel@766 195 getDocLink(LinkInfoImpl.CONTEXT_INDEX, member, name));
bpatel@766 196 Content dt = HtmlTree.DT(span);
bpatel@766 197 dt.addContent(" - ");
bpatel@766 198 addMemberDesc(member, dt);
bpatel@766 199 dlTree.addContent(dt);
bpatel@766 200 Content dd = new HtmlTree(HtmlTag.DD);
bpatel@766 201 addComment(member, dd);
bpatel@766 202 dlTree.addContent(dd);
duke@1 203 }
duke@1 204
duke@1 205 /**
bpatel@766 206 * Add comment for each element in the index. If the element is deprecated
duke@1 207 * and it has a @deprecated tag, use that comment. Else if the containing
duke@1 208 * class for this element is deprecated, then add the word "Deprecated." at
duke@1 209 * the start and then print the normal comment.
duke@1 210 *
bpatel@766 211 * @param element Index element
bpatel@766 212 * @param contentTree the content tree to which the comment will be added
duke@1 213 */
bpatel@766 214 protected void addComment(ProgramElementDoc element, Content contentTree) {
duke@1 215 Tag[] tags;
bpatel@766 216 Content span = HtmlTree.SPAN(HtmlStyle.strong, deprecatedPhrase);
bpatel@766 217 HtmlTree div = new HtmlTree(HtmlTag.DIV);
bpatel@766 218 div.addStyle(HtmlStyle.block);
duke@1 219 if (Util.isDeprecated(element)) {
bpatel@766 220 div.addContent(span);
duke@1 221 if ((tags = element.tags("deprecated")).length > 0)
bpatel@766 222 addInlineDeprecatedComment(element, tags[0], div);
bpatel@766 223 contentTree.addContent(div);
duke@1 224 } else {
duke@1 225 ClassDoc cont = element.containingClass();
duke@1 226 while (cont != null) {
duke@1 227 if (Util.isDeprecated(cont)) {
bpatel@766 228 div.addContent(span);
bpatel@766 229 contentTree.addContent(div);
duke@1 230 break;
duke@1 231 }
duke@1 232 cont = cont.containingClass();
duke@1 233 }
bpatel@766 234 addSummaryComment(element, contentTree);
duke@1 235 }
duke@1 236 }
duke@1 237
duke@1 238 /**
bpatel@766 239 * Add description about the Static Varible/Method/Constructor for a
duke@1 240 * member.
duke@1 241 *
bpatel@766 242 * @param member MemberDoc for the member within the Class Kind
bpatel@766 243 * @param contentTree the content tree to which the member description will be added
duke@1 244 */
bpatel@766 245 protected void addMemberDesc(MemberDoc member, Content contentTree) {
duke@1 246 ClassDoc containing = member.containingClass();
bpatel@766 247 String classdesc = Util.getTypeName(
bpatel@766 248 configuration, containing, true) + " ";
duke@1 249 if (member.isField()) {
duke@1 250 if (member.isStatic()) {
bpatel@766 251 contentTree.addContent(
bpatel@766 252 getResource("doclet.Static_variable_in", classdesc));
duke@1 253 } else {
bpatel@766 254 contentTree.addContent(
bpatel@766 255 getResource("doclet.Variable_in", classdesc));
duke@1 256 }
duke@1 257 } else if (member.isConstructor()) {
bpatel@766 258 contentTree.addContent(
bpatel@766 259 getResource("doclet.Constructor_for", classdesc));
duke@1 260 } else if (member.isMethod()) {
duke@1 261 if (member.isStatic()) {
bpatel@766 262 contentTree.addContent(
bpatel@766 263 getResource("doclet.Static_method_in", classdesc));
duke@1 264 } else {
bpatel@766 265 contentTree.addContent(
bpatel@766 266 getResource("doclet.Method_in", classdesc));
duke@1 267 }
duke@1 268 }
bpatel@766 269 addPreQualifiedClassLink(LinkInfoImpl.CONTEXT_INDEX, containing,
bpatel@766 270 false, contentTree);
duke@1 271 }
duke@1 272 }

mercurial