Search in sources :

Example 1 with DynamicSchemaContext

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

the class SchemaBasedYamlASTReconciler method checkRequiredProperties.

private void checkRequiredProperties(Node parent, MappingNode map, YType type, Map<String, YTypedProperty> beanProperties, DynamicSchemaContext dc) {
    Set<String> foundProps = NodeUtil.getScalarKeys(map);
    boolean allPropertiesKnown = beanProperties.keySet().containsAll(foundProps);
    // Don't check for missing properties if some properties look like they might be spelled incorrectly.
    if (allPropertiesKnown) {
        // Check for missing required properties:
        List<YTypedProperty> missingProps = beanProperties.values().stream().filter(YTypedProperty::isRequired).filter(prop -> !foundProps.contains(prop.getName())).collect(CollectorUtil.toImmutableList());
        Set<String> missingPropNames = missingProps.stream().map(YTypedProperty::getName).collect(Collectors.toCollection(TreeSet::new));
        if (!missingPropNames.isEmpty()) {
            String message;
            if (missingPropNames.size() == 1) {
                // slightly more specific message when only one missing property
                String missing = missingPropNames.stream().findFirst().get();
                message = "Property '" + missing + "' is required for '" + type + "'";
            } else {
                message = "Properties " + missingPropNames + " are required for '" + type + "'";
            }
            SchemaBasedSnippetGenerator snippetProvider = new SchemaBasedSnippetGenerator(typeUtil, SnippetBuilder::gimped);
            Snippet snippet = snippetProvider.getSnippet(missingProps);
            problems.accept(YamlSchemaProblems.missingProperties(message, dc, missingPropNames, snippet.getSnippet(), snippet.getPlaceHolder(1).getOffset(), parent, map, quickfixes.MISSING_PROP_FIX));
        }
    }
}
Also used : ReconcileException(org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileException) SequenceNode(org.yaml.snakeyaml.nodes.SequenceNode) IDocument(org.springframework.ide.vscode.commons.util.text.IDocument) QuickfixData(org.springframework.ide.vscode.commons.languageserver.quickfix.Quickfix.QuickfixData) SchemaContextAware(org.springframework.ide.vscode.commons.yaml.schema.SchemaContextAware) NodeUtil(org.springframework.ide.vscode.commons.yaml.ast.NodeUtil) YTypeUtil(org.springframework.ide.vscode.commons.yaml.schema.YTypeUtil) ProblemType(org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType) TreeSet(java.util.TreeSet) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Node(org.yaml.snakeyaml.nodes.Node) StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) YamlQuickfixes(org.springframework.ide.vscode.commons.yaml.quickfix.YamlQuickfixes) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) NodeId(org.yaml.snakeyaml.nodes.NodeId) Map(java.util.Map) ValueParseException(org.springframework.ide.vscode.commons.util.ValueParseException) IProblemCollector(org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector) YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) ValueParser(org.springframework.ide.vscode.commons.util.ValueParser) DynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext) SnippetBuilder(org.springframework.ide.vscode.commons.languageserver.util.SnippetBuilder) ASTDynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.ASTDynamicSchemaContext) NodeUtil.asScalar(org.springframework.ide.vscode.commons.yaml.ast.NodeUtil.asScalar) YamlPathSegment(org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment) ExceptionUtil(org.springframework.ide.vscode.commons.util.ExceptionUtil) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty) CollectorUtil(org.springframework.ide.vscode.commons.util.CollectorUtil) Log(org.springframework.ide.vscode.commons.util.Log) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) ReconcileProblemImpl(org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileProblemImpl) YamlSchema(org.springframework.ide.vscode.commons.yaml.schema.YamlSchema) Set(java.util.Set) ReplacementQuickfix(org.springframework.ide.vscode.commons.languageserver.reconcile.ReplacementQuickfix) Constraint(org.springframework.ide.vscode.commons.yaml.schema.constraints.Constraint) IntegerRange(org.springframework.ide.vscode.commons.util.IntegerRange) Collectors(java.util.stream.Collectors) YType(org.springframework.ide.vscode.commons.yaml.schema.YType) SchemaBasedSnippetGenerator(org.springframework.ide.vscode.commons.yaml.snippet.SchemaBasedSnippetGenerator) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple) List(java.util.List) ProblemTypeProvider(org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemTypeProvider) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) ExceptionUtil.getSimpleError(org.springframework.ide.vscode.commons.util.ExceptionUtil.getSimpleError) Snippet(org.springframework.ide.vscode.commons.yaml.snippet.Snippet) Pattern(java.util.regex.Pattern) SnippetBuilder(org.springframework.ide.vscode.commons.languageserver.util.SnippetBuilder) SchemaBasedSnippetGenerator(org.springframework.ide.vscode.commons.yaml.snippet.SchemaBasedSnippetGenerator) Snippet(org.springframework.ide.vscode.commons.yaml.snippet.Snippet) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty)

