Search in sources :

Example 6 with XtextDocument

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

the class DocumentRewriterTest method createDocument.

protected XtextDocument createDocument(final String content) throws Exception {
    XtextDocument _xblockexpression = null;
    {
        final IFile file = this._workbenchTestHelper.createFile("Foo", content);
        final Resource resource = this._workbenchTestHelper.getResourceSet().getResource(URI.createPlatformResourceURI(file.getFullPath().toString(), true), true);
        XtendDocumentTokenSource _xtendDocumentTokenSource = new XtendDocumentTokenSource();
        final Procedure1<XtendDocumentTokenSource> _function = (XtendDocumentTokenSource it) -> {
            AntlrTokenDefProvider _antlrTokenDefProvider = new AntlrTokenDefProvider();
            final Procedure1<AntlrTokenDefProvider> _function_1 = (AntlrTokenDefProvider it_1) -> {
                XtendAntlrTokenFileProvider _xtendAntlrTokenFileProvider = new XtendAntlrTokenFileProvider();
                it_1.setAntlrTokenFileProvider(_xtendAntlrTokenFileProvider);
            };
            AntlrTokenDefProvider _doubleArrow = ObjectExtensions.<AntlrTokenDefProvider>operator_doubleArrow(_antlrTokenDefProvider, _function_1);
            it.setTokenDefProvider(_doubleArrow);
            final Provider<Lexer> _function_2 = () -> {
                InternalXtendLexer _internalXtendLexer = new InternalXtendLexer();
                return ((Lexer) _internalXtendLexer);
            };
            it.setLexer(_function_2);
            it.setFlexerFactory(this.flexerFactory);
        };
        final XtendDocumentTokenSource source = ObjectExtensions.<XtendDocumentTokenSource>operator_doubleArrow(_xtendDocumentTokenSource, _function);
        final XtextDocument document = new XtextDocument(source, null, this.outdatedStateManager, this.operationCanceledManager);
        document.set(content);
        document.setInput(((XtextResource) resource));
        _xblockexpression = document;
    }
    return _xblockexpression;
}
Also used : AntlrTokenDefProvider(org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider) InternalXtendLexer(org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer) Lexer(org.eclipse.xtext.parser.antlr.Lexer) IFile(org.eclipse.core.resources.IFile) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtendDocumentTokenSource(org.eclipse.xtend.ide.editor.model.XtendDocumentTokenSource) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) XtendAntlrTokenFileProvider(org.eclipse.xtend.core.parser.antlr.XtendAntlrTokenFileProvider) InternalXtendLexer(org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer)

Example 7 with XtextDocument

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

the class ImportAwareActionTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    this.document = this.<XtextDocument>get(XtextDocument.class);
    IDocumentPartitioner partitioner = this.<IDocumentPartitioner>get(IDocumentPartitioner.class);
    partitioner.connect(this.document);
    this.document.setDocumentPartitioner(partitioner);
}
Also used : IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument)

Example 8 with XtextDocument

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

the class AbstractOutlineTests method newAssertBuilder.

protected AssertBuilder newAssertBuilder(XtendFile xtendFile) throws Exception, CoreException {
    XtextDocument document = documentProvider.get();
    document.setInput((XtextResource) xtendFile.eResource());
    IOutlineNode root = treeProvider.createRoot(document);
    AssertBuilder assertBuilder = new AssertBuilder(root);
    return assertBuilder;
}
Also used : XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) IOutlineNode(org.eclipse.xtext.ui.editor.outline.IOutlineNode)

Example 9 with XtextDocument

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

the class XtendFormatterPreview method doUpdate.

@SuppressWarnings("deprecation")
public void doUpdate(final Map<String, String> map) {
    checkEditorHandleIsSet();
    final MapBasedPreferenceValues values = new MapBasedPreferenceValues(map);
    String maxLineWidthValue = values.getPreference(maxLineWidth);
    if (maxLineWidthValue != null) {
        moveMarginToColumn(maxLineWidthValue);
    }
    StyledText widget = null;
    try {
        widget = (StyledText) editorHandle.getViewer().getControl();
        // disable redraw, otherwise this would causes funny animation effects during formating.
        widget.setRedraw(false);
        this.modelAccess.updateModel("", previewContent, "");
        XtextDocument document = editorHandle.getDocument();
        ContentFormatter formatter = formatterProvider.get();
        formatter.setPreferencesProvider(values);
        formatter.format(document, new Region(0, document.getLength()));
        // reset selection, otherwise the whole new content will be selected
        editorHandle.getViewer().setSelection(null);
    } finally {
        if (widget != null)
            widget.setRedraw(true);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) Region(org.eclipse.jface.text.Region) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) ContentFormatter(org.eclipse.xtext.ui.editor.formatting2.ContentFormatter)

Example 10 with XtextDocument

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

the class ReplacingAppendableTest method testImports_4.

@Test
public void testImports_4() throws Exception {
    final XtextDocument document = insertListField("package test\n" + "/**\n" + "*/\n" + "\n" + "class Foo {|}", "foo");
    assertEqualsIgnoreWhitespace("package test\n" + "\n" + "import java.util.List\n" + "\n" + "/**\n" + "*/\n" + "\n" + "class Foo {List<?> foo}", document.get());
}
Also used : XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) Test(org.junit.Test)

Aggregations

XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)13 Test (org.junit.Test)7 XtendAntlrTokenFileProvider (org.eclipse.xtend.core.parser.antlr.XtendAntlrTokenFileProvider)2 InternalXtendLexer (org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer)2 XtendDocumentTokenSource (org.eclipse.xtend.ide.editor.model.XtendDocumentTokenSource)2 AntlrTokenDefProvider (org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider)2 Lexer (org.eclipse.xtext.parser.antlr.Lexer)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)2 IFile (org.eclipse.core.resources.IFile)1 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)1 Region (org.eclipse.jface.text.Region)1 StyledText (org.eclipse.swt.custom.StyledText)1 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)1 MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)1 ContentFormatter (org.eclipse.xtext.ui.editor.formatting2.ContentFormatter)1 IOutlineNode (org.eclipse.xtext.ui.editor.outline.IOutlineNode)1 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)1