Take the 2-minute tour ×

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:


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.

share|improve this question
related stackoverflow.com/questions/492184/… –  Narayan Sep 15 '09 at 10:05
@Narayan: I've seen the question, but that one is about doing it programmatically. I hoped for a solution with a few clicks. –  Grzegorz Oledzki Sep 15 '09 at 10:08
You could get a custom view indeed, lot less complicated the TypeHierarchyViewPart of the "hierarchy view", but using the same underlying mechanism to retrieve/display the hierarchy of classes. –  VonC Sep 15 '09 at 11:35
If you can make Rich's solution work, I would propose his answer to be considered as the official one for this question. –  VonC Sep 15 '09 at 16:52
add comment

4 Answers

up vote 0 down vote accepted

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())).

share|improve this answer
add comment

Update: my original answer wouldn't work as there is no context to the structured selection.

This answer shows how to contribute the action to the context menu and retrieve the structured selection. You can modify that type's execute method to process the Hierarchy (as VonC suggests, +1) and obtain all the sub-types and set the content to the clipboard as follows:

public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    try {
        IStructuredSelection selection = SelectionConverter

        IJavaElement[] elements = SelectionConverter.getElements(selection);

        if (elements != null && elements.length > 0) {
            if (elements[0] != null && elements[0] instanceof IType) {
                IType type = (IType)elements[0];

                ITypeHierarchy hierarchy =
                    type.newTypeHierarchy(new NullProgressMonitor());

                IType[] subTypes = hierarchy.getAllSubtypes(type);

                StringBuffer buf = new StringBuffer();
                for (IType iType : subTypes) {

                Shell shell = HandlerUtil.getActiveShell(event);

                Clipboard clipboard = new Clipboard(shell.getDisplay());

                    new Object[]{buf.toString()}, 
                    new Transfer[]{TextTransfer.getInstance()});
    } catch (JavaModelException e) {
    return null;
share|improve this answer
Let me see... awesome? +1 (heck +10 if I could). –  VonC Sep 15 '09 at 14:22
:) thanks very much –  Rich Seller Sep 15 '09 at 14:31
add comment

nWire for Java can give you the complete list of classes which extend a given class or implement a specific interface. You will get it in the nWire navigator, which does not provide a copy command.

However, you can tap into the nWire database, which is a standard H2 database and has a very simple structure, and get everything you need with a simple query. We will be introducing reporting capabilities some time in the future.

IMHO, it will be less of an effort and you'll get a tool which gives you a lot more.

share|improve this answer
I've installed the plugin. How do I "tap into the nWire database". I don't see any view like this. Neither does the website help about it. Or should I use some database client to access it? What is the database name then? –  Grzegorz Oledzki Sep 15 '09 at 13:24
Send me an email to support [at] nwiresoftware.com and I'll send you more details. –  zvikico Sep 15 '09 at 13:42
add comment

The method in the Hierarchy view which does build the hierarchy tree is in the org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyLifeCycle:

private ITypeHierarchy createTypeHierarchy(IJavaElement element, IProgressMonitor pm) throws JavaModelException {
    if (element.getElementType() == IJavaElement.TYPE) {
        IType type= (IType) element;
        if (fIsSuperTypesOnly) {
            return type.newSupertypeHierarchy(pm);
        } else {
            return type.newTypeHierarchy(pm);
    } else {

Which uses org.eclipse.jdt.internal.core.SourceType class

 * @see IType
public ITypeHierarchy newTypeHierarchy(IJavaProject project, IProgressMonitor monitor) throws JavaModelException {
    return newTypeHierarchy(project, DefaultWorkingCopyOwner.PRIMARY, monitor);

So if you can get a IJavaElement, you can check those classes to emulate the same result.

It uses a org.eclipse.jdt.internal.core.CreateTypeHierarchyOperation

share|improve this answer
So you suggest implementing a custom view in Eclipse. Do I get it right? –  Grzegorz Oledzki Sep 15 '09 at 11:33
add comment

Your Answer