Example 2 with DynamicSchemaContext

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

the class ConcourseModel method addExtraInsertion.

private YValueHint addExtraInsertion(YValueHint h, DynamicSchemaContext dc) {
    return new BasicYValueHint(h.getValue(), h.getLabel()).setExtraInsertion(() -> {
        String resourceTypeName = h.getValue();
        AbstractType sourceType = (AbstractType) resourceTypes.getSourceType(resourceTypeName);
        if (sourceType != null && getParentPropertyNode("source", dc) == null) {
            // don't auto insert what's already there!
            List<YTypedProperty> requiredProps = sourceType.getProperties().stream().filter(p -> p.isRequired()).collect(Collectors.toList());
            if (!requiredProps.isEmpty()) {
                SnippetBuilder snippet = snippetBuilderFactory.get();
                snippet.text("\nsource:");
                for (YTypedProperty p : requiredProps) {
                    snippet.text("\n  " + p.getName() + ": ");
                    snippet.placeHolder();
                }
                return snippet.toString();
            }
        }
        return null;
    });
}
Also used : AbstractType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType) Arrays(java.util.Arrays) IDocument(org.springframework.ide.vscode.commons.util.text.IDocument) YamlPathSegment.valueAt(org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment.valueAt) ASTRootCursor(org.springframework.ide.vscode.commons.yaml.path.ASTRootCursor) NodeTypes(org.springframework.ide.vscode.commons.yaml.reconcile.ASTTypeCache.NodeTypes) YamlSchemaProblems(org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaProblems) Multiset(com.google.common.collect.Multiset) NodeUtil(org.springframework.ide.vscode.commons.yaml.ast.NodeUtil) NodeCursor(org.springframework.ide.vscode.commons.yaml.path.NodeCursor) Supplier(com.google.common.base.Supplier) YamlAstCache(org.springframework.ide.vscode.commons.yaml.ast.YamlAstCache) Function(java.util.function.Function) ASTTypeCache(org.springframework.ide.vscode.commons.yaml.reconcile.ASTTypeCache) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Node(org.yaml.snakeyaml.nodes.Node) StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) YamlTraversal(org.springframework.ide.vscode.commons.yaml.path.YamlTraversal) YTypeFactory(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory) BasicYValueHint(org.springframework.ide.vscode.commons.yaml.schema.BasicYValueHint) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) ImmutableMultiset(com.google.common.collect.ImmutableMultiset) IProblemCollector(org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector) YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) YamlPathSegment.anyChild(org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment.anyChild) YamlPathSegment.keyAt(org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment.keyAt) DynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext) SnippetBuilder(org.springframework.ide.vscode.commons.languageserver.util.SnippetBuilder) YBeanUnionType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanUnionType) YamlPathSegment(org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty) CollectorUtil(org.springframework.ide.vscode.commons.util.CollectorUtil) Log(org.springframework.ide.vscode.commons.util.Log) Builder(com.google.common.collect.ImmutableMultiset.Builder) Collection(java.util.Collection) Set(java.util.Set) Constraint(org.springframework.ide.vscode.commons.yaml.schema.constraints.Constraint) Collectors(java.util.stream.Collectors) Assert(org.springframework.ide.vscode.commons.util.Assert) YType(org.springframework.ide.vscode.commons.yaml.schema.YType) List(java.util.List) Stream(java.util.stream.Stream) Streams(org.springframework.ide.vscode.commons.yaml.util.Streams) Entry(java.util.Map.Entry) Optional(java.util.Optional) YValueHint(org.springframework.ide.vscode.commons.yaml.schema.YValueHint) SimpleLanguageServer(org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer) YAMLException(org.yaml.snakeyaml.error.YAMLException) BasicYValueHint(org.springframework.ide.vscode.commons.yaml.schema.BasicYValueHint) AbstractType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType) SnippetBuilder(org.springframework.ide.vscode.commons.languageserver.util.SnippetBuilder) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty)

