use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class ProjectionMapping method getCoverage.
@Override
public IRegion getCoverage() {
Position[] fragments = getFragments();
if (fragments != null && fragments.length > 0) {
Position first = fragments[0];
Position last = fragments[fragments.length - 1];
return new Region(first.offset, exclusiveEnd(last) - first.offset);
}
return new Region(0, 0);
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class ProjectionDocumentTest method test20_6.
@Test
public void test20_6() {
// test adding a range to the slave document beginning in a segment and ending in a segment gap
createProjectionA();
try {
fSlaveDocument.addMasterDocumentRange(50, 20);
} catch (BadLocationException e) {
assertTrue(false);
}
Position[] expected = { new Position(0, 20), new Position(40, 30), new Position(80, 20), new Position(120, 20), new Position(160, 20) };
assertFragmentation(expected);
StringBuffer buffer = new StringBuffer(getProjectionASlaveContents());
String addition = getOriginalMasterContents().substring(60, 70);
buffer.insert(40, addition);
assertSlaveContents(buffer.toString());
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class ProjectionDocumentTest method test20_7.
@Test
public void test20_7() {
// test adding a range to the slave document beginning in a segment and ending in a segment
createProjectionA();
try {
fSlaveDocument.addMasterDocumentRange(50, 40);
} catch (BadLocationException e) {
assertTrue(false);
}
Position[] expected = { new Position(0, 20), new Position(40, 60), new Position(120, 20), new Position(160, 20) };
assertFragmentation(expected);
StringBuffer buffer = new StringBuffer(getProjectionASlaveContents());
String addition = getOriginalMasterContents().substring(60, 80);
buffer.insert(40, addition);
assertSlaveContents(buffer.toString());
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class ProjectionDocumentTest method test24_1.
@Test
public void test24_1() {
// test auto expand mode when manipulating the master document
// master event completely left of slave document
createProjectionB();
fSlaveDocument.setAutoExpandMode(true);
try {
DocumentEvent event = new DocumentEvent(fMasterDocument, 5, 10, "~");
fSlaveDocument.adaptProjectionToMasterChange2(event);
} catch (BadLocationException e) {
assertTrue(false);
}
Position[] expected = { new Position(5, 10), new Position(20, 20), new Position(60, 20), new Position(100, 20), new Position(140, 20) };
assertFragmentation(expected);
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class ProjectionDocumentTest method test21_1.
@Test
public void test21_1() {
// test removing a range from the slave document at the beginning of a segment
createProjectionA();
try {
fSlaveDocument.removeMasterDocumentRange(40, 10);
} catch (BadLocationException e) {
assertTrue(false);
}
Position[] expected = { new Position(0, 20), new Position(50, 10), new Position(80, 20), new Position(120, 20), new Position(160, 20) };
assertFragmentation(expected);
StringBuffer buffer = new StringBuffer(getProjectionASlaveContents());
buffer.delete(20, 30);
assertSlaveContents(buffer.toString());
}
Aggregations