Search in sources :

Example 16 with XtextDocument

use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.

the class XtextReconciler method run.

@Override
protected IStatus run(final IProgressMonitor monitor) {
    if (monitor.isCanceled() || paused)
        return Status.CANCEL_STATUS;
    if (pendingChanges.isEmpty()) {
        return Status.OK_STATUS;
    }
    long start = System.currentTimeMillis();
    final IXtextDocument document = xtextDocumentUtil.getXtextDocument(textViewer);
    if (document instanceof XtextDocument) {
        ((XtextDocument) document).internalModify(new IUnitOfWork.Void<XtextResource>() {

            @Override
            public void process(XtextResource state) throws Exception {
                doRun(state, monitor);
            }
        });
    }
    if (monitor.isCanceled()) {
        return Status.CANCEL_STATUS;
    }
    if (log.isDebugEnabled())
        // $NON-NLS-1$
        log.debug("Reconciliation finished. Time required: " + (System.currentTimeMillis() - start));
    return Status.OK_STATUS;
}
Also used : IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextResource(org.eclipse.xtext.resource.XtextResource) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 17 with XtextDocument

use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.

the class XbaseDocumentProvider method setDocumentContent.

@Override
protected boolean setDocumentContent(IDocument document, IEditorInput input, String encoding) throws CoreException {
    if (input instanceof IClassFileEditorInput && document instanceof XtextDocument) {
        IClassFile classFile = ((IClassFileEditorInput) input).getClassFile();
        ILocationInEclipseResource source = getClassFileSourceStorage(classFile);
        if (source == null) {
            return false;
        }
        InputStream contents = null;
        try {
            contents = source.getContents();
            if (contents != null)
                setDocumentContent(document, contents, encoding);
        } catch (WrappedCoreException e) {
            throw e.getCause();
        } catch (IOException e) {
            throw new CoreException(new Status(IStatus.ERROR, plugin.getBundle().getSymbolicName(), e.getMessage(), e));
        } finally {
            try {
                if (contents != null)
                    contents.close();
            } catch (IOException e1) {
            }
        }
        setDocumentResource((XtextDocument) document, input, encoding);
        return true;
    }
    return super.setDocumentContent(document, input, encoding);
}
Also used : ILocationInEclipseResource(org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IClassFile(org.eclipse.jdt.core.IClassFile) CoreException(org.eclipse.core.runtime.CoreException) WrappedCoreException(org.eclipse.xtext.ui.generator.trace.WrappedCoreException) InputStream(java.io.InputStream) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) WrappedCoreException(org.eclipse.xtext.ui.generator.trace.WrappedCoreException) IOException(java.io.IOException) IClassFileEditorInput(org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput)

Example 18 with XtextDocument

use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.

the class XtextOutlineTreeProviderTest method assertNoException.

protected IOutlineNode assertNoException(String model) throws Exception {
    try {
        XtextResource resource = getResourceAndExpect(new StringInputStream(model), UNKNOWN_EXPECTATION);
        XtextDocument document = documentProvider.get();
        document.setInput(resource);
        IOutlineNode root = treeProvider.createRoot(document);
        traverseChildren(root);
        return root;
    } catch (Exception exc) {
        exc.printStackTrace();
        fail("Exception in outline tree construction");
    }
    // unreachable
    return null;
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResource(org.eclipse.xtext.resource.XtextResource) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) IOutlineNode(org.eclipse.xtext.ui.editor.outline.IOutlineNode)

Example 19 with XtextDocument

use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.

the class XtextDocumentModifyTest method createDocument.

private IXtextDocument createDocument(String model) throws Exception {
    resource = getResource(new StringInputStream(model));
    DocumentTokenSource tokenSource = new DocumentTokenSource();
    tokenSource.setLexer(new Provider<Lexer>() {

        @Override
        public Lexer get() {
            return new InternalXtextLexer();
        }
    });
    final XtextDocument document = new XtextDocument(tokenSource, get(ITextEditComposer.class), new OutdatedStateManager(), new OperationCanceledManager()) {

        @Override
        public <T> T internalModify(IUnitOfWork<T, XtextResource> work) {
            try {
                return work.exec((XtextResource) resource);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    document.set(model);
    return document;
}
Also used : OutdatedStateManager(org.eclipse.xtext.resource.OutdatedStateManager) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) ITextEditComposer(org.eclipse.xtext.ui.editor.model.edit.ITextEditComposer) OperationCanceledManager(org.eclipse.xtext.service.OperationCanceledManager) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) StringInputStream(org.eclipse.xtext.util.StringInputStream) InternalXtextLexer(org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer) Lexer(org.eclipse.xtext.parser.antlr.Lexer) DocumentTokenSource(org.eclipse.xtext.ui.editor.model.DocumentTokenSource) InternalXtextLexer(org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer)

Example 20 with XtextDocument

use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.

the class DocumentLockerTest method testModifySetsOutdatedFalse.

@Test
public void testModifySetsOutdatedFalse() {
    XtextDocument document = new XtextDocument(createTokenSource(), createTextEditComposer(), outdatedStateManager, operationCanceledManager);
    XtextResource resource = new XtextResource();
    new XtextResourceSet().getResources().add(resource);
    document.setInput(resource);
    document.internalModify((XtextResource it) -> {
        Assert.assertFalse(document.getCancelIndicator().isCanceled());
        return null;
    });
    CancelIndicator indicator = document.getCancelIndicator();
    Assert.assertFalse(indicator.isCanceled());
    document.set("fupp");
    Assert.assertTrue(indicator.isCanceled());
    document.internalModify((XtextResource it) -> {
        Assert.assertFalse(document.getCancelIndicator().isCanceled());
        return null;
    });
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) XtextResource(org.eclipse.xtext.resource.XtextResource) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) Test(org.junit.Test)

Aggregations

XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)50 Test (org.junit.Test)21 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)14 XtextResource (org.eclipse.xtext.resource.XtextResource)13 Lexer (org.eclipse.xtext.parser.antlr.Lexer)9 DocumentTokenSource (org.eclipse.xtext.ui.editor.model.DocumentTokenSource)8 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)5 AntlrTokenDefProvider (org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider)4 DocumentPartitioner (org.eclipse.xtext.ui.editor.model.DocumentPartitioner)4 IOutlineNode (org.eclipse.xtext.ui.editor.outline.IOutlineNode)4 ArrayList (java.util.ArrayList)3 Job (org.eclipse.core.runtime.jobs.Job)3 IDocument (org.eclipse.jface.text.IDocument)3 ITypedRegion (org.eclipse.jface.text.ITypedRegion)3 CancelIndicator (org.eclipse.xtext.util.CancelIndicator)3 StringInputStream (org.eclipse.xtext.util.StringInputStream)3 Injector (com.google.inject.Injector)2 IFile (org.eclipse.core.resources.IFile)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2