Java Reflection Method Signature getMethodSignature(Method method)

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

Description

Generate the method signature used to uniquely identity a method during remote invocation.

License

Open Source License

Parameter

Parameter Description
method the method

Return

the signature

Declaration

public static String getMethodSignature(Method method) 

Method Source Code

//package com.java2s;
/**/*w ww  .jav  a 2 s  . c om*/
 * Licensed under Apache License v2. See LICENSE for more information.
 */

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class Main {
    private static final Map<Class<?>, String> TYPESCODES = new HashMap<Class<?>, String>();

    /**
     * Generate the method signature used to uniquely identity a method during remote
     * invocation.
     * 
     * @param method the method
     * @return the signature
     */
    public static String getMethodSignature(Method method) {
        StringBuilder sb = new StringBuilder(method.getName()).append("(");
        for (Class<?> parameterType : method.getParameterTypes()) {
            appendTypeSignature(sb, parameterType);
        }
        sb.append(")");
        appendTypeSignature(sb, method.getReturnType());
        return sb.toString();
    }

    private static void appendTypeSignature(StringBuilder buffer, Class<?> clazz) {
        if (clazz.isArray()) {
            buffer.append("[");
            appendTypeSignature(buffer, clazz.getComponentType());
        } else if (clazz.isPrimitive()) {
            buffer.append(TYPESCODES.get(clazz));
        } else {
            buffer.append("L").append(clazz.getName().replaceAll("\\.", "/")).append(";");
        }
    }
}

Related

  1. getMethodFromSignature(Class clazz, String methodSig)
  2. getMethodSignature(Class[] paramTypes, Class retType)
  3. getMethodSignature(Method m)
  4. getMethodSignature(Method method)
  5. getMethodSignature(Method method)
  6. getMethodSignature(Method method)
  7. getMethodSignature(Method method)
  8. getMethodSignature(Method method)
  9. getMethodSignature(Method method)