author | jjg |
Fri, 27 May 2016 13:06:58 -0700 | |
changeset 38617 | d93a7f64e231 |
parent 25874 | 83c19f00452c |
permissions | -rw-r--r-- |
10 | 1 |
/* |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
19497
diff
changeset
|
2 |
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.doclets.formats.html; |
|
27 |
||
15385 | 28 |
import java.util.List; |
29 |
||
10 | 30 |
import com.sun.javadoc.*; |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
31 |
import com.sun.tools.doclets.formats.html.markup.ContentBuilder; |
10 | 32 |
import com.sun.tools.doclets.internal.toolkit.*; |
33 |
import com.sun.tools.doclets.internal.toolkit.util.*; |
|
14258 | 34 |
import com.sun.tools.doclets.internal.toolkit.util.links.*; |
10 | 35 |
|
36 |
/** |
|
37 |
* A factory that returns a link given the information about it. |
|
38 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
39 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
40 |
* If you write code that depends on this, you do so at your own risk. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
41 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
42 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
43 |
* |
10 | 44 |
* @author Jamie Ho |
45 |
* @since 1.5 |
|
46 |
*/ |
|
38617 | 47 |
@Deprecated |
10 | 48 |
public class LinkFactoryImpl extends LinkFactory { |
49 |
||
50 |
private HtmlDocletWriter m_writer; |
|
51 |
||
52 |
public LinkFactoryImpl(HtmlDocletWriter writer) { |
|
53 |
m_writer = writer; |
|
54 |
} |
|
55 |
||
56 |
/** |
|
57 |
* {@inheritDoc} |
|
58 |
*/ |
|
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
59 |
protected Content newContent() { |
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
60 |
return new ContentBuilder(); |
10 | 61 |
} |
62 |
||
63 |
/** |
|
64 |
* {@inheritDoc} |
|
65 |
*/ |
|
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
66 |
protected Content getClassLink(LinkInfo linkInfo) { |
10 | 67 |
LinkInfoImpl classLinkInfo = (LinkInfoImpl) linkInfo; |
17560 | 68 |
boolean noLabel = linkInfo.label == null || linkInfo.label.isEmpty(); |
10 | 69 |
ClassDoc classDoc = classLinkInfo.classDoc; |
70 |
//Create a tool tip if we are linking to a class or interface. Don't |
|
71 |
//create one if we are linking to a member. |
|
72 |
String title = |
|
73 |
(classLinkInfo.where == null || classLinkInfo.where.length() == 0) ? |
|
74 |
getClassToolTip(classDoc, |
|
75 |
classLinkInfo.type != null && |
|
76 |
!classDoc.qualifiedTypeName().equals(classLinkInfo.type.qualifiedTypeName())) : |
|
77 |
""; |
|
17560 | 78 |
Content label = classLinkInfo.getClassLinkLabel(m_writer.configuration); |
14542 | 79 |
Configuration configuration = m_writer.configuration; |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
80 |
Content link = new ContentBuilder(); |
10 | 81 |
if (classDoc.isIncluded()) { |
82 |
if (configuration.isGeneratedDoc(classDoc)) { |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14263
diff
changeset
|
83 |
DocPath filename = getPath(classLinkInfo); |
10 | 84 |
if (linkInfo.linkToSelf || |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14263
diff
changeset
|
85 |
!(DocPath.forName(classDoc)).equals(m_writer.filename)) { |
17560 | 86 |
link.addContent(m_writer.getHyperLink( |
14358
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
87 |
filename.fragment(classLinkInfo.where), |
17560 | 88 |
label, |
1787
1aa079321cd2
6786028: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Bold tags should be strong
bpatel
parents:
10
diff
changeset
|
89 |
classLinkInfo.isStrong, classLinkInfo.styleName, |
17560 | 90 |
title, classLinkInfo.target)); |
10 | 91 |
if (noLabel && !classLinkInfo.excludeTypeParameterLinks) { |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
92 |
link.addContent(getTypeParameterLinks(linkInfo)); |
10 | 93 |
} |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
94 |
return link; |
10 | 95 |
} |
96 |
} |
|
97 |
} else { |
|
17560 | 98 |
Content crossLink = m_writer.getCrossClassLink( |
10 | 99 |
classDoc.qualifiedName(), classLinkInfo.where, |
17560 | 100 |
label, classLinkInfo.isStrong, classLinkInfo.styleName, |
10 | 101 |
true); |
102 |
if (crossLink != null) { |
|
17560 | 103 |
link.addContent(crossLink); |
10 | 104 |
if (noLabel && !classLinkInfo.excludeTypeParameterLinks) { |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
105 |
link.addContent(getTypeParameterLinks(linkInfo)); |
10 | 106 |
} |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
107 |
return link; |
10 | 108 |
} |
109 |
} |
|
110 |
// Can't link so just write label. |
|
19497
407ed5b28a44
8017191: Javadoc is confused by @link to imported classes outside of the set of generated packages
jjg
parents:
17570
diff
changeset
|
111 |
link.addContent(label); |
10 | 112 |
if (noLabel && !classLinkInfo.excludeTypeParameterLinks) { |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
113 |
link.addContent(getTypeParameterLinks(linkInfo)); |
10 | 114 |
} |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
115 |
return link; |
10 | 116 |
} |
117 |
||
118 |
/** |
|
119 |
* {@inheritDoc} |
|
120 |
*/ |
|
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
121 |
protected Content getTypeParameterLink(LinkInfo linkInfo, |
10 | 122 |
Type typeParam) { |
14542 | 123 |
LinkInfoImpl typeLinkInfo = new LinkInfoImpl(m_writer.configuration, |
17558
eee4ccf66cfd
8010440: Replace int constants in LinkInfoImpl with enum
jjg
parents:
16969
diff
changeset
|
124 |
((LinkInfoImpl) linkInfo).getContext(), typeParam); |
10 | 125 |
typeLinkInfo.excludeTypeBounds = linkInfo.excludeTypeBounds; |
126 |
typeLinkInfo.excludeTypeParameterLinks = linkInfo.excludeTypeParameterLinks; |
|
127 |
typeLinkInfo.linkToSelf = linkInfo.linkToSelf; |
|
15385 | 128 |
typeLinkInfo.isJava5DeclarationLocation = false; |
17564
c329fe11193d
8011288: Erratic/inconsistent indentation of signatures
jjg
parents:
17560
diff
changeset
|
129 |
return getLink(typeLinkInfo); |
10 | 130 |
} |
131 |
||
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
132 |
protected Content getTypeAnnotationLink(LinkInfo linkInfo, |
15385 | 133 |
AnnotationDesc annotation) { |
134 |
throw new RuntimeException("Not implemented yet!"); |
|
135 |
} |
|
136 |
||
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
137 |
public Content getTypeAnnotationLinks(LinkInfo linkInfo) { |
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
138 |
ContentBuilder links = new ContentBuilder(); |
15385 | 139 |
AnnotationDesc[] annotations; |
140 |
if (linkInfo.type instanceof AnnotatedType) { |
|
141 |
annotations = linkInfo.type.asAnnotatedType().annotations(); |
|
142 |
} else if (linkInfo.type instanceof TypeVariable) { |
|
143 |
annotations = linkInfo.type.asTypeVariable().annotations(); |
|
144 |
} else { |
|
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
145 |
return links; |
15385 | 146 |
} |
147 |
||
148 |
if (annotations.length == 0) |
|
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
149 |
return links; |
15385 | 150 |
|
17570
78512b2899db
8012183: replace some uses of Configuration.getText with Configuration.getResource
jjg
parents:
17569
diff
changeset
|
151 |
List<Content> annos = m_writer.getAnnotations(0, annotations, false, linkInfo.isJava5DeclarationLocation); |
15385 | 152 |
|
153 |
boolean isFirst = true; |
|
17570
78512b2899db
8012183: replace some uses of Configuration.getText with Configuration.getResource
jjg
parents:
17569
diff
changeset
|
154 |
for (Content anno : annos) { |
15385 | 155 |
if (!isFirst) { |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
156 |
links.addContent(" "); |
15385 | 157 |
} |
17570
78512b2899db
8012183: replace some uses of Configuration.getText with Configuration.getResource
jjg
parents:
17569
diff
changeset
|
158 |
links.addContent(anno); |
16969
b58d8a70d921
8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents:
15385
diff
changeset
|
159 |
isFirst = false; |
15385 | 160 |
} |
161 |
if (!annos.isEmpty()) { |
|
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
162 |
links.addContent(" "); |
15385 | 163 |
} |
164 |
||
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
165 |
return links; |
15385 | 166 |
} |
167 |
||
10 | 168 |
/** |
169 |
* Given a class, return the appropriate tool tip. |
|
170 |
* |
|
171 |
* @param classDoc the class to get the tool tip for. |
|
172 |
* @return the tool tip for the appropriate class. |
|
173 |
*/ |
|
174 |
private String getClassToolTip(ClassDoc classDoc, boolean isTypeLink) { |
|
14542 | 175 |
Configuration configuration = m_writer.configuration; |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
19497
diff
changeset
|
176 |
Utils utils = configuration.utils; |
10 | 177 |
if (isTypeLink) { |
178 |
return configuration.getText("doclet.Href_Type_Param_Title", |
|
14542 | 179 |
classDoc.name()); |
10 | 180 |
} else if (classDoc.isInterface()){ |
181 |
return configuration.getText("doclet.Href_Interface_Title", |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
19497
diff
changeset
|
182 |
utils.getPackageName(classDoc.containingPackage())); |
10 | 183 |
} else if (classDoc.isAnnotationType()) { |
184 |
return configuration.getText("doclet.Href_Annotation_Title", |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
19497
diff
changeset
|
185 |
utils.getPackageName(classDoc.containingPackage())); |
10 | 186 |
} else if (classDoc.isEnum()) { |
187 |
return configuration.getText("doclet.Href_Enum_Title", |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
19497
diff
changeset
|
188 |
utils.getPackageName(classDoc.containingPackage())); |
10 | 189 |
} else { |
190 |
return configuration.getText("doclet.Href_Class_Title", |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
19497
diff
changeset
|
191 |
utils.getPackageName(classDoc.containingPackage())); |
10 | 192 |
} |
193 |
} |
|
194 |
||
195 |
/** |
|
196 |
* Return path to the given file name in the given package. So if the name |
|
197 |
* passed is "Object.html" and the name of the package is "java.lang", and |
|
198 |
* if the relative path is "../.." then returned string will be |
|
199 |
* "../../java/lang/Object.html" |
|
200 |
* |
|
201 |
* @param linkInfo the information about the link. |
|
202 |
*/ |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14263
diff
changeset
|
203 |
private DocPath getPath(LinkInfoImpl linkInfo) { |
17558
eee4ccf66cfd
8010440: Replace int constants in LinkInfoImpl with enum
jjg
parents:
16969
diff
changeset
|
204 |
if (linkInfo.context == LinkInfoImpl.Kind.PACKAGE_FRAME) { |
10 | 205 |
//Not really necessary to do this but we want to be consistent |
206 |
//with 1.4.2 output. |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14263
diff
changeset
|
207 |
return DocPath.forName(linkInfo.classDoc); |
10 | 208 |
} |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14263
diff
changeset
|
209 |
return m_writer.pathToRoot.resolve(DocPath.forClass(linkInfo.classDoc)); |
10 | 210 |
} |
211 |
} |