use of org.eclipse.xtext.serializer.ISerializer in project xtext-core by eclipse.
the class GrammarAccessExtensions method getSerializer.
private ISerializer getSerializer() {
final String delimiter = this.codeConfig.getLineDelimiter();
ISerializer result = this.xtextSerializerByLineDelimiter.get(delimiter);
if ((result != null)) {
return result;
}
final ILineSeparatorInformation _function = () -> {
return delimiter;
};
GrammarAccessExtensions.LineSeparatorModule _lineSeparatorModule = new GrammarAccessExtensions.LineSeparatorModule(_function);
final Injector injector = Guice.createInjector(_lineSeparatorModule);
result = injector.<ISerializer>getInstance(ISerializer.class);
this.xtextSerializerByLineDelimiter.put(delimiter, result);
return result;
}
use of org.eclipse.xtext.serializer.ISerializer in project xtext-core by eclipse.
the class DefaultTerminalConverterTest method testSerializeAndReparse.
@Test
public void testSerializeAndReparse() throws Exception {
int intValue = 34786482;
double doubleValue = 2.32E-17;
Date dateValue = new SimpleDateFormat("YYYY-MM-DD").parse("2010-05-25");
Model model = EcoreTerminalsTestLanguageFactory.eINSTANCE.createModel();
model.getIntValues().add(intValue);
model.getDoubleValues().add(doubleValue);
model.getDateValues().add(dateValue);
ISerializer serializer = get(ISerializer.class);
String modelAsString = serializer.serialize(model);
Model reparsedModel = (Model) getModel(modelAsString);
assertEquals(intValue, (int) reparsedModel.getIntValues().get(0));
assertEquals(doubleValue, reparsedModel.getDoubleValues().get(0), 0.00001);
assertEquals(dateValue, reparsedModel.getDateValues().get(0));
try {
model.getDoubleValues().add(-doubleValue);
modelAsString = serializer.serialize(model);
fail("Serialization should fail");
} catch (Exception exc) {
// normal case
}
}
Aggregations