Java 类org.eclipse.xtext.serializer.ISerializer 实例源码

项目:xtext-extras    文件:GrammarAccessUtil.java   
private static ISerializer getSerializer(final String delimiter) {
    ISerializer result = xtextSerializerByLineDelimiter.get(delimiter);
    if (result != null) {
        return result;
    }
    final ILineSeparatorInformation lineSeparatorInformation = new ILineSeparatorInformation() {
        @Override
        public String getLineSeparator() {
            return delimiter;
        }
    };
    Injector injector = Guice.createInjector(new LineSeparatorModule(lineSeparatorInformation));
    result = injector.getInstance(ISerializer.class);
    xtextSerializerByLineDelimiter.put(delimiter, result);
    return result;
}
项目:xtext-extras    文件:SerializerTest.java   
@Test public void testSerialize_01() throws Exception {
    Resource resource = newResource("'foo' as String");
    XCastedExpression casted = (XCastedExpression) resource.getContents().get(0);

    XbaseFactory factory = XbaseFactory.eINSTANCE;
    XClosure closure = factory.createXClosure();
    XStringLiteral stringLiteral = factory.createXStringLiteral();
    stringLiteral.setValue("value");
    XBlockExpression blockExpression = factory.createXBlockExpression();
    blockExpression.getExpressions().add(stringLiteral);
    closure.setExpression(blockExpression);
    closure.setExplicitSyntax(true);
    XInstanceOfExpression instanceOfExpression = factory.createXInstanceOfExpression();
    instanceOfExpression.setExpression(closure);
    instanceOfExpression.setType(EcoreUtil.copy(casted.getType()));
    resource.getContents().clear();
    resource.getContents().add(instanceOfExpression);
    ISerializer serializer = get(ISerializer.class);
    String string = serializer.serialize(instanceOfExpression);
    assertEquals("[|\"value\"] instanceof String", string);

    XInstanceOfExpression parsedExpression = parseHelper.parse(string);
    assertTrue(EcoreUtil.equals(instanceOfExpression, parsedExpression));
}
项目:xtext-core    文件:GrammarAccessExtensions.java   
/**
 * @noreference
 */
public static String grammarFragmentToString(final ISerializer serializer, final EObject object, final String prefix) {
  String s = null;
  try {
    final SaveOptions options = SaveOptions.newBuilder().format().getOptions();
    s = serializer.serialize(object, options);
  } catch (final Throwable _t) {
    if (_t instanceof Exception) {
      final Exception e = (Exception)_t;
      s = e.toString();
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
  String _replace = s.trim().replaceAll("(\\r?\\n)", ("$1" + prefix)).replace("\\u", "\\\\u");
  String _plus = (prefix + _replace);
  s = _plus;
  return s;
}
项目:xtext-core    文件:DefaultTerminalConverterTest.java   
@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
    }
}
项目:xtext-extras    文件:SerializerFragment.java   
@Override
public Set<Binding> getGuiceBindingsRt(final Grammar grammar) {
  final BindFactory bf = new BindFactory();
  bf.addTypeToType(ISemanticSequencer.class.getName(), this.names.getSemanticSequencer().getQualifiedName());
  bf.addTypeToType(ISyntacticSequencer.class.getName(), this.names.getSyntacticSequencer().getQualifiedName());
  bf.addTypeToType(ISerializer.class.getName(), Serializer.class.getName());
  return bf.getBindings();
}
项目:xtext-extras    文件:SerializerTest.java   
@Test public void testSerialize_ExtrasIssue164() throws Exception {
    DerivedStateAwareResource resource = (DerivedStateAwareResource) newResource("org.eclipse.xtext.xbase.tests.serializer.SerializerTest.Demo.demo");
    XMemberFeatureCall call = (XMemberFeatureCall) resource.getContents().get(0);
    ISerializer serializer = get(ISerializer.class);
    call.eAdapters().clear();
    String string = serializer.serialize(call);
    assertEquals("org.eclipse.xtext.xbase.tests.serializer.SerializerTest.Demo.demo", string);
}
项目:xtext-extras    文件:SerializerTest.java   
@Test public void testSerialize_ExtrasIssue164_02() throws Exception {
    DerivedStateAwareResource resource = (DerivedStateAwareResource) newResource("org.eclipse.xtext.xbase.tests.serializer.SerializerTest.Demo.getDemo2(1)");
    XMemberFeatureCall call = (XMemberFeatureCall) resource.getContents().get(0);
    ISerializer serializer = get(ISerializer.class);
    call.eAdapters().clear();
    String string = serializer.serialize(call);
    assertEquals("org.eclipse.xtext.xbase.tests.serializer.SerializerTest.Demo.getDemo2(1)", string);
}
项目:xtext-core    文件:GrammarAccessExtensions.java   
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;
}
项目:pokemon-tcgo-deck-generator    文件:AbstractPkmntcgoRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:n4js    文件:AbstractTypeExpressionsRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:n4js    文件:AbstractTypesRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:n4js    文件:AbstractUnicodeRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:n4js    文件:AbstractRegularExpressionRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:n4js    文件:AbstractN4JSRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:n4js    文件:N4JSRuntimeModule.java   
/**
 * A custom serializer class that allows to access otherwise protected methods.
 */
@Override
public Class<? extends ISerializer> bindISerializer() {
    return AccessibleSerializer.class;
}
项目:n4js    文件:AbstractN4MFRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:Xtext_Xtend_HTML_Generator    文件:AbstractMyDslRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:bromium    文件:AbstractBromiumRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:gw4e.project    文件:AbstractDSLPoliciesRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:lcdsl    文件:AbstractLcDslRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:gemoc-studio    文件:AbstractDslRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:org.xtext.dsl.restaurante    文件:AbstractRestauranteRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:OCCI-Studio    文件:AbstractOCCIRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-extras    文件:AbstractPureXbaseRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-core    文件:AbstractEnumAndReferenceTestLanguageRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-extras    文件:AbstractXbaseWithAnnotationsRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-extras    文件:AbstractXtypeRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-extras    文件:AbstractRefactoringTestLanguageRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-extras    文件:AbstractRefactoringTestLanguage1RuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-core    文件:AbstractRegionAccessTestLanguageRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-extras    文件:AbstractRefactoringTestLanguage2RuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-extras    文件:AbstractBuilderTestLanguageRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-core    文件:AbstractAbstractIgnoreCaseLinkingTestLanguageRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-core    文件:AbstractSimpleExpressionsTestLanguageRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-extras    文件:AbstractBug462047LangRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-extras    文件:AbstractContentAssistFragmentTestLangRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-core    文件:AbstractAbstractTestLanguageRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-extras    文件:AbstractEnumRulesTestLanguageRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-extras    文件:AbstractMultiRuleEnumTestLanguageRuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}
项目:xtext-core    文件:AbstractBug305397RuntimeModule.java   
public Class<? extends ISerializer> bindISerializer() {
    return Serializer.class;
}