@Override public int getStartLine() { return start(); }
@Override public int getStartLine() { return start(); }
/** * Returns the first line after this range. Equivalent to {@linkplain #start() start} + {@linkplain #length() length}. * * @return the first line after this range */ public int end() { return start() + length(); }
/** * Sets the end of this range, keeping {@link #start()} constant. * * @param end the new end, must be > {@link #start()} * @throws LineIndexOutOfBoundsException if <code>end</code> <= {@link #start()} */ public void setEnd(int end) throws LineIndexOutOfBoundsException { setLength(end - start()); }
/** * Moves the range by <code>delta</code> lines, keeping {@link #length()} constant. The * resulting start line must be >= 0. * * @param delta the number of lines to shift the range * @throws LineIndexOutOfBoundsException if <code>-delta</code> > {@link #start()} */ public void moveBy(int delta) throws LineIndexOutOfBoundsException { moveTo(start() + delta); }
/** * Returns the first line after this range. Equivalent to {@linkplain #start() start} + {@linkplain #length() length}. * * @return the first line after this range */ public int end() { return start() + length(); }
/** * Resizes the range by <code>delta</code> lines by moving the start offset, {@link #end()} remains unchanged. * * @param delta the number of lines to resize the range * @throws LineIndexOutOfBoundsException if <code>-delta</code> >= {@link #length()} */ public void resizeAndMoveBy(int delta) throws LineIndexOutOfBoundsException { setStart(start() + delta); }
/** * Moves the range by <code>delta</code> lines, keeping {@link #length()} constant. The * resulting start line must be >= 0. * * @param delta the number of lines to shift the range * @throws LineIndexOutOfBoundsException if <code>-delta</code> > {@link #start()} */ public void moveBy(int delta) throws LineIndexOutOfBoundsException { moveTo(start() + delta); }
/** * Sets the end of this range, keeping {@link #start()} constant. * * @param end the new end, must be > {@link #start()} * @throws LineIndexOutOfBoundsException if <code>end</code> <= {@link #start()} */ public void setEnd(int end) throws LineIndexOutOfBoundsException { setLength(end - start()); }
/** * Resizes the range by <code>delta</code> lines by moving the start offset, {@link #end()} remains unchanged. * * @param delta the number of lines to resize the range * @throws LineIndexOutOfBoundsException if <code>-delta</code> >= {@link #length()} */ public void resizeAndMoveBy(int delta) throws LineIndexOutOfBoundsException { setStart(start() + delta); }
/** * Creates a new range equal to the passed line range. * * @param range the range to copy * @return a <code>Range</code> equal to <code>range</code> */ public static Range copy(Range range) { return createRelative(range.start(), range.length()); }
/** * Returns the line coverage of the adjusted ranges, an empty range if the coverage is empty. * * @return the line coverage of the adjusted ranges */ public ILineRange getAdjustedCoverage() { if (fAdjusted.isEmpty()) return new LineRange(fLines.getStartLine(), 0); Range first= fAdjusted.get(0); Range last= fAdjusted.get(fAdjusted.size() - 1); return Range.createAbsolute(first.start(), last.end()); }
/** * Creates a new range equal to the passed line range. * * @param range the range to copy * @return a <code>Range</code> equal to <code>range</code> */ public static Range copy(Range range) { return createRelative(range.start(), range.length()); }
/** * Returns the line coverage of the adjusted ranges, an empty range if the coverage is empty. * * @return the line coverage of the adjusted ranges */ public ILineRange getAdjustedCoverage() { if (fAdjusted.isEmpty()) return new LineRange(fLines.getStartLine(), 0); Range first= fAdjusted.get(0); Range last= fAdjusted.get(fAdjusted.size() - 1); return Range.createAbsolute(first.start(), last.end()); }
/** * Returns <code>true</code> if the passed range has the same offset and length as the receiver. * * @param range another line range to compare the receiver to * @return <code>true</code> if <code>range</code> has the same offset and length as the receiver */ public boolean equalRange(ILineRange range) { if (range == this) return true; if (range == null) return false; return range.getStartLine() == start() && range.getNumberOfLines() == length(); }
/** * Returns <code>true</code> if the passed range has the same offset and length as the receiver. * * @param range another line range to compare the receiver to * @return <code>true</code> if <code>range</code> has the same offset and length as the receiver */ public boolean equalRange(ILineRange range) { if (range == this) return true; if (range == null) return false; return range.getStartLine() == start() && range.getNumberOfLines() == length(); }
/** * Adjusts this change region to a diff hunk. This will change the adjusted ranges. * * @param hunk the diff hunk to adjust to */ public void adjustTo(Hunk hunk) { for (ListIterator<Range> it= fAdjusted.listIterator(); it.hasNext();) { Range range= it.next(); // do we need a split? int unchanged= getUnchanged(hunk, range.start()); if (unchanged > 0) { if (unchanged >= range.length()) continue; range= range.split(unchanged); it.add(range); it.previous(); it.next(); // needed so we can remove below } int line= range.start(); Assert.isTrue(hunk.line <= line); // by how much do we shrink? int overlap= getOverlap(hunk, line); if (overlap >= range.length()) { it.remove(); continue; } // by how much do we move? range.moveBy(hunk.delta + overlap); range.resizeBy(-overlap); } }
/** * Adjusts this change region to a diff hunk. This will change the adjusted ranges. * * @param hunk the diff hunk to adjust to */ public void adjustTo(Hunk hunk) { for (ListIterator<Range> it= fAdjusted.listIterator(); it.hasNext();) { Range range= it.next(); // do we need a split? int unchanged= getUnchanged(hunk, range.start()); if (unchanged > 0) { if (unchanged >= range.length()) continue; range= range.split(unchanged); it.add(range); it.previous(); it.next(); // needed so we can remove below } int line= range.start(); Assert.isTrue(hunk.line <= line); // by how much do we shrink? int overlap= getOverlap(hunk, line); if (overlap >= range.length()) { it.remove(); continue; } // by how much do we move? range.moveBy(hunk.delta + overlap); range.resizeBy(-overlap); } }