Java Utililty Methods Reflection Method Signature

List of utility methods to do Reflection Method Signature

Description

The list of methods to do Reflection Method Signature are organized into topic(s).

Method

MethodgetMethod(Class cls, String name, Class[] signature)
get Method
Method[] metharr = cls.getMethods();
for (Method meth : metharr) {
    if (name.equals(meth.getName())) {
        Class<?>[] paramtypes = meth.getParameterTypes();
        if (java.util.Arrays.equals(signature, paramtypes))
            return meth;
return null;
MethodgetMethod(Signature signature)
Returns the reference of the Method of the advice.
if (signature instanceof MethodSignature) {
    Method m = signature.getClass().getDeclaredMethod("getMethod");
    m.setAccessible(true);
    return (Method) m.invoke(signature);
return null;
MethodgetMethodByFunctionSignature(Class clazz, String signature)
Finds method by function signature string which is compliant with Tag Library function signature in Java Server Page (TM) Specification.
Matcher m1 = FUNCTION_SIGNATURE_PATTERN.matcher(signature);
if (!m1.matches()) {
    throw new IllegalArgumentException("Invalid function signature.");
String methodName = m1.group(3);
String params = m1.group(4).trim();
Class[] paramTypes = null;
if ("".equals(params)) {
...
MethodgetMethodFromSignature(Class clazz, String methodSig)
Get method from signature
Method retVal = null;
final String methodName = getMethodNameFromSignature(methodSig);
final Class<?>[] paramTypes = getParametersFromSignature(methodSig);
retVal = clazz.getMethod(methodName, paramTypes);
return retVal;
StringgetMethodSignature(Class[] paramTypes, Class retType)
Returns JVM type signature for given list of parameters and return type.
StringBuffer sbuf = new StringBuffer();
sbuf.append('(');
for (int i = 0; i < paramTypes.length; i++) {
    sbuf.append(getClassSignature(paramTypes[i]));
sbuf.append(')');
sbuf.append(getClassSignature(retType));
return sbuf.toString();
...
StringgetMethodSignature(Method m)
get Method Signature
StringBuilder buf = new StringBuilder("(");
for (Class<?> cl : m.getParameterTypes()) {
    buf.append(getClassCode(cl));
buf.append(")");
buf.append(getClassCode(m.getReturnType()));
return buf.toString();
StringgetMethodSignature(Method method)
get Method Signature
String methodName = method.getName();
Class<?>[] classes = method.getParameterTypes();
StringBuilder builder = new StringBuilder();
builder.append("[ ");
builder.append(methodName);
builder.append("(");
for (int i = 0; i < classes.length; i++) {
    Class<?> aClass = classes[i];
...
String[]getMethodSignature(Method method)
Create a String[] representing the argument signature of a method.
Class<?>[] types = method.getParameterTypes();
String[] signature = new String[types.length];
for (int x = 0; x < types.length; x++) {
    signature[x] = types[x].getName();
return signature;
StringgetMethodSignature(Method method)
Generate the method signature used to uniquely identity a method during remote invocation.
StringBuilder sb = new StringBuilder(method.getName()).append("(");
for (Class<?> parameterType : method.getParameterTypes()) {
    appendTypeSignature(sb, parameterType);
sb.append(")");
appendTypeSignature(sb, method.getReturnType());
return sb.toString();
StringgetMethodSignature(Method method)
get Method Signature
StringBuilder sb = new StringBuilder();
sb.append(method.getName()).append('(');
Class<?>[] params = method.getParameterTypes();
for (int i = 0; i < params.length; i++) {
    if (i > 0)
        sb.append(',');
    sb.append(getTypeSignature(params[i]));
sb.append(')');
return sb.toString();