1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.datadictionary.util; |
17 |
|
|
18 |
|
import java.beans.BeanInfo; |
19 |
|
import java.beans.IntrospectionException; |
20 |
|
import java.beans.Introspector; |
21 |
|
import java.beans.PropertyDescriptor; |
22 |
|
import java.lang.reflect.Field; |
23 |
|
import java.lang.reflect.ParameterizedType; |
24 |
|
import java.lang.reflect.Type; |
25 |
|
import java.lang.reflect.TypeVariable; |
26 |
|
import java.util.Date; |
27 |
|
import java.util.LinkedHashSet; |
28 |
|
import java.util.List; |
29 |
|
import java.util.Set; |
30 |
|
|
|
|
| 0% |
Uncovered Elements: 51 (51) |
Complexity: 25 |
Complexity Density: 0.69 |
|
31 |
|
public class ComplexSubstructuresHelper { |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
33 |
0
|
public Set<String> getComplexStructures(String className) {... |
34 |
0
|
Set<String> complexStructures = new LinkedHashSet<String>(); |
35 |
0
|
loadComplexStructures(className, complexStructures); |
36 |
0
|
return complexStructures; |
37 |
|
} |
38 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 18 |
Complexity Density: 1.06 |
|
39 |
0
|
private void loadComplexStructures(String className,... |
40 |
|
Set<String> complexStructures) { |
41 |
0
|
if (!complexStructures.add(className)) { |
42 |
0
|
return; |
43 |
|
} |
44 |
0
|
BeanInfo beanInfo; |
45 |
0
|
Class<?> clazz; |
46 |
0
|
try { |
47 |
0
|
clazz = Thread.currentThread().getContextClassLoader().loadClass(className); |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
} catch (ClassNotFoundException ex) { |
52 |
0
|
System.out.println("ComplexSubstructuresHelper: Could not process because the class must be a freestanding object: " + className); |
53 |
0
|
return; |
54 |
|
} |
55 |
0
|
try { |
56 |
0
|
beanInfo = Introspector.getBeanInfo(clazz); |
57 |
|
} catch (IntrospectionException ex) { |
58 |
0
|
throw new RuntimeException(ex); |
59 |
|
} |
60 |
0
|
for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) { |
61 |
0
|
Class<?> subClass = pd.getPropertyType(); |
62 |
0
|
if (List.class.equals(subClass)) { |
63 |
|
|
64 |
0
|
subClass = getActualClassFromList(clazz, pd.getName()); |
65 |
|
} |
66 |
0
|
if (!Class.class.equals(subClass) |
67 |
|
&& !String.class.equals(subClass) |
68 |
|
&& !Integer.class.equals(subClass) |
69 |
|
&& !Long.class.equals(subClass) |
70 |
|
&& !Boolean.class.equals(subClass) |
71 |
|
&& !boolean.class.equals(subClass) |
72 |
|
&& !int.class.equals(subClass) |
73 |
|
&& !long.class.equals(subClass) |
74 |
|
&& !Double.class.equals(subClass) |
75 |
|
&& !Float.class.equals(subClass) |
76 |
|
&& !Date.class.equals(subClass) |
77 |
|
&& !Enum.class.isAssignableFrom(subClass) |
78 |
|
&& !Object.class.equals(subClass)) { |
79 |
0
|
loadComplexStructures(subClass.getName(), complexStructures); |
80 |
|
} |
81 |
|
} |
82 |
|
} |
83 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 6 |
Complexity Density: 0.38 |
|
84 |
0
|
public static Class<?> getActualClassFromList(Class<?> originalClass, String fieldName) {... |
85 |
0
|
if (originalClass.isInterface()) { |
86 |
0
|
throw new RuntimeException("Interface used in getter, use xxxInfo instead for field: " + originalClass.getName() + "." + fieldName); |
87 |
|
} |
88 |
|
|
89 |
0
|
Class<?> classToCheck = originalClass; |
90 |
0
|
while (true) { |
91 |
0
|
try { |
92 |
0
|
Field field = classToCheck.getDeclaredField(fieldName); |
93 |
0
|
Type type = field.getGenericType(); |
94 |
0
|
ParameterizedType pt = (ParameterizedType) type; |
95 |
0
|
Type actualType = pt.getActualTypeArguments()[0]; |
96 |
0
|
return (Class<?>) actualType; |
97 |
|
} catch (NoSuchFieldException ex) { |
98 |
0
|
classToCheck = classToCheck.getSuperclass(); |
99 |
0
|
if (classToCheck == null) { |
100 |
0
|
throw new RuntimeException("No such field: " + originalClass.getName() + "." + fieldName, ex); |
101 |
|
} |
102 |
0
|
if (classToCheck.equals(Object.class)) { |
103 |
0
|
throw new RuntimeException("No such field: " + originalClass.getName() + "." + fieldName, ex); |
104 |
|
} |
105 |
|
} catch (SecurityException ex) { |
106 |
0
|
throw new RuntimeException(originalClass.getName() + "." + fieldName, ex); |
107 |
|
} |
108 |
|
} |
109 |
|
} |
110 |
|
} |