1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.exceptions.report.sort;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.Collections;
21 import java.util.Comparator;
22 import java.util.List;
23
24 import com.sun.javadoc.ClassDoc;
25 import com.sun.javadoc.Doc;
26 import com.sun.javadoc.FieldDoc;
27
28 import de.smartics.analysis.javadoc.runtime.RuntimeUtils;
29 import de.smartics.exceptions.core.Code;
30 import de.smartics.exceptions.report.message.PlaceHolderHandler;
31 import de.smartics.exceptions.report.message.PlaceHolderInfo;
32 import de.smartics.report.conf.ProjectConfiguration;
33 import de.smartics.report.util.JavadocUtils;
34
35
36
37
38
39
40
41 public final class CodeUtils
42 {
43
44
45
46
47
48
49
50
51
52
53
54
55
56 private CodeUtils()
57 {
58 }
59
60
61
62
63
64
65
66
67
68
69
70 public static final class CodeContainer
71 {
72
73
74
75 private final Code code;
76
77
78
79
80 private final ClassDoc classDoc;
81
82
83
84
85 private final FieldDoc fieldDoc;
86
87
88
89
90 private final PlaceHolderInfo placeHolderInfo;
91
92
93
94
95
96
97
98
99
100 public CodeContainer(final Code code, final ClassDoc classDoc,
101 final FieldDoc fieldDoc, final PlaceHolderInfo placeHolderInfo)
102 {
103 this.code = code;
104 this.classDoc = classDoc;
105 this.fieldDoc = fieldDoc;
106 this.placeHolderInfo = placeHolderInfo;
107 }
108
109
110
111
112
113
114 public Code getCode()
115 {
116 return code;
117 }
118
119
120
121
122
123
124 public ClassDoc getClassDoc()
125 {
126 return classDoc;
127 }
128
129
130
131
132
133
134 public FieldDoc getFieldDoc()
135 {
136 return fieldDoc;
137 }
138
139
140
141
142
143
144 public PlaceHolderInfo getPlaceHolderInfo()
145 {
146 return placeHolderInfo;
147 }
148 }
149
150
151
152
153
154
155
156 public static List<CodeContainer> getCodeList(
157 final ProjectConfiguration<?> config, final Collection<Doc> javadocs)
158 {
159 return getCodeList(config, javadocs, new CodeComparator());
160 }
161
162 public static List<CodeContainer> getCodeList(
163 final ProjectConfiguration<?> config, final Collection<Doc> javadocs,
164 final Comparator<CodeContainer> comparator)
165 {
166 final ClassLoader classLoader = config.getProjectClassLoader();
167 final PlaceHolderHandler placeHolderHandler =
168 new PlaceHolderHandler(config);
169
170 final List<CodeContainer> codeList =
171 new ArrayList<CodeContainer>(javadocs.size());
172 for (Doc doc : javadocs)
173 {
174 if (doc.isClass())
175 {
176 final ClassDoc classDoc = (ClassDoc) doc;
177 for (FieldDoc fieldDoc : JavadocUtils.getClassElements(classDoc))
178 {
179 final Code code = loadCode(classLoader, fieldDoc);
180 if (code != null)
181 {
182 final PlaceHolderInfo placeHolderInfo =
183 placeHolderHandler.readPlaceholderDesc(classLoader, fieldDoc);
184 codeList.add(new CodeContainer(code, classDoc, fieldDoc,
185 placeHolderInfo));
186 }
187 }
188 }
189 }
190
191 Collections.sort(codeList, comparator);
192 return codeList;
193 }
194
195 private static Code loadCode(final ClassLoader classLoader,
196 final FieldDoc fieldDoc)
197 {
198 try
199 {
200 final Code code = (Code) RuntimeUtils.loadInstance(classLoader, fieldDoc);
201 return code;
202 }
203 catch (final Exception e)
204 {
205
206 }
207 return null;
208 }
209
210
211
212
213
214 }