Get functions / variables / classes from Processing and user

Here is my approach:

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

void setup() {
  printMethods(getClass().getMethods()); // all default processing methods
  printMethods(getClass().getDeclaredMethods()); // user methods
  exit();
}

String clean(String str) {
  str = str.substring(str.lastIndexOf('.') + 1);
  return str.replaceAll("[^\\w]", "");
}

void printMethods(Method[] list) {
  ArrayList<String> result = new ArrayList();

  for (Method m : list) {
    String methodName = clean(m.getName());  
    String returnType = clean(m.getReturnType().toString());
    String params = "";
    for (Class p : m.getParameterTypes()) {
      params += clean(p.getName()) + " ";
    }

    result.add(methodName + "(" + params.trim() + ") : " + returnType);
  }

  Collections.sort(result);

  for (String s : result) println(s);
}

in short, you can do this through Java Reflections.

1 Like