2 comments
Comment actions Permalink

Just typecast PsiFile to PsiJavaFile. Then call getClasses() method.

PsiJavaFile psiJavaFile = (PsiJavaFile)psiFile;
final PsiClass[] classes = psiJavaFile.getClasses();
2
Comment actions Permalink

To support both Java and Kotlin, you will have to type cast to "PsiClassOwner"

val psiClassOwner = psiFile as PsiClassOwner
psiClassOwner.classes.forEach { ... }
1

Please sign in to leave a comment.