Search in sources :

Example 1 with IndexNavigator

use of org.springframework.ide.vscode.boot.metadata.IndexNavigator in project sts4 by spring-projects.

the class ApplicationYamlASTReconciler method reconcile.

private void reconcile(YamlFileAST root, NodeTuple entry, IndexNavigator nav) {
    Node keyNode = entry.getKeyNode();
    String key = asScalar(keyNode);
    if (key == null) {
        expectScalar(keyNode);
    } else {
        IndexNavigator subNav = nav.selectSubProperty(key);
        PropertyInfo match = subNav.getExactMatch();
        PropertyInfo extension = subNav.getExtensionCandidate();
        if (match == null && extension == null) {
            // nothing found for this key. Maybe user is using camelCase variation of the key?
            String keyAlias = StringUtil.camelCaseToHyphens(key);
            IndexNavigator subNavAlias = nav.selectSubProperty(keyAlias);
            match = subNavAlias.getExactMatch();
            extension = subNavAlias.getExtensionCandidate();
            if (match != null || extension != null) {
                // Got something for the alias, so use that instead.
                // Note: do not swap for alias unless we actually found something.
                // This gives more logical errors (in terms of user's key, not its canonical alias)
                subNav = subNavAlias;
            }
        }
        if (match != null && extension != null) {
            // This ambiguity is hard to deal with and we choose not to do so for now
            return;
        } else if (match != null) {
            Type type = TypeParser.parse(match.getType());
            if (match.isDeprecated()) {
                deprecatedProperty(match, keyNode);
            }
            reconcile(root, entry.getValueNode(), type);
        } else if (extension != null) {
            // We don't really care about the extension only about the fact that it
            // exists and so it is meaningful to continue checking...
            Node valueNode = entry.getValueNode();
            reconcile(root, valueNode, subNav);
        } else {
            // both are null, this means there's no valid property with the current prefix
            // whether exact or extending it with further navigation
            unkownProperty(keyNode, subNav.getPrefix(), entry);
        }
    }
}
Also used : Type(org.springframework.ide.vscode.boot.metadata.types.Type) SequenceNode(org.yaml.snakeyaml.nodes.SequenceNode) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Node(org.yaml.snakeyaml.nodes.Node) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) PropertyInfo(org.springframework.ide.vscode.boot.metadata.PropertyInfo) IndexNavigator(org.springframework.ide.vscode.boot.metadata.IndexNavigator)

Aggregations

IndexNavigator (org.springframework.ide.vscode.boot.metadata.IndexNavigator)1 PropertyInfo (org.springframework.ide.vscode.boot.metadata.PropertyInfo)1 Type (org.springframework.ide.vscode.boot.metadata.types.Type)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