|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
EnhancedClassValidatorImpl.java | 100% | 100% | 100% | 100% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.tapestry.enhance;
|
|
16 |
|
|
17 |
import java.lang.reflect.Method;
|
|
18 |
import java.lang.reflect.Modifier;
|
|
19 |
import java.util.HashSet;
|
|
20 |
import java.util.Set;
|
|
21 |
|
|
22 |
import org.apache.hivemind.ErrorLog;
|
|
23 |
import org.apache.hivemind.service.MethodSignature;
|
|
24 |
import org.apache.tapestry.spec.IComponentSpecification;
|
|
25 |
|
|
26 |
/**
|
|
27 |
* Validates that an enhanced class is correct; checks that all inherited abstract methods are, in
|
|
28 |
* fact, implemented in the class.
|
|
29 |
*
|
|
30 |
* @author Howard M. Lewis Ship
|
|
31 |
* @since 4.0
|
|
32 |
*/
|
|
33 |
public class EnhancedClassValidatorImpl implements EnhancedClassValidator |
|
34 |
{ |
|
35 |
private ErrorLog _errorLog;
|
|
36 |
|
|
37 | 465 |
public void validate(Class baseClass, Class enhancedClass, IComponentSpecification specification) |
38 |
{ |
|
39 | 465 |
Set implementedMethods = new HashSet();
|
40 |
|
|
41 | 465 |
Class current = enhancedClass; |
42 |
|
|
43 | 465 |
while (true) |
44 |
{ |
|
45 | 1275 |
Method[] methods = current.getDeclaredMethods(); |
46 |
|
|
47 | 1275 |
for (int i = 0; i < methods.length; i++) |
48 |
{ |
|
49 | 22292 |
Method m = methods[i]; |
50 |
|
|
51 | 22292 |
boolean isAbstract = Modifier.isAbstract(m.getModifiers());
|
52 |
|
|
53 | 22292 |
MethodSignature s = new MethodSignature(m);
|
54 |
|
|
55 | 22292 |
if (isAbstract)
|
56 |
{ |
|
57 | 2112 |
if (implementedMethods.contains(s))
|
58 | 2111 |
continue;
|
59 |
|
|
60 | 1 |
_errorLog.error(EnhanceMessages.noImplForAbstractMethod(m, current, baseClass |
61 |
.getName(), enhancedClass), specification.getLocation(), null);
|
|
62 |
} |
|
63 |
|
|
64 | 20181 |
implementedMethods.add(s); |
65 |
} |
|
66 |
|
|
67 |
// An earlier version of this code walked the interfaces directly,
|
|
68 |
// but it appears that implementing an interface actually
|
|
69 |
// puts abstract method declarations into the class
|
|
70 |
// (at least, in terms of what getDeclaredMethods() returns).
|
|
71 |
|
|
72 |
// March up to the super class.
|
|
73 |
|
|
74 | 1275 |
current = current.getSuperclass(); |
75 |
|
|
76 |
// Once advanced up to a concrete class, we trust that
|
|
77 |
// the compiler did its checking. Alternately, if
|
|
78 |
// we started on java.lang.Object for some reason, current
|
|
79 |
// will be null and we can stop.S
|
|
80 |
|
|
81 | 1275 |
if (current == null || !Modifier.isAbstract(current.getModifiers())) |
82 | 465 |
break;
|
83 |
} |
|
84 |
|
|
85 |
} |
|
86 |
|
|
87 | 46 |
public void setErrorLog(ErrorLog errorLog) |
88 |
{ |
|
89 | 46 |
_errorLog = errorLog; |
90 |
} |
|
91 |
} |
|