Java Reflection Method Setter Get getSetterMethod(Class containingClass, Class propertyType, String propertyName)

Here you can find the source of getSetterMethod(Class containingClass, Class propertyType, String propertyName)

Description

get Setter Method

License

Apache License

Parameter

Parameter Description
containingClass never null
propertyType never null
propertyName never null

Return

null if it doesn't exist

Declaration

public static Method getSetterMethod(Class containingClass, Class propertyType, String propertyName) 

Method Source Code

//package com.java2s;
/*/*  www .j  a  va 2  s  .  c o  m*/
 * Copied from the Hibernate Validator project
 * Original authors: Hardy Ferentschik, Gunnar Morling and Kevin Pollet.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.lang.reflect.Method;

public class Main {
    private static final String PROPERTY_MUTATOR_PREFIX = "set";

    /**
     * @param containingClass never null
     * @param propertyType never null
     * @param propertyName never null
     * @return null if it doesn't exist
     */
    public static Method getSetterMethod(Class containingClass, Class propertyType, String propertyName) {
        String setterName = PROPERTY_MUTATOR_PREFIX + (propertyName.isEmpty() ? ""
                : propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1));
        try {
            return containingClass.getMethod(setterName, propertyType);
        } catch (NoSuchMethodException e) {
            return null;
        }
    }
}

Related

  1. getSetterForGetter(Method[] methods, Method getter)
  2. getSetterFromCache(Class clazz)
  3. getSetterMap(Class cls)
  4. getSetterMethod(Class beanClass, String fieldName, List supportedTypes)
  5. getSetterMethod(Class c, String methodName)
  6. getSetterMethod(Class type, String property)
  7. getSetterMethod(Class beanClass, String property)
  8. getSetterMethod(Class classType, String fieldName, Class paramType)
  9. getSetterMethod(Class clazz, Field field)