Search in sources :

Example 76 with Position

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

the class ProjectionDocumentTest method test18_2.

@Test
public void test18_2() {
    // test manipulations overlapping multiple segments of the slave document
    // replace range overlapping two neighboring segments
    createProjectionA();
    try {
        fSlaveDocument.replace(30, 20, "~~~~~");
    } catch (BadLocationException e) {
        assertTrue(false);
    }
    Position[] expected = { new Position(0, 20), new Position(40, 25), new Position(85, 20), new Position(125, 20) };
    assertFragmentation(expected);
    StringBuffer buffer = new StringBuffer(getProjectionASlaveContents());
    buffer.replace(30, 50, "~~~~~");
    assertSlaveContents(buffer.toString());
    buffer = new StringBuffer(getOriginalMasterContents());
    buffer.replace(50, 90, "~~~~~");
    assertMasterContents(buffer.toString());
}
Also used : Position(org.eclipse.jface.text.Position) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Example 77 with Position

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

the class ProjectionDocumentTest method test21_7.

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

Example 78 with Position

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

the class ProjectionDocumentTest method test24_5.

@Test
public void test24_5() {
    // test auto expand mode when manipulating the master document
    // master event starts left of fragment and ends inside of a fragment
    createProjectionB();
    fSlaveDocument.setAutoExpandMode(true);
    try {
        DocumentEvent event = new DocumentEvent(fMasterDocument, 50, 20, "~");
        fSlaveDocument.adaptProjectionToMasterChange2(event);
    } catch (BadLocationException e) {
        assertTrue(false);
    }
    Position[] expected = { new Position(20, 20), new Position(50, 30), 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 79 with Position

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

the class ProjectionDocumentTest method test24_4.

@Test
public void test24_4() {
    // test auto expand mode when manipulating the master document
    // master event completely right of fragment
    // -> is also left of the fragment in this setup
    createProjectionB();
    fSlaveDocument.setAutoExpandMode(true);
    try {
        DocumentEvent event = new DocumentEvent(fMasterDocument, 85, 10, "~");
        fSlaveDocument.adaptProjectionToMasterChange2(event);
    } catch (BadLocationException e) {
        assertTrue(false);
    }
    Position[] expected = { new Position(20, 20), new Position(60, 20), new Position(85, 10), 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 80 with Position

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

the class AnnotationModelStressTest method assertAdd.

private void assertAdd(AnnotationData data, ArrayList<AnnotationData> added) {
    Annotation annotation = new Annotation(false);
    Position position = new Position(data.offset, data.length);
    IAnnotationModel model = getModel(data.annotationNumber);
    model.addAnnotation(annotation, position);
    assertTrue(model.getPosition(annotation) == position);
    data.annotation = annotation;
    data.position = position;
    added.add(data);
}
Also used : Position(org.eclipse.jface.text.Position) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Annotation(org.eclipse.jface.text.source.Annotation)

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