Find all classes that extend a given class or interface

Hi All,

Im writting a PhpStorm plugin that will help our developers to list all the controller helpers for a giver controllerAction (zend framework). Is there a way to find all files that extend a given class (Zend_Controller_Action_Helper_Abstract in this case) ? Or maybe find all files in a specified directory and go through them to check for any method implementation ?

Currently I ended up with something like this and I don't know where to go next.

public class ActionHelperCompletionContributor extends DefaultCompletionContributor {

    private static final ElementPattern<PsiElement> AFTER_CLASS_ARROW = psiElement().afterLeaf("->");
    private static final PsiElementPattern.Capture<PsiElement> AFTER_PHP_ARROW = psiElement().withLanguage(PhpLanguage.INSTANCE).afterLeaf("->");

    public ActionHelperCompletionContributor() {

        extend(CompletionType.BASIC, AFTER_CLASS_ARROW, new CompletionProvider<CompletionParameters>() {
            @Override
            protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext,
                                          @NotNull CompletionResultSet completionResultSet) {
                completionResultSet.addElement(LookupElementBuilder.create(PhpClass.class, "hello"));

                if(completionParameters.getPosition().getLanguage() == PhpLanguage.INSTANCE) {

                    Project project = completionParameters.getOriginalFile().getProject();

                    PsiElement el = completionParameters.getPosition();
                    PsiElement parent = el.getParent();
                }
            }
        });
    }
}

3 comments
Comment actions Permalink

I'm not familiar with PHP and its PSI, but com.jetbrains.php.PhpIndex#getDirectSubclasses or com.jetbrains.php.PhpIndex#getAllSubclasses sounds like a start.

0
Comment actions Permalink

How can I do the same thing for a Java project?

0

Please sign in to leave a comment.