Class GitPositionTransformer.Position

java.lang.Object
com.google.gerrit.server.patch.GitPositionTransformer.Position
Enclosing class:
GitPositionTransformer

public abstract static class GitPositionTransformer.Position extends Object
A position within the tree of a Git commit.

The term 'position' is our own invention. The underlying idea is that a Gerrit comment is at a specific position within the commit of a patchset. That position is defined by the attributes defined in this class.

The same thinking can be applied to diff hunks (= JGit edits). Each diff hunk maps a position in one commit (e.g. in the parent of the patchset) to a position in another commit (e.g. in the commit of the patchset).

We only refer to lines and not character offsets within the lines here as Git only works with line precision. In theory, we could do better in Gerrit as we also have intraline diffs. Incorporating those requires careful considerations, though.

  • Constructor Details

    • Position

      public Position()
  • Method Details

    • filePath

      public abstract Optional<String> filePath()
      Absolute file path.
    • lineRange

      public abstract Optional<GitPositionTransformer.Range> lineRange()
      Affected lines. An empty Optional indicates that this position does not refer to any specific lines (e.g. used for a file comment).
    • shiftBy

      public GitPositionTransformer.Position shiftBy(int amount)
      Creates a copy of this Position whose range is shifted by the indicated amount.

      Note: There's no guarantee that this method returns a new instance.

      Parameters:
      amount - number of lines to shift. Negative values mean moving the range up, positive values mean moving the range down.
      Returns:
      a Position instance with the updated range
    • withoutLineRange

      public GitPositionTransformer.Position withoutLineRange()
      Creates a copy of this Position which doesn't refer to any specific lines.

      Note: There's no guarantee that this method returns a new instance.

      Returns:
      a Position instance without a line range
    • withFilePath

      public GitPositionTransformer.Position withFilePath(String filePath)
      Creates a copy of this Position whose file path is adjusted to the indicated value.

      Note: There's no guarantee that this method returns a new instance.

      Parameters:
      filePath - the new file path to use
      Returns:
      a Position instance with the indicated file path
    • builder

      public static GitPositionTransformer.Position.Builder builder()