|
1 /* |
|
2 * Copyright 2001-2003 Sun Microsystems, Inc. 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. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 |
|
26 package com.sun.tools.doclets.internal.toolkit.taglets; |
|
27 |
|
28 import com.sun.tools.doclets.internal.toolkit.util.*; |
|
29 import com.sun.javadoc.*; |
|
30 |
|
31 /** |
|
32 * A taglet that represents the @return tag. |
|
33 * |
|
34 * This code is not part of an API. |
|
35 * It is implementation that is subject to change. |
|
36 * Do not use it as an API |
|
37 * |
|
38 * @author Jamie Ho |
|
39 * @since 1.4 |
|
40 */ |
|
41 public class ReturnTaglet extends BaseExecutableMemberTaglet |
|
42 implements InheritableTaglet { |
|
43 |
|
44 public ReturnTaglet() { |
|
45 name = "return"; |
|
46 } |
|
47 |
|
48 /** |
|
49 * {@inheritDoc} |
|
50 */ |
|
51 public void inherit(DocFinder.Input input, DocFinder.Output output) { |
|
52 Tag[] tags = input.method.tags("return"); |
|
53 if (tags.length > 0) { |
|
54 output.holder = input.method; |
|
55 output.holderTag = tags[0]; |
|
56 output.inlineTags = input.isFirstSentence ? |
|
57 tags[0].firstSentenceTags() : tags[0].inlineTags(); |
|
58 } |
|
59 } |
|
60 |
|
61 /** |
|
62 * Return true if this <code>Taglet</code> |
|
63 * is used in constructor documentation. |
|
64 * @return true if this <code>Taglet</code> |
|
65 * is used in constructor documentation and false |
|
66 * otherwise. |
|
67 */ |
|
68 public boolean inConstructor() { |
|
69 return false; |
|
70 } |
|
71 |
|
72 /** |
|
73 * {@inheritDoc} |
|
74 */ |
|
75 public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) { |
|
76 Type returnType = ((MethodDoc) holder).returnType(); |
|
77 Tag[] tags = holder.tags(name); |
|
78 |
|
79 //Make sure we are not using @return tag on method with void return type. |
|
80 if (returnType.isPrimitive() && returnType.typeName().equals("void")) { |
|
81 if (tags.length > 0) { |
|
82 writer.getMsgRetriever().warning(holder.position(), |
|
83 "doclet.Return_tag_on_void_method"); |
|
84 } |
|
85 return null; |
|
86 } |
|
87 //Inherit @return tag if necessary. |
|
88 if (tags.length == 0) { |
|
89 DocFinder.Output inheritedDoc = |
|
90 DocFinder.search(new DocFinder.Input((MethodDoc) holder, this)); |
|
91 tags = inheritedDoc.holderTag == null ? tags : new Tag[] {inheritedDoc.holderTag}; |
|
92 } |
|
93 return tags.length > 0 ? writer.returnTagOutput(tags[0]) : null; |
|
94 } |
|
95 } |