Search in sources :

Example 61 with IndexNotReadyException

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

the class OccurenceNavigatorActionBase method update.

public void update(AnActionEvent event) {
    Presentation presentation = event.getPresentation();
    Project project = event.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        presentation.setEnabled(false);
        // make it invisible only in main menu to avoid initial invisibility in toolbars
        presentation.setVisible(!ActionPlaces.isMainMenuOrActionSearch(event.getPlace()));
        return;
    }
    OccurenceNavigator navigator = getNavigator(event.getDataContext());
    if (navigator == null) {
        presentation.setEnabled(false);
        // make it invisible only in main menu to avoid initial invisibility in toolbars
        presentation.setVisible(!ActionPlaces.isMainMenuOrActionSearch(event.getPlace()));
        return;
    }
    presentation.setVisible(true);
    try {
        presentation.setEnabled(hasOccurenceToGo(navigator));
        presentation.setText(getDescription(navigator));
    } catch (IndexNotReadyException e) {
        presentation.setEnabled(false);
    }
}
Also used : Project(com.intellij.openapi.project.Project) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) OccurenceNavigator(com.intellij.ide.OccurenceNavigator)

Example 62 with IndexNotReadyException

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

the class DependenciesHandlerBase method perform.

private void perform(List<DependenciesBuilder> builders) {
    try {
        PerformanceWatcher.Snapshot snapshot = PerformanceWatcher.takeSnapshot();
        for (AnalysisScope scope : myScopes) {
            builders.add(createDependenciesBuilder(scope));
        }
        for (DependenciesBuilder builder : builders) {
            builder.analyze();
        }
        snapshot.logResponsivenessSinceCreation("Dependency analysis");
    } catch (IndexNotReadyException e) {
        DumbService.getInstance(myProject).showDumbModeNotification("Analyze dependencies is not available until indices are ready");
        throw new ProcessCanceledException();
    }
}
Also used : PerformanceWatcher(com.intellij.diagnostic.PerformanceWatcher) AnalysisScope(com.intellij.analysis.AnalysisScope) DependenciesBuilder(com.intellij.packageDependencies.DependenciesBuilder) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 63 with IndexNotReadyException

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

the class ContributorsBasedGotoByModel method processNames.

