Search in sources :

Example 56 with IRegion

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

the class LineTrackerTest3 method testReplace4.

@Test
public void testReplace4() throws Exception {
    checkLines(new int[] { 1, 1, 1, 1, 1, 0 });
    int lines = fTracker.getNumberOfLines();
    IRegion previous = fTracker.getLineInformation(0);
    for (int i = 1; i < lines; i++) {
        int lastLineEnd = previous.getOffset() + previous.getLength();
        int lineStart = fTracker.getLineInformation(i).getOffset();
        replace(lastLineEnd, lineStart - lastLineEnd, "\n");
        checkLines(new int[] { 1, 1, 1, 1, 1, 0 });
        previous = fTracker.getLineInformation(i);
    }
}
Also used : IRegion(org.eclipse.jface.text.IRegion) Test(org.junit.Test)

Example 57 with IRegion

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

the class TextStoreTest method testOffsets.

@Test
public void testOffsets() throws Exception {
    for (int i = 0; i < 5; i++) {
        IRegion line = fTracker.getLineInformation(i);
        int pos = line.getOffset() + line.getLength();
        int offset = (2 * i) + 1;
        assertTrue("invalid line end offset " + pos + " for line " + i + " should be " + offset, offset == pos);
    }
    for (int i = 0; i < 5; i++) {
        int pos = fTracker.getLineOffset(i);
        int offset = 2 * i;
        assertTrue("invalid line start offset " + pos + " for line " + i + " should be " + offset, pos == offset);
    }
    for (int i = 0; i < 10; i++) {
        int line = fTracker.getLineNumberOfOffset(i);
        double l = Math.floor(i / 2);
        assertTrue("invalid line number " + line + " for position " + i + " should be " + l, l == line);
    }
}
Also used : IRegion(org.eclipse.jface.text.IRegion) Test(org.junit.Test)

Example 58 with IRegion

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

the class TextStoreTest method testReplace4.

@Test
public void testReplace4() throws Exception {
    int lines = fTracker.getNumberOfLines();
    IRegion previous = fTracker.getLineInformation(0);
    for (int i = 1; i < lines; i++) {
        int lastLineEnd = previous.getOffset() + previous.getLength();
        int lineStart = fTracker.getLineInformation(i).getOffset();
        replace(lastLineEnd, lineStart - lastLineEnd, "\n");
        assertTextStoreContents("x\nx\nx\nx\nx\n");
        previous = fTracker.getLineInformation(i);
    }
}
Also used : IRegion(org.eclipse.jface.text.IRegion) Test(org.junit.Test)

Example 59 with IRegion

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

the class ProjectionDocument method computeFirstUnprojectedMasterRegion.

/**
 * Returns the first master document region which is contained in the given
 * master document range and which is not yet part of this projection
 * document.
 *
 * @param offsetInMaster the range offset in the master document
 * @param lengthInMaster the range length in the master document
 * @return the first region that is not yet part of the projection document
 * @throws BadLocationException in case the given range is invalid in the
 *         master document
 * @since 3.1
 */
private IRegion computeFirstUnprojectedMasterRegion(int offsetInMaster, int lengthInMaster) throws BadLocationException {
    IRegion[] fragments = null;
    IRegion imageRegion = fMapping.toImageRegion(new Region(offsetInMaster, lengthInMaster));
    if (imageRegion != null)
        fragments = fMapping.toExactOriginRegions(imageRegion);
    if (fragments == null || fragments.length == 0)
        return new Region(offsetInMaster, lengthInMaster);
    IRegion region = fragments[0];
    if (offsetInMaster < region.getOffset())
        return new Region(offsetInMaster, region.getOffset() - offsetInMaster);
    for (int i = 0; i < fragments.length - 1; i++) {
        IRegion left = fragments[i];
        IRegion right = fragments[i + 1];
        int leftEnd = left.getOffset() + left.getLength();
        if (leftEnd < right.getOffset())
            return new Region(leftEnd, right.getOffset() - leftEnd);
    }
    region = fragments[fragments.length - 1];
    int leftEnd = region.getOffset() + region.getLength();
    int rightEnd = offsetInMaster + lengthInMaster;
    if (leftEnd < rightEnd)
        return new Region(leftEnd, rightEnd - leftEnd);
    return null;
}
Also used : Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion)

Example 60 with IRegion

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

the class ProjectionDocument method computeUnprojectedMasterRegions.

/**
 * Returns the sequence of all master document regions which are contained
 * in the given master document range and which are not yet part of this
 * projection document.
 *
 * @param offsetInMaster the range offset in the master document
 * @param lengthInMaster the range length in the master document
 * @return the sequence of regions which are not yet part of the projection
 *         document
 * @throws BadLocationException in case the given range is invalid in the
 *         master document
 */
public final IRegion[] computeUnprojectedMasterRegions(int offsetInMaster, int lengthInMaster) throws BadLocationException {
    IRegion[] fragments = null;
    IRegion imageRegion = fMapping.toImageRegion(new Region(offsetInMaster, lengthInMaster));
    if (imageRegion != null)
        fragments = fMapping.toExactOriginRegions(imageRegion);
    if (fragments == null || fragments.length == 0)
        return new IRegion[] { new Region(offsetInMaster, lengthInMaster) };
    List<Region> gaps = new ArrayList<>();
    IRegion region = fragments[0];
    if (offsetInMaster < region.getOffset())
        gaps.add(new Region(offsetInMaster, region.getOffset() - offsetInMaster));
    for (int i = 0; i < fragments.length - 1; i++) {
        IRegion left = fragments[i];
        IRegion right = fragments[i + 1];
        int leftEnd = left.getOffset() + left.getLength();
        if (leftEnd < right.getOffset())
            gaps.add(new Region(leftEnd, right.getOffset() - leftEnd));
    }
    region = fragments[fragments.length - 1];
    int leftEnd = region.getOffset() + region.getLength();
    int rightEnd = offsetInMaster + lengthInMaster;
    if (leftEnd < rightEnd)
        gaps.add(new Region(leftEnd, rightEnd - leftEnd));
    IRegion[] result = new IRegion[gaps.size()];
    gaps.toArray(result);
    return result;
}
Also used : ArrayList(java.util.ArrayList) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion)

Aggregations

IRegion (org.eclipse.jface.text.IRegion)341 BadLocationException (org.eclipse.jface.text.BadLocationException)158 Region (org.eclipse.jface.text.Region)151 Test (org.junit.Test)94 IDocument (org.eclipse.jface.text.IDocument)68 Point (org.eclipse.swt.graphics.Point)49 Position (org.eclipse.jface.text.Position)38 ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)20 ITypedRegion (org.eclipse.jface.text.ITypedRegion)20 FindReplaceDocumentAdapter (org.eclipse.jface.text.FindReplaceDocumentAdapter)18 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)17 IEditorPart (org.eclipse.ui.IEditorPart)13 ArrayList (java.util.ArrayList)11 Document (org.eclipse.jface.text.Document)11 StyledText (org.eclipse.swt.custom.StyledText)10 ITextSelection (org.eclipse.jface.text.ITextSelection)9 IFile (org.eclipse.core.resources.IFile)8 Annotation (org.eclipse.jface.text.source.Annotation)7 HashMap (java.util.HashMap)6 CoreException (org.eclipse.core.runtime.CoreException)6