Search in sources :

Example 51 with IndexNotReadyException

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

the class RunConfigurationsComboBoxAction method update.

@Override
public void update(AnActionEvent e) {
    Presentation presentation = e.getPresentation();
    Project project = e.getData(CommonDataKeys.PROJECT);
    if (ActionPlaces.isMainMenuOrActionSearch(e.getPlace())) {
        presentation.setDescription(ExecutionBundle.message("choose.run.configuration.action.description"));
    }
    try {
        if (project == null || project.isDisposed() || !project.isInitialized()) {
            updatePresentation(null, null, null, presentation);
            presentation.setEnabled(false);
        } else {
            updatePresentation(ExecutionTargetManager.getActiveTarget(project), RunManagerEx.getInstanceEx(project).getSelectedConfiguration(), project, presentation);
            presentation.setEnabled(true);
        }
    } catch (IndexNotReadyException e1) {
        presentation.setEnabled(false);
    }
}
Also used : Project(com.intellij.openapi.project.Project) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Example 52 with IndexNotReadyException

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

the class RunConfigurationsComboBoxAction method setConfigurationIcon.

private static void setConfigurationIcon(final Presentation presentation, final RunnerAndConfigurationSettings settings, final Project project) {
    try {
        Icon icon = RunManagerEx.getInstanceEx(project).getConfigurationIcon(settings);
        ExecutionManagerImpl executionManager = ExecutionManagerImpl.getInstance(project);
        List<RunContentDescriptor> runningDescriptors = executionManager.getRunningDescriptors(s -> s == settings);
        if (runningDescriptors.size() == 1) {
            icon = ExecutionUtil.getLiveIndicator(icon);
        }
        if (runningDescriptors.size() > 1) {
            icon = IconUtil.addText(icon, String.valueOf(runningDescriptors.size()));
        }
        presentation.setIcon(icon);
    } catch (IndexNotReadyException ignored) {
    }
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) SizedIcon(com.intellij.ui.SizedIcon) EmptyIcon(com.intellij.util.ui.EmptyIcon) ExecutionManagerImpl(com.intellij.execution.impl.ExecutionManagerImpl)

Example 53 with IndexNotReadyException

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

the class MethodBreakpoint method getMethodDescriptor.

//public boolean canMoveTo(final SourcePosition position) {
//  return super.canMoveTo(position) && PositionUtil.getPsiElementAt(getProject(), PsiMethod.class, position) != null;
//}
/**
   * finds FQ method's class name and method's signature
   */
