use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class DocumentPositionMapImpl method computeIndexInPositionList.
protected int computeIndexInPositionList(final List<TypedPosition> positions, final int offset, final boolean orderedByOffset) {
if (positions.size() == 0) {
return 0;
}
int left = 0;
int right = positions.size() - 1;
int mid = 0;
Position p = null;
while (left < right) {
mid = (left + right) / 2;
p = positions.get(mid);
final int pOffset = getOffset(orderedByOffset, p);
if (offset < pOffset) {
if (left == mid) {
right = left;
} else {
right = mid - 1;
}
} else if (offset > pOffset) {
if (right == mid) {
left = right;
} else {
left = mid + 1;
}
} else if (offset == pOffset) {
left = right = mid;
}
}
int pos = left;
p = positions.get(pos);
int pPosition = getOffset(orderedByOffset, p);
if (offset > pPosition) {
// append to the end
pos++;
} else {
// entry will become the first of all entries with the same offset
do {
--pos;
if (pos < 0) {
break;
}
p = positions.get(pos);
pPosition = getOffset(orderedByOffset, p);
} while (offset == pPosition);
++pos;
}
Assert.isTrue(0 <= pos && pos <= positions.size());
return pos;
}
use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class DocumentPositionMapImpl method getPositions.
@Override
public List<TypedPosition> getPositions(String category, int offset, int length, boolean canStartBefore, boolean canEndAfter) throws BadPositionCategoryException {
if (canStartBefore && canEndAfter || (!canStartBefore && !canEndAfter)) {
List<TypedPosition> documentPositions;
if (canStartBefore && canEndAfter) {
if (offset < this.contentLength / 2) {
documentPositions = getStartingPositions(category, 0, offset + length);
} else {
documentPositions = getEndingPositions(category, offset, this.contentLength - offset + 1);
}
} else {
documentPositions = getStartingPositions(category, offset, length);
}
final List<TypedPosition> list = new ArrayList<TypedPosition>(documentPositions.size());
final Position region = new Position(offset, length);
for (final TypedPosition position : documentPositions) {
if (isWithinRegion(region, position, canStartBefore, canEndAfter)) {
list.add(position);
}
}
return list;
} else if (canStartBefore) {
final List<TypedPosition> list = getEndingPositions(category, offset, length);
return list;
} else {
Assert.isLegal(canEndAfter && !canStartBefore);
final List<TypedPosition> list = getStartingPositions(category, offset, length);
return list;
}
}
use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class RegionIterator method findNext.
private Annotation findNext() {
while (parentIterator.hasNext()) {
final Annotation next = parentIterator.next();
final Position position = model.getPosition(next);
if (position != null) {
final int offset = position.getOffset();
if (isWithinRegion(offset, position.getLength())) {
return next;
}
}
}
return null;
}
use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class DefaultPartitioner method getFirstIndexStartingAfterOffset.
/**
* Returns the index of the first position which starts at or after the given offset.
*
* @param positions the positions in linear order
* @param offset the offset
* @return the index of the first position which starts after the offset
*/
private static int getFirstIndexStartingAfterOffset(List<TypedPosition> positions, 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() >= offset) {
j = k;
} else {
i = k;
}
}
return j;
}
use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class JavaAnnotationModel method reportProblems.
private void reportProblems(final List<Problem> problems) {
boolean temporaryProblemsChanged = false;
if (!generatedAnnotations.isEmpty()) {
temporaryProblemsChanged = true;
super.clear();
generatedAnnotations.clear();
}
if (reportedProblems != null && !reportedProblems.isEmpty()) {
for (final Problem problem : reportedProblems) {
final Position position = createPositionFromProblem(problem);
if (position != null) {
final ProblemAnnotation annotation = new ProblemAnnotation(problem);
addAnnotation(annotation, position, false);
generatedAnnotations.add(annotation);
temporaryProblemsChanged = true;
}
}
}
if (temporaryProblemsChanged) {
fireModelChanged();
}
}
Aggregations