Search in sources :

Example 6 with DumbService

use of com.intellij.openapi.project.DumbService in project intellij-community by JetBrains.

the class CreateTemplateInPackageAction method checkOrCreate.

@Nullable
private T checkOrCreate(String newName, PsiDirectory directory, String templateName) throws IncorrectOperationException {
    PsiDirectory dir = directory;
    String className = removeExtension(templateName, newName);
    if (className.contains(".")) {
        String[] names = className.split("\\.");
        for (int i = 0; i < names.length - 1; i++) {
            dir = CreateFileAction.findOrCreateSubdirectory(dir, names[i]);
        }
        className = names[names.length - 1];
    }
    DumbService service = DumbService.getInstance(dir.getProject());
    service.setAlternativeResolveEnabled(true);
    try {
        return doCreate(dir, className, templateName);
    } finally {
        service.setAlternativeResolveEnabled(false);
    }
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) DumbService(com.intellij.openapi.project.DumbService) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with DumbService

use of com.intellij.openapi.project.DumbService in project intellij-community by JetBrains.

the class CreateTestDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints constr = new GridBagConstraints();
    constr.fill = GridBagConstraints.HORIZONTAL;
    constr.anchor = GridBagConstraints.WEST;
    int gridy = 1;
    constr.insets = insets(4);
    constr.gridy = gridy++;
    constr.gridx = 0;
    constr.weightx = 0;
    final JLabel libLabel = new JLabel(CodeInsightBundle.message("intention.create.test.dialog.testing.library"));
    libLabel.setLabelFor(myLibrariesCombo);
    panel.add(libLabel, constr);
    constr.gridx = 1;
    constr.weightx = 1;
    constr.gridwidth = GridBagConstraints.REMAINDER;
    panel.add(myLibrariesCombo, constr);
    myFixLibraryPanel = new JPanel(new BorderLayout());
    myFixLibraryLabel = new JLabel();
    myFixLibraryLabel.setIcon(AllIcons.Actions.IntentionBulb);
    myFixLibraryPanel.add(myFixLibraryLabel, BorderLayout.CENTER);
    myFixLibraryPanel.add(myFixLibraryButton, BorderLayout.EAST);
    constr.insets = insets(1);
    constr.gridy = gridy++;
    constr.gridx = 0;
    panel.add(myFixLibraryPanel, constr);
    constr.gridheight = 1;
    constr.insets = insets(6);
    constr.gridy = gridy++;
    constr.gridx = 0;
    constr.weightx = 0;
    constr.gridwidth = 1;
    panel.add(new JLabel(CodeInsightBundle.message("intention.create.test.dialog.class.name")), constr);
    myTargetClassNameField = new EditorTextField(suggestTestClassName(myTargetClass));
    myTargetClassNameField.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            getOKAction().setEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(getClassName()));
        }
    });
    constr.gridx = 1;
    constr.weightx = 1;
    panel.add(myTargetClassNameField, constr);
    constr.insets = insets(1);
    constr.gridy = gridy++;
    constr.gridx = 0;
    constr.weightx = 0;
    panel.add(new JLabel(CodeInsightBundle.message("intention.create.test.dialog.super.class")), constr);
    mySuperClassField = new ReferenceEditorComboWithBrowseButton(new MyChooseSuperClassAction(), null, myProject, true, JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE, RECENT_SUPERS_KEY);
    mySuperClassField.setMinimumSize(mySuperClassField.getPreferredSize());
    constr.gridx = 1;
    constr.weightx = 1;
    panel.add(mySuperClassField, constr);
    constr.insets = insets(1);
    constr.gridy = gridy++;
    constr.gridx = 0;
    constr.weightx = 0;
    panel.add(new JLabel(CodeInsightBundle.message("dialog.create.class.destination.package.label")), constr);
    constr.gridx = 1;
    constr.weightx = 1;
    String targetPackageName = myTargetPackage != null ? myTargetPackage.getQualifiedName() : "";
    myTargetPackageField = new PackageNameReferenceEditorCombo(targetPackageName, myProject, RECENTS_KEY, CodeInsightBundle.message("dialog.create.class.package.chooser.title"));
    new AnAction() {

        public void actionPerformed(AnActionEvent e) {
            myTargetPackageField.getButton().doClick();
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK)), myTargetPackageField.getChildComponent());
    JPanel targetPackagePanel = new JPanel(new BorderLayout());
    targetPackagePanel.add(myTargetPackageField, BorderLayout.CENTER);
    panel.add(targetPackagePanel, constr);
    constr.insets = insets(6);
    constr.gridy = gridy++;
    constr.gridx = 0;
    constr.weightx = 0;
    panel.add(new JLabel(CodeInsightBundle.message("intention.create.test.dialog.generate")), constr);
    constr.gridx = 1;
    constr.weightx = 1;
    panel.add(myGenerateBeforeBox, constr);
    constr.insets = insets(1);
    constr.gridy = gridy++;
    panel.add(myGenerateAfterBox, constr);
    constr.insets = insets(6);
    constr.gridy = gridy++;
    constr.gridx = 0;
    constr.weightx = 0;
    final JLabel membersLabel = new JLabel(CodeInsightBundle.message("intention.create.test.dialog.select.methods"));
    membersLabel.setLabelFor(myMethodsTable);
    panel.add(membersLabel, constr);
    constr.gridx = 1;
    constr.weightx = 1;
    panel.add(myShowInheritedMethodsBox, constr);
    constr.insets = insets(1, 8);
    constr.gridy = gridy++;
    constr.gridx = 0;
    constr.gridwidth = GridBagConstraints.REMAINDER;
    constr.fill = GridBagConstraints.BOTH;
    constr.weighty = 1;
    panel.add(ScrollPaneFactory.createScrollPane(myMethodsTable), constr);
    myLibrariesCombo.setRenderer(new ListCellRendererWrapper<TestFramework>() {

        @Override
        public void customize(JList list, TestFramework value, int index, boolean selected, boolean hasFocus) {
            if (value != null) {
                setText(value.getName());
                setIcon(value.getIcon());
            }
        }
    });
    final boolean hasTestRoots = !ModuleRootManager.getInstance(myTargetModule).getSourceRoots(JavaModuleSourceRootTypes.TESTS).isEmpty();
    final List<TestFramework> attachedLibraries = new ArrayList<>();
    final String defaultLibrary = getDefaultLibraryName();
    TestFramework defaultDescriptor = null;
    final DefaultComboBoxModel model = (DefaultComboBoxModel) myLibrariesCombo.getModel();
    final List<TestFramework> descriptors = new ArrayList<>();
    descriptors.addAll(Arrays.asList(Extensions.getExtensions(TestFramework.EXTENSION_NAME)));
    descriptors.sort((d1, d2) -> Comparing.compare(d1.getName(), d2.getName()));
    for (final TestFramework descriptor : descriptors) {
        model.addElement(descriptor);
        if (hasTestRoots && descriptor.isLibraryAttached(myTargetModule)) {
            attachedLibraries.add(descriptor);
            if (defaultLibrary == null) {
                defaultDescriptor = descriptor;
            }
        }
        if (Comparing.equal(defaultLibrary, descriptor.getName())) {
            defaultDescriptor = descriptor;
        }
    }
    myLibrariesCombo.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            final Object selectedItem = myLibrariesCombo.getSelectedItem();
            if (selectedItem != null) {
                final DumbService dumbService = DumbService.getInstance(myProject);
                dumbService.setAlternativeResolveEnabled(true);
                try {
                    onLibrarySelected((TestFramework) selectedItem);
                } finally {
                    dumbService.setAlternativeResolveEnabled(false);
                }
            }
        }
    });
    if (defaultDescriptor != null && (attachedLibraries.contains(defaultDescriptor) || attachedLibraries.isEmpty())) {
        myLibrariesCombo.setSelectedItem(defaultDescriptor);
    } else {
        myLibrariesCombo.setSelectedIndex(0);
    }
    myFixLibraryButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (mySelectedFramework instanceof JavaTestFramework) {
                ((JavaTestFramework) mySelectedFramework).setupLibrary(myTargetModule);
            } else {
                OrderEntryFix.addJarToRoots(mySelectedFramework.getLibraryPath(), myTargetModule, null);
            }
            myFixLibraryPanel.setVisible(false);
        }
    });
    myShowInheritedMethodsBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            updateMethodsTable();
        }
    });
    restoreShowInheritedMembersStatus();
    updateMethodsTable();
    return panel;
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ActionEvent(java.awt.event.ActionEvent) JavaTestFramework(com.intellij.testIntegration.JavaTestFramework) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) DumbService(com.intellij.openapi.project.DumbService) PackageNameReferenceEditorCombo(com.intellij.refactoring.ui.PackageNameReferenceEditorCombo) TestFramework(com.intellij.testIntegration.TestFramework) JavaTestFramework(com.intellij.testIntegration.JavaTestFramework) ActionListener(java.awt.event.ActionListener)

