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

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 798
4868a36f6fd8
child 1359
25e14ad23cef
permissions
-rw-r--r--

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

mercurial