author | ksrini |
Sun, 15 Jun 2014 08:41:57 -0700 | |
changeset 25454 | 376a52c9540c |
parent 19497 | 407ed5b28a44 |
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 |
*/ |
|
47 |
public class LinkFactoryImpl extends LinkFactory { |
|
48 |
||
49 |
private HtmlDocletWriter m_writer; |
|
50 |
||
51 |
public LinkFactoryImpl(HtmlDocletWriter writer) { |
|
52 |
m_writer = writer; |
|
53 |
} |
|
54 |
||
55 |
/** |
|
56 |
* {@inheritDoc} |
|
57 |
*/ |
|
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
58 |
protected Content newContent() { |
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
59 |
return new ContentBuilder(); |
10 | 60 |
} |
61 |
||
62 |
/** |
|
63 |
* {@inheritDoc} |
|
64 |
*/ |
|
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
65 |
protected Content getClassLink(LinkInfo linkInfo) { |
10 | 66 |
LinkInfoImpl classLinkInfo = (LinkInfoImpl) linkInfo; |
17560 | 67 |
boolean noLabel = linkInfo.label == null || linkInfo.label.isEmpty(); |
10 | 68 |
ClassDoc classDoc = classLinkInfo.classDoc; |
69 |
//Create a tool tip if we are linking to a class or interface. Don't |
|
70 |
//create one if we are linking to a member. |
|
71 |
String title = |
|
72 |
(classLinkInfo.where == null || classLinkInfo.where.length() == 0) ? |
|
73 |
getClassToolTip(classDoc, |
|
74 |
classLinkInfo.type != null && |
|
75 |
!classDoc.qualifiedTypeName().equals(classLinkInfo.type.qualifiedTypeName())) : |
|
76 |
""; |
|
17560 | 77 |
Content label = classLinkInfo.getClassLinkLabel(m_writer.configuration); |
14542 | 78 |
Configuration configuration = m_writer.configuration; |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
79 |
Content link = new ContentBuilder(); |
10 | 80 |
if (classDoc.isIncluded()) { |
81 |
if (configuration.isGeneratedDoc(classDoc)) { |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14263
diff
changeset
|
82 |
DocPath filename = getPath(classLinkInfo); |
10 | 83 |
if (linkInfo.linkToSelf || |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14263
diff
changeset
|
84 |
!(DocPath.forName(classDoc)).equals(m_writer.filename)) { |
17560 | 85 |
link.addContent(m_writer.getHyperLink( |
14358
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
86 |
filename.fragment(classLinkInfo.where), |
17560 | 87 |
label, |
1787
1aa079321cd2
6786028: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Bold tags should be strong
bpatel
parents:
10
diff
changeset
|
88 |
classLinkInfo.isStrong, classLinkInfo.styleName, |
17560 | 89 |
title, classLinkInfo.target)); |
10 | 90 |
if (noLabel && !classLinkInfo.excludeTypeParameterLinks) { |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
91 |
link.addContent(getTypeParameterLinks(linkInfo)); |
10 | 92 |
} |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
93 |
return link; |
10 | 94 |
} |
95 |
} |
|
96 |
} else { |
|
17560 | 97 |
Content crossLink = m_writer.getCrossClassLink( |
10 | 98 |
classDoc.qualifiedName(), classLinkInfo.where, |
17560 | 99 |
label, classLinkInfo.isStrong, classLinkInfo.styleName, |
10 | 100 |
true); |
101 |
if (crossLink != null) { |
|
17560 | 102 |
link.addContent(crossLink); |
10 | 103 |
if (noLabel && !classLinkInfo.excludeTypeParameterLinks) { |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
104 |
link.addContent(getTypeParameterLinks(linkInfo)); |
10 | 105 |
} |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
106 |
return link; |
10 | 107 |
} |
108 |
} |
|
109 |
// 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
|
110 |
link.addContent(label); |
10 | 111 |
if (noLabel && !classLinkInfo.excludeTypeParameterLinks) { |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
112 |
link.addContent(getTypeParameterLinks(linkInfo)); |
10 | 113 |
} |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
114 |
return link; |
10 | 115 |
} |
116 |
||
117 |
/** |
|
118 |
* {@inheritDoc} |
|
119 |
*/ |
|
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
120 |
protected Content getTypeParameterLink(LinkInfo linkInfo, |
10 | 121 |
Type typeParam) { |
14542 | 122 |
LinkInfoImpl typeLinkInfo = new LinkInfoImpl(m_writer.configuration, |
17558
eee4ccf66cfd
8010440: Replace int constants in LinkInfoImpl with enum
jjg
parents:
16969
diff
changeset
|
123 |
((LinkInfoImpl) linkInfo).getContext(), typeParam); |
10 | 124 |
typeLinkInfo.excludeTypeBounds = linkInfo.excludeTypeBounds; |
125 |
typeLinkInfo.excludeTypeParameterLinks = linkInfo.excludeTypeParameterLinks; |
|
126 |
typeLinkInfo.linkToSelf = linkInfo.linkToSelf; |
|
15385 | 127 |
typeLinkInfo.isJava5DeclarationLocation = false; |
17564
c329fe11193d
8011288: Erratic/inconsistent indentation of signatures
jjg
parents:
17560
diff
changeset
|
128 |
return getLink(typeLinkInfo); |
10 | 129 |
} |
130 |
||
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
131 |
protected Content getTypeAnnotationLink(LinkInfo linkInfo, |
15385 | 132 |
AnnotationDesc annotation) { |
133 |
throw new RuntimeException("Not implemented yet!"); |
|
134 |
} |
|
135 |
||
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
136 |
public Content getTypeAnnotationLinks(LinkInfo linkInfo) { |
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
137 |
ContentBuilder links = new ContentBuilder(); |
15385 | 138 |
AnnotationDesc[] annotations; |
139 |
if (linkInfo.type instanceof AnnotatedType) { |
|
140 |
annotations = linkInfo.type.asAnnotatedType().annotations(); |
|
141 |
} else if (linkInfo.type instanceof TypeVariable) { |
|
142 |
annotations = linkInfo.type.asTypeVariable().annotations(); |
|
143 |
} else { |
|
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
144 |
return links; |
15385 | 145 |
} |
146 |
||
147 |
if (annotations.length == 0) |
|
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
148 |
return links; |
15385 | 149 |
|
17570
78512b2899db
8012183: replace some uses of Configuration.getText with Configuration.getResource
jjg
parents:
17569
diff
changeset
|
150 |
List<Content> annos = m_writer.getAnnotations(0, annotations, false, linkInfo.isJava5DeclarationLocation); |
15385 | 151 |
|
152 |
boolean isFirst = true; |
|
17570
78512b2899db
8012183: replace some uses of Configuration.getText with Configuration.getResource
jjg
parents:
17569
diff
changeset
|
153 |
for (Content anno : annos) { |
15385 | 154 |
if (!isFirst) { |
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
155 |
links.addContent(" "); |
15385 | 156 |
} |
17570
78512b2899db
8012183: replace some uses of Configuration.getText with Configuration.getResource
jjg
parents:
17569
diff
changeset
|
157 |
links.addContent(anno); |
16969
b58d8a70d921
8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents:
15385
diff
changeset
|
158 |
isFirst = false; |
15385 | 159 |
} |
160 |
if (!annos.isEmpty()) { |
|
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
161 |
links.addContent(" "); |
15385 | 162 |
} |
163 |
||
17559
87c28ee29329
8011642: Remove LinkOutput in favor of direct use of Content
jjg
parents:
17558
diff
changeset
|
164 |
return links; |
15385 | 165 |
} |
166 |
||
10 | 167 |
/** |
168 |
* Given a class, return the appropriate tool tip. |
|
169 |
* |
|
170 |
* @param classDoc the class to get the tool tip for. |
|
171 |
* @return the tool tip for the appropriate class. |
|
172 |
*/ |
|
173 |
private String getClassToolTip(ClassDoc classDoc, boolean isTypeLink) { |
|
14542 | 174 |
Configuration configuration = m_writer.configuration; |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
19497
diff
changeset
|
175 |
Utils utils = configuration.utils; |
10 | 176 |
if (isTypeLink) { |
177 |
return configuration.getText("doclet.Href_Type_Param_Title", |
|
14542 | 178 |
classDoc.name()); |
10 | 179 |
} else if (classDoc.isInterface()){ |
180 |
return configuration.getText("doclet.Href_Interface_Title", |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
19497
diff
changeset
|
181 |
utils.getPackageName(classDoc.containingPackage())); |
10 | 182 |
} else if (classDoc.isAnnotationType()) { |
183 |
return configuration.getText("doclet.Href_Annotation_Title", |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
19497
diff
changeset
|
184 |
utils.getPackageName(classDoc.containingPackage())); |
10 | 185 |
} else if (classDoc.isEnum()) { |
186 |
return configuration.getText("doclet.Href_Enum_Title", |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
19497
diff
changeset
|
187 |
utils.getPackageName(classDoc.containingPackage())); |
10 | 188 |
} else { |
189 |
return configuration.getText("doclet.Href_Class_Title", |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
19497
diff
changeset
|
190 |
utils.getPackageName(classDoc.containingPackage())); |
10 | 191 |
} |
192 |
} |
|
193 |
||
194 |
/** |
|
195 |
* Return path to the given file name in the given package. So if the name |
|
196 |
* passed is "Object.html" and the name of the package is "java.lang", and |
|
197 |
* if the relative path is "../.." then returned string will be |
|
198 |
* "../../java/lang/Object.html" |
|
199 |
* |
|
200 |
* @param linkInfo the information about the link. |
|
201 |
*/ |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14263
diff
changeset
|
202 |
private DocPath getPath(LinkInfoImpl linkInfo) { |
17558
eee4ccf66cfd
8010440: Replace int constants in LinkInfoImpl with enum
jjg
parents:
16969
diff
changeset
|
203 |
if (linkInfo.context == LinkInfoImpl.Kind.PACKAGE_FRAME) { |
10 | 204 |
//Not really necessary to do this but we want to be consistent |
205 |
//with 1.4.2 output. |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14263
diff
changeset
|
206 |
return DocPath.forName(linkInfo.classDoc); |
10 | 207 |
} |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14263
diff
changeset
|
208 |
return m_writer.pathToRoot.resolve(DocPath.forClass(linkInfo.classDoc)); |
10 | 209 |
} |
210 |
} |