Java Reflection Method Getter Get getGetterName(Method m)

Here you can find the source of getGetterName(Method m)

Description

Get getter name.

License

Apache License

Parameter

Parameter Description
m Method object.

Return

Property name of this getter.

Declaration

private static String getGetterName(Method m) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;

public class Main {
    /**/*from   w w  w .  jav a2 s  .  c  om*/
     * Get getter name. "getName" -> "name", "isMale" -> "male".
     * 
     * @param m Method object.
     * @return Property name of this getter.
     */
    private static String getGetterName(Method m) {
        String name = m.getName();
        if (name.startsWith("get") && (name.length() >= 4) && !m.getReturnType().equals(void.class)
                && (m.getParameterTypes().length == 0)) {
            return Character.toLowerCase(name.charAt(3)) + name.substring(4);
        }
        if (name.startsWith("is") && (name.length() >= 3)
                && (m.getReturnType().equals(boolean.class) || m.getReturnType().equals(Boolean.class))
                && (m.getParameterTypes().length == 0)) {
            return Character.toLowerCase(name.charAt(2)) + name.substring(3);
        }
        return null;
    }
}

Related

  1. getGetterMethods(final Class clazz)
  2. getGetterName(Field field)
  3. getGetterName(Field field)
  4. getGetterName(final Field field)
  5. getGetterName(Method m)
  6. getGetterName(Method method)
  7. getGetterName(Method mtd)
  8. getGetterOrNull(Class clazz, String name, Class type)
  9. getGetterPropertyName(Method getterMethod)