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

     1 /*
     2  * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.doclets.formats.html;
    28 import com.sun.javadoc.*;
    29 import com.sun.tools.doclets.internal.toolkit.*;
    30 import com.sun.tools.doclets.internal.toolkit.util.*;
    31 import com.sun.tools.doclets.internal.toolkit.util.links.*;
    33 /**
    34  * A factory that returns a link given the information about it.
    35  *
    36  *  <p><b>This is NOT part of any supported API.
    37  *  If you write code that depends on this, you do so at your own risk.
    38  *  This code and its internal interfaces are subject to change or
    39  *  deletion without notice.</b>
    40  *
    41  * @author Jamie Ho
    42  * @since 1.5
    43  */
    44 public class LinkFactoryImpl extends LinkFactory {
    46     private HtmlDocletWriter m_writer;
    48     public LinkFactoryImpl(HtmlDocletWriter writer) {
    49         m_writer = writer;
    50     }
    52     /**
    53      * {@inheritDoc}
    54      */
    55     protected LinkOutput getOutputInstance() {
    56         return new LinkOutputImpl();
    57     }
    59     /**
    60      * {@inheritDoc}
    61      */
    62     protected LinkOutput getClassLink(LinkInfo linkInfo) {
    63         LinkInfoImpl classLinkInfo = (LinkInfoImpl) linkInfo;
    64         boolean noLabel = linkInfo.label == null || linkInfo.label.length() == 0;
    65         ClassDoc classDoc = classLinkInfo.classDoc;
    66         //Create a tool tip if we are linking to a class or interface.  Don't
    67         //create one if we are linking to a member.
    68         String title =
    69             (classLinkInfo.where == null || classLinkInfo.where.length() == 0) ?
    70                 getClassToolTip(classDoc,
    71                     classLinkInfo.type != null &&
    72                     !classDoc.qualifiedTypeName().equals(classLinkInfo.type.qualifiedTypeName())) :
    73             "";
    74         StringBuilder label = new StringBuilder(
    75             classLinkInfo.getClassLinkLabel(m_writer.configuration));
    76         classLinkInfo.displayLength += label.length();
    77         Configuration configuration = m_writer.configuration;
    78         LinkOutputImpl linkOutput = new LinkOutputImpl();
    79         if (classDoc.isIncluded()) {
    80             if (configuration.isGeneratedDoc(classDoc)) {
    81                 DocPath filename = getPath(classLinkInfo);
    82                 if (linkInfo.linkToSelf ||
    83                                 !(DocPath.forName(classDoc)).equals(m_writer.filename)) {
    84                         linkOutput.append(m_writer.getHyperLinkString(
    85                                 filename.fragment(classLinkInfo.where),
    86                             label.toString(),
    87                             classLinkInfo.isStrong, classLinkInfo.styleName,
    88                             title, classLinkInfo.target));
    89                         if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
    90                             linkOutput.append(getTypeParameterLinks(linkInfo).toString());
    91                         }
    92                         return linkOutput;
    93                 }
    94             }
    95         } else {
    96             String crossLink = m_writer.getCrossClassLink(
    97                 classDoc.qualifiedName(), classLinkInfo.where,
    98                 label.toString(), classLinkInfo.isStrong, classLinkInfo.styleName,
    99                 true);
   100             if (crossLink != null) {
   101                 linkOutput.append(crossLink);
   102                 if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
   103                     linkOutput.append(getTypeParameterLinks(linkInfo).toString());
   104                 }
   105                 return linkOutput;
   106             }
   107         }
   108         // Can't link so just write label.
   109         linkOutput.append(label.toString());
   110         if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
   111             linkOutput.append(getTypeParameterLinks(linkInfo).toString());
   112         }
   113         return linkOutput;
   114     }
   116     /**
   117      * {@inheritDoc}
   118      */
   119     protected LinkOutput getTypeParameterLink(LinkInfo linkInfo,
   120         Type typeParam) {
   121         LinkInfoImpl typeLinkInfo = new LinkInfoImpl(m_writer.configuration,
   122                 linkInfo.getContext(), typeParam);
   123         typeLinkInfo.excludeTypeBounds = linkInfo.excludeTypeBounds;
   124         typeLinkInfo.excludeTypeParameterLinks = linkInfo.excludeTypeParameterLinks;
   125         typeLinkInfo.linkToSelf = linkInfo.linkToSelf;
   126         LinkOutput output = getLinkOutput(typeLinkInfo);
   127         ((LinkInfoImpl) linkInfo).displayLength += typeLinkInfo.displayLength;
   128         return output;
   129     }
   131     /**
   132      * Given a class, return the appropriate tool tip.
   133      *
   134      * @param classDoc the class to get the tool tip for.
   135      * @return the tool tip for the appropriate class.
   136      */
   137     private String getClassToolTip(ClassDoc classDoc, boolean isTypeLink) {
   138         Configuration configuration = m_writer.configuration;
   139         if (isTypeLink) {
   140             return configuration.getText("doclet.Href_Type_Param_Title",
   141                 classDoc.name());
   142         } else if (classDoc.isInterface()){
   143             return configuration.getText("doclet.Href_Interface_Title",
   144                 Util.getPackageName(classDoc.containingPackage()));
   145         } else if (classDoc.isAnnotationType()) {
   146             return configuration.getText("doclet.Href_Annotation_Title",
   147                 Util.getPackageName(classDoc.containingPackage()));
   148         } else if (classDoc.isEnum()) {
   149             return configuration.getText("doclet.Href_Enum_Title",
   150                 Util.getPackageName(classDoc.containingPackage()));
   151         } else {
   152             return configuration.getText("doclet.Href_Class_Title",
   153                 Util.getPackageName(classDoc.containingPackage()));
   154         }
   155     }
   157     /**
   158      * Return path to the given file name in the given package. So if the name
   159      * passed is "Object.html" and the name of the package is "java.lang", and
   160      * if the relative path is "../.." then returned string will be
   161      * "../../java/lang/Object.html"
   162      *
   163      * @param linkInfo the information about the link.
   164      */
   165     private DocPath getPath(LinkInfoImpl linkInfo) {
   166         if (linkInfo.context == LinkInfoImpl.PACKAGE_FRAME) {
   167             //Not really necessary to do this but we want to be consistent
   168             //with 1.4.2 output.
   169             return DocPath.forName(linkInfo.classDoc);
   170         }
   171         return m_writer.pathToRoot.resolve(DocPath.forClass(linkInfo.classDoc));
   172     }
   173 }

mercurial