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;
}
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;
}
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()]);
}
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()]);
}
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);
}
Aggregations