Search in sources :

Example 6 with ImplementationViewComponent

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)" });
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) PsiElement(com.intellij.psi.PsiElement)

Example 7 with ImplementationViewComponent

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)" });
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) PsiElement(com.intellij.psi.PsiElement)

Example 8 with ImplementationViewComponent

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)" });
}
Also used : PsiClass(com.intellij.psi.PsiClass) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) PsiElement(com.intellij.psi.PsiElement)

Example 9 with ImplementationViewComponent

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);
        }
    }
}
Also used : DataInputStream(java.io.DataInputStream) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) HashSet(com.intellij.util.containers.HashSet) LineCoverage(com.intellij.rt.coverage.data.LineCoverage) Comparing(com.intellij.openapi.util.Comparing) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) PlatformIcons(com.intellij.util.PlatformIcons) ProgressManager(com.intellij.openapi.progress.ProgressManager) LineData(com.intellij.rt.coverage.data.LineData) CoverageSuitesBundle(com.intellij.coverage.CoverageSuitesBundle) ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) StringUtil(com.intellij.openapi.util.text.StringUtil) PanelWithText(com.intellij.openapi.ui.PanelWithText) CoverageDataManager(com.intellij.coverage.CoverageDataManager) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup) File(java.io.File) CoverageSuite(com.intellij.coverage.CoverageSuite) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) NotLookupOrSearchCondition(com.intellij.ui.popup.NotLookupOrSearchCondition) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) HintManager(com.intellij.codeInsight.hint.HintManager) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) javax.swing(javax.swing) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) CoverageSuitesBundle(com.intellij.coverage.CoverageSuitesBundle) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) Project(com.intellij.openapi.project.Project) PanelWithText(com.intellij.openapi.ui.PanelWithText) ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup) File(java.io.File) PsiElement(com.intellij.psi.PsiElement) HashSet(com.intellij.util.containers.HashSet)

Aggregations

ImplementationViewComponent (com.intellij.codeInsight.hint.ImplementationViewComponent)9 PsiElement (com.intellij.psi.PsiElement)8 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)3 Project (com.intellij.openapi.project.Project)3 JBPopup (com.intellij.openapi.ui.popup.JBPopup)3 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)3 PsiClass (com.intellij.psi.PsiClass)3 PsiMethod (com.intellij.psi.PsiMethod)3 java.util (java.util)3 Nullable (org.jetbrains.annotations.Nullable)3 DataManager (com.intellij.ide.DataManager)2 Logger (com.intellij.openapi.diagnostic.Logger)2 Editor (com.intellij.openapi.editor.Editor)2 ProgressManager (com.intellij.openapi.progress.ProgressManager)2 FileUtil (com.intellij.openapi.util.io.FileUtil)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 NonNls (org.jetbrains.annotations.NonNls)2 NotNull (org.jetbrains.annotations.NotNull)2 CodeInsightBundle (com.intellij.codeInsight.CodeInsightBundle)1 TargetElementUtil (com.intellij.codeInsight.TargetElementUtil)1