use of org.eclipse.jface.text.BadPositionCategoryException 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.BadPositionCategoryException in project eclipse.platform.text by eclipse.
the class SourceViewer method rememberSelection.
/**
* Remembers and returns the current selection. The saved selection can be restored
* by calling <code>restoreSelection()</code>.
*
* @return the current selection
* @see org.eclipse.jface.text.ITextViewer#getSelectedRange()
* @since 3.0
*/
protected Point rememberSelection() {
final ITextSelection selection = (ITextSelection) getSelection();
final IDocument document = getDocument();
if (fSelections.isEmpty()) {
fSelectionCategory = _SELECTION_POSITION_CATEGORY + hashCode();
fSelectionUpdater = new NonDeletingPositionUpdater(fSelectionCategory);
document.addPositionCategory(fSelectionCategory);
document.addPositionUpdater(fSelectionUpdater);
}
try {
final Position position;
if (selection instanceof IBlockTextSelection)
position = new ColumnPosition(selection.getOffset(), selection.getLength(), ((IBlockTextSelection) selection).getStartColumn(), ((IBlockTextSelection) selection).getEndColumn());
else
position = new Position(selection.getOffset(), selection.getLength());
document.addPosition(fSelectionCategory, position);
fSelections.push(position);
} catch (BadLocationException exception) {
// Should not happen
} catch (BadPositionCategoryException exception) {
// Should not happen
}
return new Point(selection.getOffset(), selection.getLength());
}
use of org.eclipse.jface.text.BadPositionCategoryException in project eclipse.platform.text by eclipse.
the class SourceViewer method restoreSelection.
/**
* Restores a previously saved selection in the document.
* <p>
* If no selection was previously saved, nothing happens.
*
* @since 3.0
*/
protected void restoreSelection() {
if (!fSelections.isEmpty()) {
final IDocument document = getDocument();
final Position position = fSelections.pop();
try {
document.removePosition(fSelectionCategory, position);
Point currentSelection = getSelectedRange();
if (currentSelection == null || currentSelection.x != position.getOffset() || currentSelection.y != position.getLength()) {
if (position instanceof ColumnPosition && getTextWidget().getBlockSelection()) {
setSelection(new BlockTextSelection(document, document.getLineOfOffset(position.getOffset()), ((ColumnPosition) position).fStartColumn, document.getLineOfOffset(position.getOffset() + position.getLength()), ((ColumnPosition) position).fEndColumn, getTextWidget().getTabs()));
} else {
setSelectedRange(position.getOffset(), position.getLength());
}
}
if (fSelections.isEmpty())
clearRememberedSelection();
} catch (BadPositionCategoryException exception) {
// Should not happen
} catch (BadLocationException x) {
// Should not happen
}
}
}
use of org.eclipse.jface.text.BadPositionCategoryException in project eclipse.platform.text by eclipse.
the class SourceViewer method clearRememberedSelection.
protected void clearRememberedSelection() {
if (!fSelections.isEmpty())
fSelections.clear();
IDocument document = getDocument();
if (document != null && fSelectionUpdater != null) {
document.removePositionUpdater(fSelectionUpdater);
try {
document.removePositionCategory(fSelectionCategory);
} catch (BadPositionCategoryException e) {
// ignore
}
}
fSelectionUpdater = null;
fSelectionCategory = null;
}
use of org.eclipse.jface.text.BadPositionCategoryException in project eclipse.platform.text by eclipse.
the class ProjectionMappingTest method addProjection.
private void addProjection(int fragmentOffset, int segmentOffset, int length) {
Fragment fragment = new Fragment(fragmentOffset, length);
Segment segment = new Segment(segmentOffset, length);
fragment.segment = segment;
segment.fragment = fragment;
try {
fMasterDocument.addPosition(fFragmentsCategory, fragment);
fSlaveDocument.addPosition(fSegmentsCategory, segment);
} catch (BadLocationException e) {
assertTrue(false);
} catch (BadPositionCategoryException e) {
assertTrue(false);
}
}
Aggregations