@Nullable
private static MethodDescriptor getMethodDescriptor(@NotNull final Project project, @NotNull final PsiFile psiJavaFile, @NotNull final SourcePosition sourcePosition) {
    final PsiDocumentManager docManager = PsiDocumentManager.getInstance(project);
    final Document document = docManager.getDocument(psiJavaFile);
    if (document == null) {
        return null;
    }
    //final int endOffset = document.getLineEndOffset(sourcePosition);
    //final MethodDescriptor descriptor = docManager.commitAndRunReadAction(new Computable<MethodDescriptor>() {
    // conflicts with readAction on initial breakpoints creation
    final MethodDescriptor descriptor = ApplicationManager.getApplication().runReadAction(new Computable<MethodDescriptor>() {

        @Nullable
        public MethodDescriptor compute() {
            //PsiMethod method = DebuggerUtilsEx.findPsiMethod(psiJavaFile, endOffset);
            PsiMethod method = PositionUtil.getPsiElementAt(project, PsiMethod.class, sourcePosition);
            if (method == null) {
                return null;
            }
            final int methodOffset = method.getTextOffset();
            if (methodOffset < 0) {
                return null;
            }
            if (document.getLineNumber(methodOffset) < sourcePosition.getLine()) {
                return null;
            }
            final PsiIdentifier identifier = method.getNameIdentifier();
            int methodNameOffset = identifier != null ? identifier.getTextOffset() : methodOffset;
            final MethodDescriptor descriptor = new MethodDescriptor();
            descriptor.methodName = JVMNameUtil.getJVMMethodName(method);
            try {
                descriptor.methodSignature = JVMNameUtil.getJVMSignature(method);
                descriptor.isStatic = method.hasModifierProperty(PsiModifier.STATIC);
            } catch (IndexNotReadyException ignored) {
                return null;
            }
            descriptor.methodLine = document.getLineNumber(methodNameOffset);
            return descriptor;
        }
    });
    if (descriptor == null || descriptor.methodName == null || descriptor.methodSignature == null) {
        return null;
    }
    return descriptor;
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Example 54 with IndexNotReadyException

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

the class ClassPresentationProvider method getPresentation.

@Override
public ItemPresentation getPresentation(@NotNull final PsiClass psiClass) {
    return new ColoredItemPresentation() {

        @Override
        public String getPresentableText() {
            return ClassPresentationUtil.getNameForClass(psiClass, false);
        }

        @Override
        public String getLocationString() {
            PsiFile file = psiClass.getContainingFile();
            if (file instanceof PsiClassOwner) {
                PsiClassOwner classOwner = (PsiClassOwner) file;
                String packageName = classOwner.getPackageName();
                if (packageName.isEmpty())
                    return null;
                return "(" + packageName + ")";
            }
            return null;
        }

        @Override
        public TextAttributesKey getTextAttributesKey() {
            try {
                if (psiClass.isDeprecated()) {
                    return CodeInsightColors.DEPRECATED_ATTRIBUTES;
                }
            } catch (IndexNotReadyException ignore) {
            }
            return null;
        }

        @Override
        public Icon getIcon(boolean open) {
            return psiClass.getIcon(Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS);
        }
    };
}
Also used : PsiClassOwner(com.intellij.psi.PsiClassOwner) ColoredItemPresentation(com.intellij.navigation.ColoredItemPresentation) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PsiFile(com.intellij.psi.PsiFile)

Example 55 with IndexNotReadyException

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

the class GroovyPositionManager method getPsiFileByLocation.

@Nullable
private PsiFile getPsiFileByLocation(@NotNull final Project project, @Nullable final Location location) {
    if (location == null)
        return null;
    final ReferenceType refType = location.declaringType();
    if (refType == null)
        return null;
    final String originalQName = refType.name().replace('/', '.');
    int dollar = originalQName.indexOf('$');
    String runtimeName = dollar >= 0 ? originalQName.substring(0, dollar) : originalQName;
    String qName = getOriginalQualifiedName(refType, runtimeName);
    GlobalSearchScope searchScope = myDebugProcess.getSearchScope();
    GroovyShortNamesCache cache = GroovyShortNamesCache.getGroovyShortNamesCache(project);
    try {
        List<PsiClass> classes = cache.getClassesByFQName(qName, searchScope, true);
        if (classes.isEmpty()) {
            classes = cache.getClassesByFQName(qName, searchScope, false);
        }
        if (classes.isEmpty()) {
            classes = cache.getClassesByFQName(qName, GlobalSearchScope.projectScope(project), false);
        }
        if (classes.isEmpty()) {
            classes = cache.getClassesByFQName(qName, addModuleContent(searchScope), false);
        }
        if (classes.isEmpty())
            return null;
        classes.sort(PsiClassUtil.createScopeComparator(searchScope));
        PsiClass clazz = classes.get(0);
        if (clazz != null)
            return clazz.getContainingFile();
    } catch (ProcessCanceledException | IndexNotReadyException e) {
        return null;
    }
    return getExtraScriptIfNotFound(project, refType, runtimeName, searchScope);
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ReferenceType(com.sun.jdi.ReferenceType) GroovyShortNamesCache(org.jetbrains.plugins.groovy.lang.stubs.GroovyShortNamesCache) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) 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