Search in sources :

Example 6 with ChangeRegion

use of org.eclipse.jface.internal.text.revisions.ChangeRegion in project eclipse.platform.text by eclipse.

the class ChangeRegionTest method testHunkBefore.

@Test
public void testHunkBefore() throws Exception {
    ChangeRegion r;
    r = new ChangeRegion(fRevision, new LineRange(12, 3));
    r.adjustTo(new Hunk(5, 3, 2));
    RangeUtil.assertEqualSingleRange(new LineRange(15, 3), r.getAdjustedRanges());
    RangeUtil.assertEqualRange(new LineRange(15, 3), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 3));
    r.adjustTo(new Hunk(5, 3, 0));
    RangeUtil.assertEqualSingleRange(new LineRange(15, 3), r.getAdjustedRanges());
    RangeUtil.assertEqualRange(new LineRange(15, 3), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 3));
    r.adjustTo(new Hunk(5, -3, 0));
    RangeUtil.assertEqualSingleRange(new LineRange(9, 3), r.getAdjustedRanges());
    RangeUtil.assertEqualRange(new LineRange(9, 3), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 3));
    r.adjustTo(new Hunk(5, 3, 3));
    RangeUtil.assertEqualSingleRange(new LineRange(15, 3), r.getAdjustedRanges());
    RangeUtil.assertEqualRange(new LineRange(15, 3), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 3));
    r.adjustTo(new Hunk(5, -3, 2));
    RangeUtil.assertEqualSingleRange(new LineRange(9, 3), r.getAdjustedRanges());
    RangeUtil.assertEqualRange(new LineRange(9, 3), r.getAdjustedCoverage());
}
Also used : Hunk(org.eclipse.jface.internal.text.revisions.Hunk) ChangeRegion(org.eclipse.jface.internal.text.revisions.ChangeRegion) LineRange(org.eclipse.jface.text.source.LineRange) Test(org.junit.Test)

Example 7 with ChangeRegion

use of org.eclipse.jface.internal.text.revisions.ChangeRegion in project eclipse.platform.text by eclipse.

the class ChangeRegionTest method testHunkInBetween.

@Test
public void testHunkInBetween() throws Exception {
    // TODO require merging of adjacent ranges?
    ChangeRegion r;
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(15, -2, 0));
    RangeUtil.assertEqualRanges(new LineRange(12, 3), new LineRange(15, 2), r.getAdjustedRanges());
    RangeUtil.assertEqualRange(new LineRange(12, 5), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(15, 2, 0));
    RangeUtil.assertEqualRanges(new LineRange(12, 3), new LineRange(17, 4), r.getAdjustedRanges());
    RangeUtil.assertEqualRange(new LineRange(12, 9), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(15, 0, 2));
    RangeUtil.assertEqualRanges(new LineRange(12, 3), new LineRange(17, 2), r.getAdjustedRanges());
    RangeUtil.assertEqualRange(new LineRange(12, 7), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(15, -1, 2));
    RangeUtil.assertEqualRanges(new LineRange(12, 3), new LineRange(17, 1), r.getAdjustedRanges());
    RangeUtil.assertEqualRange(new LineRange(12, 6), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(15, 2, 2));
    RangeUtil.assertEqualRanges(new LineRange(12, 3), new LineRange(19, 2), r.getAdjustedRanges());
    RangeUtil.assertEqualRange(new LineRange(12, 9), r.getAdjustedCoverage());
}
Also used : Hunk(org.eclipse.jface.internal.text.revisions.Hunk) ChangeRegion(org.eclipse.jface.internal.text.revisions.ChangeRegion) LineRange(org.eclipse.jface.text.source.LineRange) Test(org.junit.Test)

Example 8 with ChangeRegion

use of org.eclipse.jface.internal.text.revisions.ChangeRegion in project eclipse.platform.text by eclipse.

the class Revision method getRegions.

