Java Reflection Method Parameter getMethodName(Method method, Class[] parameterClasses, String rightCode)

Here you can find the source of getMethodName(Method method, Class[] parameterClasses, String rightCode)

Description

get Method Name

License

Apache License

Declaration

public static String getMethodName(Method method, Class<?>[] parameterClasses, String rightCode) 

Method Source Code

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

import java.lang.reflect.*;

public class Main {
    public static String getMethodName(Method method, Class<?>[] parameterClasses, String rightCode) {
        if (method.getParameterTypes().length > parameterClasses.length) {
            Class<?>[] types = method.getParameterTypes();
            StringBuilder buf = new StringBuilder(rightCode);
            for (int i = parameterClasses.length; i < types.length; i++) {
                if (buf.length() > 0) {
                    buf.append(",");
                }//from w  w  w. ja v a2  s .c om
                Class<?> type = types[i];
                String def;
                if (type == boolean.class) {
                    def = "false";
                } else if (type == char.class) {
                    def = "\'\\0\'";
                } else if (type == byte.class || type == short.class || type == int.class || type == long.class
                        || type == float.class || type == double.class) {
                    def = "0";
                } else {
                    def = "null";
                }
                buf.append(def);
            }
        }
        return method.getName() + "(" + rightCode + ")";
    }
}

Related

  1. getMethodFromClass(String className, String methodName, Class... parameterTypes)
  2. getMethodFromClassName(String classAndMethodName, Class... parameterTypes)
  3. getMethodFullName(Method m, boolean includeClassPackage, boolean includeParametersType, boolean includeTypesPackage)
  4. getMethodGenericParameterTypes(Method method, int index)
  5. getMethodHandle(final Lookup lookup, final Class receiver, final String methodName, final Class... parameterTypes)
  6. getMethodParameterAnnotations(Method method, int index, Class annotationClass)
  7. getMethodParameterIndexes(final Method m)
  8. getMethodParameters(final Method method, final Map generics)
  9. getMethodParametersType(Class clazz, String methodName)