Example 3 with DynamicSchemaContext

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

the class BoshCommandCloudConfigProviderTest method getStuff2.

@Test
public void getStuff2() throws Exception {
    DynamicSchemaContext dc = Mockito.mock(DynamicSchemaContext.class);
    provider.readWith(() -> "azs:\n" + "- cloud_properties:\n" + "    datacenters:\n" + "    - clusters:\n" + "      - AppFabric: {}\n" + "  name: z1\n" + "- cloud_properties:\n" + "    datacenters:\n" + "    - clusters:\n" + "      - AppFabric: {}\n" + "  name: z2\n" + "- cloud_properties:\n" + "    datacenters:\n" + "    - clusters:\n" + "      - AppFabric: {}\n" + "  name: z3\n" + "compilation:\n" + "  az: z1\n" + "  network: default-nw\n" + "  reuse_compilation_vms: true\n" + "  vm_type: default\n" + "  workers: 5\n" + "disk_types:\n" + "- disk_size: 3000\n" + "  name: default-dsk\n" + "- disk_size: 50000\n" + "  name: large-dsk\n" + "networks:\n" + "- name: default-nw\n" + "  subnets:\n" + "  - azs:\n" + "    - z1\n" + "    - z2\n" + "    - z3\n" + "    cloud_properties:\n" + "      name: VLAN 40 - AF\n" + "    dns:\n" + "    - 10.192.2.10\n" + "    - 8.8.8.8\n" + "    gateway: 10.194.4.1\n" + "    range: 10.194.4.0/23\n" + "    reserved:\n" + "    - 10.194.4.1-10.194.4.34\n" + "    - 10.194.4.40-10.194.5.255\n" + "  type: manual\n" + "vm_extensions:\n" + "- cloud_properties: {}\n" + "  name: fake-vmx-1\n" + "- cloud_properties: {}\n" + "  name: fake-vmx-2\n" + "vm_types:\n" + "- cloud_properties:\n" + "    cpu: 2\n" + "    disk: 3240\n" + "    ram: 1024\n" + "  name: default-vm\n" + "- cloud_properties:\n" + "    cpu: 2\n" + "    disk: 30240\n" + "    ram: 4096\n" + "  name: large-vm\n");
    CloudConfigModel cloudConfig = provider.getModel(dc);
    assertEquals(ImmutableMultiset.of("default-vm", "large-vm"), cloudConfig.getVMTypes());
    assertEquals(ImmutableMultiset.of("default-nw"), cloudConfig.getNetworkNames());
    assertEquals(ImmutableMultiset.of("default-dsk", "large-dsk"), cloudConfig.getDiskTypes());
    assertEquals(ImmutableMultiset.of("fake-vmx-1", "fake-vmx-2"), cloudConfig.getVMExtensions());
    assertEquals(ImmutableMultiset.of("z1", "z2", "z3"), cloudConfig.getAvailabilityZones());
}
Also used : DynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext) Test(org.junit.Test)

Example 4 with DynamicSchemaContext

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

the class YTypeAssistContext method getKeyCompletions.

