use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.
the class UsageViewTest method createUsage.
private static Usage createUsage(PsiFile psiFile, int offset) {
PsiElement element = psiFile.findElementAt(offset % psiFile.getTextLength());
assertNotNull(element);
return new UsageInfo2UsageAdapter(new UsageInfo(element));
}
use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.
the class UsageViewTest method testTextUsageInfoHandlesDocumentChange.
public void testTextUsageInfoHandlesDocumentChange() throws Exception {
PsiFile psiFile = myFixture.addFileToProject("X.java", "public class X{ int xxx; } //comment");
Usage usage = new UsageInfo2UsageAdapter(new UsageInfo(psiFile, psiFile.getText().indexOf("xxx"), StringUtil.indexOfSubstringEnd(psiFile.getText(), "xxx")));
UsageView usageView = UsageViewManager.getInstance(getProject()).createUsageView(UsageTarget.EMPTY_ARRAY, new Usage[] { usage }, new UsageViewPresentation(), null);
Disposer.register(myFixture.getTestRootDisposable(), usageView);
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
Document document = documentManager.getDocument(psiFile);
WriteCommandAction.runWriteCommandAction(getProject(), () -> document.insertString(0, "/* sdfsdfsd */"));
documentManager.commitAllDocuments();
int navigationOffset = ((UsageInfo2UsageAdapter) usage).getUsageInfo().getNavigationOffset();
assertEquals(psiFile.getText().indexOf("xxx"), navigationOffset);
}
use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.
the class CodeInsightTestFixtureImpl method findUsages.
@NotNull
public Collection<UsageInfo> findUsages(@NotNull final PsiElement targetElement, @Nullable SearchScope scope) {
final Project project = getProject();
final FindUsagesHandler handler = ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager().getFindUsagesHandler(targetElement, false);
final CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<>();
assertNotNull("Cannot find handler for: " + targetElement, handler);
final PsiElement[] psiElements = ArrayUtil.mergeArrays(handler.getPrimaryElements(), handler.getSecondaryElements());
final FindUsagesOptions options = handler.getFindUsagesOptions(null);
if (scope != null)
options.searchScope = scope;
for (PsiElement psiElement : psiElements) {
handler.processElementUsages(psiElement, processor, options);
}
return processor.getResults();
}
use of com.intellij.usageView.UsageInfo in project intellij-plugins by JetBrains.
the class DartRenameDialog method fillTargetsAndUsageToEditIdMap.
private void fillTargetsAndUsageToEditIdMap(@NotNull final List<UsageTarget> usageTargets, @NotNull final Map<Usage, String> usageToEditIdMap) {
final SourceChange change = myRefactoring.getChange();
assert change != null;
final DartAnalysisServerService service = DartAnalysisServerService.getInstance(myProject);
final PsiManager psiManager = PsiManager.getInstance(myProject);
for (SourceFileEdit fileEdit : change.getEdits()) {
final VirtualFile file = AssistUtils.findVirtualFile(fileEdit);
final PsiFile psiFile = file == null ? null : psiManager.findFile(file);
if (psiFile == null)
continue;
for (SourceEdit sourceEdit : fileEdit.getEdits()) {
final int offset = service.getConvertedOffset(file, sourceEdit.getOffset());
final int length = service.getConvertedOffset(file, sourceEdit.getOffset() + sourceEdit.getLength()) - offset;
final TextRange range = TextRange.create(offset, offset + length);
final boolean potentialUsage = myRefactoring.getPotentialEdits().contains(sourceEdit.getId());
final PsiElement usageElement = DartServerFindUsagesHandler.getUsagePsiElement(psiFile, range);
if (usageElement != null) {
if (DartComponentType.typeOf(usageElement) != null) {
usageTargets.add(new PsiElement2UsageTargetAdapter(usageElement));
} else {
final UsageInfo usageInfo = DartServerFindUsagesHandler.getUsageInfo(usageElement, range, potentialUsage);
if (usageInfo != null) {
usageToEditIdMap.put(new UsageInfo2UsageAdapter(usageInfo), sourceEdit.getId());
}
}
}
}
}
}
use of com.intellij.usageView.UsageInfo in project android by JetBrains.
the class AndroidFindUsagesTest method findCodeUsages.
public List<UsageInfo> findCodeUsages(String path, String pathInProject) throws Throwable {
Collection<UsageInfo> usages = findUsages(path, myFixture, pathInProject);
List<UsageInfo> result = new ArrayList<>();
for (UsageInfo usage : usages) {
if (!usage.isNonCodeUsage) {
result.add(usage);
}
}
return result;
}
Aggregations