本文整理汇总了Java中org.eclipse.xtext.serializer.ISerializer类的典型用法代码示例。如果您正苦于以下问题:Java ISerializer类的具体用法?Java ISerializer怎么用?Java ISerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISerializer类属于org.eclipse.xtext.serializer包,在下文中一共展示了ISerializer类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSerializer
import org.eclipse.xtext.serializer.ISerializer; //导入依赖的package包/类
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;
}
示例2: testSerialize_01
import org.eclipse.xtext.serializer.ISerializer; //导入依赖的package包/类
@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));
}
示例3: grammarFragmentToString
import org.eclipse.xtext.serializer.ISerializer; //导入依赖的package包/类
/**
* @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;
}
示例4: testSerializeAndReparse
import org.eclipse.xtext.serializer.ISerializer; //导入依赖的package包/类
@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
}
}
示例5: getGuiceBindingsRt
import org.eclipse.xtext.serializer.ISerializer; //导入依赖的package包/类
@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();
}
示例6: testSerialize_ExtrasIssue164
import org.eclipse.xtext.serializer.ISerializer; //导入依赖的package包/类
@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);
}
示例7: testSerialize_ExtrasIssue164_02
import org.eclipse.xtext.serializer.ISerializer; //导入依赖的package包/类
@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);
}
示例8: getSerializer
import org.eclipse.xtext.serializer.ISerializer; //导入依赖的package包/类
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;
}
示例9: bindISerializer
import org.eclipse.xtext.serializer.ISerializer; //导入依赖的package包/类
public Class<? extends ISerializer> bindISerializer() {
return Serializer.class;
}
示例10: bindISerializer
import org.eclipse.xtext.serializer.ISerializer; //导入依赖的package包/类
/**
* A custom serializer class that allows to access otherwise protected methods.
*/
@Override
public Class<? extends ISerializer> bindISerializer() {
return AccessibleSerializer.class;
}