1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.base.utility; |
17 |
|
|
18 |
|
import java.lang.reflect.Field; |
19 |
|
import java.lang.reflect.InvocationTargetException; |
20 |
|
import java.lang.reflect.Method; |
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
@author |
28 |
|
|
|
|
| 84.3% |
Uncovered Elements: 14 (89) |
Complexity: 31 |
Complexity Density: 0.46 |
|
29 |
|
public abstract class YodaUtility { |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
34 |
0
|
private YodaUtility() {... |
35 |
|
|
36 |
|
} |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@param |
46 |
|
@param |
47 |
|
@param |
48 |
|
@return |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
50 |
5
|
public static boolean existsMethod(final String clazz, final String name,... |
51 |
|
final Class[] parameterTypes) { |
52 |
5
|
Class c; |
53 |
5
|
try { |
54 |
5
|
c = Class.forName(clazz); |
55 |
|
} catch (ClassNotFoundException e) { |
56 |
1
|
return false; |
57 |
|
} |
58 |
4
|
return existsMethod(c, name, parameterTypes); |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
@param |
69 |
|
@param |
70 |
|
@param |
71 |
|
@return |
72 |
|
|
|
|
| 93.8% |
Uncovered Elements: 1 (16) |
Complexity: 5 |
Complexity Density: 0.42 |
|
73 |
12
|
public static boolean existsMethod(final Class clazz, final String name,... |
74 |
|
final Class[] parameterTypes) { |
75 |
12
|
Method method = null; |
76 |
12
|
Class cl = clazz; |
77 |
12
|
try { |
78 |
30
|
while (!Object.class.equals(cl)) { |
79 |
26
|
try { |
80 |
26
|
method = cl.getDeclaredMethod(name, parameterTypes); |
81 |
8
|
break; |
82 |
|
} catch (NoSuchMethodException ex) { |
83 |
18
|
cl = cl.getSuperclass(); |
84 |
|
} |
85 |
|
} |
86 |
12
|
if (method == null) { |
87 |
4
|
return false; |
88 |
|
} |
89 |
8
|
return true; |
90 |
|
} catch (SecurityException e) { |
91 |
0
|
throw new RuntimeException(e); |
92 |
|
} |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
@param |
105 |
|
@param |
106 |
|
@param |
107 |
|
@param |
108 |
|
@return |
109 |
|
@throws |
110 |
|
@throws |
111 |
|
|
|
|
| 85% |
Uncovered Elements: 3 (20) |
Complexity: 7 |
Complexity Density: 0.44 |
|
112 |
7
|
public static Object executeMethod(final Object obj, final String name,... |
113 |
|
final Class[] parameterTypes, final Object[] parameter) throws NoSuchMethodException, |
114 |
|
InvocationTargetException { |
115 |
7
|
Method method = null; |
116 |
7
|
try { |
117 |
7
|
Class cl = obj.getClass(); |
118 |
20
|
while (!Object.class.equals(cl)) { |
119 |
17
|
try { |
120 |
17
|
method = cl.getDeclaredMethod(name, parameterTypes); |
121 |
4
|
break; |
122 |
|
} catch (NoSuchMethodException ex) { |
123 |
13
|
cl = cl.getSuperclass(); |
124 |
|
} |
125 |
|
} |
126 |
7
|
if (method == null) { |
127 |
3
|
throw new NoSuchMethodException(name); |
128 |
|
} |
129 |
4
|
method.setAccessible(true); |
130 |
|
} catch (SecurityException e) { |
131 |
0
|
throw new RuntimeException(e); |
132 |
|
} |
133 |
4
|
try { |
134 |
4
|
return method.invoke(obj, parameter); |
135 |
|
} catch (IllegalArgumentException e) { |
136 |
0
|
throw new RuntimeException(e); |
137 |
|
} catch (IllegalAccessException e) { |
138 |
0
|
throw new RuntimeException(e); |
139 |
|
} |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
@param |
152 |
|
@param |
153 |
|
@param |
154 |
|
@param |
155 |
|
@return |
156 |
|
@throws |
157 |
|
@throws |
158 |
|
|
|
|
| 61.5% |
Uncovered Elements: 5 (13) |
Complexity: 5 |
Complexity Density: 0.45 |
|
159 |
5
|
public static Object executeMethod(final String clazzName, final String name,... |
160 |
|
final Class[] parameterTypes, final Object[] parameter) throws NoSuchMethodException, |
161 |
|
InvocationTargetException { |
162 |
5
|
Method method = null; |
163 |
5
|
try { |
164 |
5
|
Class cl = Class.forName(clazzName); |
165 |
5
|
method = cl.getDeclaredMethod(name, parameterTypes); |
166 |
1
|
if (method == null) { |
167 |
0
|
throw new NoSuchMethodException(name); |
168 |
|
} |
169 |
1
|
method.setAccessible(true); |
170 |
1
|
return method.invoke(cl, parameter); |
171 |
|
} catch (SecurityException e) { |
172 |
0
|
throw new RuntimeException(e); |
173 |
|
} catch (ClassNotFoundException e) { |
174 |
0
|
throw new RuntimeException(e); |
175 |
|
} catch (IllegalAccessException e) { |
176 |
0
|
throw new RuntimeException(e); |
177 |
|
} |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
@param |
185 |
|
@param |
186 |
|
@return |
187 |
|
@throws |
188 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 3 |
Complexity Density: 0.6 |
|
189 |
3
|
public static Object getFieldValue(final Object obj, final String name) throws NoSuchFieldException {... |
190 |
3
|
final Field field = getField(obj, name); |
191 |
2
|
try { |
192 |
2
|
return field.get(obj); |
193 |
|
} catch (IllegalArgumentException e) { |
194 |
0
|
throw new RuntimeException(e); |
195 |
|
} catch (IllegalAccessException e) { |
196 |
0
|
throw new RuntimeException(e); |
197 |
|
} |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
@param |
205 |
|
@param |
206 |
|
@param |
207 |
|
@throws |
208 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 3 |
Complexity Density: 0.6 |
|
209 |
2
|
public static void setFieldContent(final Object obj, final String name, final Object value)... |
210 |
|
throws NoSuchFieldException { |
211 |
2
|
final Field field = getField(obj, name); |
212 |
2
|
try { |
213 |
2
|
field.set(obj, value); |
214 |
|
} catch (IllegalArgumentException e) { |
215 |
0
|
throw new RuntimeException(e); |
216 |
|
} catch (IllegalAccessException e) { |
217 |
1
|
throw new RuntimeException(e); |
218 |
|
} |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
@param |
226 |
|
@param |
227 |
|
@return |
228 |
|
@throws |
229 |
|
|
|
|
| 94.1% |
Uncovered Elements: 1 (17) |
Complexity: 5 |
Complexity Density: 0.38 |
|
230 |
8
|
public static Field getField(final Object obj, final String name) throws NoSuchFieldException {... |
231 |
8
|
Field field = null; |
232 |
8
|
try { |
233 |
8
|
Class cl = obj.getClass(); |
234 |
18
|
while (!Object.class.equals(cl)) { |
235 |
16
|
try { |
236 |
16
|
field = cl.getDeclaredField(name); |
237 |
6
|
break; |
238 |
|
} catch (NoSuchFieldException ex) { |
239 |
10
|
cl = cl.getSuperclass(); |
240 |
|
} |
241 |
|
} |
242 |
8
|
if (field == null) { |
243 |
2
|
throw (new NoSuchFieldException(name + " within " + obj.getClass())); |
244 |
|
} |
245 |
6
|
field.setAccessible(true); |
246 |
|
} catch (SecurityException e) { |
247 |
0
|
throw new RuntimeException(e); |
248 |
|
} |
249 |
6
|
return field; |
250 |
|
} |
251 |
|
|
252 |
|
} |
253 |
|
|