Grzegorz Oledzki Grzegorz Oledzki - 1 month ago 8
Java Question

List all subclasses with fully qualified names

I would like to get a list of all subclasses of a given class with their fully qualified names. I wanted to copy it from Eclipse and paste into a text file like this:

some.package.Class1
some.package.Class2
some.other.package.Class3
...


I've tried:


  • doing
    Search | Java | Type, Limit to implementors
    . But this one for some strange reasons doesn't list subclasses of subclasses, only direct descendants.

  • opening
    Hierarchy
    view for the class which prints all the subclasses in a tree component, but this view doesn't allow me to select all the rows and copy their names.



Any other tricks? There are hundreds of classes, so I wanted to avoid doing it manually.

Answer

Following the pattern described in http://internna.blogspot.com/2007/11/java-5-retrieving-all-classes-from.html one can do it programmatically. It's a shame Eclipse can't do it OOTB. Doing it in Java code allows to do the filtering with no additional cost (e.g. !(klazz.isEnum())).

Comments