Example 8 with DumbService

use of com.intellij.openapi.project.DumbService in project intellij-community by JetBrains.

the class JavaCoverageSuite method getCurrentSuiteClasses.

@NotNull
public List<PsiClass> getCurrentSuiteClasses(final Project project) {
    final List<PsiClass> classes = new ArrayList<>();
    final String[] classNames = getFilteredClassNames();
    if (classNames.length > 0) {
        for (final String className : classNames) {
            final PsiClass aClass = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {

                @Nullable
                public PsiClass compute() {
                    final DumbService dumbService = DumbService.getInstance(project);
                    dumbService.setAlternativeResolveEnabled(true);
                    try {
                        return JavaPsiFacade.getInstance(project).findClass(className.replace("$", "."), GlobalSearchScope.allScope(project));
                    } finally {
                        dumbService.setAlternativeResolveEnabled(false);
                    }
                }
            });
            if (aClass != null) {
                classes.add(aClass);
            }
        }
    }
    return classes;
}
Also used : ArrayList(java.util.ArrayList) PsiClass(com.intellij.psi.PsiClass) DumbService(com.intellij.openapi.project.DumbService) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with DumbService

use of com.intellij.openapi.project.DumbService in project kotlin by JetBrains.

the class KotlinJavaPsiFacade method filteredFinders.

