use of org.eclipse.che.ide.api.editor.text.TypedPosition in project che by eclipse.
the class DefaultPartitioner method updatePositions.
private void updatePositions() {
// set before the scan as the scan uses the content length
this.documentPositionMap.setContentLength(getContentLength());
this.documentPositionMap.resetPositions();
Position current = null;
try {
Token token = scanner.nextToken();
while (!token.isEOF()) {
final String contentType = getTokenContentType(token);
if (isSupportedContentType(contentType)) {
final TypedPosition position = new TypedPosition(scanner.getTokenOffset(), scanner.getTokenLength(), contentType);
current = position;
this.documentPositionMap.addPosition(this.positionCategory, position);
}
token = scanner.nextToken();
}
} catch (final BadLocationException x) {
Log.error(DefaultPartitioner.class, "Invalid position: " + String.valueOf(current) + " (max:" + getContentLength() + ").", x);
} catch (final BadPositionCategoryException x) {
Log.error(DefaultPartitioner.class, "Invalid position category: " + this.positionCategory, x);
}
}
use of org.eclipse.che.ide.api.editor.text.TypedPosition in project che by eclipse.
the class DefaultPartitioner method getFirstIndexEndingAfterOffset.
/**
* Returns the index of the first position which ends after the given offset.
*
* @param positions the positions in linear order
* @param offset the offset
* @return the index of the first position which ends after the offset
*/
private static int getFirstIndexEndingAfterOffset(final List<TypedPosition> positions, final int offset) {
int i = -1;
int j = positions.size();
while (j - i > 1) {
final int k = (i + j) >> 1;
final Position p = positions.get(k);
if (p.getOffset() + p.getLength() > offset) {
j = k;
} else {
i = k;
}
}
return j;
}
use of org.eclipse.che.ide.api.editor.text.TypedPosition in project che by eclipse.
the class DocumentPositionMapImpl method containsPosition.
@Override
public boolean containsPosition(String category, int offset, int length) {
if (category == null) {
return false;
}
final List<TypedPosition> list = this.positions.get(category);
if (list == null) {
return false;
}
final int size = list.size();
if (size == 0) {
return false;
}
int index = computeIndexInPositionList(list, offset, true);
if (index < size) {
Position p = list.get(index);
while (p != null && p.offset == offset) {
if (p.length == length) {
return true;
}
++index;
p = (index < size) ? (Position) list.get(index) : null;
}
}
return false;
}
Aggregations