duke@1: /* jjg@1521: * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html; duke@1: jjg@1521: import java.util.List; jjg@1521: duke@1: import com.sun.javadoc.*; duke@1: import com.sun.tools.doclets.internal.toolkit.*; duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; jjg@1357: import com.sun.tools.doclets.internal.toolkit.util.links.*; duke@1: duke@1: /** duke@1: * A factory that returns a link given the information about it. duke@1: * jjg@1359: *
This is NOT part of any supported API.
jjg@1359: * If you write code that depends on this, you do so at your own risk.
jjg@1359: * This code and its internal interfaces are subject to change or
jjg@1359: * deletion without notice.
jjg@1359: *
duke@1: * @author Jamie Ho
duke@1: * @since 1.5
duke@1: */
duke@1: public class LinkFactoryImpl extends LinkFactory {
duke@1:
duke@1: private HtmlDocletWriter m_writer;
duke@1:
duke@1: public LinkFactoryImpl(HtmlDocletWriter writer) {
duke@1: m_writer = writer;
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc}
duke@1: */
duke@1: protected LinkOutput getOutputInstance() {
duke@1: return new LinkOutputImpl();
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc}
duke@1: */
duke@1: protected LinkOutput getClassLink(LinkInfo linkInfo) {
duke@1: LinkInfoImpl classLinkInfo = (LinkInfoImpl) linkInfo;
duke@1: boolean noLabel = linkInfo.label == null || linkInfo.label.length() == 0;
duke@1: ClassDoc classDoc = classLinkInfo.classDoc;
duke@1: //Create a tool tip if we are linking to a class or interface. Don't
duke@1: //create one if we are linking to a member.
duke@1: String title =
duke@1: (classLinkInfo.where == null || classLinkInfo.where.length() == 0) ?
duke@1: getClassToolTip(classDoc,
duke@1: classLinkInfo.type != null &&
duke@1: !classDoc.qualifiedTypeName().equals(classLinkInfo.type.qualifiedTypeName())) :
duke@1: "";
jjg@1362: StringBuilder label = new StringBuilder(
duke@1: classLinkInfo.getClassLinkLabel(m_writer.configuration));
duke@1: classLinkInfo.displayLength += label.length();
jjg@1410: Configuration configuration = m_writer.configuration;
duke@1: LinkOutputImpl linkOutput = new LinkOutputImpl();
duke@1: if (classDoc.isIncluded()) {
duke@1: if (configuration.isGeneratedDoc(classDoc)) {
jjg@1372: DocPath filename = getPath(classLinkInfo);
duke@1: if (linkInfo.linkToSelf ||
jjg@1372: !(DocPath.forName(classDoc)).equals(m_writer.filename)) {
jjg@1373: linkOutput.append(m_writer.getHyperLinkString(
jjg@1373: filename.fragment(classLinkInfo.where),
jjg@1373: label.toString(),
bpatel@182: classLinkInfo.isStrong, classLinkInfo.styleName,
duke@1: title, classLinkInfo.target));
duke@1: if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
duke@1: linkOutput.append(getTypeParameterLinks(linkInfo).toString());
duke@1: }
duke@1: return linkOutput;
duke@1: }
duke@1: }
duke@1: } else {
duke@1: String crossLink = m_writer.getCrossClassLink(
duke@1: classDoc.qualifiedName(), classLinkInfo.where,
bpatel@182: label.toString(), classLinkInfo.isStrong, classLinkInfo.styleName,
duke@1: true);
duke@1: if (crossLink != null) {
duke@1: linkOutput.append(crossLink);
duke@1: if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
duke@1: linkOutput.append(getTypeParameterLinks(linkInfo).toString());
duke@1: }
duke@1: return linkOutput;
duke@1: }
duke@1: }
duke@1: // Can't link so just write label.
duke@1: linkOutput.append(label.toString());
duke@1: if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
duke@1: linkOutput.append(getTypeParameterLinks(linkInfo).toString());
duke@1: }
duke@1: return linkOutput;
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc}
duke@1: */
duke@1: protected LinkOutput getTypeParameterLink(LinkInfo linkInfo,
duke@1: Type typeParam) {
jjg@1410: LinkInfoImpl typeLinkInfo = new LinkInfoImpl(m_writer.configuration,
jjg@1735: ((LinkInfoImpl) linkInfo).getContext(), typeParam);
duke@1: typeLinkInfo.excludeTypeBounds = linkInfo.excludeTypeBounds;
duke@1: typeLinkInfo.excludeTypeParameterLinks = linkInfo.excludeTypeParameterLinks;
duke@1: typeLinkInfo.linkToSelf = linkInfo.linkToSelf;
jjg@1521: typeLinkInfo.isJava5DeclarationLocation = false;
duke@1: LinkOutput output = getLinkOutput(typeLinkInfo);
duke@1: ((LinkInfoImpl) linkInfo).displayLength += typeLinkInfo.displayLength;
duke@1: return output;
duke@1: }
duke@1:
jjg@1521: protected LinkOutput getTypeAnnotationLink(LinkInfo linkInfo,
jjg@1521: AnnotationDesc annotation) {
jjg@1521: throw new RuntimeException("Not implemented yet!");
jjg@1521: }
jjg@1521:
jjg@1521: public LinkOutput getTypeAnnotationLinks(LinkInfo linkInfo) {
jjg@1521: LinkOutput output = getOutputInstance();
jjg@1521: AnnotationDesc[] annotations;
jjg@1521: if (linkInfo.type instanceof AnnotatedType) {
jjg@1521: annotations = linkInfo.type.asAnnotatedType().annotations();
jjg@1521: } else if (linkInfo.type instanceof TypeVariable) {
jjg@1521: annotations = linkInfo.type.asTypeVariable().annotations();
jjg@1521: } else {
jjg@1521: return output;
jjg@1521: }
jjg@1521:
jjg@1521: if (annotations.length == 0)
jjg@1521: return output;
jjg@1521:
jjg@1521: List