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

Tue, 14 May 2013 10:14:55 -0700

author
jjg
date
Tue, 14 May 2013 10:14:55 -0700
changeset 1745
937aa020c667
parent 1741
4c43e51433ba
child 1746
bd51ca92c013
permissions
-rw-r--r--

8012177: HTMLDocletWriter methods should generate Content, not Strings
Reviewed-by: darcy

duke@1 1 /*
jjg@1521 2 * Copyright (c) 2003, 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
jjg@1521 28 import java.util.List;
jjg@1521 29
duke@1 30 import com.sun.javadoc.*;
jjg@1736 31 import com.sun.tools.doclets.formats.html.markup.ContentBuilder;
jjg@1736 32 import com.sun.tools.doclets.formats.html.markup.RawHtml;
jjg@1737 33 import com.sun.tools.doclets.formats.html.markup.StringContent;
duke@1 34 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 35 import com.sun.tools.doclets.internal.toolkit.util.*;
jjg@1357 36 import com.sun.tools.doclets.internal.toolkit.util.links.*;
duke@1 37
duke@1 38 /**
duke@1 39 * A factory that returns a link given the information about it.
duke@1 40 *
jjg@1359 41 * <p><b>This is NOT part of any supported API.
jjg@1359 42 * If you write code that depends on this, you do so at your own risk.
jjg@1359 43 * This code and its internal interfaces are subject to change or
jjg@1359 44 * deletion without notice.</b>
jjg@1359 45 *
duke@1 46 * @author Jamie Ho
duke@1 47 * @since 1.5
duke@1 48 */
duke@1 49 public class LinkFactoryImpl extends LinkFactory {
duke@1 50
duke@1 51 private HtmlDocletWriter m_writer;
duke@1 52
duke@1 53 public LinkFactoryImpl(HtmlDocletWriter writer) {
duke@1 54 m_writer = writer;
duke@1 55 }
duke@1 56
duke@1 57 /**
duke@1 58 * {@inheritDoc}
duke@1 59 */
jjg@1736 60 protected Content newContent() {
jjg@1736 61 return new ContentBuilder();
duke@1 62 }
duke@1 63
duke@1 64 /**
duke@1 65 * {@inheritDoc}
duke@1 66 */
jjg@1736 67 protected Content getClassLink(LinkInfo linkInfo) {
duke@1 68 LinkInfoImpl classLinkInfo = (LinkInfoImpl) linkInfo;
jjg@1737 69 boolean noLabel = linkInfo.label == null || linkInfo.label.isEmpty();
duke@1 70 ClassDoc classDoc = classLinkInfo.classDoc;
duke@1 71 //Create a tool tip if we are linking to a class or interface. Don't
duke@1 72 //create one if we are linking to a member.
duke@1 73 String title =
duke@1 74 (classLinkInfo.where == null || classLinkInfo.where.length() == 0) ?
duke@1 75 getClassToolTip(classDoc,
duke@1 76 classLinkInfo.type != null &&
duke@1 77 !classDoc.qualifiedTypeName().equals(classLinkInfo.type.qualifiedTypeName())) :
duke@1 78 "";
jjg@1737 79 Content label = classLinkInfo.getClassLinkLabel(m_writer.configuration);
jjg@1410 80 Configuration configuration = m_writer.configuration;
jjg@1736 81 Content link = new ContentBuilder();
duke@1 82 if (classDoc.isIncluded()) {
duke@1 83 if (configuration.isGeneratedDoc(classDoc)) {
jjg@1372 84 DocPath filename = getPath(classLinkInfo);
duke@1 85 if (linkInfo.linkToSelf ||
jjg@1372 86 !(DocPath.forName(classDoc)).equals(m_writer.filename)) {
jjg@1737 87 link.addContent(m_writer.getHyperLink(
jjg@1373 88 filename.fragment(classLinkInfo.where),
jjg@1737 89 label,
bpatel@182 90 classLinkInfo.isStrong, classLinkInfo.styleName,
jjg@1737 91 title, classLinkInfo.target));
duke@1 92 if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
jjg@1736 93 link.addContent(getTypeParameterLinks(linkInfo));
duke@1 94 }
jjg@1736 95 return link;
duke@1 96 }
duke@1 97 }
duke@1 98 } else {
jjg@1737 99 Content crossLink = m_writer.getCrossClassLink(
duke@1 100 classDoc.qualifiedName(), classLinkInfo.where,
jjg@1737 101 label, classLinkInfo.isStrong, classLinkInfo.styleName,
duke@1 102 true);
duke@1 103 if (crossLink != null) {
jjg@1737 104 link.addContent(crossLink);
duke@1 105 if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
jjg@1736 106 link.addContent(getTypeParameterLinks(linkInfo));
duke@1 107 }
jjg@1736 108 return link;
duke@1 109 }
duke@1 110 }
duke@1 111 // Can't link so just write label.
jjg@1737 112 link.addContent(label.toString());
duke@1 113 if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
jjg@1736 114 link.addContent(getTypeParameterLinks(linkInfo));
duke@1 115 }
jjg@1736 116 return link;
duke@1 117 }
duke@1 118
duke@1 119 /**
duke@1 120 * {@inheritDoc}
duke@1 121 */
jjg@1736 122 protected Content getTypeParameterLink(LinkInfo linkInfo,
duke@1 123 Type typeParam) {
jjg@1410 124 LinkInfoImpl typeLinkInfo = new LinkInfoImpl(m_writer.configuration,
jjg@1735 125 ((LinkInfoImpl) linkInfo).getContext(), typeParam);
duke@1 126 typeLinkInfo.excludeTypeBounds = linkInfo.excludeTypeBounds;
duke@1 127 typeLinkInfo.excludeTypeParameterLinks = linkInfo.excludeTypeParameterLinks;
duke@1 128 typeLinkInfo.linkToSelf = linkInfo.linkToSelf;
jjg@1521 129 typeLinkInfo.isJava5DeclarationLocation = false;
jjg@1741 130 return getLink(typeLinkInfo);
duke@1 131 }
duke@1 132
jjg@1736 133 protected Content getTypeAnnotationLink(LinkInfo linkInfo,
jjg@1521 134 AnnotationDesc annotation) {
jjg@1521 135 throw new RuntimeException("Not implemented yet!");
jjg@1521 136 }
jjg@1521 137
jjg@1736 138 public Content getTypeAnnotationLinks(LinkInfo linkInfo) {
jjg@1736 139 ContentBuilder links = new ContentBuilder();
jjg@1521 140 AnnotationDesc[] annotations;
jjg@1521 141 if (linkInfo.type instanceof AnnotatedType) {
jjg@1521 142 annotations = linkInfo.type.asAnnotatedType().annotations();
jjg@1521 143 } else if (linkInfo.type instanceof TypeVariable) {
jjg@1521 144 annotations = linkInfo.type.asTypeVariable().annotations();
jjg@1521 145 } else {
jjg@1736 146 return links;
jjg@1521 147 }
jjg@1521 148
jjg@1521 149 if (annotations.length == 0)
jjg@1736 150 return links;
jjg@1521 151
jjg@1521 152 List<String> annos = m_writer.getAnnotations(0, annotations, false, linkInfo.isJava5DeclarationLocation);
jjg@1521 153
jjg@1521 154 boolean isFirst = true;
jjg@1521 155 for (String anno : annos) {
jjg@1521 156 if (!isFirst) {
jjg@1736 157 links.addContent(" ");
jjg@1521 158 }
jjg@1736 159 links.addContent(new RawHtml(anno));
bpatel@1691 160 isFirst = false;
jjg@1521 161 }
jjg@1521 162 if (!annos.isEmpty()) {
jjg@1736 163 links.addContent(" ");
jjg@1521 164 }
jjg@1521 165
jjg@1736 166 return links;
jjg@1521 167 }
jjg@1521 168
duke@1 169 /**
duke@1 170 * Given a class, return the appropriate tool tip.
duke@1 171 *
duke@1 172 * @param classDoc the class to get the tool tip for.
duke@1 173 * @return the tool tip for the appropriate class.
duke@1 174 */
duke@1 175 private String getClassToolTip(ClassDoc classDoc, boolean isTypeLink) {
jjg@1410 176 Configuration configuration = m_writer.configuration;
duke@1 177 if (isTypeLink) {
duke@1 178 return configuration.getText("doclet.Href_Type_Param_Title",
jjg@1410 179 classDoc.name());
duke@1 180 } else if (classDoc.isInterface()){
duke@1 181 return configuration.getText("doclet.Href_Interface_Title",
jjg@1736 182 Util.escapeHtmlChars(Util.getPackageName(classDoc.containingPackage())));
duke@1 183 } else if (classDoc.isAnnotationType()) {
duke@1 184 return configuration.getText("doclet.Href_Annotation_Title",
jjg@1736 185 Util.escapeHtmlChars(Util.getPackageName(classDoc.containingPackage())));
duke@1 186 } else if (classDoc.isEnum()) {
duke@1 187 return configuration.getText("doclet.Href_Enum_Title",
jjg@1736 188 Util.escapeHtmlChars(Util.getPackageName(classDoc.containingPackage())));
duke@1 189 } else {
duke@1 190 return configuration.getText("doclet.Href_Class_Title",
jjg@1736 191 Util.escapeHtmlChars(Util.getPackageName(classDoc.containingPackage())));
duke@1 192 }
duke@1 193 }
duke@1 194
duke@1 195 /**
duke@1 196 * Return path to the given file name in the given package. So if the name
duke@1 197 * passed is "Object.html" and the name of the package is "java.lang", and
duke@1 198 * if the relative path is "../.." then returned string will be
duke@1 199 * "../../java/lang/Object.html"
duke@1 200 *
duke@1 201 * @param linkInfo the information about the link.
duke@1 202 */
jjg@1372 203 private DocPath getPath(LinkInfoImpl linkInfo) {
jjg@1735 204 if (linkInfo.context == LinkInfoImpl.Kind.PACKAGE_FRAME) {
duke@1 205 //Not really necessary to do this but we want to be consistent
duke@1 206 //with 1.4.2 output.
jjg@1372 207 return DocPath.forName(linkInfo.classDoc);
duke@1 208 }
jjg@1372 209 return m_writer.pathToRoot.resolve(DocPath.forClass(linkInfo.classDoc));
duke@1 210 }
duke@1 211 }

mercurial