Search in sources :

Example 1 with IndexNotReadyException

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

the class JUnitConfigurationModel method applyTo.

private void applyTo(final JUnitConfiguration.Data data, final Module module) {
    final String testObject = getTestObject();
    final String className = getJUnitTextValue(CLASS);
    data.TEST_OBJECT = testObject;
    if (testObject != JUnitConfiguration.TEST_PACKAGE && testObject != JUnitConfiguration.TEST_PATTERN && testObject != JUnitConfiguration.TEST_DIRECTORY && testObject != JUnitConfiguration.TEST_CATEGORY && testObject != JUnitConfiguration.BY_SOURCE_CHANGES) {
        try {
            data.METHOD_NAME = getJUnitTextValue(METHOD);
            final PsiClass testClass = !myProject.isDefault() && !StringUtil.isEmptyOrSpaces(className) ? JUnitUtil.findPsiClass(className, module, myProject) : null;
            if (testClass != null && testClass.isValid()) {
                data.setMainClass(testClass);
            } else {
                data.MAIN_CLASS_NAME = className;
            }
        } catch (ProcessCanceledException | IndexNotReadyException e) {
            data.MAIN_CLASS_NAME = className;
        }
    } else if (testObject != JUnitConfiguration.BY_SOURCE_CHANGES) {
        if (testObject == JUnitConfiguration.TEST_PACKAGE) {
            data.PACKAGE_NAME = getJUnitTextValue(ALL_IN_PACKAGE);
        } else if (testObject == JUnitConfiguration.TEST_DIRECTORY) {
            data.setDirName(getJUnitTextValue(DIR));
        } else if (testObject == JUnitConfiguration.TEST_CATEGORY) {
            data.setCategoryName(getJUnitTextValue(CATEGORY));
        } else {
            final LinkedHashSet<String> set = new LinkedHashSet<>();
            final String[] patterns = getJUnitTextValue(PATTERN).split("\\|\\|");
            for (String pattern : patterns) {
                if (pattern.length() > 0) {
                    set.add(pattern);
                }
            }
            data.setPatterns(set);
        }
        data.MAIN_CLASS_NAME = "";
        data.METHOD_NAME = "";
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PsiClass(com.intellij.psi.PsiClass) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 2 with IndexNotReadyException

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

the class JavaFxControllerClassIndex method findFxmls.

static <T> List<T> findFxmls(ID<String, ?> id, Project project, @NotNull String className, Function<VirtualFile, T> f, GlobalSearchScope scope) {
    return ReadAction.compute(() -> {
        final Collection<VirtualFile> files;
        try {
            files = FileBasedIndex.getInstance().getContainingFiles(id, className, GlobalSearchScope.projectScope(project).intersectWith(scope));
        } catch (IndexNotReadyException e) {
            return Collections.emptyList();
        }
        if (files.isEmpty())
            return Collections.emptyList();
        List<T> result = new ArrayList<>();
        for (VirtualFile file : files) {
            if (!file.isValid())
                continue;
            final T fFile = f.fun(file);
            if (fFile != null) {
                result.add(fFile);
            }
        }
        return result;
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Example 3 with IndexNotReadyException

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

the class JavaDebuggerEvaluator method getExpressionRangeAtOffset.

@Nullable
@Override
public TextRange getExpressionRangeAtOffset(final Project project, final Document document, final int offset, final boolean sideEffectsAllowed) {
    final Ref<TextRange> currentRange = Ref.create(null);
    PsiDocumentManager.getInstance(project).commitAndRunReadAction(() -> {
        try {
            PsiElement elementAtCursor = DebuggerUtilsEx.findElementAt(PsiDocumentManager.getInstance(project).getPsiFile(document), offset);
            if (elementAtCursor == null || !elementAtCursor.isValid()) {
                return;
            }
            Pair<PsiElement, TextRange> pair = findExpression(elementAtCursor, sideEffectsAllowed);
            if (pair != null) {
                currentRange.set(pair.getSecond());
            }
        } catch (IndexNotReadyException ignored) {
        }
    });
    return currentRange.get();
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with IndexNotReadyException

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

the class IndexCacheManagerImpl method collectVirtualFilesWithWord.

// IMPORTANT!!!
// Since implementation of virtualFileProcessor.process() may call indices directly or indirectly,
// we cannot call it inside FileBasedIndex.processValues() method except in collecting form
// If we do, deadlocks are possible (IDEADEV-42137). Process the files without not holding indices' read lock.
private boolean collectVirtualFilesWithWord(@NotNull final String word, final short occurrenceMask, @NotNull final GlobalSearchScope scope, final boolean caseSensitively, @NotNull final Processor<VirtualFile> fileProcessor) {
    if (myProject.isDefault()) {
        return true;
    }
    try {
        return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {

            @Override
            public Boolean compute() {
                return FileBasedIndex.getInstance().processValues(IdIndex.NAME, new IdIndexEntry(word, caseSensitively), null, new FileBasedIndex.ValueProcessor<Integer>() {

                    final FileIndexFacade index = FileIndexFacade.getInstance(myProject);

                    @Override
                    public boolean process(final VirtualFile file, final Integer value) {
                        ProgressIndicatorProvider.checkCanceled();
                        final int mask = value.intValue();
                        if ((mask & occurrenceMask) != 0 && index.shouldBeFound(scope, file)) {
                            if (!fileProcessor.process(file))
                                return false;
                        }
                        return true;
                    }
                }, scope);
            }
        });
    } catch (IndexNotReadyException e) {
        throw new ProcessCanceledException();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) IdIndexEntry(com.intellij.psi.impl.cache.impl.id.IdIndexEntry) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 5 with IndexNotReadyException

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

the class IdentifierHighlighterPass method doCollectInformation.

@Override
public void doCollectInformation(@NotNull final ProgressIndicator progress) {
    if (myHighlightUsagesHandler != null) {
        List<PsiElement> targets = myHighlightUsagesHandler.getTargets();
        myHighlightUsagesHandler.computeUsages(targets);
        final List<TextRange> readUsages = myHighlightUsagesHandler.getReadUsages();
        for (TextRange readUsage : readUsages) {
            LOG.assertTrue(readUsage != null, "null text range from " + myHighlightUsagesHandler);
        }
        myReadAccessRanges.addAll(readUsages);
        final List<TextRange> writeUsages = myHighlightUsagesHandler.getWriteUsages();
        for (TextRange writeUsage : writeUsages) {
            LOG.assertTrue(writeUsage != null, "null text range from " + myHighlightUsagesHandler);
        }
        myWriteAccessRanges.addAll(writeUsages);
        if (!myHighlightUsagesHandler.highlightReferences())
            return;
    }
    int flags = TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED;
    PsiElement myTarget;
    try {
        myTarget = TargetElementUtil.getInstance().findTargetElement(myEditor, flags, myCaretOffset);
    } catch (IndexNotReadyException e) {
        return;
    }
    if (myTarget == null) {
        if (!PsiDocumentManager.getInstance(myProject).isUncommited(myEditor.getDocument())) {
            // when document is committed, try to check injected stuff - it's fast
            Editor injectedEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(myEditor, myFile, myCaretOffset);
            myTarget = TargetElementUtil.getInstance().findTargetElement(injectedEditor, flags, injectedEditor.getCaretModel().getOffset());
        }
    }
    if (myTarget != null) {
        highlightTargetUsages(myTarget);
    } else {
        PsiReference ref = TargetElementUtil.findReference(myEditor);
        if (ref instanceof PsiPolyVariantReference) {
            if (!ref.getElement().isValid()) {
                throw new PsiInvalidElementAccessException(ref.getElement(), "Invalid element in " + ref + " of " + ref.getClass() + "; editor=" + myEditor);
            }
            ResolveResult[] results = ((PsiPolyVariantReference) ref).multiResolve(false);
            if (results.length > 0) {
                for (ResolveResult result : results) {
                    PsiElement target = result.getElement();
                    if (target != null) {
                        if (!target.isValid()) {
                            throw new PsiInvalidElementAccessException(target, "Invalid element returned from " + ref + " of " + ref.getClass() + "; editor=" + myEditor);
                        }
                        highlightTargetUsages(target);
                    }
                }
            }
        }
    }
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor)

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