本文整理汇总了Java中org.eclipse.jface.text.IDocument.addPosition方法的典型用法代码示例。如果您正苦于以下问题:Java IDocument.addPosition方法的具体用法?Java IDocument.addPosition怎么用?Java IDocument.addPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.IDocument
的用法示例。
在下文中一共展示了IDocument.addPosition方法的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;
}