Search in sources :

Example 16 with IndexNotReadyException

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

the class SmartElementDescriptor method update.

// Should be called in atomic action
@Override
public boolean update() {
    PsiElement element = mySmartPointer.getElement();
    if (element == null)
        return true;
    int flags = Iconable.ICON_FLAG_VISIBILITY;
    if (isMarkReadOnly()) {
        flags |= Iconable.ICON_FLAG_READ_STATUS;
    }
    Icon icon = null;
    try {
        icon = element.getIcon(flags);
    } catch (IndexNotReadyException ignored) {
    }
    Color color = null;
    if (isMarkModified()) {
        VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
        if (virtualFile != null) {
            color = FileStatusManager.getInstance(myProject).getStatus(virtualFile).getColor();
        }
    }
    if (CopyPasteManager.getInstance().isCutElement(element)) {
        color = CopyPasteManager.CUT_COLOR;
    }
    boolean changes = !Comparing.equal(icon, getIcon()) || !Comparing.equal(color, myColor);
    setIcon(icon);
    myColor = color;
    return changes;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PsiElement(com.intellij.psi.PsiElement)

Example 17 with IndexNotReadyException

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

the class CompletionAutoPopupHandler method invokeCompletion.

public static void invokeCompletion(@NotNull CompletionType completionType, boolean autopopup, Project project, Editor editor, int time, boolean restart) {
    if (editor.isDisposed()) {
        CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
        return;
    }
    // retrieve the injected file from scratch since our typing might have destroyed the old one completely
    Editor topLevelEditor = InjectedLanguageUtil.getTopLevelEditor(editor);
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(topLevelEditor.getDocument());
    if (file == null) {
        CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
        return;
    }
    PsiFile topLevelFile = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
    if (!PsiDocumentManager.getInstance(project).isCommitted(editor.getDocument())) {
        LOG.error("Non-committed document");
        PsiDocumentManager.getInstance(project).commitAllDocuments();
    }
    Editor newEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(topLevelEditor, topLevelFile);
    try {
        CodeCompletionHandlerBase.createHandler(completionType, false, autopopup, false).invokeCompletion(project, newEditor, time, false, restart);
    } catch (IndexNotReadyException ignored) {
    }
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor)

Example 18 with IndexNotReadyException

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

the class GlobalInspectionContextImpl method inspectFile.

private void inspectFile(@NotNull final PsiFile file, @NotNull final InspectionManager inspectionManager, @NotNull List<Tools> localTools, @NotNull List<Tools> globalSimpleTools, @NotNull final Map<String, InspectionToolWrapper> wrappersMap) {
    Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file);
    if (document == null)
        return;
    VirtualFile virtualFile = file.getVirtualFile();
    String url = ProjectUtilCore.displayUrlRelativeToProject(virtualFile, virtualFile.getPresentableUrl(), getProject(), true, false);
    incrementJobDoneAmount(getStdJobDescriptors().LOCAL_ANALYSIS, url);
    final LocalInspectionsPass pass = new LocalInspectionsPass(file, document, 0, file.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true, HighlightInfoProcessor.getEmpty());
    try {
        boolean includeDoNotShow = includeDoNotShow(getCurrentProfile());
        final List<LocalInspectionToolWrapper> lTools = getWrappersFromTools(localTools, file, includeDoNotShow);
        List<LocalInspectionToolWrapper> nonExternalAnnotators = lTools.stream().filter(wrapper -> !(wrapper.getTool() instanceof ExternalAnnotatorBatchInspection)).collect(Collectors.toList());
        pass.doInspectInBatch(this, inspectionManager, nonExternalAnnotators);
        List<GlobalInspectionToolWrapper> globalSTools = getWrappersFromTools(globalSimpleTools, file, includeDoNotShow);
        final List<GlobalInspectionToolWrapper> tools = globalSTools.stream().filter(wrapper -> !(wrapper.getTool() instanceof ExternalAnnotatorBatchInspection)).collect(Collectors.toList());
        JobLauncher.getInstance().invokeConcurrentlyUnderProgress(tools, myProgressIndicator, false, toolWrapper -> {
            GlobalSimpleInspectionTool tool = (GlobalSimpleInspectionTool) toolWrapper.getTool();
            ProblemsHolder holder = new ProblemsHolder(inspectionManager, file, false);
            ProblemDescriptionsProcessor problemDescriptionProcessor = getProblemDescriptionProcessor(toolWrapper, wrappersMap);
            tool.checkFile(file, inspectionManager, holder, this, problemDescriptionProcessor);
            InspectionToolPresentation toolPresentation = getPresentation(toolWrapper);
            LocalDescriptorsUtil.addProblemDescriptors(holder.getResults(), false, this, null, CONVERT, toolPresentation);
            return true;
        });
    } catch (ProcessCanceledException e) {
        final Throwable cause = e.getCause();
        if (cause == null) {
            throw e;
        }
        LOG.error("In file: " + file, cause);
    } catch (IndexNotReadyException e) {
        throw e;
    } catch (Throwable e) {
        LOG.error("In file: " + file.getName(), e);
    } finally {
        InjectedLanguageManager.getInstance(getProject()).dropFileCaches(file);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) com.intellij.openapi.util(com.intellij.openapi.util) UIUtil(com.intellij.util.ui.UIUtil) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) MessageType(com.intellij.openapi.ui.MessageType) ToggleAction(com.intellij.openapi.actionSystem.ToggleAction) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(com.intellij.util.containers.HashMap) Document(com.intellij.openapi.editor.Document) HashSet(com.intellij.util.containers.HashSet) DefaultInspectionToolPresentation(com.intellij.codeInspection.ui.DefaultInspectionToolPresentation) THashSet(gnu.trove.THashSet) TripleFunction(com.intellij.util.TripleFunction) com.intellij.openapi.application(com.intellij.openapi.application) ProjectUtilCore(com.intellij.openapi.project.ProjectUtilCore) ProblemHighlightFilter(com.intellij.codeInsight.daemon.ProblemHighlightFilter) FileIndex(com.intellij.openapi.roots.FileIndex) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) InspectionToolPresentation(com.intellij.codeInspection.ui.InspectionToolPresentation) FileModificationService(com.intellij.codeInsight.FileModificationService) com.intellij.openapi.progress(com.intellij.openapi.progress) RefElement(com.intellij.codeInspection.reference.RefElement) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PathMacroManager(com.intellij.openapi.components.PathMacroManager) java.util.concurrent(java.util.concurrent) InspectionResultsView(com.intellij.codeInspection.ui.InspectionResultsView) ProjectUtil(com.intellij.openapi.project.ProjectUtil) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) Stream(java.util.stream.Stream) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) Processor(com.intellij.util.Processor) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) JobLauncherImpl(com.intellij.concurrency.JobLauncherImpl) com.intellij.ui.content(com.intellij.ui.content) java.util(java.util) LocalInspectionsPass(com.intellij.codeInsight.daemon.impl.LocalInspectionsPass) CharsetToolkit(com.intellij.openapi.vfs.CharsetToolkit) CleanupInspectionIntention(com.intellij.codeInspection.actions.CleanupInspectionIntention) PerformAnalysisInBackgroundOption(com.intellij.analysis.PerformAnalysisInBackgroundOption) JobLauncher(com.intellij.concurrency.JobLauncher) GlobalInspectionContextExtension(com.intellij.codeInspection.lang.GlobalInspectionContextExtension) SensitiveProgressWrapper(com.intellij.concurrency.SensitiveProgressWrapper) NonNls(org.jetbrains.annotations.NonNls) ProgressIndicatorUtils(com.intellij.openapi.progress.util.ProgressIndicatorUtils) SearchScope(com.intellij.psi.search.SearchScope) ContainerUtil(com.intellij.util.containers.ContainerUtil) Constructor(java.lang.reflect.Constructor) ThreadDumper(com.intellij.diagnostic.ThreadDumper) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) CoreProgressManager(com.intellij.openapi.progress.impl.CoreProgressManager) ProblemGroup(com.intellij.lang.annotation.ProblemGroup) NotificationGroup(com.intellij.notification.NotificationGroup) ToolWindowId(com.intellij.openapi.wm.ToolWindowId) Project(com.intellij.openapi.project.Project) OutputStreamWriter(java.io.OutputStreamWriter) RefVisitor(com.intellij.codeInspection.reference.RefVisitor) RefManagerImpl(com.intellij.codeInspection.reference.RefManagerImpl) StringUtil(com.intellij.openapi.util.text.StringUtil) HighlightInfoProcessor(com.intellij.codeInsight.daemon.impl.HighlightInfoProcessor) AnalysisScope(com.intellij.analysis.AnalysisScope) FileOutputStream(java.io.FileOutputStream) ConcurrencyUtil(com.intellij.util.ConcurrencyUtil) IOException(java.io.IOException) com.intellij.codeInspection(com.intellij.codeInspection) AnalysisUIOptions(com.intellij.analysis.AnalysisUIOptions) GuiUtils(com.intellij.ui.GuiUtils) InspectionTreeState(com.intellij.codeInspection.ui.InspectionTreeState) Disposable(com.intellij.openapi.Disposable) File(java.io.File) ApplicationManagerEx(com.intellij.openapi.application.ex.ApplicationManagerEx) Element(org.jdom.Element) RefEntity(com.intellij.codeInspection.reference.RefEntity) DefaultInspectionToolPresentation(com.intellij.codeInspection.ui.DefaultInspectionToolPresentation) InspectionToolPresentation(com.intellij.codeInspection.ui.InspectionToolPresentation) Document(com.intellij.openapi.editor.Document) LocalInspectionsPass(com.intellij.codeInsight.daemon.impl.LocalInspectionsPass) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Example 19 with IndexNotReadyException

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