@Override
public void processNames(final Processor<String> nameProcessor, final boolean checkBoxState) {
    long start = System.currentTimeMillis();
    List<ChooseByNameContributor> liveContribs = filterDumb(myContributors);
    ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    Processor<ChooseByNameContributor> processor = new ReadActionProcessor<ChooseByNameContributor>() {

        @Override
        public boolean processInReadAction(@NotNull ChooseByNameContributor contributor) {
            try {
                if (!myProject.isDisposed()) {
                    long contributorStarted = System.currentTimeMillis();
                    final TIntHashSet filter = new TIntHashSet(1000);
                    myContributorToItsSymbolsMap.put(contributor, filter);
                    if (contributor instanceof ChooseByNameContributorEx) {
                        ((ChooseByNameContributorEx) contributor).processNames(s -> {
                            if (nameProcessor.process(s)) {
                                filter.add(s.hashCode());
                            }
                            return true;
                        }, FindSymbolParameters.searchScopeFor(myProject, checkBoxState), getIdFilter(checkBoxState));
                    } else {
                        String[] names = contributor.getNames(myProject, checkBoxState);
                        for (String element : names) {
                            if (nameProcessor.process(element)) {
                                filter.add(element.hashCode());
                            }
                        }
                    }
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(contributor + " for " + (System.currentTimeMillis() - contributorStarted));
                    }
                }
            } catch (ProcessCanceledException | IndexNotReadyException ex) {
            // index corruption detected, ignore
            } catch (Exception ex) {
                LOG.error(ex);
            }
            return true;
        }
    };
    if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(liveContribs, indicator, true, processor)) {
        throw new ProcessCanceledException();
    }
    if (indicator != null) {
        indicator.checkCanceled();
    }
    long finish = System.currentTimeMillis();
    if (LOG.isDebugEnabled()) {
        LOG.debug("processNames(): " + (finish - start) + "ms;");
    }
}
Also used : NotNull(org.jetbrains.annotations.NotNull) TIntHashSet(gnu.trove.TIntHashSet) PluginException(com.intellij.diagnostic.PluginException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ChooseByNameContributorEx(com.intellij.navigation.ChooseByNameContributorEx) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ChooseByNameContributor(com.intellij.navigation.ChooseByNameContributor) ReadActionProcessor(com.intellij.openapi.application.ReadActionProcessor) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 64 with IndexNotReadyException

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

the class PsiViewerDialog method init.

@Override
protected void init() {
    initMnemonics();
    initTree(myPsiTree);
    final TreeCellRenderer renderer = myPsiTree.getCellRenderer();
    myPsiTree.setCellRenderer(new TreeCellRenderer() {

        @Override
        public Component getTreeCellRendererComponent(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            final Component c = renderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
            if (value instanceof DefaultMutableTreeNode) {
                final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
                if (userObject instanceof ViewerNodeDescriptor) {
                    final Object element = ((ViewerNodeDescriptor) userObject).getElement();
                    if (c instanceof NodeRenderer) {
                        ((NodeRenderer) c).setToolTipText(element == null ? null : element.getClass().getName());
                    }
                    if (element instanceof PsiElement && FileContextUtil.getFileContext(((PsiElement) element).getContainingFile()) != null || element instanceof ViewerTreeStructure.Inject) {
                        final TextAttributes attr = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.INJECTED_LANGUAGE_FRAGMENT);
                        c.setBackground(attr.getBackgroundColor());
                    }
                }
            }
            return c;
        }
    });
    myPsiTreeBuilder = new ViewerTreeBuilder(myProject, myPsiTree);
    Disposer.register(getDisposable(), myPsiTreeBuilder);
    myPsiTree.addTreeSelectionListener(new MyPsiTreeSelectionListener());
    final GoToListener listener = new GoToListener();
    myRefs.addKeyListener(listener);
    myRefs.addMouseListener(listener);
    myRefs.getSelectionModel().addListSelectionListener(listener);
    myRefs.setCellRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(@NotNull JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            final Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            try {
                if (resolve(index) == null) {
                    comp.setForeground(JBColor.RED);
                }
            } catch (IndexNotReadyException ignore) {
            }
            return comp;
        }
    });
    initTree(myBlockTree);
    myEditor.getSettings().setFoldingOutlineShown(false);
    myEditor.getDocument().addDocumentListener(myEditorListener);
    myEditor.getSelectionModel().addSelectionListener(myEditorListener);
    myEditor.getCaretModel().addCaretListener(myEditorListener);
    getPeer().getWindow().setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() {

        @Override
        public Component getInitialComponent(@NotNull Window window) {
            return myEditor.getComponent();
        }
    });
    PsiViewerSettings settings = PsiViewerSettings.getSettings();
    VirtualFile file = myExternalDocument ? FileDocumentManager.getInstance().getFile(myEditor.getDocument()) : null;
    Language curLanguage = LanguageUtil.getLanguageForPsi(myProject, file);
    String type = curLanguage != null ? curLanguage.getDisplayName() : settings.type;
    SourceWrapper lastUsed = null;
    for (PsiViewerExtension extension : Extensions.getExtensions(PsiViewerExtension.EP_NAME)) {
        SourceWrapper wrapper = new SourceWrapper(extension);
        mySourceWrappers.add(wrapper);
    }
    Set<FileType> allFileTypes = ContainerUtil.newHashSet();
    Collections.addAll(allFileTypes, FileTypeManager.getInstance().getRegisteredFileTypes());
    for (Language language : Language.getRegisteredLanguages()) {
        FileType fileType = language.getAssociatedFileType();
        if (fileType != null) {
            allFileTypes.add(fileType);
        }
    }
    for (FileType fileType : allFileTypes) {
        if (fileType != StdFileTypes.GUI_DESIGNER_FORM && fileType != StdFileTypes.IDEA_MODULE && fileType != StdFileTypes.IDEA_PROJECT && fileType != StdFileTypes.IDEA_WORKSPACE && fileType != FileTypes.ARCHIVE && fileType != FileTypes.UNKNOWN && fileType != FileTypes.PLAIN_TEXT && !(fileType instanceof AbstractFileType) && !fileType.isBinary() && !fileType.isReadOnly()) {
            final SourceWrapper wrapper = new SourceWrapper(fileType);
            mySourceWrappers.add(wrapper);
            if (lastUsed == null && wrapper.getText().equals(type))
                lastUsed = wrapper;
            if (curLanguage != null && wrapper.myFileType == curLanguage.getAssociatedFileType()) {
                lastUsed = wrapper;
            }
        }
    }
    myFileTypeComboBox.setModel(new CollectionComboBoxModel<>(ContainerUtil.newArrayList(mySourceWrappers), lastUsed));
    myFileTypeComboBox.setRenderer(new ListCellRendererWrapper<SourceWrapper>() {

        @Override
        public void customize(JList list, SourceWrapper value, int index, boolean selected, boolean hasFocus) {
            if (value != null) {
                setText(value.getText());
                setIcon(value.getIcon());
            }
        }
    });
    new ComboboxSpeedSearch(myFileTypeComboBox) {

        @Override
        protected String getElementText(Object element) {
            return element instanceof SourceWrapper ? ((SourceWrapper) element).getText() : null;
        }
    };
    myFileTypeComboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            updateDialectsCombo(null);
            updateExtensionsCombo();
            updateEditor();
        }
    });
    myDialectComboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            updateEditor();
        }
    });
    new ComboboxSpeedSearch(myDialectComboBox) {

        @Override
        protected String getElementText(Object element) {
            return element instanceof Language ? ((Language) element).getDisplayName() : "<default>";
        }
    };
    myFileTypeComboBox.addFocusListener(new AutoExpandFocusListener(myFileTypeComboBox));
    if (!myExternalDocument && lastUsed == null && mySourceWrappers.size() > 0) {
        myFileTypeComboBox.setSelectedIndex(0);
    }
    myDialectComboBox.setRenderer(new ListCellRendererWrapper<Language>() {

        @Override
        public void customize(final JList list, final Language value, final int index, final boolean selected, final boolean hasFocus) {
            setText(value != null ? value.getDisplayName() : "<default>");
        }
    });
    myDialectComboBox.addFocusListener(new AutoExpandFocusListener(myDialectComboBox));
    myExtensionComboBox.setRenderer(new ListCellRendererWrapper<String>() {

        @Override
        public void customize(JList list, String value, int index, boolean selected, boolean hasFocus) {
            if (value != null)
                setText("." + value);
        }
    });
    myExtensionComboBox.addFocusListener(new AutoExpandFocusListener(myExtensionComboBox));
    final ViewerTreeStructure psiTreeStructure = getTreeStructure();
    myShowWhiteSpacesBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            psiTreeStructure.setShowWhiteSpaces(myShowWhiteSpacesBox.isSelected());
            myPsiTreeBuilder.queueUpdate();
        }
    });
    myShowTreeNodesCheckBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            psiTreeStructure.setShowTreeNodes(myShowTreeNodesCheckBox.isSelected());
            myPsiTreeBuilder.queueUpdate();
        }
    });
    myShowWhiteSpacesBox.setSelected(settings.showWhiteSpaces);
    psiTreeStructure.setShowWhiteSpaces(settings.showWhiteSpaces);
    myShowTreeNodesCheckBox.setSelected(settings.showTreeNodes);
    psiTreeStructure.setShowTreeNodes(settings.showTreeNodes);
    myShowBlocksCheckBox.setSelected(settings.showBlocks);
    myBlockStructurePanel.setVisible(settings.showBlocks);
    myShowBlocksCheckBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            if (!myShowBlocksCheckBox.isSelected()) {
                settings.blockRefDividerLocation = myBlockRefSplitPane.getDividerLocation();
            } else {
                myBlockRefSplitPane.setDividerLocation(settings.blockRefDividerLocation);
            }
            myBlockStructurePanel.setVisible(myShowBlocksCheckBox.isSelected());
            myBlockStructurePanel.repaint();
        }
    });
    myTextPanel.setLayout(new BorderLayout());
    myTextPanel.add(myEditor.getComponent(), BorderLayout.CENTER);
    updateDialectsCombo(settings.dialect);
    updateExtensionsCombo();
    registerCustomKeyboardActions();
    final Dimension size = DimensionService.getInstance().getSize(getDimensionServiceKey(), myProject);
    if (size == null) {
        DimensionService.getInstance().setSize(getDimensionServiceKey(), JBUI.size(800, 600));
    }
    myTextSplit.setDividerLocation(settings.textDividerLocation);
    myTreeSplit.setDividerLocation(settings.treeDividerLocation);
    myBlockRefSplitPane.setDividerLocation(settings.blockRefDividerLocation);
    updateEditor();
    super.init();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) AbstractFileType(com.intellij.openapi.fileTypes.impl.AbstractFileType) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) Language(com.intellij.lang.Language) AbstractFileType(com.intellij.openapi.fileTypes.impl.AbstractFileType) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Example 65 with IndexNotReadyException

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

