Is there any way to generate a list of all classes and methods in my Java codebase?
Asked
Active
Viewed 384 times
-4
-
I am not sure if I understand your question correctly. Can you give some example? – Pshemo Apr 17 '15 at 12:54
-
You mean classes, not objects, right? – Kuba Apr 17 '15 at 12:54
-
Have you considered using reflection E.G. https://docs.oracle.com/javase/tutorial/reflect/class/classMembers.html, maybe combined with some resource scanning to pick up all the classes? – Robert Bain Apr 17 '15 at 12:55
-
want you get all objects from memory? ..... methods using reflection @RobertBain Bain solution – Jose Ricardo Bustos M. Apr 17 '15 at 12:55
-
4Wouldn't JavaDoc do this for you or are you looking to implement something similar? A recursive directory listing and finding method signatures in each found class perhaps? – Ocracoke Apr 17 '15 at 12:56
-
Check this: http://stackoverflow.com/questions/686453/generate-java-classes-from-xsd-files – Abhishek Agarwal Apr 17 '15 at 13:01
1 Answers
1
My interpretation of your question is that you want to get all classes and methods in the "codebase" (interpreting as package
). This is not possible, as class loaders only serve requests for classes by returning the requested class, or by throwing an exception. Class loaders make no commitment to tell the VM what classes it may provide.
EDIT
A lot can be achieved with the reflections library:
Reflections reflections = new Reflections("com.example.project", new SubTypesScanner(false));
Set<Class<? extends Object>> classes =
reflections.getSubTypesOf(Object.class);

EvenLisle
- 4,672
- 3
- 24
- 47