Search in sources :

Example 91 with IXtextDocument

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);
    }
}
Also used : BadLocationException(org.eclipse.jface.text.BadLocationException) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 92 with IXtextDocument

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;
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 93 with IXtextDocument

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;
}
Also used : XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) DocumentPartitioner(org.eclipse.xtext.ui.editor.model.DocumentPartitioner)

Example 94 with IXtextDocument

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();
    }
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) Shell(org.eclipse.swt.widgets.Shell) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) ContentAssistContext(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext) XtextResource(org.eclipse.xtext.resource.XtextResource) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextSourceViewerConfiguration(org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration)

Example 95 with IXtextDocument

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);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) XtextHyperlink(org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEditorPart(org.eclipse.ui.IEditorPart) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) StringInputStream(org.eclipse.xtext.util.StringInputStream) IJavaProject(org.eclipse.jdt.core.IJavaProject) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Aggregations

IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)147 XtextResource (org.eclipse.xtext.resource.XtextResource)51 Test (org.junit.Test)46 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)38 IFile (org.eclipse.core.resources.IFile)37 BadLocationException (org.eclipse.jface.text.BadLocationException)26 AbstractEditorTest (org.eclipse.xtext.ui.testing.AbstractEditorTest)26 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)25 IModificationContext (org.eclipse.xtext.ui.editor.model.edit.IModificationContext)23 EObject (org.eclipse.emf.ecore.EObject)22 DefaultFoldingRegionProvider (org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider)18 FoldedPosition (org.eclipse.xtext.ui.editor.folding.FoldedPosition)18 Fix (org.eclipse.xtext.ui.editor.quickfix.Fix)16 List (java.util.List)12 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)12 ArrayList (java.util.ArrayList)11 Issue (org.eclipse.xtext.validation.Issue)11 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)10 URI (org.eclipse.emf.common.util.URI)9 IRegion (org.eclipse.jface.text.IRegion)9