Search in sources :

Example 1 with Segment

use of org.eclipse.jface.text.projection.Segment in project eclipse.platform.text by eclipse.

the class ProjectionDocumentTest method assertFragmentation.

private void assertFragmentation(Position[] expected, boolean checkWellFormedness) {
    if (checkWellFormedness) {
        assertWellFormedSegmentation();
        assertWellFormedFragmentation();
    }
    Position[] segmentation = fSlaveDocument.getSegments2();
    assertTrue("invalid number of segments", expected.length == segmentation.length);
    for (int i = 0; i < expected.length; i++) {
        Segment segment = (Segment) segmentation[i];
        Fragment actual = segment.fragment;
        Assert.assertEquals(print(actual) + " != " + print(expected[i]), expected[i], actual);
    }
}
Also used : Position(org.eclipse.jface.text.Position) Fragment(org.eclipse.jface.text.projection.Fragment) Segment(org.eclipse.jface.text.projection.Segment)

Example 2 with Segment

use of org.eclipse.jface.text.projection.Segment in project eclipse.platform.text by eclipse.

the class ProjectionDocumentTest method assertWellFormedFragmentation.

private void assertWellFormedFragmentation() {
    Position[] segmentation = fSlaveDocument.getSegments2();
    assertNotNull(segmentation);
    Position[] fragmention = fSlaveDocument.getFragments2();
    assertNotNull(fragmention);
    assertTrue(fragmention.length == segmentation.length);
    Position previous = null;
    for (int i = 0; i < segmentation.length; i++) {
        Segment segment = (Segment) segmentation[i];
        Fragment fragment = (Fragment) fragmention[i];
        assertTrue(fragment == segment.fragment);
        assertTrue(segment == fragment.segment);
        assertFalse(segmentation.length > 1 && (fragment.getLength() == 0 && i < segmentation.length - 1));
        assertTrue(fragment.length == segment.length);
        if (previous != null && i < segmentation.length - 1)
            assertFalse(previous.getOffset() + previous.getLength() == fragment.getOffset());
        previous = fragment;
    }
}
Also used : Position(org.eclipse.jface.text.Position) Fragment(org.eclipse.jface.text.projection.Fragment) Segment(org.eclipse.jface.text.projection.Segment)

Example 3 with Segment

use of org.eclipse.jface.text.projection.Segment in project eclipse.platform.text by eclipse.

the class ProjectionMappingTest method addProjection.

private void addProjection(int fragmentOffset, int segmentOffset, int length) {
    Fragment fragment = new Fragment(fragmentOffset, length);
    Segment segment = new Segment(segmentOffset, length);
    fragment.segment = segment;
    segment.fragment = fragment;
    try {
        fMasterDocument.addPosition(fFragmentsCategory, fragment);
        fSlaveDocument.addPosition(fSegmentsCategory, segment);
    } catch (BadLocationException e) {
        assertTrue(false);
    } catch (BadPositionCategoryException e) {
        assertTrue(false);
    }
}
Also used : BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) Fragment(org.eclipse.jface.text.projection.Fragment) Segment(org.eclipse.jface.text.projection.Segment) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

Fragment (org.eclipse.jface.text.projection.Fragment)3 Segment (org.eclipse.jface.text.projection.Segment)3 Position (org.eclipse.jface.text.Position)2 BadLocationException (org.eclipse.jface.text.BadLocationException)1 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)1