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

Wed, 10 Oct 2012 16:48:21 -0700

author
jjg
date
Wed, 10 Oct 2012 16:48:21 -0700
changeset 1359
25e14ad23cef
parent 1358
fc123bdeddb8
child 1362
c46e0c9940d6
permissions
-rw-r--r--

8000665: fix "internal API" comments on javadoc files
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         StringBuffer label = new StringBuffer(
    75             classLinkInfo.getClassLinkLabel(m_writer.configuration));
    76         classLinkInfo.displayLength += label.length();
    77         Configuration configuration = ConfigurationImpl.getInstance();
    78         LinkOutputImpl linkOutput = new LinkOutputImpl();
    79         if (classDoc.isIncluded()) {
    80             if (configuration.isGeneratedDoc(classDoc)) {
    81                 String filename = pathString(classLinkInfo);
    82                 if (linkInfo.linkToSelf ||
    83                                 !(linkInfo.classDoc.name() + ".html").equals(m_writer.filename)) {
    84                         linkOutput.append(m_writer.getHyperLinkString(filename,
    85                             classLinkInfo.where, label.toString(),
    86                             classLinkInfo.isStrong, classLinkInfo.styleName,
    87                             title, classLinkInfo.target));
    88                         if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
    89                             linkOutput.append(getTypeParameterLinks(linkInfo).toString());
    90                         }
    91                         return linkOutput;
    92                 }
    93             }
    94         } else {
    95             String crossLink = m_writer.getCrossClassLink(
    96                 classDoc.qualifiedName(), classLinkInfo.where,
    97                 label.toString(), classLinkInfo.isStrong, classLinkInfo.styleName,
    98                 true);
    99             if (crossLink != null) {
   100                 linkOutput.append(crossLink);
   101                 if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
   102                     linkOutput.append(getTypeParameterLinks(linkInfo).toString());
   103                 }
   104                 return linkOutput;
   105             }
   106         }
   107         // Can't link so just write label.
   108         linkOutput.append(label.toString());
   109         if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
   110             linkOutput.append(getTypeParameterLinks(linkInfo).toString());
   111         }
   112         return linkOutput;
   113     }
   115     /**
   116      * {@inheritDoc}
   117      */
   118     protected LinkOutput getTypeParameterLink(LinkInfo linkInfo,
   119         Type typeParam) {
   120         LinkInfoImpl typeLinkInfo = new LinkInfoImpl(linkInfo.getContext(),
   121             typeParam);
   122         typeLinkInfo.excludeTypeBounds = linkInfo.excludeTypeBounds;
   123         typeLinkInfo.excludeTypeParameterLinks = linkInfo.excludeTypeParameterLinks;
   124         typeLinkInfo.linkToSelf = linkInfo.linkToSelf;
   125         LinkOutput output = getLinkOutput(typeLinkInfo);
   126         ((LinkInfoImpl) linkInfo).displayLength += typeLinkInfo.displayLength;
   127         return output;
   128     }
   130     /**
   131      * Given a class, return the appropriate tool tip.
   132      *
   133      * @param classDoc the class to get the tool tip for.
   134      * @return the tool tip for the appropriate class.
   135      */
   136     private String getClassToolTip(ClassDoc classDoc, boolean isTypeLink) {
   137         Configuration configuration = ConfigurationImpl.getInstance();
   138         if (isTypeLink) {
   139             return configuration.getText("doclet.Href_Type_Param_Title",
   140             classDoc.name());
   141         } else if (classDoc.isInterface()){
   142             return configuration.getText("doclet.Href_Interface_Title",
   143                 Util.getPackageName(classDoc.containingPackage()));
   144         } else if (classDoc.isAnnotationType()) {
   145             return configuration.getText("doclet.Href_Annotation_Title",
   146                 Util.getPackageName(classDoc.containingPackage()));
   147         } else if (classDoc.isEnum()) {
   148             return configuration.getText("doclet.Href_Enum_Title",
   149                 Util.getPackageName(classDoc.containingPackage()));
   150         } else {
   151             return configuration.getText("doclet.Href_Class_Title",
   152                 Util.getPackageName(classDoc.containingPackage()));
   153         }
   154     }
   156     /**
   157      * Return path to the given file name in the given package. So if the name
   158      * passed is "Object.html" and the name of the package is "java.lang", and
   159      * if the relative path is "../.." then returned string will be
   160      * "../../java/lang/Object.html"
   161      *
   162      * @param linkInfo the information about the link.
   163      */
   164     private String pathString(LinkInfoImpl linkInfo) {
   165         if (linkInfo.context == LinkInfoImpl.PACKAGE_FRAME) {
   166             //Not really necessary to do this but we want to be consistent
   167             //with 1.4.2 output.
   168             return linkInfo.classDoc.name() + ".html";
   169         }
   170         StringBuffer buf = new StringBuffer(m_writer.relativePath);
   171         buf.append(DirectoryManager.getPathToPackage(
   172             linkInfo.classDoc.containingPackage(),
   173             linkInfo.classDoc.name() + ".html"));
   174         return buf.toString();
   175     }
   176 }

mercurial