Search in sources :

Example 1 with YamlPath

use of org.springframework.ide.vscode.commons.yaml.path.YamlPath in project sts4 by spring-projects.

the class BoshDeploymentManifestSchema method getCurrentStemcell.

private StemcellModel getCurrentStemcell(DynamicSchemaContext dc) throws Exception {
    YamlPath path = dc.getPath();
    YamlFileAST ast = asts.getAst(dc.getDocument(), true);
    return new StemcellModel(path.dropLast().traverseToNode(ast));
}
Also used : YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) StemcellModel(org.springframework.ide.vscode.bosh.models.StemcellModel)

Example 2 with YamlPath

use of org.springframework.ide.vscode.commons.yaml.path.YamlPath 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)

Example 3 with YamlPath

use of org.springframework.ide.vscode.commons.yaml.path.YamlPath in project sts4 by spring-projects.

the class YamlStructureParserTest method testTraverseSeqKey.

@Test
public void testTraverseSeqKey() throws Exception {
    MockYamlEditor editor = new MockYamlEditor("foo:\n" + "- bar:\n" + "  - a\n" + "  - key: lol\n" + "- e\n");
    SRootNode root = editor.parseStructure();
    YamlPath path;
    path = pathWith(0, "foo", 0, "bar", 1, "key");
    assertEquals("KEY(4): key: lol\n", path.traverse((SNode) root).toString());
}
Also used : YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) SRootNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode) Test(org.junit.Test)

Example 4 with YamlPath

use of org.springframework.ide.vscode.commons.yaml.path.YamlPath in project sts4 by spring-projects.

the class YamlStructureParserTest method testTraverse.

@Test
public void testTraverse() throws Exception {
    MockYamlEditor editor = new MockYamlEditor("world:\n" + "  europe:\n" + "    france:\n" + "      cheese\n" + "    belgium:\n" + // At same level as key, technically this is a syntax error but we tolerate it
    "    beer\n" + "  canada:\n" + "    montreal: poutine\n" + "    vancouver:\n" + "      salmon\n" + "moon:\n" + "  moonbase-alfa:\n" + "    moonstone\n");
    SRootNode root = editor.parseStructure();
    YamlPath pathToFrance = pathWith(0, "world", "europe", "france");
    assertEquals("KEY(4): france:\n" + "  RAW(6): cheese\n", pathToFrance.traverse((SNode) root).toString());
    assertNull(pathWith(0, "world", "europe", "bogus").traverse((SNode) root));
}
Also used : YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) SRootNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode) SNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SNode) Test(org.junit.Test)

Example 5 with YamlPath

use of org.springframework.ide.vscode.commons.yaml.path.YamlPath in project sts4 by spring-projects.

the class YTypeAssistContext method getSchemaContext.

protected DynamicSchemaContext getSchemaContext() {
    try {
        SNode contextNode = getContextNode();
        YamlPath fullContextPath = contextPath.prepend(YamlPathSegment.valueAt(documentSelector));
        return new SNodeDynamicSchemaContext(contextNode, fullContextPath);
    } catch (Exception e) {
        Log.log(e);
        return DynamicSchemaContext.NULL;
    }
}
Also used : YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) SNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SNode) SNodeDynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.SNodeDynamicSchemaContext) ValueParseException(org.springframework.ide.vscode.commons.util.ValueParseException)

Aggregations

YamlPath (org.springframework.ide.vscode.commons.yaml.path.YamlPath)12 YamlFileAST (org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST)4 SNode (org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SNode)4 SRootNode (org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode)4 Test (org.junit.Test)3 Node (org.yaml.snakeyaml.nodes.Node)3 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)2 StemcellModel (org.springframework.ide.vscode.bosh.models.StemcellModel)1 QuickfixData (org.springframework.ide.vscode.commons.languageserver.quickfix.Quickfix.QuickfixData)1 IntegerRange (org.springframework.ide.vscode.commons.util.IntegerRange)1 Renderable (org.springframework.ide.vscode.commons.util.Renderable)1 ValueParseException (org.springframework.ide.vscode.commons.util.ValueParseException)1 DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)1 IRegion (org.springframework.ide.vscode.commons.util.text.IRegion)1 NodeRef (org.springframework.ide.vscode.commons.yaml.ast.NodeRef)1 YamlAssistContext (org.springframework.ide.vscode.commons.yaml.completion.YamlAssistContext)1 SNodeDynamicSchemaContext (org.springframework.ide.vscode.commons.yaml.schema.SNodeDynamicSchemaContext)1 Constraint (org.springframework.ide.vscode.commons.yaml.schema.constraints.Constraint)1 YamlDocument (org.springframework.ide.vscode.commons.yaml.structure.YamlDocument)1 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)1