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);
}
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations