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);
}
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);
}
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);
}
Aggregations