Java Reflection Method Name getMethodNameList(Class theClass)

Here you can find the source of getMethodNameList(Class theClass)

Description

getMethodNameList

License

Open Source License

Parameter

Parameter Description
theClass a parameter

Declaration

public final static HashMap<String, Integer> getMethodNameList(Class<?> theClass) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*from w  ww  .ja v  a 2s. co m*/
     * getMethodNameList
     * @param theClass
     * @return
     */
    public final static HashMap<String, Integer> getMethodNameList(Class<?> theClass) {
        // Method - Number of params
        HashMap<String, Integer> methodsAndParams = new HashMap<String, Integer>();
        // Get the class name
        String className = theClass.getCanonicalName();

        Method[] classMethods = theClass.getDeclaredMethods();
        String currMethodCanonicalName = "";
        String currMethodName = "";
        int currMethodNumberParams = 0;
        for (int i = 0; i < classMethods.length; i++) {
            currMethodCanonicalName = classMethods[i].toString();

            // Get method name only
            String methodString = currMethodCanonicalName.substring(currMethodCanonicalName.lastIndexOf(className),
                    currMethodCanonicalName.indexOf('('));
            currMethodName = methodString.substring(methodString.lastIndexOf('.') + 1, methodString.length());

            // Get method number of params
            String params = currMethodCanonicalName.substring(currMethodCanonicalName.indexOf('(') + 1,
                    currMethodCanonicalName.lastIndexOf(')'));
            String theParams[] = params.split(",");
            currMethodNumberParams = theParams.length;

            methodsAndParams.put(currMethodName, currMethodNumberParams);
        }

        /**
        for (String name: methodsAndParams.keySet()){
           String key =name.toString();
           String value = methodsAndParams.get(name).toString();  
           System.out.println(key + " " + value);  
        } 
        */

        return methodsAndParams;

    }
}

Related

  1. getMethodName(Method method)
  2. getMethodName(Method method)
  3. getMethodName(Method method, boolean useSegment, String segment, String value)
  4. getMethodName(String prefix, String fieldName)
  5. getMethodNameAndDescriptor(Method m)
  6. getMethodNameMinusGet(Method aMethod)
  7. getMethodNames(Class cls, boolean insertDefaultValues)
  8. getMethodNames(Class cls)
  9. getMethodNameWithClassName(Method a_Method)