use of org.eclipse.xtext.ide.server.Document in project xtext-core by eclipse.
the class DocumentTest method testOffSet.
@Test
public void testOffSet() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hello world");
_builder.newLine();
_builder.append("foo");
_builder.newLine();
_builder.append("bar");
_builder.newLine();
String _normalize = this.normalize(_builder);
Document _document = new Document(1, _normalize);
final Procedure1<Document> _function = (Document it) -> {
Assert.assertEquals(0, it.getOffSet(this.position(0, 0)));
Assert.assertEquals(11, it.getOffSet(this.position(0, 11)));
try {
it.getOffSet(this.position(0, 12));
Assert.fail();
} catch (final Throwable _t) {
if (_t instanceof IndexOutOfBoundsException) {
} else {
throw Exceptions.sneakyThrow(_t);
}
}
Assert.assertEquals(12, it.getOffSet(this.position(1, 0)));
Assert.assertEquals(13, it.getOffSet(this.position(1, 1)));
Assert.assertEquals(14, it.getOffSet(this.position(1, 2)));
Assert.assertEquals(16, it.getOffSet(this.position(2, 0)));
Assert.assertEquals(19, it.getOffSet(this.position(2, 3)));
};
ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
use of org.eclipse.xtext.ide.server.Document in project xtext-core by eclipse.
the class FormattingTest method doTestAPIMaintenanceLayer.
private void doTestAPIMaintenanceLayer(final FormattingService fs) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Foo{int bar} type Bar{Foo foo}");
final String model = _builder.toString();
final XtextResourceSet rs = this.rsp.get();
Resource _createResource = rs.createResource(URI.createURI("dummy.testlang"));
final XtextResource r = ((XtextResource) _createResource);
StringInputStream _stringInputStream = new StringInputStream(model);
r.load(_stringInputStream, null);
try {
Document _document = new Document(1, model);
DocumentFormattingParams _documentFormattingParams = new DocumentFormattingParams();
fs.format(_document, r, _documentFormattingParams, CancelIndicator.NullImpl);
Assert.fail("IllegalStateException expected");
} catch (final Throwable _t) {
if (_t instanceof IllegalStateException) {
final IllegalStateException e = (IllegalStateException) _t;
String _message = e.getMessage();
boolean _notEquals = (!Objects.equal(_message, "api maintenance layer broken"));
if (_notEquals) {
throw e;
}
} else {
throw Exceptions.sneakyThrow(_t);
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations