@Override public int getNumberOfLines() { return length(); }
@Override public int getNumberOfLines() { return length(); }
/** * 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(); }
/** * Moves this range such that the {@link #end()} is at <code>end</code>, keeping * {@link #length()} constant. * * @param end the new end * @throws LineIndexOutOfBoundsException if <code>end</code> <= {@link #start()} */ public void moveEndTo(int end) throws LineIndexOutOfBoundsException { moveTo(end - length()); }
/** * Moves this range such that the {@link #end()} is at <code>end</code>, keeping * {@link #length()} constant. * * @param end the new end * @throws LineIndexOutOfBoundsException if <code>end</code> <= {@link #start()} */ public void moveEndTo(int end) throws LineIndexOutOfBoundsException { moveTo(end - length()); }
/** * Resizes the range by <code>delta</code> lines, keeping {@link #start()} constant. * * @param delta the number of lines to resize the range * @throws LineIndexOutOfBoundsException if <code>-delta</code> >= {@link #length()} */ public void resizeBy(int delta) throws LineIndexOutOfBoundsException { setLength(length() + 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, keeping {@link #start()} constant. * * @param delta the number of lines to resize the range * @throws LineIndexOutOfBoundsException if <code>-delta</code> >= {@link #length()} */ public void resizeBy(int delta) throws LineIndexOutOfBoundsException { setLength(length() + delta); }
/** * Splits a range off the end of the receiver. The receiver is shortened to only include * <code>remaining</code> lines after the split. * * @param remaining the number of lines to remain in the receiver, must be in [1, {@link #length() length}) * @return the split off range * @throws LineIndexOutOfBoundsException if <code>remaining</code>>= {@link #length()} or <code>remaining</code><t;= 0 */ public Range split(int remaining) throws LineIndexOutOfBoundsException { if (!(remaining < length())) // assert before modification throw new LineIndexOutOfBoundsException("Remaining must be less than length: " + length()); //$NON-NLS-1$ int splitLength= length() - remaining; setLength(remaining); return new Range(end(), splitLength); }
/** * Splits a range off the end of the receiver. The receiver is shortened to only include * <code>remaining</code> lines after the split. * * @param remaining the number of lines to remain in the receiver, must be in [1, {@link #length() length}) * @return the split off range * @throws LineIndexOutOfBoundsException if <code>remaining</code>>= {@link #length()} or <code>remaining</code><t;= 0 */ public Range split(int remaining) throws LineIndexOutOfBoundsException { if (!(remaining < length())) // assert before modification throw new LineIndexOutOfBoundsException("Remaining must be less than length: " + length()); //$NON-NLS-1$ int splitLength= length() - remaining; setLength(remaining); return new Range(end(), splitLength); }
/** * 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()); }
/** * 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 <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); } }