33 import javax.lang.model.type.TypeMirror; |
33 import javax.lang.model.type.TypeMirror; |
34 |
34 |
35 import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; |
35 import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; |
36 import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration; |
36 import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration; |
37 import jdk.javadoc.internal.doclets.toolkit.Content; |
37 import jdk.javadoc.internal.doclets.toolkit.Content; |
|
38 import jdk.javadoc.internal.doclets.toolkit.Resources; |
38 import jdk.javadoc.internal.doclets.toolkit.util.DocPath; |
39 import jdk.javadoc.internal.doclets.toolkit.util.DocPath; |
39 import jdk.javadoc.internal.doclets.toolkit.util.Utils; |
40 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; |
40 import jdk.javadoc.internal.doclets.toolkit.util.links.LinkFactory; |
41 import jdk.javadoc.internal.doclets.toolkit.util.links.LinkFactory; |
41 import jdk.javadoc.internal.doclets.toolkit.util.links.LinkInfo; |
42 import jdk.javadoc.internal.doclets.toolkit.util.links.LinkInfo; |
42 |
43 |
43 /** |
44 /** |
44 * A factory that returns a link given the information about it. |
45 * A factory that returns a link given the information about it. |
51 * @author Jamie Ho |
52 * @author Jamie Ho |
52 */ |
53 */ |
53 public class LinkFactoryImpl extends LinkFactory { |
54 public class LinkFactoryImpl extends LinkFactory { |
54 |
55 |
55 private final HtmlDocletWriter m_writer; |
56 private final HtmlDocletWriter m_writer; |
|
57 private final DocPaths docPaths; |
56 |
58 |
57 public LinkFactoryImpl(HtmlDocletWriter writer) { |
59 public LinkFactoryImpl(HtmlDocletWriter writer) { |
|
60 super(writer.configuration.utils); |
58 m_writer = writer; |
61 m_writer = writer; |
|
62 docPaths = writer.configuration.docPaths; |
59 } |
63 } |
60 |
64 |
61 /** |
65 /** |
62 * {@inheritDoc} |
66 * {@inheritDoc} |
63 */ |
67 */ |
70 * {@inheritDoc} |
74 * {@inheritDoc} |
71 */ |
75 */ |
72 @Override |
76 @Override |
73 protected Content getClassLink(LinkInfo linkInfo) { |
77 protected Content getClassLink(LinkInfo linkInfo) { |
74 BaseConfiguration configuration = m_writer.configuration; |
78 BaseConfiguration configuration = m_writer.configuration; |
75 Utils utils = configuration.utils; |
|
76 LinkInfoImpl classLinkInfo = (LinkInfoImpl) linkInfo; |
79 LinkInfoImpl classLinkInfo = (LinkInfoImpl) linkInfo; |
77 boolean noLabel = linkInfo.label == null || linkInfo.label.isEmpty(); |
80 boolean noLabel = linkInfo.label == null || linkInfo.label.isEmpty(); |
78 TypeElement typeElement = classLinkInfo.typeElement; |
81 TypeElement typeElement = classLinkInfo.typeElement; |
79 // Create a tool tip if we are linking to a class or interface. Don't |
82 // Create a tool tip if we are linking to a class or interface. Don't |
80 // create one if we are linking to a member. |
83 // create one if we are linking to a member. |
82 if (classLinkInfo.where == null || classLinkInfo.where.length() == 0) { |
85 if (classLinkInfo.where == null || classLinkInfo.where.length() == 0) { |
83 boolean isTypeLink = classLinkInfo.type != null && |
86 boolean isTypeLink = classLinkInfo.type != null && |
84 utils.isTypeVariable(utils.getComponentType(classLinkInfo.type)); |
87 utils.isTypeVariable(utils.getComponentType(classLinkInfo.type)); |
85 title = getClassToolTip(typeElement, isTypeLink); |
88 title = getClassToolTip(typeElement, isTypeLink); |
86 } |
89 } |
87 Content label = classLinkInfo.getClassLinkLabel(m_writer.configuration); |
90 Content label = classLinkInfo.getClassLinkLabel(configuration); |
88 |
91 |
89 Content link = new ContentBuilder(); |
92 Content link = new ContentBuilder(); |
90 if (utils.isIncluded(typeElement)) { |
93 if (utils.isIncluded(typeElement)) { |
91 if (configuration.isGeneratedDoc(typeElement)) { |
94 if (configuration.isGeneratedDoc(typeElement)) { |
92 DocPath filename = getPath(classLinkInfo); |
95 DocPath filename = getPath(classLinkInfo); |
93 if (linkInfo.linkToSelf || |
96 if (linkInfo.linkToSelf || |
94 !(DocPath.forName(utils, typeElement)).equals(m_writer.filename)) { |
97 !(docPaths.forName(typeElement)).equals(m_writer.filename)) { |
95 link.addContent(m_writer.links.createLink( |
98 link.addContent(m_writer.links.createLink( |
96 filename.fragment(classLinkInfo.where), |
99 filename.fragment(classLinkInfo.where), |
97 label, |
100 label, |
98 classLinkInfo.isStrong, |
101 classLinkInfo.isStrong, |
99 title, |
102 title, |
138 return getLink(typeLinkInfo); |
141 return getLink(typeLinkInfo); |
139 } |
142 } |
140 |
143 |
141 @Override |
144 @Override |
142 public Content getTypeAnnotationLinks(LinkInfo linkInfo) { |
145 public Content getTypeAnnotationLinks(LinkInfo linkInfo) { |
143 Utils utils = ((LinkInfoImpl)linkInfo).utils; |
|
144 ContentBuilder links = new ContentBuilder(); |
146 ContentBuilder links = new ContentBuilder(); |
145 List<? extends AnnotationMirror> annotations; |
147 List<? extends AnnotationMirror> annotations; |
146 if (utils.isAnnotated(linkInfo.type)) { |
148 if (utils.isAnnotated(linkInfo.type)) { |
147 annotations = linkInfo.type.getAnnotationMirrors(); |
149 annotations = linkInfo.type.getAnnotationMirrors(); |
148 } else if (utils.isTypeVariable(linkInfo.type)) { |
150 } else if (utils.isTypeVariable(linkInfo.type)) { |
189 * |
191 * |
190 * @param typeElement the class to get the tool tip for. |
192 * @param typeElement the class to get the tool tip for. |
191 * @return the tool tip for the appropriate class. |
193 * @return the tool tip for the appropriate class. |
192 */ |
194 */ |
193 private String getClassToolTip(TypeElement typeElement, boolean isTypeLink) { |
195 private String getClassToolTip(TypeElement typeElement, boolean isTypeLink) { |
194 BaseConfiguration configuration = m_writer.configuration; |
196 Resources resources = m_writer.configuration.getResources(); |
195 Utils utils = configuration.utils; |
|
196 if (isTypeLink) { |
197 if (isTypeLink) { |
197 return configuration.getText("doclet.Href_Type_Param_Title", |
198 return resources.getText("doclet.Href_Type_Param_Title", |
198 utils.getSimpleName(typeElement)); |
199 utils.getSimpleName(typeElement)); |
199 } else if (utils.isInterface(typeElement)){ |
200 } else if (utils.isInterface(typeElement)){ |
200 return configuration.getText("doclet.Href_Interface_Title", |
201 return resources.getText("doclet.Href_Interface_Title", |
201 utils.getPackageName(utils.containingPackage(typeElement))); |
202 utils.getPackageName(utils.containingPackage(typeElement))); |
202 } else if (utils.isAnnotationType(typeElement)) { |
203 } else if (utils.isAnnotationType(typeElement)) { |
203 return configuration.getText("doclet.Href_Annotation_Title", |
204 return resources.getText("doclet.Href_Annotation_Title", |
204 utils.getPackageName(utils.containingPackage(typeElement))); |
205 utils.getPackageName(utils.containingPackage(typeElement))); |
205 } else if (utils.isEnum(typeElement)) { |
206 } else if (utils.isEnum(typeElement)) { |
206 return configuration.getText("doclet.Href_Enum_Title", |
207 return resources.getText("doclet.Href_Enum_Title", |
207 utils.getPackageName(utils.containingPackage(typeElement))); |
208 utils.getPackageName(utils.containingPackage(typeElement))); |
208 } else { |
209 } else { |
209 return configuration.getText("doclet.Href_Class_Title", |
210 return resources.getText("doclet.Href_Class_Title", |
210 utils.getPackageName(utils.containingPackage(typeElement))); |
211 utils.getPackageName(utils.containingPackage(typeElement))); |
211 } |
212 } |
212 } |
213 } |
213 |
214 |
214 /** |
215 /** |
221 */ |
222 */ |
222 private DocPath getPath(LinkInfoImpl linkInfo) { |
223 private DocPath getPath(LinkInfoImpl linkInfo) { |
223 if (linkInfo.context == LinkInfoImpl.Kind.PACKAGE_FRAME) { |
224 if (linkInfo.context == LinkInfoImpl.Kind.PACKAGE_FRAME) { |
224 //Not really necessary to do this but we want to be consistent |
225 //Not really necessary to do this but we want to be consistent |
225 //with 1.4.2 output. |
226 //with 1.4.2 output. |
226 return DocPath.forName(linkInfo.utils, linkInfo.typeElement); |
227 return docPaths.forName(linkInfo.typeElement); |
227 } |
228 } |
228 return m_writer.pathToRoot.resolve(DocPath.forClass(linkInfo.utils, linkInfo.typeElement)); |
229 return m_writer.pathToRoot.resolve(docPaths.forClass(linkInfo.typeElement)); |
229 } |
230 } |
230 } |
231 } |