Search in sources :

Example 56 with UsageInfo

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));
}
Also used : PsiElement(com.intellij.psi.PsiElement) UsageInfo(com.intellij.usageView.UsageInfo)

Example 57 with UsageInfo

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);
}
Also used : PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) UsageInfo(com.intellij.usageView.UsageInfo) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 58 with UsageInfo

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();
}
Also used : Project(com.intellij.openapi.project.Project) FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) FindUsagesOptions(com.intellij.find.findUsages.FindUsagesOptions) UsageInfo(com.intellij.usageView.UsageInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 59 with UsageInfo

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());
                    }
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFileEdit(org.dartlang.analysis.server.protocol.SourceFileEdit) PsiManager(com.intellij.psi.PsiManager) PsiElement2UsageTargetAdapter(com.intellij.find.findUsages.PsiElement2UsageTargetAdapter) TextRange(com.intellij.openapi.util.TextRange) SourceEdit(org.dartlang.analysis.server.protocol.SourceEdit) SourceChange(org.dartlang.analysis.server.protocol.SourceChange) PsiFile(com.intellij.psi.PsiFile) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) PsiElement(com.intellij.psi.PsiElement) UsageInfo(com.intellij.usageView.UsageInfo)

Example 60 with UsageInfo

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;
}
Also used : 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