/** * Adds a line range to this revision. The range must be non-empty and have a legal start line * (not -1). * * @param range a line range that was changed with this revision * @throws IndexOutOfBoundsException if the line range is empty or has a negative start line */ public final void addRange(ILineRange range) throws IndexOutOfBoundsException { fChangeRegions.add(new ChangeRegion(this, range)); }
/** * Adjusts the revision information to the given diff information. Any previous diff information * is discarded. * * @param hunks the diff hunks to adjust the revision information to * @since 3.3 */ final void applyDiff(Hunk[] hunks) { fRanges= null; // mark for recomputation for (ChangeRegion region : fChangeRegions) { region.clearDiff(); for (Hunk hunk : hunks) { region.adjustTo(hunk); } } }
/** * 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); } }
/** * Creates a new change region for the given revision and line range. * * @param revision the revision of the new region * @param lines the line range of the new region * @throws IndexOutOfBoundsException if the line range is not well-formed */ public ChangeRegion(Revision revision, ILineRange lines) throws IndexOutOfBoundsException { Assert.isLegal(revision != null); Assert.isLegal(lines != null); fLines= Range.copy(lines); fRevision=revision; clearDiff(); }
/** * Returns the contained {@link RevisionRange}s adapted to the current diff state. The returned * information is only valid at the moment it is returned, and may change as the annotated * document is modified. * * @return an unmodifiable view of the contained ranges */ public final List<RevisionRange> getRegions() { if (fRanges == null) { List<RevisionRange> ranges= new ArrayList<>(fChangeRegions.size()); for (Iterator<ChangeRegion> it= fChangeRegions.iterator(); it.hasNext();) { ChangeRegion region= it.next(); for (Iterator<Range> inner= region.getAdjustedRanges().iterator(); inner.hasNext();) { ILineRange range= inner.next(); ranges.add(new RevisionRange(this, range)); } } fRanges= Collections.unmodifiableList(ranges); } return fRanges; }
/** * 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); } }
/** * Creates a new change region for the given revision and line range. * * @param revision the revision of the new region * @param lines the line range of the new region * @throws IndexOutOfBoundsException if the line range is not well-formed */ public ChangeRegion(Revision revision, ILineRange lines) throws IndexOutOfBoundsException { Assert.isLegal(revision != null); Assert.isLegal(lines != null); fLines= Range.copy(lines); fRevision=revision; clearDiff(); }
/** * Returns the contained {@link RevisionRange}s adapted to the current diff state. The returned * information is only valid at the moment it is returned, and may change as the annotated * document is modified. * * @return an unmodifiable view of the contained ranges */ public final List<RevisionRange> getRegions() { if (fRanges == null) { List<RevisionRange> ranges= new ArrayList<>(fChangeRegions.size()); for (ChangeRegion region : fChangeRegions) { for (ILineRange range : region.getAdjustedRanges()) { ranges.add(new RevisionRange(this, range)); } } fRanges= Collections.unmodifiableList(ranges); } return fRanges; }
/** * Adjusts the revision information to the given diff information. Any previous diff information * is discarded. * * @param hunks the diff hunks to adjust the revision information to * @since 3.3 */ final void applyDiff(Hunk[] hunks) { fRanges= null; // mark for recomputation for (Iterator<ChangeRegion> regions= fChangeRegions.iterator(); regions.hasNext();) { ChangeRegion region= regions.next(); region.clearDiff(); for (int i= 0; i < hunks.length; i++) { Hunk hunk= hunks[i]; region.adjustTo(hunk); } } }
/** * Adds a line range to this revision. The range must be non-empty and have a legal start line * (not -1). * * @param range a line range that was changed with this revision * @throws IndexOutOfBoundsException if the line range is empty or has a negative start line */ public final void addRange(ILineRange range) throws IndexOutOfBoundsException { fChangeRegions.add(new ChangeRegion(this, range)); }