|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.enhance; |
|
16 |
| |
|
17 |
| import java.lang.reflect.Method; |
|
18 |
| import java.lang.reflect.Modifier; |
|
19 |
| import java.util.HashMap; |
|
20 |
| import java.util.HashSet; |
|
21 |
| import java.util.Iterator; |
|
22 |
| import java.util.Map; |
|
23 |
| import java.util.Set; |
|
24 |
| |
|
25 |
| import org.apache.hivemind.ErrorLog; |
|
26 |
| import org.apache.hivemind.Location; |
|
27 |
| import org.apache.hivemind.service.MethodSignature; |
|
28 |
| import org.apache.tapestry.spec.IComponentSpecification; |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| public class EnhancedClassValidatorImpl implements EnhancedClassValidator |
|
38 |
| { |
|
39 |
| private ErrorLog _errorLog; |
|
40 |
| |
|
41 |
1179
| public void validate(Class baseClass, Class enhancedClass, IComponentSpecification specification)
|
|
42 |
| { |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
1179
| Set implementedMethods = new HashSet();
|
|
47 |
| |
|
48 |
| |
|
49 |
1179
| Map interfaceMethods = new HashMap();
|
|
50 |
| |
|
51 |
1179
| Location location = specification.getLocation();
|
|
52 |
| |
|
53 |
1179
| Class current = enhancedClass;
|
|
54 |
| |
|
55 |
1179
| while (true)
|
|
56 |
| { |
|
57 |
5757
| addInterfaceMethods(current, interfaceMethods);
|
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
5757
| Method[] methods = current.getDeclaredMethods();
|
|
69 |
| |
|
70 |
5757
| for (int i = 0; i < methods.length; i++)
|
|
71 |
| { |
|
72 |
103245
| Method m = methods[i];
|
|
73 |
| |
|
74 |
103245
| MethodSignature s = new MethodSignature(m);
|
|
75 |
| |
|
76 |
103245
| boolean isAbstract = Modifier.isAbstract(m.getModifiers());
|
|
77 |
| |
|
78 |
103245
| if (isAbstract)
|
|
79 |
| { |
|
80 |
7122
| if (interfaceMethods.containsKey(s))
|
|
81 |
1572
| continue;
|
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
5550
| if (implementedMethods.contains(s))
|
|
87 |
5547
| continue;
|
|
88 |
| |
|
89 |
3
| _errorLog.error(EnhanceMessages.noImplForAbstractMethod(
|
|
90 |
| m, |
|
91 |
| current, |
|
92 |
| baseClass, |
|
93 |
| enhancedClass), location, null); |
|
94 |
| } |
|
95 |
| |
|
96 |
96126
| implementedMethods.add(s);
|
|
97 |
| } |
|
98 |
| |
|
99 |
5757
| current = current.getSuperclass();
|
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
5757
| if (current == null || current == Object.class)
|
|
106 |
1179
| break;
|
|
107 |
| } |
|
108 |
| |
|
109 |
1179
| Iterator i = interfaceMethods.entrySet().iterator();
|
|
110 |
1179
| while (i.hasNext())
|
|
111 |
| { |
|
112 |
55941
| Map.Entry entry = (Map.Entry) i.next();
|
|
113 |
| |
|
114 |
55941
| MethodSignature sig = (MethodSignature) entry.getKey();
|
|
115 |
| |
|
116 |
55941
| if (implementedMethods.contains(sig))
|
|
117 |
55938
| continue;
|
|
118 |
| |
|
119 |
3
| Method method = (Method) entry.getValue();
|
|
120 |
| |
|
121 |
3
| _errorLog.error(EnhanceMessages.unimplementedInterfaceMethod(
|
|
122 |
| method, |
|
123 |
| baseClass, |
|
124 |
| enhancedClass), location, null); |
|
125 |
| } |
|
126 |
| |
|
127 |
| } |
|
128 |
| |
|
129 |
5757
| private void addInterfaceMethods(Class current, Map interfaceMethods)
|
|
130 |
| { |
|
131 |
5757
| Class[] interfaces = current.getInterfaces();
|
|
132 |
| |
|
133 |
5757
| for (int i = 0; i < interfaces.length; i++)
|
|
134 |
3699
| addMethodsFromInterface(interfaces[i], interfaceMethods);
|
|
135 |
| } |
|
136 |
| |
|
137 |
3699
| private void addMethodsFromInterface(Class interfaceClass, Map interfaceMethods)
|
|
138 |
| { |
|
139 |
3699
| Method[] methods = interfaceClass.getMethods();
|
|
140 |
| |
|
141 |
3699
| for (int i = 0; i < methods.length; i++)
|
|
142 |
| { |
|
143 |
96897
| MethodSignature sig = new MethodSignature(methods[i]);
|
|
144 |
| |
|
145 |
96897
| if (interfaceMethods.containsKey(sig))
|
|
146 |
40956
| continue;
|
|
147 |
| |
|
148 |
55941
| interfaceMethods.put(sig, methods[i]);
|
|
149 |
| } |
|
150 |
| } |
|
151 |
| |
|
152 |
123
| public void setErrorLog(ErrorLog errorLog)
|
|
153 |
| { |
|
154 |
123
| _errorLog = errorLog;
|
|
155 |
| } |
|
156 |
| } |