the class HighlightVisitorImpl method visitExpressionList.

@Override
public void visitExpressionList(PsiExpressionList list) {
    super.visitExpressionList(list);
    PsiElement parent = list.getParent();
    if (parent instanceof PsiMethodCallExpression) {
        PsiMethodCallExpression expression = (PsiMethodCallExpression) parent;
        if (expression.getArgumentList() == list) {
            PsiReferenceExpression referenceExpression = expression.getMethodExpression();
            JavaResolveResult[] results = resolveOptimised(referenceExpression);
            if (results == null)
                return;
            JavaResolveResult result = results.length == 1 ? results[0] : JavaResolveResult.EMPTY;
            PsiElement resolved = result.getElement();
            if ((!result.isAccessible() || !result.isStaticsScopeCorrect()) && !HighlightMethodUtil.isDummyConstructorCall(expression, myResolveHelper, list, referenceExpression) && // this check is for fake expression from JspMethodCallImpl
            referenceExpression.getParent() == expression) {
                try {
                    if (PsiTreeUtil.findChildrenOfType(expression.getArgumentList(), PsiLambdaExpression.class).isEmpty()) {
                        myHolder.add(HighlightMethodUtil.checkAmbiguousMethodCallArguments(referenceExpression, results, list, resolved, result, expression, myResolveHelper, list));
                    }
                } catch (IndexNotReadyException ignored) {
                }
            }
        }
    }
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) LocalQuickFixAndIntentionActionOnPsiElement(com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement)

