use of org.eclipse.jface.text.BadPositionCategoryException in project linuxtools by eclipse.
the class SpecfileContentProvider method inputChanged.
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if (oldInput != null) {
IDocument document = documentProvider.getDocument(oldInput);
if (document != null) {
try {
document.removePositionCategory(SECTION_POSITIONS);
} catch (BadPositionCategoryException x) {
}
document.removePositionUpdater(positionUpdater);
}
}
if (newInput != null) {
IDocument document = documentProvider.getDocument(newInput);
if (document != null) {
document.addPositionCategory(SECTION_POSITIONS);
document.addPositionUpdater(positionUpdater);
specfile = new SpecfileParser().parse(document);
}
}
}
use of org.eclipse.jface.text.BadPositionCategoryException in project che by eclipse.
the class DocumentCommand method execute.
/**
* Executes the document commands on a document.
*
* @param document the document on which to execute the commands
* @throws BadLocationException in case access to the given document fails
* @since 2.1
*/
void execute(IDocument document) throws BadLocationException {
if (length == 0 && text == null && fCommands.size() == 0)
return;
DefaultPositionUpdater updater = new DefaultPositionUpdater(getCategory());
Position caretPosition = null;
try {
if (updateCaret()) {
document.addPositionCategory(getCategory());
document.addPositionUpdater(updater);
caretPosition = new Position(caretOffset);
document.addPosition(getCategory(), caretPosition);
}
final Command originalCommand = new Command(offset, length, text, owner);
for (final Iterator iterator = new CommandIterator(fCommands, originalCommand, false); iterator.hasNext(); ) ((Command) iterator.next()).execute(document);
} catch (BadLocationException e) {
// ignore
} catch (BadPositionCategoryException e) {
// ignore
} finally {
if (updateCaret()) {
document.removePositionUpdater(updater);
try {
document.removePositionCategory(getCategory());
} catch (BadPositionCategoryException e) {
Assert.isTrue(false);
}
caretOffset = caretPosition.getOffset();
}
}
}
use of org.eclipse.jface.text.BadPositionCategoryException in project che by eclipse.
the class FastPartitioner method initialize.
/**
* Performs the initial partitioning of the partitioner's document.
* <p>
* May be extended by subclasses.
* </p>
*/
protected void initialize() {
fIsInitialized = true;
clearPositionCache();
fScanner.setRange(fDocument, 0, fDocument.getLength());
try {
IToken token = fScanner.nextToken();
while (!token.isEOF()) {
String contentType = getTokenContentType(token);
if (isSupportedContentType(contentType)) {
TypedPosition p = new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType);
fDocument.addPosition(fPositionCategory, p);
}
token = fScanner.nextToken();
}
} catch (BadLocationException x) {
// cannot happen as offsets come from scanner
} catch (BadPositionCategoryException x) {
// cannot happen if document has been connected before
}
}
use of org.eclipse.jface.text.BadPositionCategoryException in project che by eclipse.
the class NonDeletingPositionUpdater method update.
/*
* @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent)
*/
public void update(DocumentEvent event) {
int eventOffset = event.getOffset();
int eventOldEndOffset = eventOffset + event.getLength();
int eventNewLength = event.getText() == null ? 0 : event.getText().length();
int eventNewEndOffset = eventOffset + eventNewLength;
int deltaLength = eventNewLength - event.getLength();
try {
Position[] positions = event.getDocument().getPositions(fCategory);
for (int i = 0; i != positions.length; i++) {
Position position = positions[i];
if (position.isDeleted())
continue;
int offset = position.getOffset();
int length = position.getLength();
int end = offset + length;
if (offset > eventOldEndOffset) {
// position comes way after change - shift
position.setOffset(offset + deltaLength);
} else if (end < eventOffset) {
// position comes way before change - leave alone
} else if (offset <= eventOffset && end >= eventOldEndOffset) {
// event completely internal to the position - adjust length
position.setLength(length + deltaLength);
} else if (offset < eventOffset) {
// event extends over end of position - include the
// replacement text into the position
position.setLength(eventNewEndOffset - offset);
} else if (end > eventOldEndOffset) {
// event extends from before position into it - adjust
// offset and length, including the replacement text into
// the position
position.setOffset(eventOffset);
int deleted = eventOldEndOffset - offset;
position.setLength(length - deleted + eventNewLength);
} else {
// event comprises the position - keep it at the same
// position, but always inside the replacement text
int newOffset = Math.min(offset, eventNewEndOffset);
int newEndOffset = Math.min(end, eventNewEndOffset);
position.setOffset(newOffset);
position.setLength(newEndOffset - newOffset);
}
}
} catch (BadPositionCategoryException e) {
// ignore and return
}
}
use of org.eclipse.jface.text.BadPositionCategoryException in project che by eclipse.
the class ExclusivePositionUpdater method update.
/*
* @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent)
*/
public void update(DocumentEvent event) {
int eventOffset = event.getOffset();
int eventOldLength = event.getLength();
int eventNewLength = event.getText() == null ? 0 : event.getText().length();
int deltaLength = eventNewLength - eventOldLength;
try {
Position[] positions = event.getDocument().getPositions(fCategory);
for (int i = 0; i != positions.length; i++) {
Position position = positions[i];
if (position.isDeleted())
continue;
int offset = position.getOffset();
int length = position.getLength();
int end = offset + length;
if (offset >= eventOffset + eventOldLength)
// position comes
// after change - shift
position.setOffset(offset + deltaLength);
else if (end <= eventOffset) {
// position comes way before change -
// leave alone
} else if (offset <= eventOffset && end >= eventOffset + eventOldLength) {
// event completely internal to the position - adjust length
position.setLength(length + deltaLength);
} else if (offset < eventOffset) {
// event extends over end of position - adjust length
int newEnd = eventOffset;
position.setLength(newEnd - offset);
} else if (end > eventOffset + eventOldLength) {
// event extends from before position into it - adjust offset
// and length
// offset becomes end of event, length adjusted accordingly
int newOffset = eventOffset + eventNewLength;
position.setOffset(newOffset);
position.setLength(end - newOffset);
} else {
// event consumes the position - delete it
position.delete();
}
}
} catch (BadPositionCategoryException e) {
// ignore and return
}
}
Aggregations