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

Wed, 18 Sep 2013 17:13:26 -0700

author
bpatel
date
Wed, 18 Sep 2013 17:13:26 -0700
changeset 2035
a2a5ad0853ed
parent 1740
ce4f0769b4b2
child 2101
933ba3f81a87
permissions
-rw-r--r--

8015249: javadoc fails to document static final fields in annotation types
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@766 92 protected void addContents(Character unicode, List<? extends Doc> memberlist,
bpatel@766 93 Content contentTree) {
bpatel@766 94 contentTree.addContent(getMarkerAnchor("_" + unicode + "_"));
bpatel@766 95 Content headContent = new StringContent(unicode.toString());
bpatel@766 96 Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, false,
bpatel@766 97 HtmlStyle.title, headContent);
bpatel@766 98 contentTree.addContent(heading);
bpatel@233 99 int memberListSize = memberlist.size();
bpatel@233 100 // Display the list only if there are elements to be displayed.
bpatel@233 101 if (memberListSize > 0) {
bpatel@766 102 Content dl = new HtmlTree(HtmlTag.DL);
bpatel@233 103 for (int i = 0; i < memberListSize; i++) {
bpatel@233 104 Doc element = memberlist.get(i);
bpatel@233 105 if (element instanceof MemberDoc) {
bpatel@766 106 addDescription((MemberDoc)element, dl);
bpatel@233 107 } else if (element instanceof ClassDoc) {
bpatel@766 108 addDescription((ClassDoc)element, dl);
bpatel@233 109 } else if (element instanceof PackageDoc) {
bpatel@766 110 addDescription((PackageDoc)element, dl);
bpatel@233 111 }
duke@1 112 }
bpatel@766 113 contentTree.addContent(dl);
duke@1 114 }
duke@1 115 }
duke@1 116
duke@1 117 /**
bpatel@766 118 * Add one line summary comment for the package.
duke@1 119 *
bpatel@766 120 * @param pkg the package to be documented
bpatel@766 121 * @param dlTree the content tree to which the description will be added
duke@1 122 */
bpatel@766 123 protected void addDescription(PackageDoc pkg, Content dlTree) {
bpatel@766 124 Content link = getPackageLink(pkg, new StringContent(Util.getPackageName(pkg)));
bpatel@766 125 Content dt = HtmlTree.DT(link);
bpatel@766 126 dt.addContent(" - ");
bpatel@766 127 dt.addContent(getResource("doclet.package"));
bpatel@766 128 dt.addContent(" " + pkg.name());
bpatel@766 129 dlTree.addContent(dt);
bpatel@766 130 Content dd = new HtmlTree(HtmlTag.DD);
bpatel@766 131 addSummaryComment(pkg, dd);
bpatel@766 132 dlTree.addContent(dd);
duke@1 133 }
duke@1 134
duke@1 135 /**
bpatel@766 136 * Add one line summary comment for the class.
bpatel@766 137 *
bpatel@766 138 * @param cd the class being documented
bpatel@766 139 * @param dlTree the content tree to which the description will be added
bpatel@766 140 */
bpatel@766 141 protected void addDescription(ClassDoc cd, Content dlTree) {
jjg@1736 142 Content link = getLink(new LinkInfoImpl(configuration,
jjg@1738 143 LinkInfoImpl.Kind.INDEX, cd).strong(true));
bpatel@766 144 Content dt = HtmlTree.DT(link);
bpatel@766 145 dt.addContent(" - ");
bpatel@766 146 addClassInfo(cd, dt);
bpatel@766 147 dlTree.addContent(dt);
bpatel@766 148 Content dd = new HtmlTree(HtmlTag.DD);
bpatel@766 149 addComment(cd, dd);
bpatel@766 150 dlTree.addContent(dd);
bpatel@766 151 }
bpatel@766 152
bpatel@766 153 /**
jjg@1735 154 * Add the classkind (class, interface, exception), error of the class
duke@1 155 * passed.
duke@1 156 *
bpatel@766 157 * @param cd the class being documented
bpatel@766 158 * @param contentTree the content tree to which the class info will be added
duke@1 159 */
bpatel@766 160 protected void addClassInfo(ClassDoc cd, Content contentTree) {
bpatel@766 161 contentTree.addContent(getResource("doclet.in",
bpatel@766 162 Util.getTypeName(configuration, cd, false),
jjg@1740 163 getPackageLink(cd.containingPackage(),
jjg@1740 164 Util.getPackageName(cd.containingPackage()))
jjg@1740 165 ));
duke@1 166 }
duke@1 167
duke@1 168 /**
bpatel@766 169 * Add description for Class, Field, Method or Constructor.
duke@1 170 *
bpatel@766 171 * @param member MemberDoc for the member of the Class Kind
bpatel@766 172 * @param dlTree the content tree to which the description will be added
duke@1 173 */
bpatel@766 174 protected void addDescription(MemberDoc member, Content dlTree) {
duke@1 175 String name = (member instanceof ExecutableMemberDoc)?
duke@1 176 member.name() + ((ExecutableMemberDoc)member).flatSignature() :
duke@1 177 member.name();
bpatel@766 178 Content span = HtmlTree.SPAN(HtmlStyle.strong,
jjg@1735 179 getDocLink(LinkInfoImpl.Kind.INDEX, member, name));
bpatel@766 180 Content dt = HtmlTree.DT(span);
bpatel@766 181 dt.addContent(" - ");
bpatel@766 182 addMemberDesc(member, dt);
bpatel@766 183 dlTree.addContent(dt);
bpatel@766 184 Content dd = new HtmlTree(HtmlTag.DD);
bpatel@766 185 addComment(member, dd);
bpatel@766 186 dlTree.addContent(dd);
duke@1 187 }
duke@1 188
duke@1 189 /**
bpatel@766 190 * Add comment for each element in the index. If the element is deprecated
duke@1 191 * and it has a @deprecated tag, use that comment. Else if the containing
duke@1 192 * class for this element is deprecated, then add the word "Deprecated." at
duke@1 193 * the start and then print the normal comment.
duke@1 194 *
bpatel@766 195 * @param element Index element
bpatel@766 196 * @param contentTree the content tree to which the comment will be added
duke@1 197 */
bpatel@766 198 protected void addComment(ProgramElementDoc element, Content contentTree) {
duke@1 199 Tag[] tags;
bpatel@766 200 Content span = HtmlTree.SPAN(HtmlStyle.strong, deprecatedPhrase);
bpatel@766 201 HtmlTree div = new HtmlTree(HtmlTag.DIV);
bpatel@766 202 div.addStyle(HtmlStyle.block);
duke@1 203 if (Util.isDeprecated(element)) {
bpatel@766 204 div.addContent(span);
duke@1 205 if ((tags = element.tags("deprecated")).length > 0)
bpatel@766 206 addInlineDeprecatedComment(element, tags[0], div);
bpatel@766 207 contentTree.addContent(div);
duke@1 208 } else {
duke@1 209 ClassDoc cont = element.containingClass();
duke@1 210 while (cont != null) {
duke@1 211 if (Util.isDeprecated(cont)) {
bpatel@766 212 div.addContent(span);
bpatel@766 213 contentTree.addContent(div);
duke@1 214 break;
duke@1 215 }
duke@1 216 cont = cont.containingClass();
duke@1 217 }
bpatel@766 218 addSummaryComment(element, contentTree);
duke@1 219 }
duke@1 220 }
duke@1 221
duke@1 222 /**
bpatel@766 223 * Add description about the Static Varible/Method/Constructor for a
duke@1 224 * member.
duke@1 225 *
bpatel@766 226 * @param member MemberDoc for the member within the Class Kind
bpatel@766 227 * @param contentTree the content tree to which the member description will be added
duke@1 228 */
bpatel@766 229 protected void addMemberDesc(MemberDoc member, Content contentTree) {
duke@1 230 ClassDoc containing = member.containingClass();
bpatel@766 231 String classdesc = Util.getTypeName(
bpatel@766 232 configuration, containing, true) + " ";
duke@1 233 if (member.isField()) {
duke@1 234 if (member.isStatic()) {
bpatel@766 235 contentTree.addContent(
bpatel@766 236 getResource("doclet.Static_variable_in", classdesc));
duke@1 237 } else {
bpatel@766 238 contentTree.addContent(
bpatel@766 239 getResource("doclet.Variable_in", classdesc));
duke@1 240 }
duke@1 241 } else if (member.isConstructor()) {
bpatel@766 242 contentTree.addContent(
bpatel@766 243 getResource("doclet.Constructor_for", classdesc));
duke@1 244 } else if (member.isMethod()) {
duke@1 245 if (member.isStatic()) {
bpatel@766 246 contentTree.addContent(
bpatel@766 247 getResource("doclet.Static_method_in", classdesc));
duke@1 248 } else {
bpatel@766 249 contentTree.addContent(
bpatel@766 250 getResource("doclet.Method_in", classdesc));
duke@1 251 }
duke@1 252 }
jjg@1735 253 addPreQualifiedClassLink(LinkInfoImpl.Kind.INDEX, containing,
bpatel@766 254 false, contentTree);
duke@1 255 }
duke@1 256 }

mercurial