use of com.intellij.codeInsight.hint.ImplementationViewComponent in project intellij-community by JetBrains.
the class ImplementationsViewTest method testMethodsInInnerClasses.
public void testMethodsInInnerClasses() {
myFixture.configureByText("a.java", "abstract class AFoo{\n" + " abstract boolean a<caret>aa();\n" + " static class AFoo1 extends AFoo {\n" + " @Override\n" + " boolean aaa() {\n" + " return false;\n" + " }\n" + " }\n" + " static class AFoo3 extends AFoo {\n" + " @Override\n" + " boolean aaa() {\n" + " return false;\n" + " }\n" + " }\n" + " static class AFoo2 extends AFoo {\n" + " @Override\n" + " boolean aaa() {\n" + " return false;\n" + " }\n" + " }\n" + " \n" + "}");
PsiMethod psiMethod = (PsiMethod) TargetElementUtil.findTargetElement(myFixture.getEditor(), TargetElementUtil.getInstance().getAllAccepted());
assert psiMethod != null;
final Collection<PsiMethod> methods = OverridingMethodsSearch.search(psiMethod).findAll();
List<PsiMethod> all = new ArrayList<>();
all.add(psiMethod);
all.addAll(methods);
//make sure they are in predefined order
Collections.sort(all, (o1, o2) -> o1.getContainingClass().getQualifiedName().compareTo(o2.getContainingClass().getQualifiedName()));
final ImplementationViewComponent component = new ImplementationViewComponent(all.toArray(new PsiElement[all.size()]), 0);
assertContent(component, new String[] { "a.java (AFoo)", "a.java (AFoo1 in AFoo)", "a.java (AFoo2 in AFoo)", "a.java (AFoo3 in AFoo)" });
}
use of com.intellij.codeInsight.hint.ImplementationViewComponent in project intellij-community by JetBrains.
the class ImplementationsViewTest method testDefaultMethodOfFunctionalInterface.
public void testDefaultMethodOfFunctionalInterface() {
myFixture.configureByText("a.java", "interface AFoo{\n" + " default boolean a<caret>aa(){}\n" + " boolean bbb();" + "}\n" + "class AFooImpl {\n" + " {\n" + " AFoo a = () -> {return false;};\n" + " }\n" + "}");
PsiMethod psiMethod = (PsiMethod) TargetElementUtil.findTargetElement(myFixture.getEditor(), TargetElementUtil.getInstance().getAllAccepted());
assert psiMethod != null;
final Collection<PsiElement> methods = getMethodImplementations(psiMethod);
List<PsiElement> all = new ArrayList<>();
all.add(psiMethod);
all.addAll(methods);
final ImplementationViewComponent component = new ImplementationViewComponent(all.toArray(new PsiElement[all.size()]), 0);
assertContent(component, new String[] { "a.java (AFoo)" });
}
use of com.intellij.codeInsight.hint.ImplementationViewComponent in project intellij-community by JetBrains.
the class ImplementationsViewTest method testInterfaceConstants.
public void testInterfaceConstants() {
myFixture.configureByText("a.java", "interface AF<caret>oo{\n" + " AFoo IMPL = new AFoo(){};\n" + " boolean aaa();\n" + "}");
PsiClass psiClass = (PsiClass) TargetElementUtil.findTargetElement(myFixture.getEditor(), TargetElementUtil.getInstance().getAllAccepted());
assert psiClass != null;
final Collection<PsiElement> classes = getClassImplementations(psiClass);
List<PsiElement> all = new ArrayList<>();
all.add(psiClass);
all.addAll(classes);
final ImplementationViewComponent component = new ImplementationViewComponent(all.toArray(new PsiElement[all.size()]), 0);
assertContent(component, new String[] { "a.java (AFoo)", "a.java (Anonymous in IMPL in AFoo)" });
}
use of com.intellij.codeInsight.hint.ImplementationViewComponent in project intellij-community by JetBrains.
the class ShowCoveringTestsAction method actionPerformed.
public void actionPerformed(final AnActionEvent e) {
final DataContext context = e.getDataContext();
final Project project = e.getProject();
LOG.assertTrue(project != null);
final Editor editor = e.getData(CommonDataKeys.EDITOR);
LOG.assertTrue(editor != null);
final CoverageSuitesBundle currentSuite = CoverageDataManager.getInstance(project).getCurrentSuitesBundle();
LOG.assertTrue(currentSuite != null);
final File[] traceFiles = getTraceFiles(project);
final Set<String> tests = new HashSet<>();
Runnable runnable = () -> {
for (File traceFile : traceFiles) {
DataInputStream in = null;
try {
in = new DataInputStream(new FileInputStream(traceFile));
extractTests(traceFile, in, tests);
} catch (Exception ex) {
LOG.error(traceFile.getName(), ex);
} finally {
try {
in.close();
} catch (IOException ex) {
LOG.error(ex);
}
}
}
};
if (ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, "Extract information about tests", false, project)) {
//todo cache them? show nothing found message
final String[] testNames = ArrayUtil.toStringArray(tests);
Arrays.sort(testNames);
if (testNames.length == 0) {
HintManager.getInstance().showErrorHint(editor, "Failed to load covered tests");
return;
}
final List<PsiElement> elements = currentSuite.getCoverageEngine().findTestsByNames(testNames, project);
final ImplementationViewComponent component;
final String title = "Tests covering line " + myClassFQName + ":" + myLineData.getLineNumber();
final ComponentPopupBuilder popupBuilder;
if (!elements.isEmpty()) {
component = new ImplementationViewComponent(PsiUtilCore.toPsiElementArray(elements), 0);
popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component.getPreferredFocusableComponent()).setDimensionServiceKey(project, "ShowTestsPopup", false).setCouldPin(popup -> {
component.showInUsageView();
popup.cancel();
return false;
});
} else {
component = null;
final JPanel panel = new PanelWithText("Following test" + (testNames.length > 1 ? "s" : "") + " could not be found: " + StringUtil.join(testNames, "<br/>").replace("_", "."));
popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null);
}
final JBPopup popup = popupBuilder.setRequestFocusCondition(project, NotLookupOrSearchCondition.INSTANCE).setProject(project).setResizable(true).setMovable(true).setTitle(title).createPopup();
popup.showInBestPositionFor(editor);
if (component != null) {
component.setHint(popup, title);
}
}
}
Aggregations