use of org.springframework.ide.vscode.commons.util.EnumValueParser in project sts4 by spring-projects.
the class YTypeFactory method yenum.
public YAtomicType yenum(String name, SchemaContextAware<BiFunction<String, Collection<String>, String>> errorMessageFormatter, SchemaContextAware<Collection<String>> values) {
YAtomicType t = yatomic(name);
t.setHintProvider((dc) -> {
return PartialCollection.compute(() -> values.withContext(dc)).map(BasicYValueHint::new);
});
t.parseWith((DynamicSchemaContext dc) -> {
EnumValueParser enumParser = new EnumValueParser(name, values.withContext(dc)) {
@Override
protected String createErrorMessage(String parseString, Collection<String> values) {
try {
return errorMessageFormatter.withContext(dc).apply(parseString, values);
} catch (Exception e) {
return super.createErrorMessage(parseString, values);
}
}
};
return enumParser;
});
return t;
}
use of org.springframework.ide.vscode.commons.util.EnumValueParser in project sts4 by spring-projects.
the class TypeUtil method getValueParser.
public ValueParser getValueParser(Type type) {
ValueParser simpleParser = VALUE_PARSERS.get(type.getErasure());
if (simpleParser != null) {
return simpleParser;
}
Collection<StsValueHint> enumValues = getAllowedValues(type, EnumCaseMode.ALIASED);
if (enumValues != null) {
// assigning anything to it is an error.
return new EnumValueParser(niceTypeName(type), getBareValues(enumValues));
}
if (isMap(type)) {
// provide a parser that allows throws
return new AlwaysFailingParser(niceTypeName(type));
}
if (isSequencable(type)) {
// Trying to parse list from scalars is possible if the domain type is parseable. Spring boot
// will try to interpret the string as a comma-separated list
Type elType = getDomainType(type);
if (elType != null) {
ValueParser elParser = getValueParser(elType);
if (elParser != null) {
return new DelimitedStringParser(elParser);
}
}
}
return null;
}
Aggregations