author | ksrini |
Mon, 05 Jun 2017 13:45:34 -0700 | |
changeset 45417 | f7479ee8de69 |
parent 40303 | 96a1226aca18 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
45417 | 2 |
* Copyright (c) 2001, 2017, 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 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
26 |
package jdk.javadoc.internal.doclets.toolkit.taglets; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
27 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
28 |
import javax.lang.model.element.Element; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
29 |
import javax.lang.model.element.ExecutableElement; |
10 | 30 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
31 |
import com.sun.source.doctree.DocTree; |
45417 | 32 |
import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
33 |
import jdk.javadoc.internal.doclets.toolkit.Content; |
40303 | 34 |
import jdk.javadoc.internal.doclets.toolkit.Messages; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
35 |
import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
36 |
import jdk.javadoc.internal.doclets.toolkit.util.DocFinder; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
37 |
import jdk.javadoc.internal.doclets.toolkit.util.DocFinder.Input; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
38 |
import jdk.javadoc.internal.doclets.toolkit.util.Utils; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
39 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
40 |
import static com.sun.source.doctree.DocTree.Kind.*; |
10 | 41 |
|
42 |
/** |
|
43 |
* An inline Taglet representing the <b>inheritDoc</b> tag. This tag should only |
|
44 |
* be used with a method. It is used to inherit documentation from overriden |
|
45 |
* and implemented methods. |
|
46 |
* |
|
14260 | 47 |
* <p><b>This is NOT part of any supported API. |
48 |
* If you write code that depends on this, you do so at your own risk. |
|
49 |
* This code and its internal interfaces are subject to change or |
|
50 |
* deletion without notice.</b> |
|
10 | 51 |
* |
52 |
* @author Jamie Ho |
|
53 |
*/ |
|
54 |
||
55 |
public class InheritDocTaglet extends BaseInlineTaglet { |
|
56 |
||
57 |
/** |
|
58 |
* The inline tag that would appear in the documentation if |
|
59 |
* the writer wanted documentation to be inherited. |
|
60 |
*/ |
|
61 |
public static final String INHERIT_DOC_INLINE_TAG = "{@inheritDoc}"; |
|
62 |
||
63 |
/** |
|
64 |
* Construct a new InheritDocTaglet. |
|
65 |
*/ |
|
66 |
public InheritDocTaglet () { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
67 |
name = INHERIT_DOC.tagName; |
10 | 68 |
} |
69 |
||
70 |
/** |
|
71 |
* Will return false because this inline tag may |
|
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
72 |
* not appear in Fields. |
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
73 |
* @return false |
10 | 74 |
*/ |
75 |
public boolean inField() { |
|
76 |
return false; |
|
77 |
} |
|
78 |
||
79 |
/** |
|
80 |
* Will return false because this inline tag may |
|
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
81 |
* not appear in Constructors. |
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
82 |
* @return false |
10 | 83 |
*/ |
84 |
public boolean inConstructor() { |
|
85 |
return false; |
|
86 |
} |
|
87 |
||
88 |
/** |
|
89 |
* Will return false because this inline tag may |
|
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
90 |
* not appear in Overview. |
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
91 |
* @return false |
10 | 92 |
*/ |
93 |
public boolean inOverview() { |
|
94 |
return false; |
|
95 |
} |
|
96 |
||
97 |
/** |
|
98 |
* Will return false because this inline tag may |
|
38911
48a00b5ee366
8156077: Support javadoc tags in module documentation
bpatel
parents:
35426
diff
changeset
|
99 |
* not appear in Modules. |
48a00b5ee366
8156077: Support javadoc tags in module documentation
bpatel
parents:
35426
diff
changeset
|
100 |
* @return false |
48a00b5ee366
8156077: Support javadoc tags in module documentation
bpatel
parents:
35426
diff
changeset
|
101 |
*/ |
48a00b5ee366
8156077: Support javadoc tags in module documentation
bpatel
parents:
35426
diff
changeset
|
102 |
public boolean inModule() { |
48a00b5ee366
8156077: Support javadoc tags in module documentation
bpatel
parents:
35426
diff
changeset
|
103 |
return false; |
48a00b5ee366
8156077: Support javadoc tags in module documentation
bpatel
parents:
35426
diff
changeset
|
104 |
} |
48a00b5ee366
8156077: Support javadoc tags in module documentation
bpatel
parents:
35426
diff
changeset
|
105 |
|
48a00b5ee366
8156077: Support javadoc tags in module documentation
bpatel
parents:
35426
diff
changeset
|
106 |
/** |
48a00b5ee366
8156077: Support javadoc tags in module documentation
bpatel
parents:
35426
diff
changeset
|
107 |
* Will return false because this inline tag may |
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
108 |
* not appear in Packages. |
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
109 |
* @return false |
10 | 110 |
*/ |
111 |
public boolean inPackage() { |
|
112 |
return false; |
|
113 |
} |
|
114 |
||
115 |
/** |
|
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
116 |
* Will return true because this inline tag may |
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
117 |
* appear in Type (Class). |
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
118 |
* @return true |
10 | 119 |
*/ |
120 |
public boolean inType() { |
|
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
121 |
return true; |
10 | 122 |
} |
123 |
||
124 |
/** |
|
125 |
* Given a <code>MethodDoc</code> item, a <code>Tag</code> in the |
|
14542 | 126 |
* <code>MethodDoc</code> item and a String, replace all occurrences |
10 | 127 |
* of @inheritDoc with documentation from it's superclass or superinterface. |
128 |
* |
|
129 |
* @param writer the writer that is writing the output. |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
130 |
* @param e the {@link Element} that we are documenting. |
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
131 |
* @param holderTag the tag that holds the inheritDoc tag or null for type |
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
132 |
* (class) docs. |
10 | 133 |
* @param isFirstSentence true if we only want to inherit the first sentence. |
134 |
*/ |
|
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17566
diff
changeset
|
135 |
private Content retrieveInheritedDocumentation(TagletWriter writer, |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
136 |
Element e, DocTree holderTag, boolean isFirstSentence) { |
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17566
diff
changeset
|
137 |
Content replacement = writer.getOutputInstance(); |
45417 | 138 |
BaseConfiguration configuration = writer.configuration(); |
40303 | 139 |
Messages messages = configuration.getMessages(); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
140 |
Utils utils = configuration.utils; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
141 |
CommentHelper ch = utils.getCommentHelper(e); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
142 |
Taglet inheritableTaglet = holderTag == null |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
143 |
? null |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
144 |
: configuration.tagletManager.getTaglet(ch.getTagName(holderTag)); |
10 | 145 |
if (inheritableTaglet != null && |
146 |
!(inheritableTaglet instanceof InheritableTaglet)) { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
147 |
String message = utils.getSimpleName(e) + |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
148 |
((utils.isExecutableElement(e)) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
149 |
? utils.flatSignature((ExecutableElement)e) |
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
150 |
: ""); |
10 | 151 |
//This tag does not support inheritence. |
40303 | 152 |
messages.warning(e, "doclet.noInheritedDoc", message); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
153 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
154 |
Input input = new DocFinder.Input(utils, e, |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
155 |
(InheritableTaglet) inheritableTaglet, new DocFinder.DocTreeInfo(holderTag, e), |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
156 |
isFirstSentence, true); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
157 |
DocFinder.Output inheritedDoc = DocFinder.search(configuration, input); |
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
158 |
if (inheritedDoc.isValidInheritDocTag) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
159 |
if (!inheritedDoc.inlineTags.isEmpty()) { |
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
160 |
replacement = writer.commentTagsToOutput(inheritedDoc.holderTag, |
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
161 |
inheritedDoc.holder, inheritedDoc.inlineTags, isFirstSentence); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
162 |
ch.setOverrideElement(inheritedDoc.holder); |
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
163 |
} |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
164 |
|
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
165 |
} else { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
166 |
String message = utils.getSimpleName(e) + |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
167 |
((utils.isExecutableElement(e)) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
168 |
? utils.flatSignature((ExecutableElement)e) |
17547
40f2f9a5a445
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents:
14542
diff
changeset
|
169 |
: ""); |
40303 | 170 |
messages.warning(e, "doclet.noInheritedDoc", message); |
10 | 171 |
} |
172 |
return replacement; |
|
173 |
} |
|
174 |
||
175 |
/** |
|
176 |
* Given the <code>Tag</code> representation of this custom |
|
177 |
* tag, return its string representation, which is output |
|
178 |
* to the generated page. |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
179 |
* |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
180 |
* @param e the element holding the tag |
10 | 181 |
* @param tag the <code>Tag</code> representation of this custom tag. |
182 |
* @param tagletWriter the taglet writer for output. |
|
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17566
diff
changeset
|
183 |
* @return the Content representation of this <code>Tag</code>. |
10 | 184 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
185 |
public Content getTagletOutput(Element e, DocTree tag, TagletWriter tagletWriter) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
186 |
DocTree inheritTag = tag.getKind() == INHERIT_DOC ? null : tag; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
187 |
return retrieveInheritedDocumentation(tagletWriter, e, |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
188 |
inheritTag, tagletWriter.isFirstSentence); |
10 | 189 |
} |
190 |
} |