|
1 /* |
|
2 * Copyright (c) 2001, 2013, 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 */ |
|
25 |
|
26 package com.sun.tools.doclets.internal.toolkit.taglets; |
|
27 |
|
28 import com.sun.javadoc.*; |
|
29 import com.sun.tools.doclets.internal.toolkit.Configuration; |
|
30 import com.sun.tools.doclets.internal.toolkit.Content; |
|
31 import com.sun.tools.doclets.internal.toolkit.util.*; |
|
32 |
|
33 /** |
|
34 * An inline Taglet representing the <b>inheritDoc</b> tag. This tag should only |
|
35 * be used with a method. It is used to inherit documentation from overriden |
|
36 * and implemented methods. |
|
37 * |
|
38 * <p><b>This is NOT part of any supported API. |
|
39 * If you write code that depends on this, you do so at your own risk. |
|
40 * This code and its internal interfaces are subject to change or |
|
41 * deletion without notice.</b> |
|
42 * |
|
43 * @author Jamie Ho |
|
44 * @since 1.4 |
|
45 */ |
|
46 |
|
47 public class InheritDocTaglet extends BaseInlineTaglet { |
|
48 |
|
49 /** |
|
50 * The inline tag that would appear in the documentation if |
|
51 * the writer wanted documentation to be inherited. |
|
52 */ |
|
53 public static final String INHERIT_DOC_INLINE_TAG = "{@inheritDoc}"; |
|
54 |
|
55 /** |
|
56 * Construct a new InheritDocTaglet. |
|
57 */ |
|
58 public InheritDocTaglet () { |
|
59 name = "inheritDoc"; |
|
60 } |
|
61 |
|
62 /** |
|
63 * Will return false because this inline tag may |
|
64 * not appear in Fields. |
|
65 * @return false |
|
66 */ |
|
67 public boolean inField() { |
|
68 return false; |
|
69 } |
|
70 |
|
71 /** |
|
72 * Will return false because this inline tag may |
|
73 * not appear in Constructors. |
|
74 * @return false |
|
75 */ |
|
76 public boolean inConstructor() { |
|
77 return false; |
|
78 } |
|
79 |
|
80 /** |
|
81 * Will return false because this inline tag may |
|
82 * not appear in Overview. |
|
83 * @return false |
|
84 */ |
|
85 public boolean inOverview() { |
|
86 return false; |
|
87 } |
|
88 |
|
89 /** |
|
90 * Will return false because this inline tag may |
|
91 * not appear in Packages. |
|
92 * @return false |
|
93 */ |
|
94 public boolean inPackage() { |
|
95 return false; |
|
96 } |
|
97 |
|
98 /** |
|
99 * Will return true because this inline tag may |
|
100 * appear in Type (Class). |
|
101 * @return true |
|
102 */ |
|
103 public boolean inType() { |
|
104 return true; |
|
105 } |
|
106 |
|
107 /** |
|
108 * Given a <code>MethodDoc</code> item, a <code>Tag</code> in the |
|
109 * <code>MethodDoc</code> item and a String, replace all occurrences |
|
110 * of @inheritDoc with documentation from it's superclass or superinterface. |
|
111 * |
|
112 * @param writer the writer that is writing the output. |
|
113 * @param ped the {@link ProgramElementDoc} that we are documenting. |
|
114 * @param holderTag the tag that holds the inheritDoc tag or null for type |
|
115 * (class) docs. |
|
116 * @param isFirstSentence true if we only want to inherit the first sentence. |
|
117 */ |
|
118 private Content retrieveInheritedDocumentation(TagletWriter writer, |
|
119 ProgramElementDoc ped, Tag holderTag, boolean isFirstSentence) { |
|
120 Content replacement = writer.getOutputInstance(); |
|
121 |
|
122 Configuration configuration = writer.configuration(); |
|
123 Taglet inheritableTaglet = holderTag == null ? |
|
124 null : configuration.tagletManager.getTaglet(holderTag.name()); |
|
125 if (inheritableTaglet != null && |
|
126 !(inheritableTaglet instanceof InheritableTaglet)) { |
|
127 String message = ped.name() + |
|
128 ((ped instanceof ExecutableMemberDoc) |
|
129 ? ((ExecutableMemberDoc)ped).flatSignature() |
|
130 : ""); |
|
131 //This tag does not support inheritence. |
|
132 configuration.message.warning(ped.position(), |
|
133 "doclet.noInheritedDoc", message); |
|
134 } |
|
135 DocFinder.Output inheritedDoc = |
|
136 DocFinder.search(new DocFinder.Input(ped, |
|
137 (InheritableTaglet) inheritableTaglet, holderTag, |
|
138 isFirstSentence, true)); |
|
139 if (inheritedDoc.isValidInheritDocTag) { |
|
140 if (inheritedDoc.inlineTags.length > 0) { |
|
141 replacement = writer.commentTagsToOutput(inheritedDoc.holderTag, |
|
142 inheritedDoc.holder, inheritedDoc.inlineTags, isFirstSentence); |
|
143 } |
|
144 } else { |
|
145 String message = ped.name() + |
|
146 ((ped instanceof ExecutableMemberDoc) |
|
147 ? ((ExecutableMemberDoc)ped).flatSignature() |
|
148 : ""); |
|
149 configuration.message.warning(ped.position(), |
|
150 "doclet.noInheritedDoc", message); |
|
151 } |
|
152 return replacement; |
|
153 } |
|
154 |
|
155 /** |
|
156 * Given the <code>Tag</code> representation of this custom |
|
157 * tag, return its string representation, which is output |
|
158 * to the generated page. |
|
159 * @param tag the <code>Tag</code> representation of this custom tag. |
|
160 * @param tagletWriter the taglet writer for output. |
|
161 * @return the Content representation of this <code>Tag</code>. |
|
162 */ |
|
163 public Content getTagletOutput(Tag tag, TagletWriter tagletWriter) { |
|
164 if (! (tag.holder() instanceof ProgramElementDoc)) { |
|
165 return tagletWriter.getOutputInstance(); |
|
166 } |
|
167 return tag.name().equals("@inheritDoc") ? |
|
168 retrieveInheritedDocumentation(tagletWriter, (ProgramElementDoc) tag.holder(), null, tagletWriter.isFirstSentence) : |
|
169 retrieveInheritedDocumentation(tagletWriter, (ProgramElementDoc) tag.holder(), tag, tagletWriter.isFirstSentence); |
|
170 } |
|
171 } |