Search in sources :

Example 11 with IndexNotReadyException

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

the class AbstractTreeUi method getChildrenFor.

//todo [kirillk] temporary consistency check
private Object[] getChildrenFor(final Object element) {
    final Ref<Object[]> passOne = new Ref<>();
    try (LockToken ignored = acquireLock()) {
        execute(new TreeRunnable("AbstractTreeUi.getChildrenFor") {

            @Override
            public void perform() {
                passOne.set(getTreeStructure().getChildElements(element));
            }
        });
    } catch (IndexNotReadyException e) {
        warnOnIndexNotReady(e);
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    if (!Registry.is("ide.tree.checkStructure"))
        return passOne.get();
    final Object[] passTwo = getTreeStructure().getChildElements(element);
    final HashSet<Object> two = new HashSet<>(Arrays.asList(passTwo));
    if (passOne.get().length != passTwo.length) {
        LOG.error("AbstractTreeStructure.getChildren() must either provide same objects or new objects but with correct hashCode() and equals() methods. Wrong parent element=" + element);
    } else {
        for (Object eachInOne : passOne.get()) {
            if (!two.contains(eachInOne)) {
                LOG.error("AbstractTreeStructure.getChildren() must either provide same objects or new objects but with correct hashCode() and equals() methods. Wrong parent element=" + element);
                break;
            }
        }
    }
    return passOne.get();
}
Also used : LockToken(com.intellij.util.concurrency.LockToken) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet)

Example 12 with IndexNotReadyException

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

the class AbstractTreeUi method update.

private boolean update(@NotNull final NodeDescriptor nodeDescriptor) {
    try (LockToken ignored = acquireLock()) {
        final AtomicBoolean update = new AtomicBoolean();
        execute(new TreeRunnable("AbstractTreeUi.update") {

            @Override
            public void perform() {
                nodeDescriptor.setUpdateCount(nodeDescriptor.getUpdateCount() + 1);
                update.set(getBuilder().updateNodeDescriptor(nodeDescriptor));
            }
        });
        return update.get();
    } catch (IndexNotReadyException e) {
        warnOnIndexNotReady(e);
        return false;
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LockToken(com.intellij.util.concurrency.LockToken) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Example 13 with IndexNotReadyException

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

the class FoldingPolicy method isCollapseByDefault.

public static boolean isCollapseByDefault(PsiElement element) {
    final Language lang = element.getLanguage();
    final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(lang);
    try {
        return foldingBuilder != null && foldingBuilder.isCollapsedByDefault(element.getNode());
    } catch (IndexNotReadyException e) {
        LOG.error(e);
        return false;
    }
}
Also used : FoldingBuilder(com.intellij.lang.folding.FoldingBuilder) Language(com.intellij.lang.Language) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Example 14 with IndexNotReadyException

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

the class GotoTargetHandler method show.

private void show(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file, @NotNull final GotoData gotoData) {
    final PsiElement[] targets = gotoData.targets;
    final List<AdditionalAction> additionalActions = gotoData.additionalActions;
    if (targets.length == 0 && additionalActions.isEmpty()) {
        HintManager.getInstance().showErrorHint(editor, getNotFoundMessage(project, editor, file));
        return;
    }
    boolean finished = gotoData.listUpdaterTask == null || gotoData.listUpdaterTask.isFinished();
    if (targets.length == 1 && additionalActions.isEmpty() && finished) {
        navigateToElement(targets[0]);
        return;
    }
    for (PsiElement eachTarget : targets) {
        gotoData.renderers.put(eachTarget, createRenderer(gotoData, eachTarget));
    }
    final String name = ((PsiNamedElement) gotoData.source).getName();
    final String title = getChooserTitle(gotoData.source, name, targets.length, finished);
    if (shouldSortTargets()) {
        Arrays.sort(targets, createComparator(gotoData.renderers, gotoData));
    }
    List<Object> allElements = new ArrayList<>(targets.length + additionalActions.size());
    Collections.addAll(allElements, targets);
    allElements.addAll(additionalActions);
    final JBList list = new JBList(new CollectionListModel<>(allElements));
    HintUpdateSupply.installSimpleHintUpdateSupply(list);
    list.setFont(EditorUtil.getEditorFont());
    list.setCellRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if (value == null)
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value instanceof AdditionalAction) {
                return myActionElementRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            }
            PsiElementListCellRenderer renderer = getRenderer(value, gotoData.renderers, gotoData);
            return renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
    });
    final Runnable runnable = () -> {
        int[] ids = list.getSelectedIndices();
        if (ids == null || ids.length == 0)
            return;
        Object[] selectedElements = list.getSelectedValues();
        for (Object element : selectedElements) {
            if (element instanceof AdditionalAction) {
                ((AdditionalAction) element).execute();
            } else {
                Navigatable nav = element instanceof Navigatable ? (Navigatable) element : EditSourceUtil.getDescriptor((PsiElement) element);
                try {
                    if (nav != null && nav.canNavigate()) {
                        navigateToElement(nav);
                    }
                } catch (IndexNotReadyException e) {
                    DumbService.getInstance(project).showDumbModeNotification("Navigation is not available while indexing");
                }
            }
        }
    };
    final PopupChooserBuilder builder = new PopupChooserBuilder(list);
    builder.setFilteringEnabled(o -> {
        if (o instanceof AdditionalAction) {
            return ((AdditionalAction) o).getText();
        }
        return getRenderer(o, gotoData.renderers, gotoData).getElementText((PsiElement) o);
    });
    final Ref<UsageView> usageView = new Ref<>();
    final JBPopup popup = builder.setTitle(title).setItemChoosenCallback(runnable).setMovable(true).setCancelCallback(() -> {
        HintUpdateSupply.hideHint(list);
        final ListBackgroundUpdaterTask task = gotoData.listUpdaterTask;
        if (task != null) {
            task.cancelTask();
        }
        return true;
    }).setCouldPin(popup1 -> {
        usageView.set(FindUtil.showInUsageView(gotoData.source, gotoData.targets, getFindUsagesTitle(gotoData.source, name, gotoData.targets.length), gotoData.source.getProject()));
        popup1.cancel();
        return false;
    }).setAdText(getAdText(gotoData.source, targets.length)).createPopup();
    builder.getScrollPane().setBorder(null);
    builder.getScrollPane().setViewportBorder(null);
    if (gotoData.listUpdaterTask != null) {
        Alarm alarm = new Alarm(popup);
        alarm.addRequest(() -> popup.showInBestPositionFor(editor), 300);
        gotoData.listUpdaterTask.init((AbstractPopup) popup, list, usageView);
        ProgressManager.getInstance().run(gotoData.listUpdaterTask);
    } else {
        popup.showInBestPositionFor(editor);
    }
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) Navigatable(com.intellij.pom.Navigatable) UsageView(com.intellij.usages.UsageView) JBPopup(com.intellij.openapi.ui.popup.JBPopup) PsiElement(com.intellij.psi.PsiElement) Ref(com.intellij.openapi.util.Ref) Alarm(com.intellij.util.Alarm) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) JBList(com.intellij.ui.components.JBList) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) PsiElementListCellRenderer(com.intellij.ide.util.PsiElementListCellRenderer)

