本文整理匯總了Java中org.eclipse.jface.text.IDocument.removePosition方法的典型用法代碼示例。如果您正苦於以下問題:Java IDocument.removePosition方法的具體用法?Java IDocument.removePosition怎麽用?Java IDocument.removePosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jface.text.IDocument
的用法示例。
在下文中一共展示了IDocument.removePosition方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doApply
import org.eclipse.jface.text.IDocument; //導入方法依賴的package包/類
/**
* Really do apply the proposal. Assumed to be run within the prevent flickering mode.
*/
private int doApply(QualifiedName qualifiedName, String alias, IDocument document,
ConfigurableCompletionProposal proposal) throws BadLocationException {
String shortSemanticReplacementString = alias != null ? alias : lastSegmentOrDefaultHost(qualifiedName);
String shortSyntacticReplacementString = valueConverter.toString(shortSemanticReplacementString);
ImportRewriter importRewriter = importRewriterFactory.create(document, context);
ReplaceEdit replaceEdit = new ReplaceEdit(
proposal.getReplacementOffset(),
proposal.getReplacementLength(),
shortSyntacticReplacementString);
MultiTextEdit compound = new MultiTextEdit();
AliasLocation aliasLocation = null;
if (alias != null) {
aliasLocation = importRewriter.addSingleImport(qualifiedName, alias, compound);
} else {
importRewriter.addSingleImport(qualifiedName, compound);
}
compound.addChild(replaceEdit);
Position caret = new Position(proposal.getReplacementOffset(), 0);
document.addPosition(caret);
compound.apply(document);
document.removePosition(caret);
int cursorPosition = caret.getOffset();
proposal.setReplacementOffset(cursorPosition - shortSemanticReplacementString.length());
proposal.setCursorPosition(shortSemanticReplacementString.length());
if (aliasLocation != null) {
final int aliasOffset = aliasLocation.getBaseOffset() + aliasLocation.getRelativeOffset();
final int aliasLength = shortSyntacticReplacementString.length();
N4JSCompletionProposal castedProposal = (N4JSCompletionProposal) proposal;
castedProposal.setLinkedModeBuilder((appliedProposal, currentDocument) -> {
try {
LinkedPositionGroup group = new LinkedPositionGroup();
group.addPosition(new LinkedPosition(
currentDocument,
aliasOffset,
aliasLength,
LinkedPositionGroup.NO_STOP));
group.addPosition(new LinkedPosition(
currentDocument,
proposal.getReplacementOffset(),
proposal.getCursorPosition(),
LinkedPositionGroup.NO_STOP));
proposal.setSelectionStart(proposal.getReplacementOffset());
proposal.setSelectionLength(proposal.getCursorPosition());
LinkedModeModel model = new LinkedModeModel();
model.addGroup(group);
model.forceInstall();
LinkedModeUI ui = new LinkedModeUI(model, viewer);
ui.setExitPolicy(new IdentifierExitPolicy('\n'));
ui.setExitPosition(
viewer,
proposal.getCursorPosition() + proposal.getReplacementOffset(),
0,
Integer.MAX_VALUE);
ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER);
ui.enter();
} catch (BadLocationException e) {
logger.error(e.getMessage(), e);
}
});
}
return cursorPosition;
}