use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class AbstractFoldingTest method openInEditor.
protected IXtextDocument openInEditor(IFile dslFile) {
try {
IXtextDocument document = openEditor(dslFile).getDocument();
assertNotNull(document);
return document;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class AbstractQuickfixTest method getDocument.
/**
* The implementation of the following helper methods are taken from the
* {@code org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder} class.
*/
protected IXtextDocument getDocument(String model) {
XtextResource xtextResource = getXtextResource(model);
XtextDocument document = injector.getInstance(XtextDocument.class);
document.set(model);
document.setInput(xtextResource);
return document;
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class ContentAssistProcessorTestBuilder method getDocument.
public IXtextDocument getDocument(final XtextResource xtextResource, final String model) {
XtextDocument document = get(XtextDocument.class);
document.set(model);
document.setInput(xtextResource);
DocumentPartitioner partitioner = get(DocumentPartitioner.class);
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
return document;
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class ContentAssistProcessorTestBuilder method assertMatchString.
public ContentAssistProcessorTestBuilder assertMatchString(String matchString) throws Exception {
String currentModelToParse = getModel();
final XtextResource xtextResource = loadHelper.getResourceFor(new StringInputStream(currentModelToParse, getEncoding()));
final IXtextDocument xtextDocument = getDocument(xtextResource, currentModelToParse);
XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
Shell shell = new Shell();
try {
ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument, configuration);
IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
String contentType = xtextDocument.getContentType(currentModelToParse.length());
if (contentAssistant.getContentAssistProcessor(contentType) != null) {
ContentAssistContext.Factory factory = get(ContentAssistContext.Factory.class);
ContentAssistContext[] contexts = factory.create(sourceViewer, currentModelToParse.length(), xtextResource);
for (ContentAssistContext context : contexts) {
Assert.assertTrue("matchString = '" + matchString + "', actual: '" + context.getPrefix() + "'", "".equals(context.getPrefix()) || matchString.equals(context.getPrefix()));
}
} else {
Assert.fail("No content assistant for content type " + contentType);
}
return this;
} finally {
shell.dispose();
}
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class ImportURINavigationTest method doTestNavigation.
protected void doTestNavigation(IUnitOfWork<URI, IFile> uriComputation, boolean expectFQN) throws Exception {
IJavaProject project = JavaProjectSetupUtil.createJavaProject("importuriuitestlanguage.project");
try {
IFile first = project.getProject().getFile("src/first.importuriuitestlanguage");
first.create(new StringInputStream("type ASimpleType"), true, null);
ResourceSet resourceSet = resourceSetProvider.get(project.getProject());
Resource resource = resourceFactory.createResource(URI.createURI("synthetic://second.importuriuitestlanguage"));
resourceSet.getResources().add(resource);
String model = "import '" + uriComputation.exec(first) + "' type MyType extends ASimpleType";
resource.load(new StringInputStream(model), null);
EcoreUtil.resolveAll(resource);
Assert.assertTrue(resource.getErrors().isEmpty());
IHyperlink[] hyperlinks = helper.createHyperlinksByOffset((XtextResource) resource, model.indexOf("SimpleType"), false);
Assert.assertEquals(1, hyperlinks.length);
IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
Assert.assertNull(activePage.getActiveEditor());
if (expectFQN) {
Assert.assertEquals(URI.createURI(first.getLocationURI().toString()), ((XtextHyperlink) hyperlinks[0]).getURI().trimFragment());
} else {
Assert.assertEquals(URI.createPlatformResourceURI(first.getFullPath().toString(), true), ((XtextHyperlink) hyperlinks[0]).getURI().trimFragment());
}
hyperlinks[0].open();
IEditorPart editor = activePage.getActiveEditor();
Assert.assertNotNull(editor);
IXtextDocument document = xtextDocumentUtil.getXtextDocument(editor);
document.readOnly(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
Assert.assertEquals("platform:/resource/importuriuitestlanguage.project/src/first.importuriuitestlanguage", state.getURI().toString());
}
});
Assert.assertEquals("type ASimpleType", document.get());
IEditorPart newPart = IDE.openEditor(activePage, first);
Assert.assertEquals(1, activePage.getEditorReferences().length);
Assert.assertEquals(editor, newPart);
} finally {
project.getProject().delete(true, null);
}
}
Aggregations