0

With this I get collection of methods from some random class that I previously loaded with URLClassLoader:

public static Collection<Method> getMethods(Class<?> clazz, String packageName) {

    Collection<Method> found = new ArrayList<Method>();
    while (clazz != null) {
        for (Method m1 : clazz.getDeclaredMethods()) {
            boolean overridden = false;

            for (Method m2 : found) {
                if (m2.getName().equals(m1.getName())
                        && Arrays.deepEquals(m1.getParameterTypes(), m2.getParameterTypes())) {
                    overridden = true;
                    break;
                }
            }

            if (!overridden)
                if (m1.getParameterTypes().length != 0) {
                    if (m1.toString().contains(packageName)) {
                        found.add(m1);
                    }
                }

        }

        clazz = clazz.getSuperclass();
    }

    return found;
}

After that I want to get method name, arguments(parameters) of that method (name,type and value). In other words I need access to these methods. Making plugin for that. Tried like this:

    /* Find class methods with input arguments */
    foundMethods = getMethods(clazz, packageName);

    /* Print class name and methods */

    for (Method itterator : foundMethods) {
        tempIndex++;
        out.println("Class name: " + className + "Method [" + tempIndex +  "] = " + itterator.getName() +  "\n");
        Parameter[] parameters = itterator.getParameters();
        for(Parameter parameter : parameters)
        {
            System.out.println(parameter.getName());
        }
    }

But I only get class name, method name and parameters but like arg0,arg1... Any thoughts how to do this?

squlerr
  • 11
  • 8

0 Answers0