public List<ICompletionProposal> getKeyCompletions(YamlDocument doc, SNode node, int offset, String query) throws Exception {
    int queryOffset = offset - query.length();
    DynamicSchemaContext dynamicCtxt = getSchemaContext();
    List<YTypedProperty> allProperties = typeUtil.getProperties(type);
    if (CollectionUtil.hasElements(allProperties)) {
        List<List<YTypedProperty>> tieredProperties = sortIntoTiers(allProperties);
        Set<String> definedProps = dynamicCtxt.getDefinedProperties();
        List<ICompletionProposal> proposals = new ArrayList<>();
        boolean suggestDeprecated = typeUtil.suggestDeprecatedProperties();
        YamlIndentUtil indenter = new YamlIndentUtil(doc);
        for (List<YTypedProperty> thisTier : tieredProperties) {
            List<YTypedProperty> undefinedProps = thisTier.stream().filter(p -> !definedProps.contains(p.getName()) && (suggestDeprecated || !p.isDeprecated())).collect(Collectors.toList());
            if (!undefinedProps.isEmpty()) {
                for (YTypedProperty p : undefinedProps) {
                    String name = p.getName();
                    double score = FuzzyMatcher.matchScore(query, name);
                    if (score != 0) {
                        TypeBasedSnippetProvider snippetProvider = typeUtil.getSnippetProvider();
                        DocumentEdits edits;
                        if (snippetProvider != null) {
                            // Generate edits from snippet
                            Snippet snippet = snippetProvider.getSnippet(p);
                            edits = createEditFromSnippet(doc, node, offset, query, indenter, snippet);
                        } else {
                            // Generate edits the old-fashioned way
                            edits = new DocumentEdits(doc.getDocument());
                            YType YType = p.getType();
                            edits.delete(queryOffset, query);
                            int referenceIndent = doc.getColumn(queryOffset);
                            boolean needNewline = node.getNodeType() == SNodeType.KEY;
                            StringBuilder snippet = new StringBuilder();
                            if (needNewline) {
                                snippet.append("\n");
                                referenceIndent = YamlIndentUtil.getNewChildKeyIndent(node);
                            } else if (queryOffset > 0 && !Character.isWhitespace(doc.getChar(queryOffset - 1))) {
                                // See https://www.pivotaltracker.com/story/show/137722057
                                snippet.append(" ");
                                referenceIndent++;
                            }
                            snippet.append(p.getName());
                            snippet.append(":");
                            snippet.append(appendTextFor(YType));
                            edits.insert(queryOffset, indenter.applyIndentation(snippet.toString(), referenceIndent));
                        }
                        ICompletionProposal completion = completionFactory().beanProperty(doc.getDocument(), contextPath.toPropString(), getType(), query, p, score, edits, typeUtil);
                        if (p.isDeprecated() && completion instanceof ScoreableProposal) {
                            completion.deemphasize(DEEMP_DEPRECATION);
                        }
                        proposals.add(completion);
                    }
                }
            }
            // We should only move on to the next tier if all required properties in this tier are defined.
            if (undefinedProps.stream().anyMatch(p -> p.isRequired())) {
                // stop here, take no more from next tier!
                return proposals;
            }
        }
        return proposals;
    }
    return Collections.emptyList();
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) YTypeUtil(org.springframework.ide.vscode.commons.yaml.schema.YTypeUtil) FuzzyMatcher(org.springframework.ide.vscode.commons.util.FuzzyMatcher) YamlIndentUtil(org.springframework.ide.vscode.commons.yaml.util.YamlIndentUtil) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) YamlPathSegmentType(org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment.YamlPathSegmentType) ImmutableList(com.google.common.collect.ImmutableList) DEEMP_DEPRECATION(org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal.DEEMP_DEPRECATION) Map(java.util.Map) ValueParseException(org.springframework.ide.vscode.commons.util.ValueParseException) YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) DynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext) SNodeType(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SNodeType) YamlPathSegment(org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment) Logger(org.slf4j.Logger) ExceptionUtil(org.springframework.ide.vscode.commons.util.ExceptionUtil) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty) Log(org.springframework.ide.vscode.commons.util.Log) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) ISubCompletionEngine(org.springframework.ide.vscode.commons.yaml.schema.ISubCompletionEngine) ScoreableProposal(org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal) Collection(java.util.Collection) TypeBasedSnippetProvider(org.springframework.ide.vscode.commons.yaml.snippet.TypeBasedSnippetProvider) Set(java.util.Set) PartialCollection(org.springframework.ide.vscode.commons.util.PartialCollection) YamlDocument(org.springframework.ide.vscode.commons.yaml.structure.YamlDocument) DEEMP_DASH_PROPOSAL(org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal.DEEMP_DASH_PROPOSAL) Collectors(java.util.stream.Collectors) YType(org.springframework.ide.vscode.commons.yaml.schema.YType) YPropertyInfoTemplates(org.springframework.ide.vscode.commons.yaml.hover.YPropertyInfoTemplates) List(java.util.List) CollectionUtil(org.springframework.ide.vscode.commons.util.CollectionUtil) DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits) ICompletionProposal(org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal) SNodeDynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.SNodeDynamicSchemaContext) SNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SNode) YValueHint(org.springframework.ide.vscode.commons.yaml.schema.YValueHint) Snippet(org.springframework.ide.vscode.commons.yaml.snippet.Snippet) Renderable(org.springframework.ide.vscode.commons.util.Renderable) ValueProposal(org.springframework.ide.vscode.commons.yaml.completion.DefaultCompletionFactory.ValueProposal) Collections(java.util.Collections) DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits) ScoreableProposal(org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal) ArrayList(java.util.ArrayList) DynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext) SNodeDynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.SNodeDynamicSchemaContext) Snippet(org.springframework.ide.vscode.commons.yaml.snippet.Snippet) YValueHint(org.springframework.ide.vscode.commons.yaml.schema.YValueHint) YamlIndentUtil(org.springframework.ide.vscode.commons.yaml.util.YamlIndentUtil) ICompletionProposal(org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal) TypeBasedSnippetProvider(org.springframework.ide.vscode.commons.yaml.snippet.TypeBasedSnippetProvider) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty) YType(org.springframework.ide.vscode.commons.yaml.schema.YType)

