Clover coverage report - Code Coverage for tapestry release 4.0-beta-2
Coverage timestamp: Sat Jul 9 2005 22:02:17 EDT
file stats: LOC: 91   Methods: 2
NCLOC: 41   Classes: 1
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
EnhancedClassValidatorImpl.java 100% 100% 100% 100%
coverage
 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  421 public void validate(Class baseClass, Class enhancedClass, IComponentSpecification specification)
 38    {
 39  421 Set implementedMethods = new HashSet();
 40   
 41  421 Class current = enhancedClass;
 42   
 43  421 while (true)
 44    {
 45  1165 Method[] methods = current.getDeclaredMethods();
 46   
 47  1165 for (int i = 0; i < methods.length; i++)
 48    {
 49  22309 Method m = methods[i];
 50   
 51  22309 boolean isAbstract = Modifier.isAbstract(m.getModifiers());
 52   
 53  22309 MethodSignature s = new MethodSignature(m);
 54   
 55  22309 if (isAbstract)
 56    {
 57  2139 if (implementedMethods.contains(s))
 58  2138 continue;
 59   
 60  1 _errorLog.error(EnhanceMessages.noImplForAbstractMethod(m, current, baseClass
 61    .getName(), enhancedClass), specification.getLocation(), null);
 62    }
 63   
 64  20171 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  1165 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  1165 if (current == null || !Modifier.isAbstract(current.getModifiers()))
 82  421 break;
 83    }
 84   
 85    }
 86   
 87  42 public void setErrorLog(ErrorLog errorLog)
 88    {
 89  42 _errorLog = errorLog;
 90    }
 91    }