# Get functions / variables / classes from Processing and user

**URL:** <https://discourse.processing.org/t/get-functions-variables-classes-from-processing-and-user/30100>\
**Category:** Development\
**Created:** [May 14, 2021, 3:25pm UTC](https://discourse.processing.org/t/get-functions-variables-classes-from-processing-and-user/30100 "2021-05-14T15:25:15Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Ov3rM1nD](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ov3rm1nd/32/1756_2.png) [@Ov3rM1nD](https://discourse.processing.org/u/Ov3rM1nD)\
**Post date:** [May 14, 2021, 6:46pm UTC](https://discourse.processing.org/t/get-functions-variables-classes-from-processing-and-user/30100/8 "2021-05-14T18:46:51Z")

</div>

> is there a way to get all the classes that I‘ve written in a sketch and for each class its methods?

Yep 😛

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

void setup() {
  println("\n *****PAPPLET METHODS:*****");
  printMethods(getClass().getMethods());
  
  println("\n *****USER METHODS:*****");
  printMethods(getClass().getDeclaredMethods());

  println("\n *****USER CLASS METHODS:*****");
  for (Class c : getClass().getDeclaredClasses()) printMethods(c.getDeclaredMethods());
  
  exit();
}

String clean(String str) {
  str = str.substring(str.lastIndexOf('.') + 1);
  if (str.contains("$")) str = str.substring(str.indexOf('$') + 1); // get rid of the sketch class name and keep only the child class name
  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);
}

class Foo {
  void fooMeth1() { }
  
  Foo fooMeth2(Foo f, String s, Integer i) {
    return f;
  }
}

class Bar {
  void barMeth1() { }
  
  String[] barMeth2(String[] s) {
    return s;
  }
}

```

---

_[View the full topic](https://discourse.processing.org/t/get-functions-variables-classes-from-processing-and-user/30100)._
