use of org.springframework.ide.vscode.commons.yaml.snippet.SchemaBasedSnippetGenerator in project sts4 by spring-projects.
the class SchemaBasedYamlASTReconciler method checkRequiredProperties.
private void checkRequiredProperties(Node parent, MappingNode map, YType type, Map<String, YTypedProperty> beanProperties, DynamicSchemaContext dc) {
Set<String> foundProps = NodeUtil.getScalarKeys(map);
boolean allPropertiesKnown = beanProperties.keySet().containsAll(foundProps);
// Don't check for missing properties if some properties look like they might be spelled incorrectly.
if (allPropertiesKnown) {
// Check for missing required properties:
List<YTypedProperty> missingProps = beanProperties.values().stream().filter(YTypedProperty::isRequired).filter(prop -> !foundProps.contains(prop.getName())).collect(CollectorUtil.toImmutableList());
Set<String> missingPropNames = missingProps.stream().map(YTypedProperty::getName).collect(Collectors.toCollection(TreeSet::new));
if (!missingPropNames.isEmpty()) {
String message;
if (missingPropNames.size() == 1) {
// slightly more specific message when only one missing property
String missing = missingPropNames.stream().findFirst().get();
message = "Property '" + missing + "' is required for '" + type + "'";
} else {
message = "Properties " + missingPropNames + " are required for '" + type + "'";
}
SchemaBasedSnippetGenerator snippetProvider = new SchemaBasedSnippetGenerator(typeUtil, SnippetBuilder::gimped);
Snippet snippet = snippetProvider.getSnippet(missingProps);
problems.accept(YamlSchemaProblems.missingProperties(message, dc, missingPropNames, snippet.getSnippet(), snippet.getPlaceHolder(1).getOffset(), parent, map, quickfixes.MISSING_PROP_FIX));
}
}
}
Aggregations