use of org.springframework.ide.vscode.commons.yaml.schema.ASTDynamicSchemaContext in project sts4 by spring-projects.
the class SchemaBasedYamlASTReconciler method reconcile.
private void reconcile(YamlFileAST ast, YamlPath path, Node parent, Node node, YType _type) {
// IDocument doc = ast.getDocument();
if (_type != null && !skipReconciling(node)) {
DynamicSchemaContext schemaContext = new ASTDynamicSchemaContext(ast, path, node);
YType type = typeUtil.inferMoreSpecificType(_type, schemaContext);
if (typeCollector != null) {
typeCollector.accept(node, type);
}
checkConstraints(parent, node, type, schemaContext);
switch(getNodeId(node)) {
case mapping:
MappingNode map = (MappingNode) node;
checkForDuplicateKeys(map);
if (typeUtil.isMap(type)) {
for (NodeTuple entry : map.getValue()) {
String key = NodeUtil.asScalar(entry.getKeyNode());
reconcile(ast, keyAt(path, key), map, entry.getKeyNode(), typeUtil.getKeyType(type));
reconcile(ast, valueAt(path, key), map, entry.getValueNode(), typeUtil.getDomainType(type));
}
} else if (typeUtil.isBean(type)) {
Map<String, YTypedProperty> beanProperties = typeUtil.getPropertiesMap(type);
checkRequiredProperties(parent, map, type, beanProperties, schemaContext);
for (NodeTuple entry : map.getValue()) {
Node keyNode = entry.getKeyNode();
String key = NodeUtil.asScalar(keyNode);
if (key == null) {
expectScalar(node);
} else {
YTypedProperty prop = beanProperties.get(key);
if (prop == null) {
unknownBeanProperty(keyNode, type, key);
} else {
if (prop.isDeprecated()) {
String msg = prop.getDeprecationMessage();
if (StringUtil.hasText(msg)) {
problems.accept(YamlSchemaProblems.deprecatedProperty(msg, keyNode));
} else {
problems.accept(YamlSchemaProblems.deprecatedProperty(keyNode, type, prop));
}
}
reconcile(ast, valueAt(path, key), map, entry.getValueNode(), prop.getType());
}
}
}
} else {
expectTypeButFoundMap(type, node);
}
break;
case sequence:
SequenceNode seq = (SequenceNode) node;
if (typeUtil.isSequencable(type)) {
for (int i = 0; i < seq.getValue().size(); i++) {
Node el = seq.getValue().get(i);
reconcile(ast, valueAt(path, i), seq, el, typeUtil.getDomainType(type));
}
} else {
expectTypeButFoundSequence(type, node);
}
break;
case scalar:
if (typeUtil.isAtomic(type)) {
SchemaContextAware<ValueParser> parserProvider = typeUtil.getValueParser(type);
if (parserProvider != null) {
// Take care not to execute parserProvider early just to check how long it should be delayed.
delayedConstraints.add(() -> {
parserProvider.safeWithContext(schemaContext).ifPresent(parser -> {
if (parser.longRunning()) {
slowDelayedConstraints.add(() -> {
parse(ast, node, type, parser);
});
} else {
parse(ast, node, type, parser);
}
});
});
}
} else {
expectTypeButFoundScalar(type, node);
}
break;
default:
}
}
}
Aggregations