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

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

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

mercurial