Clover coverage report - Code Coverage for tapestry-annotations release 4.0-beta-8
Coverage timestamp: Sat Sep 24 2005 11:56:46 EDT
file stats: LOC: 72   Methods: 3
NCLOC: 41   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AnnotationUtils.java 100% 100% 100% 100%
coverage
 1    // Copyright 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.annotations;
 16   
 17    import java.beans.Introspector;
 18    import java.lang.reflect.Method;
 19   
 20    import org.apache.hivemind.ApplicationRuntimeException;
 21   
 22    /**
 23    * @author Howard M. Lewis Ship
 24    * @since 4.0
 25    */
 26   
 27    public class AnnotationUtils
 28    {
 29  34 public static String getPropertyName(Method method)
 30    {
 31  34 String name = method.getName();
 32   
 33  34 if (name.startsWith("is"))
 34    {
 35  2 checkGetter(method);
 36  1 return Introspector.decapitalize(name.substring(2));
 37    }
 38   
 39  32 if (name.startsWith("get"))
 40    {
 41  28 checkGetter(method);
 42  27 return Introspector.decapitalize(name.substring(3));
 43    }
 44   
 45  4 if (name.startsWith("set"))
 46    {
 47  3 checkSetter(method);
 48  1 return Introspector.decapitalize(name.substring(3));
 49    }
 50   
 51  1 throw new ApplicationRuntimeException(AnnotationMessages.notAccessor(method));
 52    }
 53   
 54  30 private static void checkGetter(Method method)
 55    {
 56  30 if (method.getParameterTypes().length > 0)
 57  1 throw new ApplicationRuntimeException(AnnotationMessages.noParametersExpected(method));
 58   
 59  29 if (method.getReturnType().equals(void.class))
 60  1 throw new ApplicationRuntimeException(AnnotationMessages.voidAccessor(method));
 61   
 62    }
 63   
 64  3 private static void checkSetter(Method method)
 65    {
 66  3 if (!method.getReturnType().equals(void.class))
 67  1 throw new ApplicationRuntimeException(AnnotationMessages.nonVoidMutator(method));
 68   
 69  2 if (method.getParameterTypes().length != 1)
 70  1 throw new ApplicationRuntimeException(AnnotationMessages.wrongParameterCount(method));
 71    }
 72    }