Search in sources :

Example 41 with IndexNotReadyException

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

the class HighlightVisitorImpl method highlightReferencedMethodOrClassName.

private void highlightReferencedMethodOrClassName(@NotNull PsiJavaCodeReferenceElement element, PsiElement resolved) {
    PsiElement parent = element.getParent();
    final TextAttributesScheme colorsScheme = myHolder.getColorsScheme();
    if (parent instanceof PsiMethodCallExpression) {
        PsiMethod method = ((PsiMethodCallExpression) parent).resolveMethod();
        PsiElement methodNameElement = element.getReferenceNameElement();
        if (method != null && methodNameElement != null && !(methodNameElement instanceof PsiKeyword)) {
            myHolder.add(HighlightNamesUtil.highlightMethodName(method, methodNameElement, false, colorsScheme));
            myHolder.add(HighlightNamesUtil.highlightClassNameInQualifier(element, colorsScheme));
        }
    } else if (parent instanceof PsiConstructorCall) {
        try {
            PsiMethod method = ((PsiConstructorCall) parent).resolveConstructor();
            PsiMember methodOrClass = method != null ? method : resolved instanceof PsiClass ? (PsiClass) resolved : null;
            if (methodOrClass != null) {
                final PsiElement referenceNameElement = element.getReferenceNameElement();
                if (referenceNameElement != null) {
                    // exclude type parameters from the highlighted text range
                    TextRange range = referenceNameElement.getTextRange();
                    myHolder.add(HighlightNamesUtil.highlightMethodName(methodOrClass, referenceNameElement, range, colorsScheme, false));
                }
            }
        } catch (IndexNotReadyException ignored) {
        }
    } else if (resolved instanceof PsiPackage) {
        // highlight package (and following dot) as a class
        myHolder.add(HighlightNamesUtil.highlightPackage(resolved, element, colorsScheme));
    } else if (resolved instanceof PsiClass) {
        myHolder.add(HighlightNamesUtil.highlightClassName((PsiClass) resolved, element, colorsScheme));
    }
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) TextAttributesScheme(com.intellij.openapi.editor.colors.TextAttributesScheme) TextRange(com.intellij.openapi.util.TextRange) LocalQuickFixAndIntentionActionOnPsiElement(com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement)

Example 42 with IndexNotReadyException

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

the class AutoPopupController method autoPopupParameterInfo.

public void autoPopupParameterInfo(@NotNull final Editor editor, @Nullable final PsiElement highlightedMethod) {
    if (ApplicationManager.getApplication().isUnitTestMode())
        return;
    if (DumbService.isDumb(myProject))
        return;
    if (PowerSaveMode.isEnabled())
        return;
    ApplicationManager.getApplication().assertIsDispatchThread();
    final CodeInsightSettings settings = CodeInsightSettings.getInstance();
    if (settings.AUTO_POPUP_PARAMETER_INFO) {
        final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
        PsiFile file = documentManager.getPsiFile(editor.getDocument());
        if (file == null)
            return;
        if (!documentManager.isUncommited(editor.getDocument())) {
            file = documentManager.getPsiFile(InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, file).getDocument());
            if (file == null)
                return;
        }
        final PsiFile file1 = file;
        Runnable request = () -> {
            if (!myProject.isDisposed() && !DumbService.isDumb(myProject) && !editor.isDisposed() && editor.getComponent().isShowing()) {
                int lbraceOffset = editor.getCaretModel().getOffset() - 1;
                try {
                    ShowParameterInfoHandler.invoke(myProject, editor, file1, lbraceOffset, highlightedMethod, false);
                } catch (IndexNotReadyException ignored) {
                //anything can happen on alarm
                }
            }
        };
        addRequest(() -> documentManager.performLaterWhenAllCommitted(request), settings.PARAMETER_INFO_DELAY);
    }
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PsiFile(com.intellij.psi.PsiFile) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 43 with IndexNotReadyException

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

the class AbstractLayoutCodeProcessor method runProcessFile.

