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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGitPositionTransformer.Position.BuilderBuilder of aGitPositionTransformer.Position.
-
Constructor Summary
Constructors Constructor Description Position()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static GitPositionTransformer.Position.Builderbuilder()abstract Optional<String>filePath()Absolute file path.abstract Optional<GitPositionTransformer.Range>lineRange()Affected lines.GitPositionTransformer.PositionshiftBy(int amount)Creates a copy of thisPositionwhose range is shifted by the indicated amount.GitPositionTransformer.PositionwithFilePath(String filePath)Creates a copy of thisPositionwhose file path is adjusted to the indicated value.GitPositionTransformer.PositionwithoutLineRange()Creates a copy of thisPositionwhich doesn't refer to any specific lines.
-
-
-
Method Detail
-
lineRange
public abstract Optional<GitPositionTransformer.Range> lineRange()
Affected lines. An emptyOptionalindicates 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 thisPositionwhose 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
Positioninstance with the updated range
-
withoutLineRange
public GitPositionTransformer.Position withoutLineRange()
Creates a copy of thisPositionwhich doesn't refer to any specific lines.Note: There's no guarantee that this method returns a new instance.
- Returns:
- a
Positioninstance without a line range
-
withFilePath
public GitPositionTransformer.Position withFilePath(String filePath)
Creates a copy of thisPositionwhose 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
Positioninstance with the indicated file path
-
builder
public static GitPositionTransformer.Position.Builder builder()
-
-