Search in sources :

Example 21 with Segment

use of com.intellij.openapi.util.Segment in project android by JetBrains.

the class AndroidFindUsagesTest method describeUsages.

private static String describeUsages(Collection<UsageInfo> collection) {
    assertNotNull(collection);
    // Ensure stable output: sort in a predictable order
    List<UsageInfo> usages = new ArrayList<>(collection);
    Collections.sort(usages, new Comparator<UsageInfo>() {

        @Override
        public int compare(UsageInfo usageInfo1, UsageInfo usageInfo2) {
            PsiFile file1 = usageInfo1.getFile();
            PsiFile file2 = usageInfo2.getFile();
            assertNotNull(file1);
            assertNotNull(file2);
            int delta = file1.getName().compareTo(file2.getName());
            if (delta != 0) {
                return delta;
            }
            VirtualFile virtualFile1 = file1.getVirtualFile();
            VirtualFile virtualFile2 = file2.getVirtualFile();
            if (virtualFile1 != null && virtualFile2 != null) {
                delta = virtualFile1.getPath().compareTo(virtualFile2.getPath());
            } else if (virtualFile1 != null) {
                delta = -1;
            } else {
                delta = 1;
            }
            if (delta != 0) {
                return delta;
            }
            return usageInfo1.getNavigationOffset() - usageInfo2.getNavigationOffset();
        }
    });
    // Remove duplicates: For some of the tests we manually add an R class with values
    // which duplicates the dynamically augmented (light) fields
    List<UsageInfo> unique = Lists.newArrayListWithExpectedSize(usages.size());
    PsiElement prev = null;
    for (UsageInfo usage : usages) {
        if (prev == null || usage.getElement() == null || !prev.isEquivalentTo(usage.getElement())) {
            unique.add(usage);
        }
        prev = usage.getElement();
    }
    usages = unique;
    // Create golden file output
    StringBuilder sb = new StringBuilder();
    for (UsageInfo usage : usages) {
        PsiFile file = usage.getFile();
        int navigationOffset = usage.getNavigationOffset();
        Segment segment = usage.getSegment();
        appendSourceDescription(sb, file, navigationOffset, segment);
    }
    return sb.toString();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) UsageInfo(com.intellij.usageView.UsageInfo) PsiElement(com.intellij.psi.PsiElement) Segment(com.intellij.openapi.util.Segment)

Aggregations

Segment (com.intellij.openapi.util.Segment)21 NotNull (org.jetbrains.annotations.NotNull)7 TextRange (com.intellij.openapi.util.TextRange)5 DocumentWindow (com.intellij.injected.editor.DocumentWindow)3 Document (com.intellij.openapi.editor.Document)3 ProperTextRange (com.intellij.openapi.util.ProperTextRange)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 DocumentWindowImpl (com.intellij.injected.editor.DocumentWindowImpl)2 UsageInfo (com.intellij.usageView.UsageInfo)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Nullable (org.jetbrains.annotations.Nullable)2 Issue (com.android.tools.lint.detector.api.Issue)1 RefManagerExtension (com.intellij.codeInspection.lang.RefManagerExtension)1 FindResult (com.intellij.find.FindResult)1 VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)1 FileASTNode (com.intellij.lang.FileASTNode)1 Language (com.intellij.lang.Language)1 Editor (com.intellij.openapi.editor.Editor)1 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1