Coverage Report - org.apache.commons.clazz.reflect.common.ReflectedMethodFeatureSupport
 
Classes in this File Line Coverage Branch Coverage Complexity
ReflectedMethodFeatureSupport
0%
0/29
0%
0/14
1.857
 
 1  
 /*
 2  
  * Copyright 2002-2004 The Apache Software Foundation
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.apache.commons.clazz.reflect.common;
 17  
 
 18  
 import java.lang.reflect.Method;
 19  
 
 20  
 import org.apache.commons.clazz.Clazz;
 21  
 import org.apache.commons.clazz.ClazzFeature;
 22  
 import org.apache.commons.clazz.ClazzLoader;
 23  
 import org.apache.commons.clazz.common.ClazzFeatureSupport;
 24  
 
 25  
 /**
 26  
  * A wrapper for a java method.
 27  
  * 
 28  
  * @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
 29  
  * @version $Id: ReflectedMethodFeatureSupport.java 155436 2005-02-26 13:17:48Z dirkv $
 30  
  */
 31  
 public class ReflectedMethodFeatureSupport extends ClazzFeatureSupport 
 32  
         implements ClazzFeature 
 33  
 {
 34  
     private Method method;
 35  
     private String signature;
 36  0
     private static final Clazz[] EMPTY_CLAZZ_ARRAY = new Clazz[0];
 37  
     private Clazz[] parameterClazzes;
 38  0
     private boolean returnClazzCached = false;
 39  
     private Clazz returnClazz;
 40  
     
 41  
     /**
 42  
      * Constructor for ReflectedClazzProperty.
 43  
      */
 44  
     public ReflectedMethodFeatureSupport(Clazz declaringClazz, Method method) {
 45  0
         super(declaringClazz);
 46  0
         this.method = method;
 47  0
     }
 48  
 
 49  
     public Method getMethod() {
 50  0
         return method;
 51  
     }
 52  
     
 53  
     public String getName() {
 54  0
         return method.getName();
 55  
     }
 56  
     
 57  
     /**
 58  
      * @see org.apache.commons.clazz.ClazzOperation#getSignature()
 59  
      */
 60  
     public String getSignature() {
 61  0
         if (signature == null) {
 62  0
             signature =
 63  
                 Clazz.constructSignature(
 64  
                     method.getName(),
 65  
                     method.getParameterTypes());
 66  
         }
 67  0
         return signature;
 68  
     }
 69  
 
 70  
     /**
 71  
      * @see org.apache.commons.clazz.ClazzOperation#getParameterClazzes()
 72  
      */
 73  
     public Clazz[] getParameterClazzes() {
 74  0
         if (parameterClazzes == null) {
 75  0
             Class paramClasses[] = method.getParameterTypes();
 76  0
             if (paramClasses == null) {
 77  0
                 parameterClazzes = EMPTY_CLAZZ_ARRAY;
 78  
             }
 79  
             else {
 80  0
                 parameterClazzes = new Clazz[paramClasses.length];
 81  0
                 ClazzLoader loader = getDeclaringClazz().getClazzLoader();
 82  0
                 for (int i = 0; i < paramClasses.length; i++) {
 83  0
                     String name = Clazz.getCanonicalClassName(paramClasses[i]);
 84  0
                     parameterClazzes[i] = loader.getClazzForName(name);
 85  
                 }
 86  
             }
 87  
         }
 88  0
         return parameterClazzes;
 89  
     }
 90  
 
 91  
     /**
 92  
      * @see org.apache.commons.clazz.ClazzOperation#getReturnClazz()
 93  
      */
 94  
     public Clazz getReturnClazz() {
 95  0
         if (!returnClazzCached) {
 96  0
             returnClazzCached = true;
 97  0
             Class returnType = method.getReturnType();
 98  0
             if (returnType == null || returnType.equals(Void.TYPE)) {
 99  0
                 returnClazz = null;
 100  
             }
 101  
             else {
 102  0
                 ClazzLoader loader = getDeclaringClazz().getClazzLoader();
 103  0
                 returnClazz = loader.getClazzForName(returnType.getName());
 104  
             }
 105  
         }
 106  0
         return returnClazz;
 107  
     }
 108  
 
 109  
     public String toString() {
 110  0
         return getSignature();
 111  
     }
 112  
 }