[kotlin] Collect inheritors from updaters to show popup dialog faster

#KTIJ-10071

GitOrigin-RevId: 39563f4c4503d01058c6652447a66e91d619981d
This commit is contained in:
Vladimir Dolzhenko
2022-07-20 11:54:26 +00:00
committed by intellij-monorepo-bot
parent 0e82289d27
commit fd739eface
2 changed files with 16 additions and 31 deletions
@@ -332,7 +332,7 @@ public class MarkerType {
ContainerUtil.addIfNotNull(inheritors, collectProcessor.getFoundElement());
ContainerUtil.addIfNotNull(inheritors, collectExprProcessor.getFoundElement());
if (inheritors.isEmpty()) return;
final SubclassUpdater subclassUpdater = new SubclassUpdater(aClass, renderer);
final SubclassUpdater subclassUpdater = new SubclassUpdater(aClass, renderer, inheritors);
inheritors.sort(renderer.getComparator());
PsiElementListNavigator.openTargets(e, inheritors.toArray(NavigatablePsiElement.EMPTY_NAVIGATABLE_ELEMENT_ARRAY),
subclassUpdater.getCaption(inheritors.size()), CodeInsightBundle.message("goto.implementation.findUsages.title", aClass.getName()), renderer, subclassUpdater);
@@ -362,10 +362,16 @@ public class MarkerType {
@IntellijInternalApi
public static final class SubclassUpdater extends OverridingMembersUpdater {
private final PsiClass myClass;
private final List<NavigatablePsiElement> myInheritors;
public SubclassUpdater(@NotNull PsiClass aClass, @NotNull PsiElementListCellRenderer<NavigatablePsiElement> renderer) {
public SubclassUpdater(
@NotNull PsiClass aClass,
@NotNull PsiElementListCellRenderer<NavigatablePsiElement> renderer,
@NotNull List<NavigatablePsiElement> inheritors
) {
super(aClass.getProject(), JavaAnalysisBundle.message("subclasses.search.progress.title"), renderer);
myClass = aClass;
myInheritors = inheritors;
}
@Override
@@ -389,6 +395,7 @@ public class MarkerType {
@Override
public void run(@NotNull final ProgressIndicator indicator) {
super.run(indicator);
final Set<NavigatablePsiElement> navigatablePsiElementSet = new HashSet<>(myInheritors);
ClassInheritorsSearch.search(myClass, ReadAction.compute(() -> PsiSearchHelper.getInstance(myProject).getUseScope(myClass)), true).forEach(
new CommonProcessors.CollectProcessor<>() {
@Override
@@ -397,6 +404,9 @@ public class MarkerType {
indicator.cancel();
}
ProgressManager.checkCanceled();
if (navigatablePsiElementSet.add(o)) {
myInheritors.add(o);
}
return super.process(o);
}
});
@@ -5,7 +5,6 @@ import com.intellij.codeInsight.CodeInsightBundle
import com.intellij.codeInsight.daemon.impl.MarkerType
import com.intellij.java.JavaBundle
import com.intellij.java.analysis.JavaAnalysisBundle
import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.project.DumbService
import com.intellij.psi.NavigatablePsiElement
@@ -14,10 +13,8 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFunctionalExpression
import com.intellij.psi.search.PsiElementProcessor
import com.intellij.psi.search.PsiElementProcessorAdapter
import com.intellij.psi.search.PsiSearchHelper
import com.intellij.psi.search.searches.ClassInheritorsSearch
import com.intellij.psi.search.searches.FunctionalExpressionSearch
import com.intellij.util.CommonProcessors.CollectProcessor
import org.jetbrains.kotlin.idea.presentation.DeclarationByModuleRenderer
import org.jetbrains.kotlin.utils.addIfNotNull
import java.awt.event.MouseEvent
@@ -54,40 +51,18 @@ fun buildNavigateToClassInheritorsPopup(e: MouseEvent?, element: PsiElement?): N
return null
}
val inheritors = mutableSetOf<NavigatablePsiElement>()
val inheritors = mutableListOf<NavigatablePsiElement>()
inheritors.addIfNotNull(collectProcessor.foundElement)
inheritors.addIfNotNull(collectExprProcessor.foundElement)
if (inheritors.isEmpty()) return null
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(
{
ClassInheritorsSearch.search(psiClass, runReadAction {
PsiSearchHelper.getInstance(project).getUseScope(psiClass)
}, true).forEach(object : CollectProcessor<PsiClass>() {
override fun process(o: PsiClass): Boolean {
ProgressManager.checkCanceled()
inheritors.add(o)
return true
}
})
},
JavaAnalysisBundle.message("progress.title.searching.for.overridden.methods"),
true,
project,
e?.component as? JComponent
)
) {
return null
}
inheritors.sortWith(renderer.comparator as Comparator<in NavigatablePsiElement>)
val inheritorList = inheritors.toMutableList()
inheritorList.sortWith(renderer.comparator as Comparator<in NavigatablePsiElement>)
val updater = MarkerType.SubclassUpdater(psiClass, renderer)
val updater = MarkerType.SubclassUpdater(psiClass, renderer, inheritors)
val className = psiClass.name
return NavigationPopupDescriptor(
inheritorList,
inheritors,
updater.getCaption(inheritors.size)!!,
CodeInsightBundle.message("goto.implementation.findUsages.title", className),
renderer,