Search in sources :

Example 1 with IntegerRange

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();
    }
}
Also used : YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) IntegerRange(org.springframework.ide.vscode.commons.util.IntegerRange) SequenceNode(org.yaml.snakeyaml.nodes.SequenceNode) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Node(org.yaml.snakeyaml.nodes.Node) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) Constraint(org.springframework.ide.vscode.commons.yaml.schema.constraints.Constraint)

Aggregations

IntegerRange (org.springframework.ide.vscode.commons.util.IntegerRange)1 YamlPath (org.springframework.ide.vscode.commons.yaml.path.YamlPath)1 Constraint (org.springframework.ide.vscode.commons.yaml.schema.constraints.Constraint)1 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)1 Node (org.yaml.snakeyaml.nodes.Node)1 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)1 SequenceNode (org.yaml.snakeyaml.nodes.SequenceNode)1