use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class ContentFormatter method format.
@Override
public void format(IDocument document, IRegion region) {
IXtextDocument doc = (IXtextDocument) document;
TextEdit r = doc.priorityReadOnly(new FormattingUnitOfWork(doc, region));
try {
if (r != null)
r.apply(document);
} catch (BadLocationException e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class ContentAssistProcessorTestBuilder method applyProposal.
public ContentAssistProcessorTestBuilder applyProposal(int position, String proposalString) throws Exception {
IXtextDocument document = getDocument(getModel());
Shell shell = new Shell();
try {
ICompletionProposal[] proposals = computeCompletionProposals(document, position, shell);
ICompletionProposal proposal = findProposal(proposalString, proposals);
return applyProposal(proposal, position, document);
} finally {
shell.dispose();
}
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class ContentAssistProcessorTestBuilder method appendAndApplyProposal.
public ContentAssistProcessorTestBuilder appendAndApplyProposal(String model, int position, String proposalString) throws Exception {
IXtextDocument document = getDocument(getModel());
Shell shell = new Shell();
try {
XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
ISourceViewer sourceViewer = getSourceViewer(shell, document, configuration);
ICompletionProposal[] proposals = computeCompletionProposals(document, position, shell);
ICompletionProposal proposal = findProposal(proposalString, proposals);
return appendAndApplyProposal(proposal, sourceViewer, model, position);
} finally {
shell.dispose();
}
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class ToSaveOrNotToSaveTest method renameFooToFooBar.
protected void renameFooToFooBar(final XtextEditor contextEditor) throws Exception {
contextEditor.getEditorSite().getPage().activate(contextEditor);
waitForDisplay();
IXtextDocument document = contextEditor.getDocument();
final int offset = document.get().indexOf("foo");
contextEditor.selectAndReveal(offset, 3);
EvaluationContext evaluationContext = new EvaluationContext(null, new Object());
evaluationContext.addVariable(ISources.ACTIVE_EDITOR_NAME, contextEditor);
ExecutionEvent executionEvent = new ExecutionEvent(null, newHashMap(), null, evaluationContext);
renameElementHandler.execute(executionEvent);
// syncUtil.totalSync(refactoringPreferences.isSaveAllBeforeRefactoring());
// IRenameElementContext context = document.readOnly(new IUnitOfWork<IRenameElementContext, XtextResource>() {
// public IRenameElementContext exec(XtextResource state) throws Exception {
// EObject target = eObjectAtOffsetHelper.resolveElementAt(state, offset);
// return renameContextFactory.createRenameElementContext(target, contextEditor, new TextSelection(offset,
// 3), state);
// }
// });
// controller.initialize(context);
// waitForDisplay();
// controller.startRefactoring(RefactoringType.LINKED_EDITING);
// waitForDisplay();
pressKeys(contextEditor, "fooBar\n");
waitForDisplay();
waitForReconciler(fooEditor);
waitForReconciler(barEditor);
waitForDisplay();
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class XtextDocumentModifyTest method testTextualModification.
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=406811
@Test
public void testTextualModification() throws Exception {
final String grammar = "grammar foo.Foo\n" + "generate foo \"http://foo.net/foo\"\n" + "Foo: 'foo';";
final IXtextDocument document = createDocument(grammar);
document.modify(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
document.replace(grammar.indexOf("Foo"), 3, "Bar");
}
});
assertEquals(grammar.replace("foo.Foo", "foo.Bar"), document.get());
}
Aggregations