Example 20 with IndexNotReadyException

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

the class PsiMethodTreeElement method getLocationString.

@Override
public String getLocationString() {
    if (!Registry.is("show.method.base.class.in.java.file.structure"))
        return null;
    final PsiMethod method = getElement();
    if (myLocation == null && method != null && !DumbService.isDumb(method.getProject())) {
        if (isInherited()) {
            return super.getLocationString();
        } else {
            try {
                final MethodSignatureBackedByPsiMethod baseMethod = SuperMethodsSearch.search(method, null, true, false).findFirst();
                if (baseMethod != null && !method.isEquivalentTo(baseMethod.getMethod())) {
                    PsiMethod base = baseMethod.getMethod();
                    PsiClass baseClass = base.getContainingClass();
                    if (baseClass != null) /*&& !CommonClassNames.JAVA_LANG_OBJECT.equals(baseClass.getQualifiedName())*/
                    {
                        if (baseClass.getMethods().length > 1) {
                            myLocation = baseClass.getName();
                        }
                    }
                }
            } catch (IndexNotReadyException e) {
            //some searchers (EJB) require indices. What shall we do?
            }
            if (StringUtil.isEmpty(myLocation)) {
                myLocation = "";
            } else {
                char upArrow = '↑';
                myLocation = UIUtil.getLabelFont().canDisplay(upArrow) ? upArrow + myLocation : myLocation;
            }
        }
    }
    return StringUtil.isEmpty(myLocation) ? null : myLocation;
}
Also used : MethodSignatureBackedByPsiMethod(com.intellij.psi.util.MethodSignatureBackedByPsiMethod) MethodSignatureBackedByPsiMethod(com.intellij.psi.util.MethodSignatureBackedByPsiMethod) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

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