Search in sources :

Example 81 with UsageInfo

use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.

the class BackgroundUpdaterTask method updateComponent.

public boolean updateComponent(final PsiElement element, @Nullable final Comparator comparator) {
    final UsageView view = myUsageView.get();
    if (view != null && !((UsageViewImpl) view).isDisposed()) {
        ApplicationManager.getApplication().runReadAction(() -> view.appendUsage(new UsageInfo2UsageAdapter(new UsageInfo(element))));
        return true;
    }
    if (myCanceled)
        return false;
    final JComponent content = myPopup.getContent();
    if (content == null || myPopup.isDisposed())
        return false;
    synchronized (lock) {
        if (myData.contains(element))
            return true;
        myData.add(element);
        if (comparator != null) {
            Collections.sort(myData, comparator);
        }
    }
    myAlarm.addRequest(() -> {
        myAlarm.cancelAllRequests();
        refreshModelImmediately();
    }, 200, ModalityState.stateForComponent(content));
    return true;
}
Also used : UsageView(com.intellij.usages.UsageView) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) UsageViewImpl(com.intellij.usages.impl.UsageViewImpl) UsageInfo(com.intellij.usageView.UsageInfo)

Example 82 with UsageInfo

use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.

the class FindInProjectUtil method addToUsages.

private static int addToUsages(@NotNull Document document, @NotNull Processor<UsageInfo> consumer, @NotNull FindModel findModel, @NotNull final PsiFile psiFile, @NotNull int[] offsetRef, int maxUsages) {
    int count = 0;
    CharSequence text = document.getCharsSequence();
    int textLength = document.getTextLength();
    int offset = offsetRef[0];
    Project project = psiFile.getProject();
    FindManager findManager = FindManager.getInstance(project);
    while (offset < textLength) {
        FindResult result = findManager.findString(text, offset, findModel, psiFile.getVirtualFile());
        if (!result.isStringFound())
            break;
        final int prevOffset = offset;
        offset = result.getEndOffset();
        if (prevOffset == offset) {
            // for regular expr the size of the match could be zero -> could be infinite loop in finding usages!
            ++offset;
        }
        final SearchScope customScope = findModel.getCustomScope();
        if (customScope instanceof LocalSearchScope) {
            final TextRange range = new TextRange(result.getStartOffset(), result.getEndOffset());
            if (!((LocalSearchScope) customScope).containsRange(psiFile, range))
                continue;
        }
        UsageInfo info = new FindResultUsageInfo(findManager, psiFile, prevOffset, findModel, result);
        if (!consumer.process(info)) {
            throw new ProcessCanceledException();
        }
        count++;
        if (maxUsages > 0 && count >= maxUsages) {
            break;
        }
    }
    offsetRef[0] = offset;
    return count;
}
Also used : Project(com.intellij.openapi.project.Project) TextRange(com.intellij.openapi.util.TextRange) UsageInfo(com.intellij.usageView.UsageInfo) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 83 with UsageInfo

use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.

the class FindDependencyUtil method findBackwardDependencies.

public static UsageInfo[] findBackwardDependencies(final List<DependenciesBuilder> builders, final Set<PsiFile> searchIn, final Set<PsiFile> searchFor) {
    final List<UsageInfo> usages = new ArrayList<>();
    ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    final Set<PsiFile> deps = new HashSet<>();
    for (PsiFile psiFile : searchFor) {
        for (DependenciesBuilder builder : builders) {
            final Set<PsiFile> depsByBuilder = builder.getDependencies().get(psiFile);
            if (depsByBuilder != null) {
                deps.addAll(depsByBuilder);
            }
        }
    }
    deps.retainAll(searchIn);
    if (deps.isEmpty())
        return UsageInfo.EMPTY_ARRAY;
    int totalCount = deps.size();
    int count = 0;
    for (final PsiFile psiFile : deps) {
        count = updateIndicator(indicator, totalCount, count, psiFile);
        analyzeFileDependencies(psiFile, searchFor, usages);
    }
    return usages.toArray(new UsageInfo[usages.size()]);
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) PsiFile(com.intellij.psi.PsiFile) UsageInfo(com.intellij.usageView.UsageInfo)

