Clover coverage report - Code Coverage for tapestry-annotations release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:15:58 EST
file stats: LOC: 94   Methods: 4
NCLOC: 52   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.annotation.Annotation;
 19    import java.lang.reflect.Method;
 20   
 21    import org.apache.hivemind.ApplicationRuntimeException;
 22    import org.apache.hivemind.Location;
 23    import org.apache.hivemind.Resource;
 24    import org.apache.tapestry.util.DescribedLocation;
 25   
 26    /**
 27    * @author Howard M. Lewis Ship
 28    * @since 4.0
 29    */
 30   
 31    public class AnnotationUtils
 32    {
 33    /**
 34    * Determines the property name for a method, by stripping off the is/get/set prefix and
 35    * decapitalizing the first name.
 36    *
 37    * @param method
 38    * accessor method (get/set/is)
 39    * @return the property name for the method
 40    * @throws ApplicationRuntimeException
 41    * if the method is not an accessor or mutator method
 42    */
 43  76 public static String getPropertyName(Method method)
 44    {
 45  76 String name = method.getName();
 46   
 47  76 if (name.startsWith("is"))
 48    {
 49  4 checkGetter(method);
 50  2 return Introspector.decapitalize(name.substring(2));
 51    }
 52   
 53  72 if (name.startsWith("get"))
 54    {
 55  64 checkGetter(method);
 56  62 return Introspector.decapitalize(name.substring(3));
 57    }
 58   
 59  8 if (name.startsWith("set"))
 60    {
 61  6 checkSetter(method);
 62  2 return Introspector.decapitalize(name.substring(3));
 63    }
 64   
 65  2 throw new ApplicationRuntimeException(AnnotationMessages.notAccessor(method));
 66    }
 67   
 68  68 private static void checkGetter(Method method)
 69    {
 70  68 if (method.getParameterTypes().length > 0)
 71  2 throw new ApplicationRuntimeException(AnnotationMessages.noParametersExpected(method));
 72   
 73  66 if (method.getReturnType().equals(void.class))
 74  2 throw new ApplicationRuntimeException(AnnotationMessages.voidAccessor(method));
 75   
 76    }
 77   
 78  6 private static void checkSetter(Method method)
 79    {
 80  6 if (!method.getReturnType().equals(void.class))
 81  2 throw new ApplicationRuntimeException(AnnotationMessages.nonVoidMutator(method));
 82   
 83  4 if (method.getParameterTypes().length != 1)
 84  2 throw new ApplicationRuntimeException(AnnotationMessages.wrongParameterCount(method));
 85    }
 86   
 87  28 public static Location buildLocationForAnnotation(Method method, Annotation annotation,
 88    Resource classResource)
 89    {
 90  28 return new DescribedLocation(classResource, AnnotationMessages.methodAnnotation(
 91    annotation,
 92    method));
 93    }
 94    }