Search in sources :

Example 71 with Position

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

the class ProjectionDocumentTest method test10_4.

@Test
public void test10_4() {
    // test manipulations overlapping projected and unprojected regions of the master document
    // replace range overlapping from an unprojected into a projected region
    // -> replaced range will appear in slave document because of auto expansion of slave document in case of overlapping events
    createProjectionA();
    try {
        fMasterDocument.replace(70, 20, "~~~~~");
    } catch (BadLocationException e) {
        assertTrue(false);
    }
    Position[] expected = { new Position(0, 20), new Position(40, 20), new Position(70, 15), new Position(105, 20), new Position(145, 20) };
    assertFragmentation(expected);
    StringBuffer buffer = new StringBuffer(getProjectionASlaveContents());
    buffer.replace(40, 50, "~~~~~");
    assertSlaveContents(buffer.toString());
}
Also used : Position(org.eclipse.jface.text.Position) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 72 with Position

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

the class ProjectionDocumentTest method test20_5.

@Test
public void test20_5() {
    // test adding a range to the slave document beginning in a segment gap and ending in a segment
    createProjectionA();
    try {
        fSlaveDocument.addMasterDocumentRange(70, 20);
    } catch (BadLocationException e) {
        assertTrue(false);
    }
    Position[] expected = { new Position(0, 20), new Position(40, 20), new Position(70, 30), new Position(120, 20), new Position(160, 20) };
    assertFragmentation(expected);
    StringBuffer buffer = new StringBuffer(getProjectionASlaveContents());
    String addition = getOriginalMasterContents().substring(70, 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 73 with Position

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

the class ProjectionDocumentTest method test21_a.

@Test
public void test21_a() {
    // test removing a range from the slave document using identical projection
    // the removed range includes the end of the master document - see bug 301023
    createIdenticalProjection();
    try {
        fSlaveDocument.removeMasterDocumentRange(80, 100);
    } catch (BadLocationException e) {
        assertTrue(false);
    }
    Position[] expected = { new Position(0, 80), new Position(180, 0) };
    assertFragmentation(expected);
    StringBuffer buffer = new StringBuffer(getOriginalMasterContents());
    buffer.delete(80, 180);
    assertSlaveContents(buffer.toString());
}
Also used : Position(org.eclipse.jface.text.Position) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 74 with Position

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

the class ProjectionDocumentTest method test10_2.

@Test
public void test10_2() {
    // test manipulations overlapping projected and unprojected regions of the master document
    // replace range overlapping from a projected into an unprojected region
    // => replaced range will appear in slave document because of auto expansion of slave document in case of overlapping events
    createProjectionA();
    try {
        fMasterDocument.replace(50, 20, "~~~~~");
    } catch (BadLocationException e) {
        assertTrue(false);
    }
    Position[] expected = { new Position(0, 20), new Position(40, 15), new Position(65, 20), new Position(105, 20), new Position(145, 20) };
    assertFragmentation(expected);
    StringBuffer buffer = new StringBuffer(getProjectionASlaveContents());
    buffer.replace(30, 40, "~~~~~");
    assertSlaveContents(buffer.toString());
}
Also used : Position(org.eclipse.jface.text.Position) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 75 with Position

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

the class ProjectionDocumentTest method test24_8.

@Test
public void test24_8() {
    // test auto expand mode when manipulating the master document
    // complete replace of master document
    createProjectionB();
    fSlaveDocument.setAutoExpandMode(true);
    try {
        DocumentEvent event = new DocumentEvent(fMasterDocument, 0, fMasterDocument.getLength(), "x" + getOriginalMasterContents() + "y");
        fSlaveDocument.adaptProjectionToMasterChange2(event);
    } catch (BadLocationException x) {
        assertTrue(false);
    }
    Position[] expected = { new Position(0, fMasterDocument.getLength()) };
    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)

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