use of org.eclipse.xtext.xbase.ui.document.DocumentRewriter in project xtext-xtend by eclipse.
the class DocumentRewriterTest method testInsertExistingType.
@Test
public void testInsertExistingType() {
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("}");
_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);
beforeFoo.append(this.services.getTypeReferences().findDeclaredType(Serializable.class, r));
beforeFoo.append(" ");
};
String _rewrite = this.rewrite(model, _function);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("import java.io.Serializable");
_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 Serializable foo() {}");
_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 testEmptyLinesAround.
@Test
public void testEmptyLinesAround() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("def foo() {}");
_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 beforeDefBar = it.newSection(model.indexOf("def bar"), 0, true);
beforeDefBar.append("val x = 42");
};
String _rewrite = this.rewrite(model, _function);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("class Foo {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def foo() {}");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("val x = 42");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def 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 testInsertText.
@Test
public void testInsertText() {
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) -> {
it.newSection(model.indexOf("class"), 0).append("abstract ");
it.newSection(model.indexOf("foo"), 0).append("static ");
it.newSection(model.indexOf("bar"), 0).append("private int ");
it.newSection(model.lastIndexOf("{}"), 2).append("{ 42 }");
};
String _rewrite = this.rewrite(model, _function);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("abstract class Foo {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def static foo() {}");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def private int bar() { 42 }");
_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 testWhitespaces.
@Test
public void testWhitespaces() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("def foo() {}");
_builder.newLine();
_builder.append("\t");
_builder.append("def bar() {");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String model = _builder.toString();
final Procedure2<DocumentRewriter, XtextResource> _function = (DocumentRewriter it, XtextResource r) -> {
int _indexOf = model.indexOf("{}");
int _plus = (_indexOf + 3);
it.newSection(_plus, 0, true).append("val x = 42");
int _lastIndexOf = model.lastIndexOf("{\n");
int _plus_1 = (_lastIndexOf + 1);
it.newSection(_plus_1, 0, 2, true).append("val y = 43");
int _indexOf_1 = model.indexOf("\t}");
int _plus_2 = (_indexOf_1 + 2);
it.newSection(_plus_2, 0, true).append("val z = 44");
};
String _rewrite = this.rewrite(model, _function);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("class Foo {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def foo() {}");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("val x = 42");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def bar() {");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("val y = 43");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("val z = 44");
_builder_1.newLine();
_builder_1.append("\t");
_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 testSectionOverlap.
@Test
public void testSectionOverlap() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("//***********");
_builder.newLine();
final Procedure2<DocumentRewriter, XtextResource> _function = (DocumentRewriter it, XtextResource r) -> {
it.newSection(3, 1).append("one");
it.newSection(4, 2).append("two");
it.newSection(6, 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("//*onetwothree******");
_builder_1.newLine();
this.andExpect(_rewrite, _builder_1);
}
Aggregations