use of org.eclipse.che.ide.api.editor.text.BadLocationException in project che by eclipse.
the class AbstractDocument method addPosition.
/*
* @see org.eclipse.jface.text.IDocument#addPosition(java.lang.String, org.eclipse.jface.text.Position)
*/
public void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException {
if (category == null)
throw new BadPositionCategoryException();
if ((0 > position.offset) || (0 > position.length) || (position.offset + position.length > getLength()))
throw new BadLocationException();
List<Position> list = fPositions.get(category);
if (list == null)
throw new BadPositionCategoryException();
list.add(computeIndexInPositionList(list, position.offset, true), position);
List<Position> endPositions = fEndPositions.get(category);
if (endPositions == null)
throw new BadPositionCategoryException();
endPositions.add(computeIndexInPositionList(endPositions, position.offset + position.length - 1, false), position);
}
use of org.eclipse.che.ide.api.editor.text.BadLocationException in project che by eclipse.
the class ListLineTracker method getLineLength.
/* @see org.eclipse.jface.text.ILineTracker#getLineLength(int) */
public final int getLineLength(int line) throws BadLocationException {
int lines = fLines.size();
if (line < 0 || line > lines)
throw new BadLocationException();
if (lines == 0 || lines == line)
return 0;
Line l = (Line) fLines.get(line);
return l.length;
}
use of org.eclipse.che.ide.api.editor.text.BadLocationException in project che by eclipse.
the class ListLineTracker method getLineInformation.
/* @see org.eclipse.jface.text.ILineTracker#getLineInformation(int) */
public final Region getLineInformation(int line) throws BadLocationException {
int lines = fLines.size();
if (line < 0 || line > lines)
throw new BadLocationException();
if (lines == 0)
return new Line(0, 0);
if (line == lines) {
Line l = (Line) fLines.get(line - 1);
return new Line(l.offset + l.length, 0);
}
Line l = (Line) fLines.get(line);
return (l.delimiter != null ? new Line(l.offset, l.length - l.delimiter.length()) : l);
}
use of org.eclipse.che.ide.api.editor.text.BadLocationException in project che by eclipse.
the class DefaultPartitioner method getPartition.
@Override
public TypedRegion getPartition(final int offset) {
final int contentLength = getContentLength();
List<TypedPosition> category = null;
try {
category = getPositions();
} catch (final BadPositionCategoryException e) {
Log.warn(DefaultPartitioner.class, "Invalid position cateory... with default category! ", e);
return defaultRegion();
}
if (category == null || category.size() == 0) {
return defaultRegion();
}
Integer index = null;
try {
index = this.documentPositionMap.computeIndexInCategory(positionCategory, offset);
} catch (final BadLocationException e) {
Log.warn(DefaultPartitioner.class, "Invalid location " + offset + " (max=" + contentLength + ").");
return defaultRegion();
} catch (final BadPositionCategoryException e) {
Log.warn(DefaultPartitioner.class, "Invalid position cateory... with default category " + positionCategory + "!", e);
return defaultRegion();
}
if (index == null) {
return defaultRegion();
}
if (index < category.size()) {
final TypedPosition next = category.get(index);
if (offset == next.offset) {
return new TypedRegionImpl(next.getOffset(), next.getLength(), next.getType());
}
if (index == 0) {
return new TypedRegionImpl(0, next.offset, DEFAULT_CONTENT_TYPE);
}
final TypedPosition previous = category.get(index - 1);
if (previous.includes(offset)) {
return new TypedRegionImpl(previous.getOffset(), previous.getLength(), previous.getType());
}
final int endOffset = previous.getOffset() + previous.getLength();
return new TypedRegionImpl(endOffset, next.getOffset() - endOffset, DEFAULT_CONTENT_TYPE);
}
final TypedPosition previous = category.get(category.size() - 1);
if (previous.includes(offset)) {
return new TypedRegionImpl(previous.getOffset(), previous.getLength(), previous.getType());
}
final int endOffset = previous.getOffset() + previous.getLength();
return new TypedRegionImpl(endOffset, contentLength - endOffset, DEFAULT_CONTENT_TYPE);
}
use of org.eclipse.che.ide.api.editor.text.BadLocationException 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);
}
}
Aggregations