/**
 * 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;
}
Also used : ILineRange(org.eclipse.jface.text.source.ILineRange) ArrayList(java.util.ArrayList) ChangeRegion(org.eclipse.jface.internal.text.revisions.ChangeRegion)

Example 9 with ChangeRegion

use of org.eclipse.jface.internal.text.revisions.ChangeRegion in project eclipse.platform.text by eclipse.

the class ChangeRegionTest method testHunkAfter.

@Test
public void testHunkAfter() throws Exception {
    ChangeRegion r = new ChangeRegion(fRevision, new LineRange(12, 3));
    List<Range> before = RangeUtil.deepClone(r.getAdjustedRanges());
    r.adjustTo(new Hunk(16, 3, 2));
    RangeUtil.assertEqualRanges(before, r.getAdjustedRanges());
    RangeUtil.assertEqualRange(before.get(0), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 3));
    before = RangeUtil.deepClone(r.getAdjustedRanges());
    r.adjustTo(new Hunk(16, -33, 2));
    RangeUtil.assertEqualRanges(before, r.getAdjustedRanges());
    RangeUtil.assertEqualRange(before.get(0), r.getAdjustedCoverage());
}
Also used : Hunk(org.eclipse.jface.internal.text.revisions.Hunk) ChangeRegion(org.eclipse.jface.internal.text.revisions.ChangeRegion) Range(org.eclipse.jface.internal.text.revisions.Range) LineRange(org.eclipse.jface.text.source.LineRange) LineRange(org.eclipse.jface.text.source.LineRange) Test(org.junit.Test)

Example 10 with ChangeRegion

use of org.eclipse.jface.internal.text.revisions.ChangeRegion in project eclipse.platform.text by eclipse.

the class ChangeRegionTest method testHunkCovering.

@Test
public void testHunkCovering() throws Exception {
    ChangeRegion r;
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(12, 0, 7));
    assertTrue(r.getAdjustedRanges().isEmpty());
    RangeUtil.assertEqualRange(new LineRange(12, 0), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(11, 0, 8));
    assertTrue(r.getAdjustedRanges().isEmpty());
    RangeUtil.assertEqualRange(new LineRange(12, 0), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(11, 0, 9));
    assertTrue(r.getAdjustedRanges().isEmpty());
    RangeUtil.assertEqualRange(new LineRange(12, 0), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(12, 0, 9));
    assertTrue(r.getAdjustedRanges().isEmpty());
    RangeUtil.assertEqualRange(new LineRange(12, 0), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(12, -7, 0));
    assertTrue(r.getAdjustedRanges().isEmpty());
    RangeUtil.assertEqualRange(new LineRange(12, 0), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(12, -8, 0));
    assertTrue(r.getAdjustedRanges().isEmpty());
    RangeUtil.assertEqualRange(new LineRange(12, 0), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(11, -8, 0));
    assertTrue(r.getAdjustedRanges().isEmpty());
    RangeUtil.assertEqualRange(new LineRange(12, 0), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(11, -9, 0));
    assertTrue(r.getAdjustedRanges().isEmpty());
    RangeUtil.assertEqualRange(new LineRange(12, 0), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(8, -9, 6));
    assertTrue(r.getAdjustedRanges().isEmpty());
    RangeUtil.assertEqualRange(new LineRange(12, 0), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(8, -4, 8));
    assertTrue(r.getAdjustedRanges().isEmpty());
    RangeUtil.assertEqualRange(new LineRange(12, 0), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(8, -3, 9));
    assertTrue(r.getAdjustedRanges().isEmpty());
    RangeUtil.assertEqualRange(new LineRange(12, 0), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(8, -12, 5));
    assertTrue(r.getAdjustedRanges().isEmpty());
    RangeUtil.assertEqualRange(new LineRange(12, 0), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(8, -12, 20));
    assertTrue(r.getAdjustedRanges().isEmpty());
    RangeUtil.assertEqualRange(new LineRange(12, 0), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(8, 12, 20));
    assertTrue(r.getAdjustedRanges().isEmpty());
    RangeUtil.assertEqualRange(new LineRange(12, 0), r.getAdjustedCoverage());
    r = new ChangeRegion(fRevision, new LineRange(12, 7));
    r.adjustTo(new Hunk(8, -3, 8));
    assertTrue(r.getAdjustedRanges().isEmpty());
    RangeUtil.assertEqualRange(new LineRange(12, 0), r.getAdjustedCoverage());
}
Also used : Hunk(org.eclipse.jface.internal.text.revisions.Hunk) ChangeRegion(org.eclipse.jface.internal.text.revisions.ChangeRegion) LineRange(org.eclipse.jface.text.source.LineRange) Test(org.junit.Test)

Aggregations

ChangeRegion (org.eclipse.jface.internal.text.revisions.ChangeRegion)12 LineRange (org.eclipse.jface.text.source.LineRange)11 Test (org.junit.Test)11 Hunk (org.eclipse.jface.internal.text.revisions.Hunk)10 Range (org.eclipse.jface.internal.text.revisions.Range)2 ArrayList (java.util.ArrayList)1 ILineRange (org.eclipse.jface.text.source.ILineRange)1