org.eclipse.xtext.conversion.IValueConverter Java Examples
The following examples show how to use
org.eclipse.xtext.conversion.IValueConverter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SitemapConverters.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@ValueConverter(rule = "Command") public IValueConverter<String> Command() { return new AbstractNullSafeConverter<String>() { @Override protected String internalToValue(String string, INode node) { if ((string.startsWith("'") && string.endsWith("'")) || (string.startsWith("\"") && string.endsWith("\""))) { return STRING().toValue(string, node); } return ID().toValue(string, node); } @Override protected String internalToString(String value) { if (ID_PATTERN.matcher(value).matches()) { return ID().toString(value); } else { return STRING().toString(value); } } }; }
Example #2
Source File: DotFontNameConverters.java From gef with Eclipse Public License 2.0 | 6 votes |
@ValueConverter(rule = "Variant") public IValueConverter<Variant> variant() { return new AbstractNullSafeConverter<Variant>() { @Override protected String internalToString(Variant value) { return value.getLiteral(); } @Override protected Variant internalToValue(String string, INode node) throws ValueConverterException { switch (string.toLowerCase(Locale.ENGLISH)) { case "small-caps": return Variant.SMALL_CAPS; default: return Variant.NORMAL; } } }; }
Example #3
Source File: DotFontNameConverters.java From gef with Eclipse Public License 2.0 | 6 votes |
@ValueConverter(rule = "Style") public IValueConverter<Style> style() { return new AbstractNullSafeConverter<Style>() { @Override protected String internalToString(Style value) { return value.getLiteral(); } @Override protected Style internalToValue(String string, INode node) throws ValueConverterException { switch (string.toLowerCase(Locale.ENGLISH)) { case "oblique": return Style.OBLIQUE; case "italic": return Style.ITALIC; case "roman": default: return Style.NORMAL; } } }; }
Example #4
Source File: Bug362902ValueConverters.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override @ValueConverter(rule = "MyId") public IValueConverter<String> ID() { return new IValueConverter<String>() { @Override public String toValue(String string, INode node) throws ValueConverterException { if (string != null && string.length() > 3) { throw new ValueConverterException("ID too long", node, null); } return string; } @Override public String toString(String value) throws ValueConverterException { return value; } }; }
Example #5
Source File: DotFontNameConverters.java From gef with Eclipse Public License 2.0 | 6 votes |
/** * A value converter for the PostScriptAlias datatype rule * * @return An IValueConverter<PostScriptFontAlias> */ @ValueConverter(rule = "PostScriptAlias") public IValueConverter<PostScriptFontAlias> postScriptFontAlias() { return new AbstractNullSafeConverter<PostScriptFontAlias>() { @Override protected String internalToString(PostScriptFontAlias value) { return value.toString(); } @Override protected PostScriptFontAlias internalToValue(String string, INode node) throws ValueConverterException { String postscriptComparator = string.toUpperCase(Locale.ENGLISH) .replaceAll("-", "_"); return PostScriptFontAlias.valueOf(postscriptComparator); } }; }
Example #6
Source File: DotDoubleOnlyGrammarConverters.java From gef with Eclipse Public License 2.0 | 6 votes |
/** * A value converter for the ID data type rule. * * @return A {@link DotIDValueConverter}. */ @ValueConverter(rule = "DOUBLE") public IValueConverter<Double> doubleConverter() { return new AbstractNullSafeConverter<Double>() { @Override protected String internalToString(Double value) { return value.toString(); } @Override protected Double internalToValue(String string, INode node) throws ValueConverterException { return DotDoubleUtil.parseDotDouble(string); } }; }
Example #7
Source File: SequencerTestLanguageRuntimeModule.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@ValueConverter(rule = "NULL_STRING") public IValueConverter<String> NULL_STRING() { return new IValueConverter<String>() { @Override public String toString(String value) throws ValueConverterException { if (value == null) return "''"; return "'" + value + "'"; } @Override public String toValue(String string, INode node) throws ValueConverterException { if (string.length() <= 2) { return null; } return string.substring(1, string.length() - 1); } }; }
Example #8
Source File: SitemapConverters.java From openhab-core with Eclipse Public License 2.0 | 6 votes |
@ValueConverter(rule = "Icon") public IValueConverter<String> Icon() { return new IValueConverter<String>() { @Override public String toValue(String string, INode node) throws ValueConverterException { if (string != null && string.startsWith("\"")) { return string.substring(1, string.length() - 1); } return string; } @Override public String toString(String value) throws ValueConverterException { if (containsWhiteSpace(value)) { return "\"" + value + "\""; } return value; } }; }
Example #9
Source File: ImportsVariableResolver.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public void validateParameters(Variable variable, ValidationMessageAcceptor validationMessageAcceptor) { if (variable.getParameters().isEmpty()) { validationMessageAcceptor.acceptError(getType() + "-variables have mandatory parameters.", variable, TemplatesPackage.Literals.VARIABLE__TYPE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); } else { EList<String> parameters = variable.getParameters(); for (int i = 0; i < parameters.size(); i++) { String param = parameters.get(i); try { IValueConverter<String> converter = ((XbaseValueConverterService) valueConverterService) .getQualifiedNameWithWildCardValueConverter(); converter.toString(param); } catch (ValueConverterException e) { validationMessageAcceptor.acceptError(getType() + " - parameter " + param + " is not a valid qualifier.", variable, TemplatesPackage.Literals.VARIABLE__PARAMETERS, i, null); } } } }
Example #10
Source File: TerminalRuleTestLanguageConverters.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@ValueConverter(rule = "ID") public IValueConverter<String> ID() { return new AbstractNullSafeConverter<String>() { @Override protected String internalToValue(String string, INode node) { return string.startsWith("^") ? string.substring(1) : string; } @Override protected String internalToString(String value) { if (GrammarUtil.getAllKeywords(getGrammar()).contains(value)) { return "^"+value; } return value; } }; }
Example #11
Source File: RewritableImportSection.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public RewritableImportSection(XtextResource resource, IImportsConfiguration importsConfiguration, XImportSection originalImportSection, String lineSeparator, ImportSectionRegionUtil regionUtil, IValueConverter<String> nameConverter) { this.importsConfiguration = importsConfiguration; this.resource = resource; this.lineSeparator = lineSeparator; this.regionUtil = regionUtil; this.nameValueConverter = nameConverter; this.implicitlyImportedPackages = importsConfiguration.getImplicitlyImportedPackages(resource); this.importRegion = regionUtil.computeRegion(resource); if (originalImportSection != null) { for (XImportDeclaration originalImportDeclaration : originalImportSection.getImportDeclarations()) { this.originalImportDeclarations.add(originalImportDeclaration); JvmDeclaredType importedType = originalImportDeclaration.getImportedType(); if (originalImportDeclaration.isStatic()) { String memberName = originalImportDeclaration.getMemberName(); if (originalImportDeclaration.isExtension()) { Maps2.putIntoSetMap(importedType, memberName, staticExtensionImports); } else { Maps2.putIntoSetMap(importedType, memberName, staticImports); } } else if (importedType != null) { Maps2.putIntoListMap(importedType.getSimpleName(), importedType, plainImports); } } } }
Example #12
Source File: FormatterTestValueConverters.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@ValueConverter(rule = "FQN") public IValueConverter<String> FQN() { return new AbstractNullSafeConverter<String>() { @Override protected String internalToString(String value) { return value; } @Override protected String internalToValue(String string, INode node) { if (!string.equals(string.trim())) throw new RuntimeException(); StringBuffer b = new StringBuffer(); for (ILeafNode leaf : node.getLeafNodes()) { if (!leaf.isHidden()) { b.append(leaf.getText()); } } return b.toString(); } }; }
Example #13
Source File: SitemapConverters.java From openhab-core with Eclipse Public License 2.0 | 6 votes |
@ValueConverter(rule = "Command") public IValueConverter<String> Command() { return new AbstractNullSafeConverter<String>() { @Override protected String internalToValue(String string, INode node) { if ((string.startsWith("'") && string.endsWith("'")) || (string.startsWith("\"") && string.endsWith("\""))) { return STRING().toValue(string, node); } return ID().toValue(string, node); } @Override protected String internalToString(String value) { if (ID_PATTERN.matcher(value).matches()) { return ID().toString(value); } else { return STRING().toString(value); } } }; }
Example #14
Source File: KeywordAlternativeConverter.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
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); } }; } }
Example #15
Source File: FormatterTestValueConverters.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@ValueConverter(rule = "WrappingDataType") public IValueConverter<String> WrappingDataType() { return new AbstractNullSafeConverter<String>() { @Override protected String internalToString(String value) { return value; } @Override protected String internalToValue(String string, INode node) throws ValueConverterException { return node.getText().trim(); } }; }
Example #16
Source File: AbstractDeclarativeValueConverterService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private IValueConverter<Object> registerIfMissing(String name, AbstractRule rule, Method method, Map<String, IValueConverter<Object>> converters) throws IllegalAccessException, InvocationTargetException { if (!converters.containsKey(name)) { IValueConverter<Object> valueConverter = reflectiveGetConverter(method, rule); converters.put(name, valueConverter); return valueConverter; } return null; }
Example #17
Source File: JdtTypesProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public void createTypeProposals(IJavaProject project, ICompletionProposalFactory proposalFactory, ContentAssistContext context, EReference typeReference, Filter filter, IValueConverter<String> valueConverter, ICompletionProposalAcceptor acceptor) { try { IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }); searchAndCreateProposals(searchScope, proposalFactory, context, typeReference, filter, valueConverter, acceptor); } catch (JavaModelException e) { // ignore } }
Example #18
Source File: Bug250313RuntimeModule.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@ValueConverter(rule = "NestedDatatype") public IValueConverter<String> NestedDatatype() { return new AbstractNullSafeConverter<String>() { @Override protected String internalToValue(String string, INode node) { return "str"; } @Override protected String internalToString(String value) { throw new UnsupportedOperationException(); } }; }
Example #19
Source File: ImportsAwareReferenceProposalCreator.java From n4js with Eclipse Public License 1.0 | 5 votes |
@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; }
Example #20
Source File: AbstractDeclarativeValueConverterService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private IValueConverter<Object> reflectiveGetConverter(Method method, AbstractRule rule) throws IllegalAccessException, InvocationTargetException { IValueConverter<Object> valueConverter = (IValueConverter<Object>) method.invoke(this); if (valueConverter instanceof IValueConverter.RuleSpecific) ((IValueConverter.RuleSpecific) valueConverter).setRule(rule); return valueConverter; }
Example #21
Source File: AbstractDeclarativeValueConverterService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.4 * @nooverride This method is not intended to be re-implemented or extended by clients. * @noreference This method is not intended to be referenced by clients. */ protected void registerEFactoryConverters(Map<String, IValueConverter<Object>> converters) { for (ParserRule parserRule : allParserRules(getGrammar())) { if (isDatatypeRule(parserRule)) { registerIfMissing(parserRule.getName(), parserRule, converters); registerIfMissing(ruleNames.getQualifiedName(parserRule), parserRule, converters); } } for (TerminalRule terminalRule : allTerminalRules(getGrammar())) { if (!terminalRule.isFragment()) { registerIfMissing(terminalRule.getName(), terminalRule, converters); registerIfMissing(ruleNames.getQualifiedName(terminalRule), terminalRule, converters); } } }
Example #22
Source File: DotFontNameConverters.java From gef with Eclipse Public License 2.0 | 5 votes |
@ValueConverter(rule = "Stretch") public IValueConverter<Stretch> stretch() { return new AbstractNullSafeConverter<Stretch>() { @Override protected String internalToString(Stretch value) { return value.getLiteral(); } @Override protected Stretch internalToValue(String string, INode node) throws ValueConverterException { switch (string.toLowerCase(Locale.ENGLISH)) { case "ultra-condensed": return Stretch.ULTRA_CONDENSED; case "extra-condensed": return Stretch.EXTRA_CONDENSED; case "condensed": return Stretch.CONDENSED; case "semi-condensed": return Stretch.SEMI_CONDENSED; case "semi-expanded": return Stretch.SEMI_EXPANDED; case "expanded": return Stretch.EXPANDED; case "extra-expanded": return Stretch.EXTRA_EXPANDED; case "ultra-expanded": return Stretch.ULTRA_EXPANDED; default: return Stretch.NORMAL; } } }; }
Example #23
Source File: AbstractDeclarativeValueConverterService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private void registerIfMissing(String name, ParserRule parserRule, Map<String, IValueConverter<Object>> converters) { if (!converters.containsKey(name)) { EDataType datatype = (EDataType) parserRule.getType().getClassifier(); converters.put(name, new EFactoryValueConverter(datatype)); } }
Example #24
Source File: DotFontNameConverters.java From gef with Eclipse Public License 2.0 | 5 votes |
@ValueConverter(rule = "Gravity") public IValueConverter<Gravity> gravity() { return new AbstractNullSafeConverter<Gravity>() { @Override protected String internalToString(Gravity value) { return value.getLiteral(); } @Override protected Gravity internalToValue(String string, INode node) throws ValueConverterException { switch (string.toLowerCase(Locale.ENGLISH)) { case "upside-down": case "north": return Gravity.NORTH; case "rotated-left": case "east": return Gravity.EAST; case "rotated-right": case "west": return Gravity.WEST; case "not-rotated": case "south": default: return Gravity.SOUTH; } } }; }
Example #25
Source File: XtendImportingTypesProposalProvider.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override protected ConfigurableCompletionProposal.IReplacementTextApplier createTextApplier(final ContentAssistContext context, final IScope typeScope, final IQualifiedNameConverter qualifiedNameConverter, final IValueConverter<String> valueConverter) { final Predicate<IEObjectDescription> _function = (IEObjectDescription it) -> { QualifiedName _name = it.getName(); return (!Objects.equal(_name, XtendImportedNamespaceScopeProvider.OLD_DATA_ANNOTATION)); }; final FilteringScope scope = new FilteringScope(typeScope, _function); return super.createTextApplier(context, scope, qualifiedNameConverter, valueConverter); }
Example #26
Source File: AssignmentsTestLanguageRuntimeModule.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@ValueConverter(rule = "StringDatatype") public IValueConverter<String> StringDatatype() { return new AbstractToStringConverter<String>() { @Override protected String internalToValue(String string, INode node) { return "StringDatatype: " + string; } }; }
Example #27
Source File: DefaultTerminalConverters.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@ValueConverter(rule = "STRING") public IValueConverter<String> STRING() { return stringValueConverter; }
Example #28
Source File: DefaultTerminalConverters.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@ValueConverter(rule = "ID") public IValueConverter<String> ID() { return idValueConverter; }
Example #29
Source File: XtendValueConverterService.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@ValueConverter(rule = "RICH_TEXT_INBETWEEN") public IValueConverter<String> getRichTextInbetweenValueConverter() { return richTextInbetweenValueConverter; }
Example #30
Source File: XbaseValueConverterService.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@ValueConverter(rule = "OpCompare") public IValueConverter<String> getOpCompareConverter() { return compareOperatorsValueConverter; }