Make a fully qualified method name for specified method. - Java Reflection

Java examples for Reflection:Method Name

Description

Make a fully qualified method name for specified method.

Demo Code


import java.lang.reflect.Method;
import java.lang.reflect.Type;
import javax.management.openmbean.OpenDataException;

public class Main{
    /**/*w w  w  . j a  va  2 s. c  o m*/
     * Make a fully qualified method name for specified method.
     *
     * @param method the method.
     * @return the fully qualified method name.
     */
    public static String makeFullyQualifiedName(final Method method) {
        final String[] signature = BeanUtil.getSignature(method);
        return makeFullyQualifiedName(method.getName(), signature);
    }
    /**
     * Make a fully qualified method name from specified parameters.
     *
     * @param actionName the name of method.
     * @param signature the types of each parameter.
     * @return the fully qualified method name.
     */
    public static String makeFullyQualifiedName(final String actionName,
            final String[] signature) {
        final StringBuilder sb = new StringBuilder();
        sb.append(actionName);
        sb.append('(');
        if (null != signature) {
            for (int i = 0; i < signature.length; i++) {
                if (i != 0) {
                    sb.append(',');
                }
                sb.append(signature[i]);
            }
        }
        sb.append(')');
        return sb.toString();
    }
    /**
     * Return the signature of method as an array of strings.
     *
     * @param method the method.
     * @return the signature.
     */
    public static String[] getSignature(final Method method) {
        final Class[] types = method.getParameterTypes();
        final String[] signature = new String[types.length];
        for (int i = 0; i < types.length; i++) {
            signature[i] = types[i].getName();
        }
        return signature;
    }
}

Related Tutorials