@Override public boolean merge(@NotNull MergeableUsage other) { if (!(other instanceof UsageInfo2UsageAdapter)) return false; UsageInfo2UsageAdapter u2 = (UsageInfo2UsageAdapter) other; assert u2 != this; if (myLineNumber != u2.myLineNumber || !Comparing.equal(getFile(), u2.getFile())) return false; UsageInfo[] merged = ArrayUtil.mergeArrays(getMergedInfos(), u2.getMergedInfos()); myMergedUsageInfos = merged.length == 1 ? merged[0] : merged; Arrays.sort(getMergedInfos(), BY_NAVIGATION_OFFSET); initChunks(); return true; }
// by start offset @Override public int compareTo(final UsageInfo2UsageAdapter o) { VirtualFile containingFile = getFile(); int shift1 = 0; if (containingFile instanceof VirtualFileWindow) { shift1 = ((VirtualFileWindow) containingFile).getDocumentWindow().injectedToHost(0); containingFile = ((VirtualFileWindow) containingFile).getDelegate(); } VirtualFile oContainingFile = o.getFile(); int shift2 = 0; if (oContainingFile instanceof VirtualFileWindow) { shift2 = ((VirtualFileWindow) oContainingFile).getDocumentWindow().injectedToHost(0); oContainingFile = ((VirtualFileWindow) oContainingFile).getDelegate(); } if (containingFile == null && oContainingFile == null || !Comparing.equal(containingFile, oContainingFile)) { return 0; } Segment s1 = getFirstSegment(); Segment s2 = o.getFirstSegment(); if (s1 == null || s2 == null) return 0; return s1.getStartOffset() + shift1 - s2.getStartOffset() - shift2; }