Search in sources :

Example 61 with Position

use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.

the class ProjectionMapping method getCoverage.

@Override
public IRegion getCoverage() {
    Position[] fragments = getFragments();
    if (fragments != null && fragments.length > 0) {
        Position first = fragments[0];
        Position last = fragments[fragments.length - 1];
        return new Region(first.offset, exclusiveEnd(last) - first.offset);
    }
    return new Region(0, 0);
}
Also used : Position(org.eclipse.jface.text.Position) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion)

Example 62 with Position

use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.

the class ProjectionDocumentTest method test20_6.

@Test
public void test20_6() {
    // test adding a range to the slave document beginning in a segment and ending in a segment gap
    createProjectionA();
    try {
        fSlaveDocument.addMasterDocumentRange(50, 20);
    } catch (BadLocationException e) {
        assertTrue(false);
    }
    Position[] expected = { new Position(0, 20), new Position(40, 30), new Position(80, 20), new Position(120, 20), new Position(160, 20) };
    assertFragmentation(expected);
    StringBuffer buffer = new StringBuffer(getProjectionASlaveContents());
    String addition = getOriginalMasterContents().substring(60, 70);
    buffer.insert(40, addition);
    assertSlaveContents(buffer.toString());
}
Also used : Position(org.eclipse.jface.text.Position) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 63 with Position

use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.

the class ProjectionDocumentTest method test20_7.

@Test
public void test20_7() {
    // test adding a range to the slave document beginning in a segment and ending in a segment
    createProjectionA();
    try {
        fSlaveDocument.addMasterDocumentRange(50, 40);
    } catch (BadLocationException e) {
        assertTrue(false);
    }
    Position[] expected = { new Position(0, 20), new Position(40, 60), new Position(120, 20), new Position(160, 20) };
    assertFragmentation(expected);
    StringBuffer buffer = new StringBuffer(getProjectionASlaveContents());
    String addition = getOriginalMasterContents().substring(60, 80);
    buffer.insert(40, addition);
    assertSlaveContents(buffer.toString());
}
Also used : Position(org.eclipse.jface.text.Position) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 64 with Position

use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.

the class ProjectionDocumentTest method test24_1.

@Test
public void test24_1() {
    // test auto expand mode when manipulating the master document
    // master event completely left of slave document
    createProjectionB();
    fSlaveDocument.setAutoExpandMode(true);
    try {
        DocumentEvent event = new DocumentEvent(fMasterDocument, 5, 10, "~");
        fSlaveDocument.adaptProjectionToMasterChange2(event);
    } catch (BadLocationException e) {
        assertTrue(false);
    }
    Position[] expected = { new Position(5, 10), new Position(20, 20), new Position(60, 20), new Position(100, 20), new Position(140, 20) };
    assertFragmentation(expected);
}
Also used : Position(org.eclipse.jface.text.Position) DocumentEvent(org.eclipse.jface.text.DocumentEvent) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 65 with Position

use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.

the class ProjectionDocumentTest method test21_1.

@Test
public void test21_1() {
    // test removing a range from the slave document at the beginning of a segment
    createProjectionA();
    try {
        fSlaveDocument.removeMasterDocumentRange(40, 10);
    } catch (BadLocationException e) {
        assertTrue(false);
    }
    Position[] expected = { new Position(0, 20), new Position(50, 10), new Position(80, 20), new Position(120, 20), new Position(160, 20) };
    assertFragmentation(expected);
    StringBuffer buffer = new StringBuffer(getProjectionASlaveContents());
    buffer.delete(20, 30);
    assertSlaveContents(buffer.toString());
}
Also used : Position(org.eclipse.jface.text.Position) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Aggregations

Position (org.eclipse.jface.text.Position)421 BadLocationException (org.eclipse.jface.text.BadLocationException)145 Annotation (org.eclipse.jface.text.source.Annotation)110 IDocument (org.eclipse.jface.text.IDocument)80 ArrayList (java.util.ArrayList)75 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)57 IRegion (org.eclipse.jface.text.IRegion)55 Test (org.junit.Test)54 HashMap (java.util.HashMap)49 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)46 Point (org.eclipse.swt.graphics.Point)40 List (java.util.List)39 Iterator (java.util.Iterator)31 TypedPosition (org.eclipse.jface.text.TypedPosition)31 Region (org.eclipse.jface.text.Region)27 IFile (org.eclipse.core.resources.IFile)22 IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)21 ProjectionAnnotation (org.eclipse.jface.text.source.projection.ProjectionAnnotation)21 Map (java.util.Map)15 CoreException (org.eclipse.core.runtime.CoreException)15