Skip to content

Commit

Permalink
SubclassTestChooser: Avoid unchecked warnings by using newer APIs
Browse files Browse the repository at this point in the history
Instead of setting the renderer on a JBList, which results in an unchecked warning, we directly set it on the IPopupChooserBuilder. That approach is even better as we avoid the previous, deprecated use of JBPopupFactory#createListPopupBuilder.

PiperOrigin-RevId: 341840854
  • Loading branch information
alice-ks authored and copybara-github committed Nov 11, 2020
1 parent 076c207 commit 6fd7565
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.search.searches.ClassInheritorsSearch;
import com.intellij.ui.components.JBList;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -50,26 +49,22 @@ static void chooseSubclass(
}
PsiClassListCellRenderer renderer = new PsiClassListCellRenderer();
classes.sort(renderer.getComparator());
JBList<PsiClass> list = new JBList<>(classes);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setCellRenderer(renderer);
JBPopupFactory.getInstance()
.createListPopupBuilder(list)
.createPopupChooserBuilder(classes)
.setTitle("Choose test class to run")
.setMovable(false)
.setResizable(false)
.setRequestFocus(true)
.setCancelOnWindowDeactivation(false)
.setItemChoosenCallback(
() -> callbackOnClassSelection.accept((PsiClass) list.getSelectedValue()))
.setRenderer(renderer)
.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
.setItemChosenCallback(callbackOnClassSelection::accept)
.createPopup()
.showInBestPositionFor(context.getDataContext());
}

static List<PsiClass> findTestSubclasses(PsiClass testClass) {
return ClassInheritorsSearch.search(testClass)
.findAll()
.stream()
return ClassInheritorsSearch.search(testClass).findAll().stream()
.filter(ProducerUtils::isTestClass)
.collect(Collectors.toList());
}
Expand Down

0 comments on commit 6fd7565

Please sign in to comment.