Fri, 05 Oct 2012 14:16:32 -0700
7068595: html files in class-use dir do not get loaded correctly when Frames link is clicked
Reviewed-by: jjg
1 /*
2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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.
24 */
26 package com.sun.tools.doclets.formats.html;
28 import com.sun.javadoc.*;
29 import com.sun.tools.doclets.internal.toolkit.*;
30 import com.sun.tools.doclets.internal.toolkit.util.*;
31 import com.sun.tools.doclets.internal.toolkit.builders.*;
32 import com.sun.tools.doclets.formats.html.markup.*;
34 /**
35 * Generate the Class Information Page.
36 * @see com.sun.javadoc.ClassDoc
37 * @see java.util.Collections
38 * @see java.util.List
39 * @see java.util.ArrayList
40 * @see java.util.HashMap
41 *
42 * @author Atul M Dambalkar
43 * @author Robert Field
44 * @author Bhavesh Patel (Modified)
45 */
46 public class AnnotationTypeWriterImpl extends SubWriterHolderWriter
47 implements AnnotationTypeWriter {
49 protected AnnotationTypeDoc annotationType;
51 protected Type prev;
53 protected Type next;
55 /**
56 * @param annotationType the annotation type being documented.
57 * @param prevType the previous class that was documented.
58 * @param nextType the next class being documented.
59 */
60 public AnnotationTypeWriterImpl (AnnotationTypeDoc annotationType,
61 Type prevType, Type nextType)
62 throws Exception {
63 super(ConfigurationImpl.getInstance(),
64 DirectoryManager.getDirectoryPath(annotationType.containingPackage()),
65 annotationType.name() + ".html",
66 DirectoryManager.getRelativePath(annotationType.containingPackage().name()));
67 this.annotationType = annotationType;
68 configuration.currentcd = annotationType.asClassDoc();
69 this.prev = prevType;
70 this.next = nextType;
71 }
73 /**
74 * Get this package link.
75 *
76 * @return a content tree for the package link
77 */
78 protected Content getNavLinkPackage() {
79 Content linkContent = getHyperLink("package-summary.html", "",
80 packageLabel);
81 Content li = HtmlTree.LI(linkContent);
82 return li;
83 }
85 /**
86 * Get the class link.
87 *
88 * @return a content tree for the class link
89 */
90 protected Content getNavLinkClass() {
91 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, classLabel);
92 return li;
93 }
95 /**
96 * Get the class use link.
97 *
98 * @return a content tree for the class use link
99 */
100 protected Content getNavLinkClassUse() {
101 Content linkContent = getHyperLink("class-use/" + filename, "", useLabel);
102 Content li = HtmlTree.LI(linkContent);
103 return li;
104 }
106 /**
107 * Get link to previous class.
108 *
109 * @return a content tree for the previous class link
110 */
111 public Content getNavLinkPrevious() {
112 Content li;
113 if (prev != null) {
114 Content prevLink = new RawHtml(getLink(new LinkInfoImpl(
115 LinkInfoImpl.CONTEXT_CLASS, prev.asClassDoc(), "",
116 configuration.getText("doclet.Prev_Class"), true)));
117 li = HtmlTree.LI(prevLink);
118 }
119 else
120 li = HtmlTree.LI(prevclassLabel);
121 return li;
122 }
124 /**
125 * Get link to next class.
126 *
127 * @return a content tree for the next class link
128 */
129 public Content getNavLinkNext() {
130 Content li;
131 if (next != null) {
132 Content nextLink = new RawHtml(getLink(new LinkInfoImpl(
133 LinkInfoImpl.CONTEXT_CLASS, next.asClassDoc(), "",
134 configuration.getText("doclet.Next_Class"), true)));
135 li = HtmlTree.LI(nextLink);
136 }
137 else
138 li = HtmlTree.LI(nextclassLabel);
139 return li;
140 }
142 /**
143 * {@inheritDoc}
144 */
145 public Content getHeader(String header) {
146 String pkgname = (annotationType.containingPackage() != null)?
147 annotationType.containingPackage().name(): "";
148 String clname = annotationType.name();
149 Content bodyTree = getBody(true, getWindowTitle(clname));
150 addTop(bodyTree);
151 addNavLinks(true, bodyTree);
152 bodyTree.addContent(HtmlConstants.START_OF_CLASS_DATA);
153 HtmlTree div = new HtmlTree(HtmlTag.DIV);
154 div.addStyle(HtmlStyle.header);
155 if (pkgname.length() > 0) {
156 Content pkgNameContent = new StringContent(pkgname);
157 Content pkgNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, pkgNameContent);
158 div.addContent(pkgNameDiv);
159 }
160 LinkInfoImpl linkInfo = new LinkInfoImpl(
161 LinkInfoImpl.CONTEXT_CLASS_HEADER, annotationType, false);
162 Content headerContent = new StringContent(header);
163 Content heading = HtmlTree.HEADING(HtmlConstants.CLASS_PAGE_HEADING, true,
164 HtmlStyle.title, headerContent);
165 heading.addContent(new RawHtml(getTypeParameterLinks(linkInfo)));
166 div.addContent(heading);
167 bodyTree.addContent(div);
168 return bodyTree;
169 }
171 /**
172 * {@inheritDoc}
173 */
174 public Content getAnnotationContentHeader() {
175 return getContentHeader();
176 }
178 /**
179 * {@inheritDoc}
180 */
181 public void addFooter(Content contentTree) {
182 contentTree.addContent(HtmlConstants.END_OF_CLASS_DATA);
183 addNavLinks(false, contentTree);
184 addBottom(contentTree);
185 }
187 /**
188 * {@inheritDoc}
189 */
190 public void printDocument(Content contentTree) {
191 printHtmlDocument(configuration.metakeywords.getMetaKeywords(annotationType),
192 true, contentTree);
193 }
195 /**
196 * {@inheritDoc}
197 */
198 public Content getAnnotationInfoTreeHeader() {
199 return getMemberTreeHeader();
200 }
202 /**
203 * {@inheritDoc}
204 */
205 public Content getAnnotationInfo(Content annotationInfoTree) {
206 return getMemberTree(HtmlStyle.description, annotationInfoTree);
207 }
209 /**
210 * {@inheritDoc}
211 */
212 public void addAnnotationTypeSignature(String modifiers, Content annotationInfoTree) {
213 annotationInfoTree.addContent(new HtmlTree(HtmlTag.BR));
214 Content pre = new HtmlTree(HtmlTag.PRE);
215 addAnnotationInfo(annotationType, pre);
216 pre.addContent(modifiers);
217 LinkInfoImpl linkInfo = new LinkInfoImpl(
218 LinkInfoImpl.CONTEXT_CLASS_SIGNATURE, annotationType, false);
219 Content annotationName = new StringContent(annotationType.name());
220 Content parameterLinks = new RawHtml(getTypeParameterLinks(linkInfo));
221 if (configuration().linksource) {
222 addSrcLink(annotationType, annotationName, pre);
223 pre.addContent(parameterLinks);
224 } else {
225 Content span = HtmlTree.SPAN(HtmlStyle.strong, annotationName);
226 span.addContent(parameterLinks);
227 pre.addContent(span);
228 }
229 annotationInfoTree.addContent(pre);
230 }
232 /**
233 * {@inheritDoc}
234 */
235 public void addAnnotationTypeDescription(Content annotationInfoTree) {
236 if(!configuration.nocomment) {
237 if (annotationType.inlineTags().length > 0) {
238 addInlineComment(annotationType, annotationInfoTree);
239 }
240 }
241 }
243 /**
244 * {@inheritDoc}
245 */
246 public void addAnnotationTypeTagInfo(Content annotationInfoTree) {
247 if(!configuration.nocomment) {
248 addTagsInfo(annotationType, annotationInfoTree);
249 }
250 }
252 /**
253 * {@inheritDoc}
254 */
255 public void addAnnotationTypeDeprecationInfo(Content annotationInfoTree) {
256 Content hr = new HtmlTree(HtmlTag.HR);
257 annotationInfoTree.addContent(hr);
258 Tag[] deprs = annotationType.tags("deprecated");
259 if (Util.isDeprecated(annotationType)) {
260 Content strong = HtmlTree.STRONG(deprecatedPhrase);
261 Content div = HtmlTree.DIV(HtmlStyle.block, strong);
262 if (deprs.length > 0) {
263 Tag[] commentTags = deprs[0].inlineTags();
264 if (commentTags.length > 0) {
265 div.addContent(getSpace());
266 addInlineDeprecatedComment(annotationType, deprs[0], div);
267 }
268 }
269 annotationInfoTree.addContent(div);
270 }
271 }
273 /**
274 * {@inheritDoc}
275 */
276 public void addAnnotationDetailsMarker(Content memberDetails) {
277 memberDetails.addContent(HtmlConstants.START_OF_ANNOTATION_TYPE_DETAILS);
278 }
280 /**
281 * {@inheritDoc}
282 */
283 protected Content getNavLinkTree() {
284 Content treeLinkContent = getHyperLink("package-tree.html",
285 "", treeLabel, "", "");
286 Content li = HtmlTree.LI(treeLinkContent);
287 return li;
288 }
290 /**
291 * Add summary details to the navigation bar.
292 *
293 * @param subDiv the content tree to which the summary detail links will be added
294 */
295 protected void addSummaryDetailLinks(Content subDiv) {
296 try {
297 Content div = HtmlTree.DIV(getNavSummaryLinks());
298 div.addContent(getNavDetailLinks());
299 subDiv.addContent(div);
300 } catch (Exception e) {
301 e.printStackTrace();
302 throw new DocletAbortException();
303 }
304 }
306 /**
307 * Get summary links for navigation bar.
308 *
309 * @return the content tree for the navigation summary links
310 */
311 protected Content getNavSummaryLinks() throws Exception {
312 Content li = HtmlTree.LI(summaryLabel);
313 li.addContent(getSpace());
314 Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li);
315 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder)
316 configuration.getBuilderFactory().getMemberSummaryBuilder(this);
317 Content liNavReq = new HtmlTree(HtmlTag.LI);
318 addNavSummaryLink(memberSummaryBuilder,
319 "doclet.navAnnotationTypeRequiredMember",
320 VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED, liNavReq);
321 addNavGap(liNavReq);
322 ulNav.addContent(liNavReq);
323 Content liNavOpt = new HtmlTree(HtmlTag.LI);
324 addNavSummaryLink(memberSummaryBuilder,
325 "doclet.navAnnotationTypeOptionalMember",
326 VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL, liNavOpt);
327 ulNav.addContent(liNavOpt);
328 return ulNav;
329 }
331 /**
332 * Add the navigation summary link.
333 *
334 * @param builder builder for the member to be documented
335 * @param label the label for the navigation
336 * @param type type to be documented
337 * @param liNav the content tree to which the navigation summary link will be added
338 */
339 protected void addNavSummaryLink(MemberSummaryBuilder builder,
340 String label, int type, Content liNav) {
341 AbstractMemberWriter writer = ((AbstractMemberWriter) builder.
342 getMemberSummaryWriter(type));
343 if (writer == null) {
344 liNav.addContent(getResource(label));
345 } else {
346 liNav.addContent(writer.getNavSummaryLink(null,
347 ! builder.getVisibleMemberMap(type).noVisibleMembers()));
348 }
349 }
351 /**
352 * Get detail links for the navigation bar.
353 *
354 * @return the content tree for the detail links
355 */
356 protected Content getNavDetailLinks() throws Exception {
357 Content li = HtmlTree.LI(detailLabel);
358 li.addContent(getSpace());
359 Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li);
360 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder)
361 configuration.getBuilderFactory().getMemberSummaryBuilder(this);
362 AbstractMemberWriter writerOptional =
363 ((AbstractMemberWriter) memberSummaryBuilder.
364 getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL));
365 AbstractMemberWriter writerRequired =
366 ((AbstractMemberWriter) memberSummaryBuilder.
367 getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED));
368 if (writerOptional != null){
369 Content liNavOpt = new HtmlTree(HtmlTag.LI);
370 writerOptional.addNavDetailLink(annotationType.elements().length > 0, liNavOpt);
371 ulNav.addContent(liNavOpt);
372 } else if (writerRequired != null){
373 Content liNavReq = new HtmlTree(HtmlTag.LI);
374 writerRequired.addNavDetailLink(annotationType.elements().length > 0, liNavReq);
375 ulNav.addContent(liNavReq);
376 } else {
377 Content liNav = HtmlTree.LI(getResource("doclet.navAnnotationTypeMember"));
378 ulNav.addContent(liNav);
379 }
380 return ulNav;
381 }
383 /**
384 * Add gap between navigation bar elements.
385 *
386 * @param liNav the content tree to which the gap will be added
387 */
388 protected void addNavGap(Content liNav) {
389 liNav.addContent(getSpace());
390 liNav.addContent("|");
391 liNav.addContent(getSpace());
392 }
394 /**
395 * {@inheritDoc}
396 */
397 public AnnotationTypeDoc getAnnotationTypeDoc() {
398 return annotationType;
399 }
400 }