Example 84 with UsageInfo

use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.

the class FindDependencyUtil method findDependencies.

public static UsageInfo[] findDependencies(@Nullable final List<DependenciesBuilder> builders, Set<PsiFile> searchIn, Set<PsiFile> searchFor) {
    final List<UsageInfo> usages = new ArrayList<>();
    ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    int totalCount = searchIn.size();
    int count = 0;
    nextFile: for (final PsiFile psiFile : searchIn) {
        count = updateIndicator(indicator, totalCount, count, psiFile);
        if (!psiFile.isValid())
            continue;
        final Set<PsiFile> precomputedDeps;
        if (builders != null) {
            final Set<PsiFile> depsByFile = new HashSet<>();
            for (DependenciesBuilder builder : builders) {
                final Set<PsiFile> deps = builder.getDependencies().get(psiFile);
                if (deps != null) {
                    depsByFile.addAll(deps);
                }
            }
            precomputedDeps = new HashSet<>(depsByFile);
            precomputedDeps.retainAll(searchFor);
            if (precomputedDeps.isEmpty())
                continue nextFile;
        } else {
            precomputedDeps = Collections.unmodifiableSet(searchFor);
        }
        analyzeFileDependencies(psiFile, precomputedDeps, usages);
    }
    return usages.toArray(new UsageInfo[usages.size()]);
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) PsiFile(com.intellij.psi.PsiFile) UsageInfo(com.intellij.usageView.UsageInfo)

Example 85 with UsageInfo

use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.

the class InvertBooleanProcessor method performRefactoring.

@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
    if (myRenameProcessor != null) {
        for (final PsiElement element : myRenameProcessor.getElements()) {
            try {
                RenameUtil.doRename(element, myRenameProcessor.getNewName(element), extractUsagesForElement(element, usages), myProject, null);
            } catch (final IncorrectOperationException e) {
                RenameUtil.showErrorMessage(e, element, myProject);
                return;
            }
        }
    }
    for (UsageInfo usage : usages) {
        final SmartPsiElementPointer pointerToInvert = myToInvert.get(usage);
        if (pointerToInvert != null) {
            PsiElement element = pointerToInvert.getElement();
            LOG.assertTrue(element != null);
            InvertBooleanDelegate delegate = InvertBooleanDelegate.findInvertBooleanDelegate(element);
            try {
                (delegate != null ? delegate : myDelegate).replaceWithNegatedExpression(element);
            } catch (IncorrectOperationException e) {
                LOG.error(e);
            }
        }
    }
    myDelegate.invertElementInitializer(myElement);
}
Also used : SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PsiElement(com.intellij.psi.PsiElement) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) UsageInfo(com.intellij.usageView.UsageInfo)

Aggregations

UsageInfo (com.intellij.usageView.UsageInfo)283 PsiElement (com.intellij.psi.PsiElement)70 NotNull (org.jetbrains.annotations.NotNull)57 ArrayList (java.util.ArrayList)41 MoveRenameUsageInfo (com.intellij.refactoring.util.MoveRenameUsageInfo)38 IncorrectOperationException (com.intellij.util.IncorrectOperationException)34 PsiFile (com.intellij.psi.PsiFile)33 MultiMap (com.intellij.util.containers.MultiMap)30 VirtualFile (com.intellij.openapi.vfs.VirtualFile)29 Nullable (org.jetbrains.annotations.Nullable)20 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)19 DefaultConstructorImplicitUsageInfo (com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo)17 NoConstructorClassUsageInfo (com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo)17 Project (com.intellij.openapi.project.Project)16 HashSet (com.intellij.util.containers.HashSet)15 TextRange (com.intellij.openapi.util.TextRange)12 PsiReference (com.intellij.psi.PsiReference)12 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)11 PsiClass (com.intellij.psi.PsiClass)11 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)11