the class AntRenameHandler method getPsiElementsIn.

@Nullable
private static PsiElement[] getPsiElementsIn(final Editor editor, final PsiFile psiFile) {
    try {
        final PsiReference reference = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
        if (reference == null) {
            return null;
        }
        final Collection<PsiElement> candidates = TargetElementUtil.getInstance().getTargetCandidates(reference);
        return ContainerUtil.toArray(candidates, new PsiElement[candidates.size()]);
    } catch (IndexNotReadyException e) {
        return null;
    }
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)70 Nullable (org.jetbrains.annotations.Nullable)14 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)12 PsiElement (com.intellij.psi.PsiElement)11 Project (com.intellij.openapi.project.Project)10 PsiFile (com.intellij.psi.PsiFile)10 TextRange (com.intellij.openapi.util.TextRange)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 NotNull (org.jetbrains.annotations.NotNull)8 Document (com.intellij.openapi.editor.Document)6 Editor (com.intellij.openapi.editor.Editor)6 LocalQuickFixAndIntentionActionOnPsiElement (com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement)5 Ref (com.intellij.openapi.util.Ref)4 LightweightHint (com.intellij.ui.LightweightHint)4 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)3 Module (com.intellij.openapi.module.Module)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 PsiClass (com.intellij.psi.PsiClass)3 javax.swing (javax.swing)3