本文整理汇总了Java中org.eclipse.xtext.conversion.IValueConverter类的典型用法代码示例。如果您正苦于以下问题:Java IValueConverter类的具体用法?Java IValueConverter怎么用?Java IValueConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IValueConverter类属于org.eclipse.xtext.conversion包,在下文中一共展示了IValueConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RewritableImportSection
import org.eclipse.xtext.conversion.IValueConverter; //导入依赖的package包/类
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);
}
}
}
}
示例2: initializeDelegateConverter
import org.eclipse.xtext.conversion.IValueConverter; //导入依赖的package包/类
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);
}
};
}
}
示例3: getDelegateConverter
import org.eclipse.xtext.conversion.IValueConverter; //导入依赖的package包/类
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);
}
};
}
}
示例4: EString
import org.eclipse.xtext.conversion.IValueConverter; //导入依赖的package包/类
@ValueConverter(rule = "EString")
public IValueConverter<String> EString() {
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);
}
}
};
}
示例5: ID
import org.eclipse.xtext.conversion.IValueConverter; //导入依赖的package包/类
@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;
}
};
}
示例6: Fraction
import org.eclipse.xtext.conversion.IValueConverter; //导入依赖的package包/类
@ValueConverter(rule = "Fraction")
public IValueConverter<BigDecimal> Fraction() {
return new AbstractNullSafeConverter<BigDecimal>(){
@Override
protected BigDecimal internalToValue(String string, INode node) {
String[] splitted = string.split("/");
if (splitted.length > 1) {
return new BigDecimal(splitted[0].trim()).divide(new BigDecimal(splitted[1].trim()));
}
return new BigDecimal(string);
}
@Override
protected String internalToString(BigDecimal value) {
BigDecimal bd = value;
int scale = bd.scale();
if (scale <= 0) {
return bd.toPlainString();
}
bd = bd.multiply(BigDecimal.valueOf(1, -1 * scale));
return bd.toPlainString() + '/' + BigDecimal.valueOf(1, -1 * scale).toPlainString();
}};
}
示例7: FQN
import org.eclipse.xtext.conversion.IValueConverter; //导入依赖的package包/类
@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();
}
};
}
示例8: WrappingDataType
import org.eclipse.xtext.conversion.IValueConverter; //导入依赖的package包/类
@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();
}
};
}
示例9: DatEnum
import org.eclipse.xtext.conversion.IValueConverter; //导入依赖的package包/类
@ValueConverter(rule = "DatEnum")
public IValueConverter<TestEnum> DatEnum() {
return new IValueConverter<TestEnum>() {
@Override
public TestEnum toValue(String string, INode node) throws ValueConverterException {
if ("lit3".equals(string))
return TestEnum.LIT3;
else
throw new ValueConverterException(null, null, null);
}
@Override
public String toString(TestEnum value) throws ValueConverterException {
if (value == TestEnum.LIT3)
return TestEnum.LIT3.getName();
else
throw new ValueConverterException(null, null, null);
}
};
}
示例10: NULL_STRING
import org.eclipse.xtext.conversion.IValueConverter; //导入依赖的package包/类
@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);
}
};
}
示例11: ID
import org.eclipse.xtext.conversion.IValueConverter; //导入依赖的package包/类
@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;
}
};
}
示例12: FQN
import org.eclipse.xtext.conversion.IValueConverter; //导入依赖的package包/类
@ValueConverter(rule = "FQN")
// CHECKSTYLE:OFF
public IValueConverter<String> FQN() { // NOPMD
// CHECKSTYLE:ON
return new AbstractNullSafeConverter<String>() {
@Override
protected String internalToValue(final String string, final INode node) {
if (!string.equals(string.trim())) {
throw new RuntimeException(); // NOPMD
}
StringBuffer b = new StringBuffer();
for (ILeafNode l : node.getLeafNodes()) {
if (!l.isHidden()) {
b.append(l.getText());
}
}
return b.toString();
}
@Override
protected String internalToString(final String value) {
return value;
}
};
}
示例13: NameString
import org.eclipse.xtext.conversion.IValueConverter; //导入依赖的package包/类
@ValueConverter(rule = "NameString")
public IValueConverter<String> NameString() {
return new AbstractNullSafeConverter<String>() {
@Override
protected String internalToString(String value) {
return String.format("\"%s\"", value);
}
@Override
protected String internalToValue(String string, INode node) throws ValueConverterException {
if (string.matches("\\\".*\\\"")) {
return string.subSequence(1, string.length() - 1).toString();
}
return string;
}
};
}
开发者ID:Cooperate-Project,项目名称:CooperateModelingEnvironment,代码行数:20,代码来源:CooperateValueConverterBase.java
示例14: FQN
import org.eclipse.xtext.conversion.IValueConverter; //导入依赖的package包/类
@ValueConverter(rule = "FQN")
public IValueConverter<String> FQN() {
return new AbstractNullSafeConverter<String>() {
@Override
protected String internalToString(String value) {
// this prohibits FQNs with spaces to be serialized
if (value.contains(" ")) {
throw new ValueConverterException("Spaces are not allowed inside FQNs.", null, null);
}
return value;
}
@Override
protected String internalToValue(String string, INode node) throws ValueConverterException {
return string;
}
};
}
开发者ID:Cooperate-Project,项目名称:CooperateModelingEnvironment,代码行数:21,代码来源:CooperateValueConverterBase.java
示例15: convertCardinalityBound
import org.eclipse.xtext.conversion.IValueConverter; //导入依赖的package包/类
@ValueConverter(rule = "CardinalityBound")
public IValueConverter<Integer> convertCardinalityBound() {
return new AbstractNullSafeConverter<Integer>() {
@Override
protected String internalToString(Integer value) {
if (value < 0) {
return "*";
}
return value.toString();
}
@Override
protected Integer internalToValue(String string, INode node) throws ValueConverterException {
if ("*".equals(string)) {
return -1;
}
return Integer.parseInt(string);
}
};
}
开发者ID:Cooperate-Project,项目名称:CooperateModelingEnvironment,代码行数:23,代码来源:CooperateValueConverterBase.java