private IValueConverter<Object> initializeDelegateConverter() { if (valueConverterService instanceof IValueConverterService.Introspectable) { return delegateConverter = ((IValueConverterService.Introspectable) valueConverterService).getConverter(getDelegateRuleName()); } else { final String ruleName = getDelegateRuleName(); return delegateConverter = new IValueConverter<Object>() { @Override public Object toValue(String string, INode node) throws ValueConverterException { return valueConverterService.toValue(string, ruleName, node); } @Override public String toString(Object value) throws ValueConverterException { return valueConverterService.toString(value, ruleName); } }; } }
private IValueConverter<Object> getDelegateConverter() { if (delegateConverter != null) { return delegateConverter; } if (delegateService instanceof IValueConverterService.Introspectable) { return delegateConverter = ((IValueConverterService.Introspectable) delegateService).getConverter(delegateRule.getName()); } else { final String ruleName = delegateRule.getName(); return delegateConverter = new IValueConverter<Object>() { @Override public Object toValue(String string, INode node) throws ValueConverterException { return delegateService.toValue(string, ruleName, node); } @Override public String toString(Object value) throws ValueConverterException { return delegateService.toString(value, ruleName); } }; } }
@Inject private void setValueConverter(IValueConverterService service, N4JSGrammarAccess grammarAccess) { @SuppressWarnings({ "unchecked", "rawtypes" }) IValueConverter<String> converter = (IValueConverter) ((IValueConverterService.Introspectable) service) .getConverter(grammarAccess .getTypeReferenceNameRule() .getName()); this.valueConverter = converter; }
@Test public void testExceptionWhenRegistered() { IValueConverterService converters = get(ConverterForFragment.class); try { converters.toValue("foo", "STRING", null); } catch(IllegalStateException e) { assertTrue(e.getMessage().contains("ESCAPED_CHAR")); } }
@Test public void testDuplicateConverters() { IValueConverterService converter = get(DuplicateConverters.class); try { converter.toString("Foo", "unknown"); fail("Expected IllegalStateException"); } catch(IllegalStateException e) { assertTrue(e.getMessage().endsWith("'STRING'")); } }
private void registerGuiceBindingsRt() { new GuiceModuleAccess.BindingFactory() .addTypeToType(typeRef(IValueConverterService.class), getValueConverterName()) .contributeTo(getLanguage().getRuntimeGenModule()); Set<String> requiredBundles = getProjectConfig().getRuntime().getManifest().getRequiredBundles(); requiredBundles.add("de.cooperateproject.modeling.textual.common;visibility:=reexport"); }
public Class<? extends IValueConverterService> bindIValueConverterService() { return Ecore2XtextTerminalConverters.class; }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return XbaseValueConverterService.class; }
@Override public Set<Binding> getGuiceBindingsRt(Grammar grammar) { return new BindFactory().addTypeToType(IValueConverterService.class.getName(), Ecore2XtextTerminalConverters.class.getName()).getBindings(); }
protected IValueConverterService getValueConverterService() { return getInjector().getInstance(IValueConverterService.class); }
public IValueConverterService getConverterService() { return converterService; }
public void setConverterService(IValueConverterService converterService) { this.converterService = converterService; }
public void setValueConverter(IValueConverterService valueConverter) { this.valueConverter = valueConverter; }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return XtextValueConverters.class; }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return PartialSerializationTestLanguageValueConverter.class; }
@Override public void generate() { new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef(IValueConverterService.class), TypeReference.typeRef(Ecore2XtextTerminalConverters.class)).contributeTo(this.getLanguage().getRuntimeGenModule()); }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return Converters.class; }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return TerminalRuleTestLanguageConverters.class; }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return AssignmentsValueConverterService.class; }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return DatatypeRulesTestLanguageValueConverters.class; }
@Test public void testSimpleIdConverter() { IValueConverterService converter = get(SimpleIdConverter.class); expectedIdent = "idConverter"; converter.toValue("Foo", "ID", null); }
@Test public void testOverriddenIdConverter() { IValueConverterService converter = get(OverriddenIdConverter.class); expectedIdent = "overriddenIdConverter"; converter.toString("Foo", "ID"); }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return AbstractTestLanguageValueConverters.class; }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return QualifiedNameTerminalConverters.class; }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return MyConverterService.class; }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return AFValueConverter.class; }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return SequencerTestValueConverter.class; }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return Bug362902ValueConverters.class; }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return ScopeValueConverterService.class; }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return FormatValueConverterService.class; }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return ExpressionValueConverterService.class; }
/** * Returns the {@link IValueConverterService}. * * @return the {@link IValueConverterService}, never {@code null} */ protected IValueConverterService getValueConverterService() { final IValueConverterService valueConverterService = getXtextTestUtil().get(IValueConverterService.class); assertNotNull("The IValueConverterService must be registered in order to test it.", valueConverterService); return valueConverterService; }
@Override public Class<? extends IValueConverterService> bindIValueConverterService() { return ValidValueConverterService.class; }
public IValueConverterService getValueConverter() { return valueConverter; }