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();
}
}
});
}
}
Please sign in to leave a comment.
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.
How can I do the same thing for a Java project?
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206791895-finding-all-derived-class-given-parent-class