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

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

author
jjg
date
Tue, 14 May 2013 10:14:51 -0700
changeset 1735
8ea30d59ac41
parent 1691
f10cffab99b4
child 1736
74cd21f2c2fe
permissions
-rw-r--r--

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

mercurial