Search in sources :

Example 6 with DocumentRewriter

use of org.eclipse.xtext.xbase.ui.document.DocumentRewriter in project xtext-xtend by eclipse.

the class DocumentRewriterTest method testInsertTypesImportsSorted.

@Test
public void testInsertTypesImportsSorted() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import java.io.Serializable");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo implements Serializable {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo() {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def bar() {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String model = _builder.toString();
    final Procedure2<DocumentRewriter, XtextResource> _function = (DocumentRewriter it, XtextResource r) -> {
        final DocumentRewriter.Section beforeFoo = it.newSection(model.indexOf("foo"), 0);
        final DocumentRewriter.Section beforeBar = it.newSection(model.indexOf("bar"), 0);
        final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, r);
        final JvmTypeReference list = this.services.getTypeReferences().getTypeForName(List.class, r, this._typesFactory.createJvmWildcardTypeReference());
        beforeFoo.append(owner.toLightweightTypeReference(list));
        beforeBar.append(owner.toLightweightTypeReference(this.services.getTypeReferences().getTypeForName(File.class, r)));
        beforeFoo.append(" ");
        beforeBar.append(" ");
    };
    String _rewrite = this.rewrite(model, _function);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import java.io.File");
    _builder_1.newLine();
    _builder_1.append("import java.io.Serializable");
    _builder_1.newLine();
    _builder_1.append("import java.util.List");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class Foo implements Serializable {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def List<?> foo() {}");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def File bar() {}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.andExpect(_rewrite, _builder_1);
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) DocumentRewriter(org.eclipse.xtext.xbase.ui.document.DocumentRewriter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) List(java.util.List) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 7 with DocumentRewriter

use of org.eclipse.xtext.xbase.ui.document.DocumentRewriter in project xtext-xtend by eclipse.

the class DocumentRewriterTest method testSectionOrderIrrelevant.

@Test
public void testSectionOrderIrrelevant() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("//***********");
    _builder.newLine();
    final Procedure2<DocumentRewriter, XtextResource> _function = (DocumentRewriter it, XtextResource r) -> {
        it.newSection(6, 1).append("one");
        it.newSection(4, 2).append("two");
        it.newSection(3, 1).append("three");
        final Procedure1<DocumentRewriter> _function_1 = (DocumentRewriter it_1) -> {
            it_1.newSection(4, 2);
        };
        this.assertFails(it, _function_1);
        final Procedure1<DocumentRewriter> _function_2 = (DocumentRewriter it_1) -> {
            it_1.newSection(5, 0);
        };
        this.assertFails(it, _function_2);
        final Procedure1<DocumentRewriter> _function_3 = (DocumentRewriter it_1) -> {
            it_1.newSection(5, 1);
        };
        this.assertFails(it, _function_3);
        final Procedure1<DocumentRewriter> _function_4 = (DocumentRewriter it_1) -> {
            it_1.newSection(5, 2);
        };
        this.assertFails(it, _function_4);
        final Procedure1<DocumentRewriter> _function_5 = (DocumentRewriter it_1) -> {
            it_1.newSection(6, 0);
        };
        this.assertFails(it, _function_5);
        final Procedure1<DocumentRewriter> _function_6 = (DocumentRewriter it_1) -> {
            it_1.newSection(6, 1);
        };
        this.assertFails(it, _function_6);
        final Procedure1<DocumentRewriter> _function_7 = (DocumentRewriter it_1) -> {
            it_1.newSection(6, 2);
        };
        this.assertFails(it, _function_7);
    };
    String _rewrite = this.rewrite(_builder, _function);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("//*threetwoone******");
    _builder_1.newLine();
    this.andExpect(_rewrite, _builder_1);
}
Also used : DocumentRewriter(org.eclipse.xtext.xbase.ui.document.DocumentRewriter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 8 with DocumentRewriter

use of org.eclipse.xtext.xbase.ui.document.DocumentRewriter in project xtext-xtend by eclipse.

the class DocumentRewriterTest method testInsertTypesWithOverlappingImports.

@Test
public void testInsertTypesWithOverlappingImports() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo() {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def bar() {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String model = _builder.toString();
    final Procedure2<DocumentRewriter, XtextResource> _function = (DocumentRewriter it, XtextResource r) -> {
        final DocumentRewriter.Section beforeFoo = it.newSection(model.indexOf("foo"), 0);
        final DocumentRewriter.Section beforeBar = it.newSection(model.indexOf("bar"), 0);
        final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, r);
        beforeFoo.append(owner.toLightweightTypeReference(this.services.getTypeReferences().getTypeForName(List.class, r, this.services.getTypeReferences().getTypeForName(String.class, r))));
        beforeBar.append(owner.toLightweightTypeReference(this.services.getTypeReferences().getTypeForName(List.class, r, this.services.getTypeReferences().getTypeForName(File.class, r))));
        beforeFoo.append(" ");
        beforeBar.append(" ");
    };
    String _rewrite = this.rewrite(model, _function);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import java.io.File");
    _builder_1.newLine();
    _builder_1.append("import java.util.List");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class Foo {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def List<String> foo() {}");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def List<File> bar() {}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.andExpect(_rewrite, _builder_1);
}
Also used : DocumentRewriter(org.eclipse.xtext.xbase.ui.document.DocumentRewriter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) List(java.util.List) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner) Test(org.junit.Test)

Aggregations

StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)8 XtextResource (org.eclipse.xtext.resource.XtextResource)8 DocumentRewriter (org.eclipse.xtext.xbase.ui.document.DocumentRewriter)8 Test (org.junit.Test)8 List (java.util.List)2 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)2 StandardTypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)2 File (java.io.File)1 IFile (org.eclipse.core.resources.IFile)1 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)1