Java Reflection Method Name getMethodPropertyName(java.lang.reflect.Method method)

Here you can find the source of getMethodPropertyName(java.lang.reflect.Method method)

Description

get Method Property Name

License

Apache License

Declaration

private static String getMethodPropertyName(java.lang.reflect.Method method) 

Method Source Code

//package com.java2s;
/*/*from w ww  .  j a  va  2s . c om*/
 * #%L
 * dbtool-orm
 * %%
 * Copyright (C) 2015 Kwanza
 * %%
 * 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.
 * #L%
 */

public class Main {
    private static String getMethodPropertyName(java.lang.reflect.Method method) {
        final String methodName = method.getName();
        if (methodName.startsWith("get") && methodName.length() > 3) {
            return uncapitalize(methodName.substring(3, methodName.length()));
        } else {
            throw new RuntimeException("Incorrect getter name: " + methodName);
        }
    }

    private static String uncapitalize(String str) {
        return changeFirstCharacterCase(str, false);
    }

    private static String changeFirstCharacterCase(String stringValue, boolean capitalize) {
        final StringBuilder stringBuilder = new StringBuilder(stringValue.length());
        if (capitalize) {
            stringBuilder.append(Character.toUpperCase(stringValue.charAt(0)));
        } else {
            stringBuilder.append(Character.toLowerCase(stringValue.charAt(0)));
        }
        stringBuilder.append(stringValue.substring(1));
        return stringBuilder.toString();
    }
}

Related

  1. getMethodNames(Class cls, boolean insertDefaultValues)
  2. getMethodNames(Class cls)
  3. getMethodNameWithClassName(Method a_Method)
  4. getMethodOnlyByName(Class c, String methodName)
  5. getMethodOrNull(Class cls, String name, Class[] args)
  6. getMethods(Class clazz, String name, int args)
  7. getMethods(Class type, String name)
  8. getMethods(final Class cl, final String name, final int params)
  9. getMethods(final Class clazz, final String methodName)