@NotNull
private KotlinPsiElementFinderWrapper[] filteredFinders() {
    DumbService dumbService = DumbService.getInstance(getProject());
    KotlinPsiElementFinderWrapper[] finders = finders();
    if (dumbService.isDumb()) {
        List<KotlinPsiElementFinderWrapper> list = dumbService.filterByDumbAwareness(Arrays.asList(finders));
        finders = list.toArray(new KotlinPsiElementFinderWrapper[list.size()]);
    }
    return finders;
}
Also used : DumbService(com.intellij.openapi.project.DumbService) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with DumbService

use of com.intellij.openapi.project.DumbService in project intellij-community by JetBrains.

the class NavigationGutterIconRenderer method navigate.

@Override
public void navigate(@Nullable final MouseEvent event, @Nullable final PsiElement elt) {
    final List<PsiElement> list;
    DumbService dumbService = elt != null ? DumbService.getInstance(elt.getProject()) : null;
    if (dumbService != null)
        dumbService.setAlternativeResolveEnabled(true);
    try {
        list = getTargetElements();
    } finally {
        if (dumbService != null)
            dumbService.setAlternativeResolveEnabled(false);
    }
    if (list.isEmpty()) {
        if (myEmptyText != null) {
            if (event != null) {
                final JComponent label = HintUtil.createErrorLabel(myEmptyText);
                label.setBorder(IdeBorderFactory.createEmptyBorder(2, 7, 2, 7));
                JBPopupFactory.getInstance().createBalloonBuilder(label).setFadeoutTime(3000).setFillColor(HintUtil.getErrorColor()).createBalloon().show(new RelativePoint(event), Balloon.Position.above);
            }
        }
        return;
    }
    if (list.size() == 1) {
        PsiNavigateUtil.navigate(list.iterator().next());
    } else {
        if (event != null) {
            final JBPopup popup = NavigationUtil.getPsiElementPopup(PsiUtilCore.toPsiElementArray(list), myCellRenderer.compute(), myPopupTitle);
            popup.show(new RelativePoint(event));
        }
    }
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) JBPopup(com.intellij.openapi.ui.popup.JBPopup) DumbService(com.intellij.openapi.project.DumbService) PsiElement(com.intellij.psi.PsiElement)

Aggregations

DumbService (com.intellij.openapi.project.DumbService)12 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 Project (com.intellij.openapi.project.Project)2 PsiElement (com.intellij.psi.PsiElement)2 HashMap (com.intellij.util.containers.HashMap)2 ArrayList (java.util.ArrayList)2 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)1 AccessToken (com.intellij.openapi.application.AccessToken)1 Application (com.intellij.openapi.application.Application)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiClass (com.intellij.psi.PsiClass)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiFile (com.intellij.psi.PsiFile)1 CodeStyleManager (com.intellij.psi.codeStyle.CodeStyleManager)1