Example 5 with DynamicSchemaContext

use of org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext 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:
        }
    }
}
Also used : ValueParser(org.springframework.ide.vscode.commons.util.ValueParser) SequenceNode(org.yaml.snakeyaml.nodes.SequenceNode) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Node(org.yaml.snakeyaml.nodes.Node) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) DynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext) ASTDynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.ASTDynamicSchemaContext) SequenceNode(org.yaml.snakeyaml.nodes.SequenceNode) Constraint(org.springframework.ide.vscode.commons.yaml.schema.constraints.Constraint) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) ASTDynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.ASTDynamicSchemaContext) YType(org.springframework.ide.vscode.commons.yaml.schema.YType) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple) Map(java.util.Map) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty)

Aggregations

DynamicSchemaContext (org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext)7 YamlPath (org.springframework.ide.vscode.commons.yaml.path.YamlPath)4 YType (org.springframework.ide.vscode.commons.yaml.schema.YType)4 YTypedProperty (org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty)4 Collection (java.util.Collection)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 CollectorUtil (org.springframework.ide.vscode.commons.util.CollectorUtil)3 Log (org.springframework.ide.vscode.commons.util.Log)3 StringUtil (org.springframework.ide.vscode.commons.util.StringUtil)3 NodeUtil (org.springframework.ide.vscode.commons.yaml.ast.NodeUtil)3 YamlFileAST (org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST)3 ArrayList (java.util.ArrayList)2 Stream (java.util.stream.Stream)2 Test (org.junit.Test)2 IProblemCollector (org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector)2 SnippetBuilder (org.springframework.ide.vscode.commons.languageserver.util.SnippetBuilder)2 IDocument (org.springframework.ide.vscode.commons.util.text.IDocument)2