Search in sources :

Example 11 with XtextDocument

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

the class ReplacingAppendableTest method insertListField.

protected XtextDocument insertListField(final String model, final String fieldName) throws Exception {
    final int cursorPosition = model.indexOf('|');
    String actualModel = model.replace("|", " ");
    final XtendFile file = testHelper.xtendFile("Foo", actualModel);
    final XtextDocument document = documentProvider.get();
    document.set(actualModel);
    XtextResource xtextResource = (XtextResource) file.eResource();
    document.setInput(xtextResource);
    final EObject context = eObjectAtOffsetHelper.resolveElementAt(xtextResource, cursorPosition);
    document.modify(new IUnitOfWork.Void<XtextResource>() {

        @Override
        public void process(XtextResource state) throws Exception {
            ReplacingAppendable a = appendableFactory.create(document, state, cursorPosition, 1);
            ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, context);
            LightweightTypeReference typeRef = owner.toLightweightTypeReference(services.getTypeReferences().getTypeForName(List.class, context, typesFactory.createJvmWildcardTypeReference()));
            a.append(typeRef);
            a.append(" ").append(fieldName);
            a.commitChanges();
        }
    });
    return document;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) XtextResource(org.eclipse.xtext.resource.XtextResource) ReplacingAppendable(org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable) ITypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) EObject(org.eclipse.emf.ecore.EObject) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 12 with XtextDocument

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

the class ReplacingAppendableTest method testImports_5.

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

Example 13 with XtextDocument

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

the class PresentationDamagerTest method createDocument.

@Override
public Document createDocument(final String before) throws Exception {
    XtextDocument _xblockexpression = null;
    {
        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 = () -> {
                return this.createLexer();
            };
            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(before);
        _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) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XtendDocumentTokenSource(org.eclipse.xtend.ide.editor.model.XtendDocumentTokenSource) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) XtendAntlrTokenFileProvider(org.eclipse.xtend.core.parser.antlr.XtendAntlrTokenFileProvider)

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