Search in sources :

Example 1 with ISerializer

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;
}
Also used : ILineSeparatorInformation(org.eclipse.xtext.formatting.ILineSeparatorInformation) Injector(com.google.inject.Injector) ISerializer(org.eclipse.xtext.serializer.ISerializer)

Example 2 with ISerializer

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
    }
}
Also used : Model(org.eclipse.xtext.parser.terminalrules.ecoreTerminalsTestLanguage.Model) SimpleDateFormat(com.ibm.icu.text.SimpleDateFormat) Date(java.util.Date) ISerializer(org.eclipse.xtext.serializer.ISerializer) Test(org.junit.Test)

Aggregations

ISerializer (org.eclipse.xtext.serializer.ISerializer)2 Injector (com.google.inject.Injector)1 SimpleDateFormat (com.ibm.icu.text.SimpleDateFormat)1 Date (java.util.Date)1 ILineSeparatorInformation (org.eclipse.xtext.formatting.ILineSeparatorInformation)1 Model (org.eclipse.xtext.parser.terminalrules.ecoreTerminalsTestLanguage.Model)1 Test (org.junit.Test)1