use of org.springframework.ide.vscode.commons.util.IntegerRange in project sts4 by spring-projects.
the class SchemaBasedYamlASTReconciler method reconcile.
@Override
public void reconcile(YamlFileAST ast) {
if (typeCollector != null)
typeCollector.beginCollecting(ast);
delayedConstraints.clear();
slowDelayedConstraints.clear();
try {
List<Node> nodes = ast.getNodes();
IntegerRange expectedDocs = schema.expectedNumberOfDocuments();
if (!expectedDocs.isInRange(nodes.size())) {
// wrong number of documents in the file. Figure out a good error message.
if (nodes.isEmpty()) {
problem(allOf(ast.getDocument()), "'" + schema.getName() + "' must have at least some Yaml content");
} else if (expectedDocs.isTooLarge(nodes.size())) {
int upperBound = expectedDocs.getUpperBound();
Node extraNode = nodes.get(upperBound);
problem(dashesAtStartOf(ast, extraNode), "'" + schema.getName() + "' should not have more than " + upperBound + " Yaml Documents");
} else if (expectedDocs.isTooSmall(nodes.size())) {
int lowerBound = expectedDocs.getLowerBound();
problem(endOf(ast.getDocument()), "'" + schema.getName() + "' should have at least " + lowerBound + " Yaml Documents");
}
}
if (nodes != null && !nodes.isEmpty()) {
for (int i = 0; i < nodes.size(); i++) {
Node node = nodes.get(i);
reconcile(ast, new YamlPath(YamlPathSegment.valueAt(i)), /*parent*/
null, node, schema.getTopLevelType());
}
}
} finally {
if (typeCollector != null) {
typeCollector.endCollecting(ast);
}
verifyDelayedConstraints();
}
}
Aggregations