Java Reflection Method Setter Get getSetterFieldName(Method method)

Here you can find the source of getSetterFieldName(Method method)

Description

Extract field name from the setter method

License

Open Source License

Declaration

public static String getSetterFieldName(Method method) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012-2017 Codenvy, S.A.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  ww  w.j ava2  s.c o m*/
 *   Codenvy, S.A. - initial API and implementation
 *******************************************************************************/

import java.lang.reflect.Method;

public class Main {
    /**
     * Extract field name from the setter method
     */
    public static String getSetterFieldName(Method method) {
        String methodName = method.getName();
        if (methodName.startsWith("set")) {
            return getFieldName(methodName.substring(3));
        }
        throw new IllegalArgumentException("Invalid setter method" + method.getName());
    }

    /**
     * Compute field name from the stringified string type
     */
    public static String getFieldName(String type) {
        char[] c = type.toCharArray();
        c[0] = Character.toLowerCase(c[0]);
        return new String(c);
    }
}

Related

  1. getSetter(String key, Class clazz, Class paramClazz)
  2. getSetter(String property, Object o)
  3. getSetter(String propertyName, Class clazz, Class arg)
  4. getSetter(String s)
  5. getSetterAttributeType(Method m)
  6. getSetterForGetter(Method[] methods, Method getter)
  7. getSetterFromCache(Class clazz)
  8. getSetterMap(Class cls)
  9. getSetterMethod(Class beanClass, String fieldName, List supportedTypes)