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));
}
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();
}
}
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());
}
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));
}
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;
}
}
Aggregations