Search in sources :

Example 51 with Position

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

the class LineConversionTest method testConvertToCharacter.

public void testConvertToCharacter() throws Exception {
    SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), fFile);
    ITextFileBuffer fb = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
    IDocument doc = fb.getDocument();
    Position p1 = new Position(2, 1);
    Position p2 = PositionTracker.convertToCharacterPosition(p1, doc);
    // assertEquals(LINE_THREE, doc.get(p2.getOffset(), p2.getLength()));
    assertEquals(p1, PositionTracker.convertToLinePosition(p2, doc));
    p1 = new Position(0, 1);
    p2 = PositionTracker.convertToCharacterPosition(p1, doc);
    assertEquals(LINE_ONE, doc.get(p2.getOffset(), p2.getLength()));
    assertEquals(p1, PositionTracker.convertToLinePosition(p2, doc));
    p1 = new Position(1, 1);
    p2 = PositionTracker.convertToCharacterPosition(p1, doc);
    assertEquals(LINE_TWO, doc.get(p2.getOffset(), p2.getLength()));
    assertEquals(p1, PositionTracker.convertToLinePosition(p2, doc));
    p1 = new Position(0, 0);
    p2 = PositionTracker.convertToCharacterPosition(p1, doc);
    assertEquals("", doc.get(p2.getOffset(), p2.getLength()));
    assertEquals(p1, PositionTracker.convertToLinePosition(p2, doc));
}
Also used : Position(org.eclipse.jface.text.Position) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument)

Example 52 with Position

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

the class DocumentUndoManagerTest method doChange.

private void doChange(IDocument document, int count) {
    try {
        String before = document.get();
        if (DEBUG)
            System.out.println(before);
        Position[] positions = new Position[count];
        String[] strings = new String[count];
        for (int i = 0; i < count; i++) {
            final Position position = createRandomPositionPoisson(document.getLength());
            final String string = createRandomStringPoisson();
            document.replace(position.getOffset(), position.getLength(), string);
            positions[i] = position;
            strings[i] = string;
        }
        if (DEBUG) {
            System.out.print("{ ");
            for (int i = 0; i < count; i++) {
                System.out.print(positions[i].getOffset());
                System.out.print(", ");
                System.out.print(positions[i].getLength());
                System.out.print(", ");
            }
            System.out.println(" }");
            System.out.print("{ ");
            for (int i = 0; i < count; i++) {
                System.out.print("\"");
                System.out.print(strings[i]);
                System.out.print("\", ");
            }
            System.out.println(" }");
        }
    } catch (BadLocationException e) {
        assertTrue(false);
    }
}
Also used : Position(org.eclipse.jface.text.Position) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 53 with Position

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

the class ExclusivePositionUpdaterTest method setUp.

@Before
public void setUp() throws Exception {
    fUpdater = new DefaultPositionUpdater(CATEGORY);
    fDoc = new Document("ccccccccccccccccccccccccccccccccccccccccccccc");
    fPos = new Position(5, 5);
    // 01234[fPo]0123456789
    fDoc.addPositionUpdater(fUpdater);
    fDoc.addPositionCategory(CATEGORY);
    fDoc.addPosition(CATEGORY, fPos);
}
Also used : Position(org.eclipse.jface.text.Position) DefaultPositionUpdater(org.eclipse.jface.text.DefaultPositionUpdater) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) Before(org.junit.Before)

Example 54 with Position

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

the class PositionUpdatingCornerCasesTest method testInsert.

@Test
public void testInsert() throws Exception {
    fDocument = new Document("x-x-x-x-x-x-x-x-x-x-x");
    fDocument.addPosition(new Position(0, 0));
    fDocument.addPosition(new Position(0, 1));
    fDocument.addPosition(new Position(5, 0));
    fDocument.addPosition(new Position(5, 3));
    fDocument.replace(0, 0, "yy");
    Position[] positions = new Position[] { new Position(2, 1), new Position(2, 0), new Position(7, 3), new Position(7, 0) };
    checkPositions(positions);
}
Also used : Position(org.eclipse.jface.text.Position) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 55 with Position

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

the class PositionUpdatingCornerCasesTest method testInsert2.

@Test
public void testInsert2() throws Exception {
    fDocument = new Document("x-x-x-x-x-x-x-x-x-x-x");
    fDocument.addPosition(new Position(0, 0));
    fDocument.addPosition(new Position(0, 1));
    fDocument.addPosition(new Position(4, 1));
    fDocument.addPosition(new Position(5, 0));
    fDocument.addPosition(new Position(5, 3));
    fDocument.addPosition(new Position(10, 0));
    fDocument.addPosition(new Position(10, 2));
    fDocument.replace(5, 0, "yy");
    Position[] positions = new Position[] { new Position(0, 1), new Position(0, 0), new Position(4, 1), new Position(7, 3), new Position(7, 0), new Position(12, 2), new Position(12, 0) };
    checkPositions(positions);
}
Also used : Position(org.eclipse.jface.text.Position) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) 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