use of org.eclipse.jface.text.DefaultPositionUpdater in project che by eclipse.
the class JavaContext method rewriteImports.
private void rewriteImports() {
if (fImportRewrite == null)
return;
if (isReadOnly())
return;
ICompilationUnit cu = getCompilationUnit();
if (cu == null)
return;
try {
Position position = new Position(getCompletionOffset(), 0);
IDocument document = getDocument();
//$NON-NLS-1$
final String category = "__template_position_importer" + System.currentTimeMillis();
IPositionUpdater updater = new DefaultPositionUpdater(category);
document.addPositionCategory(category);
document.addPositionUpdater(updater);
document.addPosition(position);
try {
JavaModelUtil.applyEdit(cu, fImportRewrite.rewriteImports(null), false, null);
setCompletionOffset(position.getOffset());
} catch (CoreException e) {
handleException(null, e);
} finally {
document.removePosition(position);
document.removePositionUpdater(updater);
document.removePositionCategory(category);
}
} catch (BadLocationException e) {
handleException(null, e);
} catch (BadPositionCategoryException e) {
handleException(null, e);
}
}
use of org.eclipse.jface.text.DefaultPositionUpdater 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();
}
}
}
Aggregations