author | jjg |
Wed, 23 Jan 2013 13:27:24 -0800 | |
changeset 15385 | ee1eebe7e210 |
parent 14542 | 7062120649c2 |
child 16969 | b58d8a70d921 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
15385 | 2 |
* Copyright (c) 2003, 2013, 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.*; |
31 |
import com.sun.tools.doclets.internal.toolkit.*; |
|
32 |
import com.sun.tools.doclets.internal.toolkit.util.*; |
|
14258 | 33 |
import com.sun.tools.doclets.internal.toolkit.util.links.*; |
10 | 34 |
|
35 |
/** |
|
36 |
* A factory that returns a link given the information about it. |
|
37 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
38 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
39 |
* 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
|
40 |
* 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
|
41 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
42 |
* |
10 | 43 |
* @author Jamie Ho |
44 |
* @since 1.5 |
|
45 |
*/ |
|
46 |
public class LinkFactoryImpl extends LinkFactory { |
|
47 |
||
48 |
private HtmlDocletWriter m_writer; |
|
49 |
||
50 |
public LinkFactoryImpl(HtmlDocletWriter writer) { |
|
51 |
m_writer = writer; |
|
52 |
} |
|
53 |
||
54 |
/** |
|
55 |
* {@inheritDoc} |
|
56 |
*/ |
|
57 |
protected LinkOutput getOutputInstance() { |
|
58 |
return new LinkOutputImpl(); |
|
59 |
} |
|
60 |
||
61 |
/** |
|
62 |
* {@inheritDoc} |
|
63 |
*/ |
|
64 |
protected LinkOutput getClassLink(LinkInfo linkInfo) { |
|
65 |
LinkInfoImpl classLinkInfo = (LinkInfoImpl) linkInfo; |
|
66 |
boolean noLabel = linkInfo.label == null || linkInfo.label.length() == 0; |
|
67 |
ClassDoc classDoc = classLinkInfo.classDoc; |
|
68 |
//Create a tool tip if we are linking to a class or interface. Don't |
|
69 |
//create one if we are linking to a member. |
|
70 |
String title = |
|
71 |
(classLinkInfo.where == null || classLinkInfo.where.length() == 0) ? |
|
72 |
getClassToolTip(classDoc, |
|
73 |
classLinkInfo.type != null && |
|
74 |
!classDoc.qualifiedTypeName().equals(classLinkInfo.type.qualifiedTypeName())) : |
|
75 |
""; |
|
14263 | 76 |
StringBuilder label = new StringBuilder( |
10 | 77 |
classLinkInfo.getClassLinkLabel(m_writer.configuration)); |
78 |
classLinkInfo.displayLength += label.length(); |
|
14542 | 79 |
Configuration configuration = m_writer.configuration; |
10 | 80 |
LinkOutputImpl linkOutput = new LinkOutputImpl(); |
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)) { |
14358
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
86 |
linkOutput.append(m_writer.getHyperLinkString( |
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
87 |
filename.fragment(classLinkInfo.where), |
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
88 |
label.toString(), |
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, |
10 | 90 |
title, classLinkInfo.target)); |
91 |
if (noLabel && !classLinkInfo.excludeTypeParameterLinks) { |
|
92 |
linkOutput.append(getTypeParameterLinks(linkInfo).toString()); |
|
93 |
} |
|
94 |
return linkOutput; |
|
95 |
} |
|
96 |
} |
|
97 |
} else { |
|
98 |
String crossLink = m_writer.getCrossClassLink( |
|
99 |
classDoc.qualifiedName(), classLinkInfo.where, |
|
1787
1aa079321cd2
6786028: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Bold tags should be strong
bpatel
parents:
10
diff
changeset
|
100 |
label.toString(), classLinkInfo.isStrong, classLinkInfo.styleName, |
10 | 101 |
true); |
102 |
if (crossLink != null) { |
|
103 |
linkOutput.append(crossLink); |
|
104 |
if (noLabel && !classLinkInfo.excludeTypeParameterLinks) { |
|
105 |
linkOutput.append(getTypeParameterLinks(linkInfo).toString()); |
|
106 |
} |
|
107 |
return linkOutput; |
|
108 |
} |
|
109 |
} |
|
110 |
// Can't link so just write label. |
|
111 |
linkOutput.append(label.toString()); |
|
112 |
if (noLabel && !classLinkInfo.excludeTypeParameterLinks) { |
|
113 |
linkOutput.append(getTypeParameterLinks(linkInfo).toString()); |
|
114 |
} |
|
115 |
return linkOutput; |
|
116 |
} |
|
117 |
||
118 |
/** |
|
119 |
* {@inheritDoc} |
|
120 |
*/ |
|
121 |
protected LinkOutput getTypeParameterLink(LinkInfo linkInfo, |
|
122 |
Type typeParam) { |
|
14542 | 123 |
LinkInfoImpl typeLinkInfo = new LinkInfoImpl(m_writer.configuration, |
124 |
linkInfo.getContext(), typeParam); |
|
10 | 125 |
typeLinkInfo.excludeTypeBounds = linkInfo.excludeTypeBounds; |
126 |
typeLinkInfo.excludeTypeParameterLinks = linkInfo.excludeTypeParameterLinks; |
|
127 |
typeLinkInfo.linkToSelf = linkInfo.linkToSelf; |
|
15385 | 128 |
typeLinkInfo.isJava5DeclarationLocation = false; |
10 | 129 |
LinkOutput output = getLinkOutput(typeLinkInfo); |
130 |
((LinkInfoImpl) linkInfo).displayLength += typeLinkInfo.displayLength; |
|
131 |
return output; |
|
132 |
} |
|
133 |
||
15385 | 134 |
protected LinkOutput getTypeAnnotationLink(LinkInfo linkInfo, |
135 |
AnnotationDesc annotation) { |
|
136 |
throw new RuntimeException("Not implemented yet!"); |
|
137 |
} |
|
138 |
||
139 |
public LinkOutput getTypeAnnotationLinks(LinkInfo linkInfo) { |
|
140 |
LinkOutput output = getOutputInstance(); |
|
141 |
AnnotationDesc[] annotations; |
|
142 |
if (linkInfo.type instanceof AnnotatedType) { |
|
143 |
annotations = linkInfo.type.asAnnotatedType().annotations(); |
|
144 |
} else if (linkInfo.type instanceof TypeVariable) { |
|
145 |
annotations = linkInfo.type.asTypeVariable().annotations(); |
|
146 |
} else { |
|
147 |
return output; |
|
148 |
} |
|
149 |
||
150 |
if (annotations.length == 0) |
|
151 |
return output; |
|
152 |
||
153 |
List<String> annos = m_writer.getAnnotations(0, annotations, false, linkInfo.isJava5DeclarationLocation); |
|
154 |
||
155 |
boolean isFirst = true; |
|
156 |
for (String anno : annos) { |
|
157 |
if (!isFirst) { |
|
158 |
linkInfo.displayLength += 1; |
|
159 |
output.append(" "); |
|
160 |
isFirst = false; |
|
161 |
} |
|
162 |
output.append(anno); |
|
163 |
} |
|
164 |
if (!annos.isEmpty()) { |
|
165 |
linkInfo.displayLength += 1; |
|
166 |
output.append(" "); |
|
167 |
} |
|
168 |
||
169 |
return output; |
|
170 |
} |
|
171 |
||
10 | 172 |
/** |
173 |
* Given a class, return the appropriate tool tip. |
|
174 |
* |
|
175 |
* @param classDoc the class to get the tool tip for. |
|
176 |
* @return the tool tip for the appropriate class. |
|
177 |
*/ |
|
178 |
private String getClassToolTip(ClassDoc classDoc, boolean isTypeLink) { |
|
14542 | 179 |
Configuration configuration = m_writer.configuration; |
10 | 180 |
if (isTypeLink) { |
181 |
return configuration.getText("doclet.Href_Type_Param_Title", |
|
14542 | 182 |
classDoc.name()); |
10 | 183 |
} else if (classDoc.isInterface()){ |
184 |
return configuration.getText("doclet.Href_Interface_Title", |
|
185 |
Util.getPackageName(classDoc.containingPackage())); |
|
186 |
} else if (classDoc.isAnnotationType()) { |
|
187 |
return configuration.getText("doclet.Href_Annotation_Title", |
|
188 |
Util.getPackageName(classDoc.containingPackage())); |
|
189 |
} else if (classDoc.isEnum()) { |
|
190 |
return configuration.getText("doclet.Href_Enum_Title", |
|
191 |
Util.getPackageName(classDoc.containingPackage())); |
|
192 |
} else { |
|
193 |
return configuration.getText("doclet.Href_Class_Title", |
|
194 |
Util.getPackageName(classDoc.containingPackage())); |
|
195 |
} |
|
196 |
} |
|
197 |
||
198 |
/** |
|
199 |
* Return path to the given file name in the given package. So if the name |
|
200 |
* passed is "Object.html" and the name of the package is "java.lang", and |
|
201 |
* if the relative path is "../.." then returned string will be |
|
202 |
* "../../java/lang/Object.html" |
|
203 |
* |
|
204 |
* @param linkInfo the information about the link. |
|
205 |
*/ |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14263
diff
changeset
|
206 |
private DocPath getPath(LinkInfoImpl linkInfo) { |
10 | 207 |
if (linkInfo.context == LinkInfoImpl.PACKAGE_FRAME) { |
208 |
//Not really necessary to do this but we want to be consistent |
|
209 |
//with 1.4.2 output. |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14263
diff
changeset
|
210 |
return DocPath.forName(linkInfo.classDoc); |
10 | 211 |
} |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14263
diff
changeset
|
212 |
return m_writer.pathToRoot.resolve(DocPath.forClass(linkInfo.classDoc)); |
10 | 213 |
} |
214 |
} |