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

Thu, 15 Nov 2012 19:54:20 -0800

author
jjg
date
Thu, 15 Nov 2012 19:54:20 -0800
changeset 1412
400a4e8accd3
parent 1410
bfec2a1cc869
child 1521
71f35e4b93a5
permissions
-rw-r--r--

8002079: update DocFile to use a JavaFileManager
Reviewed-by: darcy

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

mercurial