use of com.google.gerrit.server.patch.PatchFile in project gerrit by GerritCodeReview.
the class CommentSender method getGroupedInlineComments.
/**
* @return a list of FileCommentGroup objects representing the inline comments grouped by the
* file.
*/
private List<CommentSender.FileCommentGroup> getGroupedInlineComments(Repository repo) {
List<CommentSender.FileCommentGroup> groups = new ArrayList<>();
// Get the patch list:
PatchList patchList = null;
if (repo != null) {
try {
patchList = getPatchList();
} catch (PatchListNotAvailableException e) {
log.error("Failed to get patch list", e);
}
}
// Loop over the comments and collect them into groups based on the file
// location of the comment.
FileCommentGroup currentGroup = null;
for (Comment c : inlineComments) {
// If it's a new group:
if (currentGroup == null || !c.key.filename.equals(currentGroup.filename) || c.key.patchSetId != currentGroup.patchSetId) {
currentGroup = new FileCommentGroup();
currentGroup.filename = c.key.filename;
currentGroup.patchSetId = c.key.patchSetId;
groups.add(currentGroup);
if (patchList != null) {
try {
currentGroup.fileData = new PatchFile(repo, patchList, c.key.filename);
} catch (IOException e) {
log.warn(String.format("Cannot load %s from %s in %s", c.key.filename, patchList.getNewId().name(), projectState.getProject().getName()), e);
currentGroup.fileData = null;
}
}
}
if (currentGroup.fileData != null) {
currentGroup.comments.add(c);
}
}
Collections.sort(groups, Comparator.comparing(g -> g.filename, FilenameComparator.INSTANCE));
return groups;
}
Aggregations