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