Class KeywordBasedValueConverter
- java.lang.Object
-
- org.eclipse.xtext.conversion.impl.AbstractValueConverter<java.lang.String>
-
- org.eclipse.xtext.conversion.impl.KeywordBasedValueConverter
-
- All Implemented Interfaces:
IValueConverter<java.lang.String>,IValueConverter.RuleSpecific
public class KeywordBasedValueConverter extends AbstractValueConverter<java.lang.String> implements IValueConverter.RuleSpecific
This
IValueConverterensures that the given string value fulfills a data type rule that consists only of an alternative of keywords.It converts the value to a string. The implementation supports the following patterns:
RuleName: 'keyword'; RuleName: 'keyword' | 'other' | 'more';
Clients who want to implement case insensitive languages have to overridetoEscapedString(String)andkeywordToString(Keyword). Clients who want to convert the value to another data type may use this implementation as a delegate.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.xtext.conversion.IValueConverter
IValueConverter.RuleSpecific
-
-
Field Summary
-
Fields inherited from interface org.eclipse.xtext.conversion.IValueConverter
NO_OP_CONVERTER
-
-
Constructor Summary
Constructors Constructor Description KeywordBasedValueConverter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertValidValue(java.lang.String value)protected java.lang.StringkeywordToString(Keyword keyword)voidsetRule(AbstractRule rule)protected java.lang.StringtoEscapedString(java.lang.String value)java.lang.StringtoString(java.lang.String value)Transforms the given value to a string that is conformant to the expected terminal or data type rule.java.lang.StringtoValue(java.lang.String string, INode node)Creates a value from the given input.
-
-
-
Method Detail
-
toValue
public java.lang.String toValue(java.lang.String string, INode node) throws ValueConverterExceptionDescription copied from interface:IValueConverterCreates a value from the given input. The input is conformant to a data type or terminal rule.
The given
stringornodemay be null but not both of them.- Specified by:
toValuein interfaceIValueConverter<java.lang.String>- Parameters:
string- the string that was inferred from the node. Usually the node's text but may be reduced to the parts of the node that are nothidden.node- the parsed node including hidden parts.- Returns:
- the new value or
null. - Throws:
ValueConverterException- indicates that the string or node did not fulfil the expected format.
-
toString
public java.lang.String toString(java.lang.String value) throws ValueConverterExceptionDescription copied from interface:IValueConverterTransforms the given value to a string that is conformant to the expected terminal or data type rule.- Specified by:
toStringin interfaceIValueConverter<java.lang.String>- Parameters:
value- the to-be-transformed value- Returns:
- a string represenation for that value.
- Throws:
ValueConverterException- indicates that the value cannot be converted to a valid string.
-
assertValidValue
protected void assertValidValue(java.lang.String value)
-
toEscapedString
protected java.lang.String toEscapedString(java.lang.String value)
-
keywordToString
protected java.lang.String keywordToString(Keyword keyword)
-
setRule
public void setRule(AbstractRule rule)
- Specified by:
setRulein interfaceIValueConverter.RuleSpecific- Throws:
java.lang.IllegalArgumentException- if the rule is not a datatype rule or does not fulfill the patternRuleName: 'keyword' | 'other';
-
-