Java Reflection Method Name getMethodUniqueName(Method method)

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

Description

get Method Unique Name

License

Apache License

Declaration

public static String getMethodUniqueName(Method method) 

Method Source Code

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

import java.lang.reflect.Method;

public class Main {
    public static String getMethodUniqueName(Method method) {
        try {/*from ww  w . j  a v  a  2s .c  o m*/
            StringBuilder sb = new StringBuilder();
            sb.append(method.getDeclaringClass().getName()).append('.');
            sb.append(method.getName()).append('(');
            Class<?>[] params = method.getParameterTypes();
            if (params != null) {
                for (int j = 0; j < params.length; j++) {
                    sb.append(getTypeName(params[j]));
                    if (j < (params.length - 1))
                        sb.append(',');
                }
            }
            sb.append(')');
            return sb.toString();
        } catch (Exception e) {
            return null;
        }
    }

    public static String getTypeName(Class<?> type) {
        if (type.isArray()) {
            try {
                Class<?> cl = type;
                int dimensions = 0;
                while (cl.isArray()) {
                    dimensions++;
                    cl = cl.getComponentType();
                }
                StringBuffer sb = new StringBuffer();
                sb.append(cl.getName());
                for (int i = 0; i < dimensions; i++) {
                    sb.append("[]");
                }
                return sb.toString();
            } catch (Throwable e) {
                /*FALLTHRU*/ }
        }
        return type.getName();
    }
}

Related

  1. getMethods(String classname)
  2. getMethodsByName(Class cls, String methodName)
  3. getMethodSubjectName(Method method)
  4. getMethodsWithName(Class clazz, String name)
  5. getMethodType(Class clazz, String methodName)