PreviousFileRevisionProvider (@NotNull FileAnnotation annotation) { List<VcsFileRevision> revisions = annotation.getRevisions(); if (revisions == null) return null; Map<VcsRevisionNumber, VcsFileRevision> map = new HashMap<>(); for (int i = 0; i < revisions.size(); i++) { VcsFileRevision revision = revisions.get(i); VcsFileRevision previousRevision = i + 1 < revisions.size() ? revisions.get(i + 1) : null; map.put(revision.getRevisionNumber(), previousRevision); } List<VcsFileRevision> lineToRevision = new ArrayList<>(annotation.getLineCount()); for (int i = 0; i < annotation.getLineCount(); i++) { lineToRevision.add(map.get(annotation.getLineRevisionNumber(i))); } VcsFileRevision lastRevision = ContainerUtil.getFirstItem(revisions); return new PreviousFileRevisionProvider() { @Nullable @Override public VcsFileRevision getPreviousRevision(int lineNumber) { LOG.assertTrue(lineNumber >= 0 && lineNumber < lineToRevision.size()); return lineToRevision.get(lineNumber); } @Nullable @Override public VcsFileRevision getLastRevision() { return lastRevision; } }; }