author | chegar |
Sun, 17 Aug 2014 15:52:32 +0100 | |
changeset 25874 | 83c19f00452c |
parent 22159 | langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ValueTaglet.java@682da512ec17 |
child 38617 | d93a7f64e231 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
17569 | 2 |
* Copyright (c) 2001, 2013, 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 |
||
26 |
package com.sun.tools.doclets.internal.toolkit.taglets; |
|
27 |
||
14258 | 28 |
import java.util.*; |
29 |
||
10 | 30 |
import com.sun.javadoc.*; |
31 |
import com.sun.tools.doclets.internal.toolkit.Configuration; |
|
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17569
diff
changeset
|
32 |
import com.sun.tools.doclets.internal.toolkit.Content; |
10 | 33 |
import com.sun.tools.doclets.internal.toolkit.util.*; |
34 |
||
35 |
/** |
|
36 |
* An inline Taglet representing the value tag. This tag should only be used with |
|
37 |
* constant fields that have a value. It is used to access the value of constant |
|
38 |
* fields. This inline tag has an optional field name parameter. If the name is |
|
39 |
* specified, the constant value is retrieved from the specified field. A link |
|
40 |
* is also created to the specified field. If a name is not specified, the value |
|
41 |
* is retrieved for the field that the inline tag appears on. The name is specifed |
|
42 |
* in the following format: [fully qualified class name]#[constant field name]. |
|
43 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
44 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
45 |
* If you write code that depends on this, you do so at your own risk. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
46 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
47 |
* deletion without notice.</b> |
10 | 48 |
* |
49 |
* @author Jamie Ho |
|
50 |
* @since 1.4 |
|
51 |
*/ |
|
52 |
||
53 |
public class ValueTaglet extends BaseInlineTaglet { |
|
54 |
||
55 |
/** |
|
56 |
* Construct a new ValueTaglet. |
|
57 |
*/ |
|
58 |
public ValueTaglet() { |
|
59 |
name = "value"; |
|
60 |
} |
|
61 |
||
62 |
/** |
|
63 |
* Will return false because this inline tag may |
|
64 |
* only appear in Fields. |
|
65 |
* @return false since this is not a method. |
|
66 |
*/ |
|
67 |
public boolean inMethod() { |
|
68 |
return true; |
|
69 |
} |
|
70 |
||
71 |
/** |
|
72 |
* Will return false because this inline tag may |
|
73 |
* only appear in Fields. |
|
74 |
* @return false since this is not a method. |
|
75 |
*/ |
|
76 |
public boolean inConstructor() { |
|
77 |
return true; |
|
78 |
} |
|
79 |
||
80 |
/** |
|
81 |
* Will return false because this inline tag may |
|
82 |
* only appear in Fields. |
|
83 |
* @return false since this is not a method. |
|
84 |
*/ |
|
85 |
public boolean inOverview() { |
|
86 |
return true; |
|
87 |
} |
|
88 |
||
89 |
/** |
|
90 |
* Will return false because this inline tag may |
|
91 |
* only appear in Fields. |
|
92 |
* @return false since this is not a method. |
|
93 |
*/ |
|
94 |
public boolean inPackage() { |
|
95 |
return true; |
|
96 |
} |
|
97 |
||
98 |
/** |
|
99 |
* Will return false because this inline tag may |
|
100 |
* only appear in Fields. |
|
101 |
* @return false since this is not a method. |
|
102 |
*/ |
|
103 |
public boolean inType() { |
|
104 |
return true; |
|
105 |
} |
|
106 |
||
107 |
/** |
|
20264 | 108 |
* Given the name of the field, return the corresponding FieldDoc. Return null |
109 |
* due to invalid use of value tag if the name is null or empty string and if |
|
110 |
* the value tag is not used on a field. |
|
10 | 111 |
* |
112 |
* @param config the current configuration of the doclet. |
|
113 |
* @param tag the value tag. |
|
114 |
* @param name the name of the field to search for. The name should be in |
|
14259 | 115 |
* {@code <qualified class name>#<field name>} format. If the class name is omitted, |
10 | 116 |
* it is assumed that the field is in the current class. |
117 |
* |
|
118 |
* @return the corresponding FieldDoc. If the name is null or empty string, |
|
20264 | 119 |
* return field that the value tag was used in. Return null if the name is null |
120 |
* or empty string and if the value tag is not used on a field. |
|
10 | 121 |
*/ |
122 |
private FieldDoc getFieldDoc(Configuration config, Tag tag, String name) { |
|
123 |
if (name == null || name.length() == 0) { |
|
124 |
//Base case: no label. |
|
125 |
if (tag.holder() instanceof FieldDoc) { |
|
126 |
return (FieldDoc) tag.holder(); |
|
127 |
} else { |
|
20264 | 128 |
// If the value tag does not specify a parameter which is a valid field and |
129 |
// it is not used within the comments of a valid field, return null. |
|
130 |
return null; |
|
10 | 131 |
} |
132 |
} |
|
133 |
StringTokenizer st = new StringTokenizer(name, "#"); |
|
134 |
String memberName = null; |
|
135 |
ClassDoc cd = null; |
|
136 |
if (st.countTokens() == 1) { |
|
137 |
//Case 2: @value in same class. |
|
138 |
Doc holder = tag.holder(); |
|
139 |
if (holder instanceof MemberDoc) { |
|
140 |
cd = ((MemberDoc) holder).containingClass(); |
|
141 |
} else if (holder instanceof ClassDoc) { |
|
142 |
cd = (ClassDoc) holder; |
|
143 |
} |
|
144 |
memberName = st.nextToken(); |
|
145 |
} else { |
|
146 |
//Case 3: @value in different class. |
|
147 |
cd = config.root.classNamed(st.nextToken()); |
|
148 |
memberName = st.nextToken(); |
|
149 |
} |
|
150 |
if (cd == null) { |
|
151 |
return null; |
|
152 |
} |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
20264
diff
changeset
|
153 |
for (FieldDoc field : cd.fields()) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
20264
diff
changeset
|
154 |
if (field.name().equals(memberName)) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
20264
diff
changeset
|
155 |
return field; |
10 | 156 |
} |
157 |
} |
|
158 |
return null; |
|
159 |
} |
|
160 |
||
161 |
/** |
|
162 |
* {@inheritDoc} |
|
163 |
*/ |
|
17574
044c7e1e4d53
8012308: Remove TagletOutput in favor of direct use of Content
jjg
parents:
17569
diff
changeset
|
164 |
public Content getTagletOutput(Tag tag, TagletWriter writer) { |
10 | 165 |
FieldDoc field = getFieldDoc( |
166 |
writer.configuration(), tag, tag.text()); |
|
167 |
if (field == null) { |
|
20264 | 168 |
if (tag.text().isEmpty()) { |
169 |
//Invalid use of @value |
|
170 |
writer.getMsgRetriever().warning(tag.holder().position(), |
|
171 |
"doclet.value_tag_invalid_use"); |
|
172 |
} else { |
|
173 |
//Reference is unknown. |
|
174 |
writer.getMsgRetriever().warning(tag.holder().position(), |
|
175 |
"doclet.value_tag_invalid_reference", tag.text()); |
|
176 |
} |
|
10 | 177 |
} else if (field.constantValue() != null) { |
178 |
return writer.valueTagOutput(field, |
|
17569 | 179 |
field.constantValueExpression(), |
10 | 180 |
! field.equals(tag.holder())); |
181 |
} else { |
|
182 |
//Referenced field is not a constant. |
|
183 |
writer.getMsgRetriever().warning(tag.holder().position(), |
|
184 |
"doclet.value_tag_invalid_constant", field.name()); |
|
185 |
} |
|
186 |
return writer.getOutputInstance(); |
|
187 |
} |
|
188 |
} |