use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class InclusivePositionUpdaterTest method setUp.
@Before
public void setUp() throws Exception {
fUpdater = new InclusivePositionUpdater(CATEGORY);
fDoc = new Document("ccccccccccccccccccccccccccccccccccccccccccccc");
fPos = new Position(5, 5);
fDoc.addPositionUpdater(fUpdater);
fDoc.addPositionCategory(CATEGORY);
fDoc.addPosition(CATEGORY, fPos);
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class LinkedPositionTest method testNotEqualsPosition.
@Test
public void testNotEqualsPosition() {
LinkedPosition p1 = new LinkedPosition(fDoc, 1, 9);
Position p2 = new Position(1, 9);
assertFalse(p1.equals(p2));
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class FragmentUpdater method affectsPositions.
/**
* Returns whether this updater considers any position affected by the given document event. A
* position is affected if <code>event</code> {@link Position#overlapsWith(int, int) overlaps}
* with it but not if the position is only shifted.
*
* @param event the event
* @return <code>true</code> if there is any affected position, <code>false</code> otherwise
*/
public boolean affectsPositions(DocumentEvent event) {
IDocument document = event.getDocument();
try {
int index = document.computeIndexInCategory(getCategory(), event.getOffset());
Position[] fragments = document.getPositions(getCategory());
if (0 < index) {
Position fragment = fragments[index - 1];
if (fragment.overlapsWith(event.getOffset(), event.getLength()))
return true;
if (index == fragments.length && fragment.offset + fragment.length == event.getOffset())
return true;
}
if (index < fragments.length) {
Position fragment = fragments[index];
return fragment.overlapsWith(event.getOffset(), event.getLength());
}
} catch (BadLocationException x) {
} catch (BadPositionCategoryException x) {
}
return false;
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class ProjectionMapping method toClosestImageLine.
@Override
public int toClosestImageLine(int originLine) throws BadLocationException {
try {
int imageLine = toImageLine(originLine);
if (imageLine > -1)
return imageLine;
Position[] fragments = getFragments();
if (fragments.length == 0)
return -1;
IRegion originLineRegion = fMasterDocument.getLineInformation(originLine);
int index = fMasterDocument.computeIndexInCategory(fFragmentsCategory, originLineRegion.getOffset());
if (0 < index && index < fragments.length) {
Fragment left = (Fragment) fragments[index - 1];
int leftDistance = originLineRegion.getOffset() - (exclusiveEnd(left));
Fragment right = (Fragment) fragments[index];
int rightDistance = right.getOffset() - (exclusiveEnd(originLineRegion));
if (leftDistance <= rightDistance)
originLine = fMasterDocument.getLineOfOffset(left.getOffset() + Math.max(left.getLength() - 1, 0));
else
originLine = fMasterDocument.getLineOfOffset(right.getOffset());
} else if (index == 0) {
Fragment right = (Fragment) fragments[index];
originLine = fMasterDocument.getLineOfOffset(right.getOffset());
} else if (index == fragments.length) {
Fragment left = (Fragment) fragments[index - 1];
originLine = fMasterDocument.getLineOfOffset(exclusiveEnd(left));
}
return toImageLine(originLine);
} catch (BadPositionCategoryException x) {
}
return -1;
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class ProjectionMapping method getExactCoverage.
@Override
public IRegion[] getExactCoverage(IRegion originRegion) throws BadLocationException {
int originOffset = originRegion.getOffset();
int originLength = originRegion.getLength();
if (originLength == 0) {
int imageOffset = toImageOffset(originOffset);
return imageOffset > -1 ? new IRegion[] { new Region(originOffset, 0) } : null;
}
int endOffset = originOffset + originLength;
Position[] fragments = getFragments();
int firstIndex = findFragmentIndex(originOffset, RIGHT);
int lastIndex = findFragmentIndex(endOffset - 1, LEFT);
if (firstIndex == -1 || firstIndex > lastIndex)
return null;
int resultLength = lastIndex - firstIndex + 1;
IRegion[] result = new IRegion[resultLength];
// first
result[0] = createOriginStartRegion((Fragment) fragments[firstIndex], originOffset - fragments[firstIndex].getOffset());
// middles
for (int i = 1; i < resultLength - 1; i++) result[i] = createOriginRegion((Fragment) fragments[firstIndex + i]);
// last
Fragment last = (Fragment) fragments[lastIndex];
int fragmentEndOffset = exclusiveEnd(last);
IRegion lastRegion = createOriginEndRegion(last, fragmentEndOffset - endOffset);
if (resultLength > 1) {
// first != last
result[resultLength - 1] = lastRegion;
} else {
// merge first and last
IRegion intersection = getIntersectingRegion(result[0], lastRegion);
if (intersection == null)
return null;
result[0] = intersection;
}
return result;
}
Aggregations