private void runProcessFile(@NotNull final PsiFile file) {
    Document document = PsiDocumentManager.getInstance(myProject).getDocument(file);
    if (document == null) {
        return;
    }
    if (!FileDocumentManager.getInstance().requestWriting(document, myProject)) {
        Messages.showMessageDialog(myProject, PsiBundle.message("cannot.modify.a.read.only.file", file.getName()), CodeInsightBundle.message("error.dialog.readonly.file.title"), Messages.getErrorIcon());
        return;
    }
    final Ref<FutureTask<Boolean>> writeActionRunnable = new Ref<>();
    Runnable readAction = () -> {
        if (!checkFileWritable(file))
            return;
        try {
            FutureTask<Boolean> writeTask = preprocessFile(file, myProcessChangedTextOnly);
            writeActionRunnable.set(writeTask);
        } catch (IncorrectOperationException e) {
            LOG.error(e);
        }
    };
    Runnable writeAction = () -> {
        if (writeActionRunnable.isNull())
            return;
        FutureTask<Boolean> task = writeActionRunnable.get();
        task.run();
        try {
            task.get();
        } catch (CancellationException ignored) {
        } catch (ExecutionException e) {
            if (e.getCause() instanceof IndexNotReadyException) {
                throw (IndexNotReadyException) e.getCause();
            }
            LOG.error(e);
        } catch (Exception e) {
            LOG.error(e);
        }
    };
    runLayoutCodeProcess(readAction, writeAction);
}
Also used : Ref(com.intellij.openapi.util.Ref) FutureTask(java.util.concurrent.FutureTask) CancellationException(java.util.concurrent.CancellationException) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Document(com.intellij.openapi.editor.Document) ExecutionException(java.util.concurrent.ExecutionException) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) CancellationException(java.util.concurrent.CancellationException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) ExecutionException(java.util.concurrent.ExecutionException)

Example 44 with IndexNotReadyException

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

the class GlobalInspectionContextImpl method runGlobalTools.

private void runGlobalTools(@NotNull final AnalysisScope scope, @NotNull final InspectionManager inspectionManager, @NotNull List<Tools> globalTools, boolean isOfflineInspections) {
    LOG.assertTrue(!ApplicationManager.getApplication().isReadAccessAllowed() || isOfflineInspections, "Must not run under read action, too unresponsive");
    final List<InspectionToolWrapper> needRepeatSearchRequest = new ArrayList<>();
    final boolean canBeExternalUsages = !(scope.getScopeType() == AnalysisScope.PROJECT && scope.isIncludeTestSource());
    for (Tools tools : globalTools) {
        for (ScopeToolState state : tools.getTools()) {
            final InspectionToolWrapper toolWrapper = state.getTool();
            final GlobalInspectionTool tool = (GlobalInspectionTool) toolWrapper.getTool();
            final InspectionToolPresentation toolPresentation = getPresentation(toolWrapper);
            try {
                if (tool.isGraphNeeded()) {
                    try {
                        ((RefManagerImpl) getRefManager()).findAllDeclarations();
                    } catch (Throwable e) {
                        getStdJobDescriptors().BUILD_GRAPH.setDoneAmount(0);
                        throw e;
                    }
                }
                ApplicationManager.getApplication().runReadAction(() -> {
                    tool.runInspection(scope, inspectionManager, this, toolPresentation);
                    //skip phase when we are sure that scope already contains everything, unused declaration though needs to proceed with its suspicious code
                    if ((canBeExternalUsages || tool.getAdditionalJobs(this) != null) && tool.queryExternalUsagesRequests(inspectionManager, this, toolPresentation)) {
                        needRepeatSearchRequest.add(toolWrapper);
                    }
                });
            } catch (ProcessCanceledException | IndexNotReadyException e) {
                throw e;
            } catch (Throwable e) {
                LOG.error(e);
            }
        }
    }
    for (GlobalInspectionContextExtension extension : myExtensions.values()) {
        try {
            extension.performPostRunActivities(needRepeatSearchRequest, this);
        } catch (ProcessCanceledException | IndexNotReadyException e) {
            throw e;
        } catch (Throwable e) {
            LOG.error(e);
        }
    }
    addProblemsToView(globalTools);
}
Also used : DefaultInspectionToolPresentation(com.intellij.codeInspection.ui.DefaultInspectionToolPresentation) InspectionToolPresentation(com.intellij.codeInspection.ui.InspectionToolPresentation) RefManagerImpl(com.intellij.codeInspection.reference.RefManagerImpl) GlobalInspectionContextExtension(com.intellij.codeInspection.lang.GlobalInspectionContextExtension) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Example 45 with IndexNotReadyException

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

the class DebuggerUtils method findClass.

@Nullable
public static PsiClass findClass(@NotNull final String className, @NotNull Project project, final GlobalSearchScope scope) {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    try {
        if (getArrayClass(className) != null) {
            return JavaPsiFacade.getInstance(project).getElementFactory().getArrayClass(LanguageLevelProjectExtension.getInstance(project).getLanguageLevel());
        }
        if (project.isDefault()) {
            return null;
        }
        PsiManager psiManager = PsiManager.getInstance(project);
        PsiClass psiClass = ClassUtil.findPsiClass(psiManager, className, null, true, scope);
        if (psiClass == null) {
            GlobalSearchScope globalScope = GlobalSearchScope.allScope(project);
            if (!globalScope.equals(scope)) {
                psiClass = ClassUtil.findPsiClass(psiManager, className, null, true, globalScope);
            }
        }
        return psiClass;
    } catch (IndexNotReadyException ignored) {
        return null;
    }
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) 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