Java Reflection Method Getter Get getGetterName(Field field)

Here you can find the source of getGetterName(Field field)

Description

get Getter Name

License

Open Source License

Declaration

public static String getGetterName(Field field) 

Method Source Code


//package com.java2s;
/*/*from  w w  w .j  av a 2 s  .  c  o  m*/
 * #%L
 * Timbuctoo core
 * =======
 * Copyright (C) 2012 - 2015 Huygens ING
 * =======
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.html>.
 * #L%
 */

import java.lang.reflect.Field;

public class Main {
    static final String GET_ACCESSOR = "get";
    static final String IS_ACCESSOR = "is";

    public static String getGetterName(Field field) {
        char[] fieldNameChars = field.getName().toCharArray();

        fieldNameChars[0] = Character.toUpperCase(fieldNameChars[0]);

        String accessor = isBoolean(field.getType()) ? IS_ACCESSOR : GET_ACCESSOR;
        return accessor.concat(String.valueOf(fieldNameChars));
    }

    private static boolean isBoolean(Class<?> cls) {
        return cls == boolean.class || cls == Boolean.class;
    }
}

Related

  1. getGetterMethods(Class clazz)
  2. getGetterMethods(Class objectType)
  3. getGetterMethods(Class pojoClass)
  4. getGetterMethods(final Class clazz)
  5. getGetterName(Field field)
  6. getGetterName(final Field field)
  7. getGetterName(Method m)
  8. getGetterName(Method m)
  9. getGetterName(Method method)