Example 15 with IndexNotReadyException

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

the class GotoDeclarationAction method invoke.

@Override
public void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file) {
    DumbService.getInstance(project).setAlternativeResolveEnabled(true);
    try {
        int offset = editor.getCaretModel().getOffset();
        PsiElement[] elements = underModalProgress(project, "Resolving Reference...", () -> findAllTargetElements(project, editor, offset));
        FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.goto.declaration");
        if (elements.length != 1) {
            if (elements.length == 0 && suggestCandidates(TargetElementUtil.findReference(editor, offset)).isEmpty()) {
                PsiElement element = findElementToShowUsagesOf(editor, editor.getCaretModel().getOffset());
                if (startFindUsages(editor, element)) {
                    return;
                }
                //disable 'no declaration found' notification for keywords
                final PsiElement elementAtCaret = file.findElementAt(offset);
                if (elementAtCaret != null) {
                    final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(elementAtCaret.getLanguage());
                    if (namesValidator != null && namesValidator.isKeyword(elementAtCaret.getText(), project)) {
                        return;
                    }
                }
            }
            chooseAmbiguousTarget(editor, offset, elements, file);
            return;
        }
        PsiElement element = elements[0];
        if (element == findElementToShowUsagesOf(editor, editor.getCaretModel().getOffset()) && startFindUsages(editor, element)) {
            return;
        }
        PsiElement navElement = element.getNavigationElement();
        navElement = TargetElementUtil.getInstance().getGotoDeclarationTarget(element, navElement);
        if (navElement != null) {
            gotoTargetElement(navElement, editor, file);
        }
    } catch (IndexNotReadyException e) {
        DumbService.getInstance(project).showDumbModeNotification("Navigation is not available here during index update");
    } finally {
        DumbService.getInstance(project).setAlternativeResolveEnabled(false);
    }
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) NamesValidator(com.intellij.lang.refactoring.NamesValidator) RelativePoint(com.intellij.ui.awt.RelativePoint) PsiElement(com.intellij.psi.PsiElement)

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