void (@NotNull final ConfigurationFromContext configuration, @NotNull final ConfigurationContext fromContext, @NotNull Runnable performRunnable) { final PsiElement psiElement = configuration.getSourceElement(); if (psiElement instanceof PsiMethod || psiElement instanceof PsiClass) { final PsiMethod psiMethod; final PsiClass containingClass; if (psiElement instanceof PsiMethod) { psiMethod = (PsiMethod)psiElement; containingClass = psiMethod.getContainingClass(); } else { psiMethod = null; containingClass = (PsiClass)psiElement; } final InheritorChooser inheritorChooser = new InheritorChooser() { @Override protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) { ReadAction.nonBlocking(() -> { ((T)configuration.getConfiguration()).bePatternConfiguration(classes, method); if (!classes.isEmpty()) { PsiClass containerClass = psiElement instanceof PsiMethod ? ((PsiMethod)psiElement).getContainingClass() : ((PsiClass)psiElement); setNestedClass(classes.get(0), containerClass); } }) .finishOnUiThread(ModalityState.nonModal(), v -> super.runForClasses(classes, method, context, performRunnable)) .submit(AppExecutorUtil.getAppExecutorService()); } @Override protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) { PsiClass containerClass; if (psiElement instanceof PsiMethod) { final Project project = psiMethod.getProject(); final MethodLocation methodLocation = new MethodLocation(project, psiMethod, PsiLocation.fromPsiElement(aClass)); ((T)configuration.getConfiguration()).beMethodConfiguration(methodLocation); containerClass = psiMethod.getContainingClass(); } else { ((T)configuration.getConfiguration()).beClassConfiguration(aClass); containerClass = (PsiClass)psiElement; } setNestedClass(aClass, containerClass); super.runForClass(aClass, psiMethod, context, performRunnable); } private void setNestedClass(PsiClass aClass, PsiClass containerClass) { if (containerClass != null && !aClass.isInheritor(containerClass, true)) { for (PsiClass innerClass : aClass.getAllInnerClasses()) { //when there are multiple inners with the same super - we just take the first for now; //otherwise chooser should have more than one step if (InheritanceUtil.isInheritorOrSelf(innerClass, containerClass, true)) { ((T)configuration.getConfiguration()).withNestedClass(innerClass); break; } } } } }; if (inheritorChooser.runMethodInAbstractClass(fromContext, performRunnable, psiMethod, containingClass, aClass -> aClass.hasModifierProperty(PsiModifier.ABSTRACT) && isTestClass(aClass))) { return; } } super.onFirstRun(configuration, fromContext, performRunnable); }