1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.maven.exceptions.sdoc;
17
18 import java.util.ArrayList;
19 import java.util.LinkedList;
20 import java.util.List;
21
22 import org.apache.commons.lang.StringUtils;
23
24 import com.thoughtworks.qdox.model.DocletTag;
25 import com.thoughtworks.qdox.model.JavaAnnotatedElement;
26 import com.thoughtworks.qdox.model.JavaClass;
27 import com.thoughtworks.qdox.model.JavaField;
28
29
30
31
32 class TagInfo
33 {
34
35
36
37
38
39
40
41
42
43
44 private final String category;
45
46
47
48
49
50 private final String subcategory;
51
52
53
54
55
56 private final List<String> tags = new ArrayList<String>();
57
58
59
60
61
62 private final List<String> parents = new ArrayList<String>();
63
64
65
66
67
68 private final String name;
69
70
71
72
73
74 private final String sortKey;
75
76
77
78
79
80 private final String shortDescription;
81
82
83
84
85
86 private final String notes;
87
88
89
90
91
92 private final String codeType;
93
94
95
96
97
98
99
100
101 public TagInfo(final JavaClass classDoc, final JavaField fieldDoc)
102 {
103 this.category = extractSingleValue(classDoc, fieldDoc, "sdoc.category");
104 this.subcategory =
105 extractSingleValue(classDoc, fieldDoc, "sdoc.subcategory");
106 extractMultiValue(classDoc, "sdoc.tag", tags);
107 extractMultiValue(fieldDoc, "sdoc.tag", tags);
108 extractMultiValue(classDoc, "sdoc.parent", parents);
109 extractMultiValue(fieldDoc, "sdoc.parent", parents);
110
111 this.name = extractSingleValue(fieldDoc, "sdoc.name");
112 this.sortKey = extractSingleValue(fieldDoc, "sdoc.sortKey");
113 this.shortDescription =
114 extractSingleValue(fieldDoc, "sdoc.shortDescription");
115 this.notes = extractSingleValue(fieldDoc, "sdoc.notes");
116 this.codeType = calcCodeType(classDoc, fieldDoc);
117 ;
118 }
119
120
121
122
123
124
125
126 private String calcCodeType(final JavaClass classDoc, final JavaField fieldDoc)
127 {
128 String type = extractSingleValue(fieldDoc, "sdoc.codeType");
129 if (StringUtils.isBlank(type))
130 {
131 type = "error";
132 }
133
134 return type;
135 }
136
137 private String extractSingleValue(final JavaAnnotatedElement doc1,
138 final JavaAnnotatedElement doc2, final String name)
139 {
140 String value = extractSingleValue(doc2, name);
141 if (StringUtils.isBlank(value))
142 {
143 value = extractSingleValue(doc1, name);
144 }
145 return value;
146 }
147
148 private String extractSingleValue(final JavaAnnotatedElement doc,
149 final String name)
150 {
151 final List<DocletTag> tags = getTagsByName(doc, name);
152 if (!tags.isEmpty())
153 {
154 final String text = getValue(tags.get(0));
155 if (StringUtils.isNotBlank(text))
156 {
157 return text;
158 }
159 }
160 return null;
161 }
162
163 private static String getValue(final DocletTag docletTag)
164 {
165 final String name = docletTag.getName();
166 final int index = name.indexOf('=');
167 if (index != -1 && index < name.length() - 1)
168 {
169 final String value = name.substring(index + 1);
170 return value;
171 }
172 else
173 {
174 return docletTag.getValue();
175 }
176 }
177
178 private static List<DocletTag> getTagsByName(final JavaAnnotatedElement doc,
179 final String name)
180 {
181 final List<DocletTag> specifiedTags = new LinkedList<DocletTag>();
182 final String tag = name + '=';
183 for (final DocletTag docletTag : doc.getTags())
184 {
185 final String currentName = docletTag.getName();
186 if (currentName.equals(name) && currentName.startsWith(tag))
187 {
188 specifiedTags.add(docletTag);
189 }
190 }
191 return specifiedTags;
192 }
193
194 private void extractMultiValue(final JavaAnnotatedElement doc,
195 final String name, final List<String> list)
196 {
197 final List<DocletTag> tags = getTagsByName(doc, name);
198 for (final DocletTag tag : tags)
199 {
200 final String text = tag.getValue();
201 if (StringUtils.isNotBlank(text))
202 {
203 list.add(text);
204 }
205 }
206 }
207
208
209
210
211
212
213
214
215
216
217 public String getCategory()
218 {
219 return category;
220 }
221
222
223
224
225
226
227
228
229 public String getSubcategory()
230 {
231 return subcategory;
232 }
233
234
235
236
237
238
239
240
241 public List<String> getTags()
242 {
243 return tags;
244 }
245
246
247
248
249
250
251
252
253 public List<String> getParents()
254 {
255 return parents;
256 }
257
258
259
260
261
262
263
264
265 public String getName()
266 {
267 return name;
268 }
269
270
271
272
273
274
275
276
277 public String getSortKey()
278 {
279 return sortKey;
280 }
281
282
283
284
285
286
287
288
289 public String getShortDescription()
290 {
291 return shortDescription;
292 }
293
294
295
296
297
298
299
300
301 public String getNotes()
302 {
303 return notes;
304 }
305
306
307
308
309
310
311
312
313 public String getCodeType()
314 {
315 return codeType;
316 }
317
318
319
320
321
322 }