use of com.intellij.usages.UsageInfo2UsageAdapter in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoFileStructureGroupRuleTest method findSingleUsage.
@NotNull
private Usage findSingleUsage() {
Collection<UsageInfo> infos = myFixture.testFindUsages(getTestName(true) + ".go");
assertEquals(1, infos.size());
UsageInfo item = ContainerUtil.getFirstItem(infos);
assertNotNull(item);
return new UsageInfo2UsageAdapter(item);
}
use of com.intellij.usages.UsageInfo2UsageAdapter 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.usages.UsageInfo2UsageAdapter in project intellij-community by JetBrains.
the class FindPopupPanel method findSettingsChanged.
private void findSettingsChanged() {
if (isShowing()) {
ScrollingUtil.ensureSelectionExists(myResultsPreviewTable);
}
final ModalityState state = ModalityState.current();
finishPreviousPreviewSearch();
mySearchRescheduleOnCancellationsAlarm.cancelAllRequests();
applyTo(myHelper.getModel(), false);
myHelper.updateFindSettings();
FindModel findInProjectModel = FindManager.getInstance(myProject).getFindInProjectModel();
FindModel copy = new FindModel();
copy.copyFrom(findInProjectModel);
findInProjectModel.copyFrom(myHelper.getModel());
//todo check if we really need to do it now
((FindManagerImpl) FindManager.getInstance(myProject)).changeGlobalSettings(myHelper.getModel());
FindSettings findSettings = FindSettings.getInstance();
myScopeUI.applyTo(findSettings, mySelectedScope);
findSettings.setFileMask(myHelper.getModel().getFileFilter());
ValidationInfo result = getValidationInfo(myHelper.getModel());
final ProgressIndicatorBase progressIndicatorWhenSearchStarted = new ProgressIndicatorBase();
myResultsPreviewSearchProgress = progressIndicatorWhenSearchStarted;
final DefaultTableModel model = new DefaultTableModel() {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
model.addColumn("Usages");
// Use previously shown usage files as hint for faster search and better usage preview performance if pattern length increased
final LinkedHashSet<VirtualFile> filesToScanInitially = new LinkedHashSet<>();
if (myHelper.myPreviousModel != null && myHelper.myPreviousModel.getStringToFind().length() < myHelper.getModel().getStringToFind().length()) {
final DefaultTableModel previousModel = (DefaultTableModel) myResultsPreviewTable.getModel();
for (int i = 0, len = previousModel.getRowCount(); i < len; ++i) {
final UsageInfo2UsageAdapter usage = (UsageInfo2UsageAdapter) previousModel.getValueAt(i, 0);
final VirtualFile file = usage.getFile();
if (file != null)
filesToScanInitially.add(file);
}
}
myHelper.myPreviousModel = myHelper.getModel().clone();
myCodePreviewComponent.setVisible(false);
mySearchTextArea.setInfoText(null);
myResultsPreviewTable.setModel(model);
if (result != null) {
myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow") + " (" + result.message + ")");
return;
}
myResultsPreviewTable.getColumnModel().getColumn(0).setCellRenderer(new FindDialog.UsageTableCellRenderer(myCbFileFilter.isSelected(), false));
myResultsPreviewTable.getEmptyText().setText("Searching...");
final AtomicInteger resultsCount = new AtomicInteger();
final AtomicInteger resultsFilesCount = new AtomicInteger();
ProgressIndicatorUtils.scheduleWithWriteActionPriority(myResultsPreviewSearchProgress, new ReadTask() {
@Override
public void computeInReadAction(@NotNull ProgressIndicator indicator) {
final UsageViewPresentation presentation = FindInProjectUtil.setupViewPresentation(findSettings.isShowResultsInSeparateView(), /*findModel*/
myHelper.getModel().clone());
final boolean showPanelIfOnlyOneUsage = !findSettings.isSkipResultsWithOneUsage();
final FindUsagesProcessPresentation processPresentation = FindInProjectUtil.setupProcessPresentation(myProject, showPanelIfOnlyOneUsage, presentation);
Ref<VirtualFile> lastUsageFileRef = new Ref<>();
FindInProjectUtil.findUsages(myHelper.getModel().clone(), myProject, info -> {
final Usage usage = UsageInfo2UsageAdapter.CONVERTER.fun(info);
usage.getPresentation().getIcon();
VirtualFile file = lastUsageFileRef.get();
VirtualFile usageFile = info.getVirtualFile();
if (file == null || !file.equals(usageFile)) {
resultsFilesCount.incrementAndGet();
lastUsageFileRef.set(usageFile);
}
ApplicationManager.getApplication().invokeLater(() -> {
model.addRow(new Object[] { usage });
myCodePreviewComponent.setVisible(true);
if (model.getRowCount() == 1 && myResultsPreviewTable.getModel() == model) {
myResultsPreviewTable.setRowSelectionInterval(0, 0);
}
}, state);
return resultsCount.incrementAndGet() < ShowUsagesAction.USAGES_PAGE_SIZE;
}, processPresentation, filesToScanInitially);
boolean succeeded = !progressIndicatorWhenSearchStarted.isCanceled();
if (succeeded) {
ApplicationManager.getApplication().invokeLater(() -> {
if (progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress && !myResultsPreviewSearchProgress.isCanceled()) {
int occurrences = resultsCount.get();
int filesWithOccurrences = resultsFilesCount.get();
if (occurrences == 0)
myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow"));
myCodePreviewComponent.setVisible(occurrences > 0);
StringBuilder info = new StringBuilder();
if (occurrences > 0) {
info.append(Math.min(ShowUsagesAction.USAGES_PAGE_SIZE, occurrences));
boolean foundAllUsages = occurrences < ShowUsagesAction.USAGES_PAGE_SIZE;
if (!foundAllUsages) {
info.append("+");
}
info.append(UIBundle.message("message.matches", occurrences));
info.append(" in ");
info.append(filesWithOccurrences);
if (!foundAllUsages) {
info.append("+");
}
info.append(UIBundle.message("message.files", filesWithOccurrences));
}
mySearchTextArea.setInfoText(info.toString());
}
}, state);
}
}
@Override
public void onCanceled(@NotNull ProgressIndicator indicator) {
if (isShowing() && progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress) {
scheduleResultsUpdate();
}
}
});
}
use of com.intellij.usages.UsageInfo2UsageAdapter in project intellij-community by JetBrains.
the class UsageViewUtil method getNotExcludedUsageInfos.
public static Set<UsageInfo> getNotExcludedUsageInfos(final UsageView usageView) {
Set<Usage> excludedUsages = usageView.getExcludedUsages();
Set<UsageInfo> usageInfos = new LinkedHashSet<>();
for (Usage usage : usageView.getUsages()) {
if (usage instanceof UsageInfo2UsageAdapter && !excludedUsages.contains(usage)) {
UsageInfo usageInfo = ((UsageInfo2UsageAdapter) usage).getUsageInfo();
usageInfos.add(usageInfo);
}
}
return usageInfos;
}
use of com.intellij.usages.UsageInfo2UsageAdapter in project intellij-community by JetBrains.
the class UsagesInAnalyzingDependenciesTest method testForwardPackageScope.
@SuppressWarnings("ConstantConditions")
public void testForwardPackageScope() {
PsiPackage bPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage("com.b");
DependenciesBuilder builder = new ForwardDependenciesBuilder(myProject, new JavaAnalysisScope(bPackage, null));
builder.analyze();
Set<PsiFile> searchFor = new HashSet<>();
searchFor.add(myJavaFacade.findClass("com.a.A", GlobalSearchScope.allScope(myProject)).getContainingFile());
Set<PsiFile> searchIn = new HashSet<>();
PsiClass bClass = myJavaFacade.findClass("com.b.B", GlobalSearchScope.allScope(myProject));
searchIn.add(bClass.getContainingFile());
PsiClass cClass = myJavaFacade.findClass("com.b.C", GlobalSearchScope.allScope(myProject));
searchIn.add(cClass.getContainingFile());
UsageInfo[] usagesInfos = FindDependencyUtil.findDependencies(builder, searchIn, searchFor);
UsageInfo2UsageAdapter[] usages = UsageInfo2UsageAdapter.convert(usagesInfos);
String[] psiUsages = new String[usagesInfos.length];
for (int i = 0; i < usagesInfos.length; i++) {
psiUsages[i] = toString(usages[i]);
}
checkResult(new String[] { "2 import com.a.A;", "4 A myA = new A();", "4 A myA = new A();", "6 myA.aa();", "2 import com.a.A;", "4 A myA = new A();", "4 A myA = new A();", "6 myA.aa();" }, psiUsages);
}
Aggregations