Search in sources :

Example 6 with TypedProperty

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

the class HintProviders method forMap.

public static HintProvider forMap(HintProvider _keyProvider, HintProvider _valueProvider, final Type valueType, final boolean dimensionAware) {
    final HintProvider keyProvider = notNull(_keyProvider);
    final HintProvider valueProvider = notNull(_valueProvider);
    if (isNull(keyProvider) && isNull(valueProvider)) {
        return NULL;
    }
    return new HintProvider() {

        @Override
        public HintProvider traverse(YamlPathSegment s) throws Exception {
            switch(s.getType()) {
                case VAL_AT_INDEX:
                case VAL_AT_KEY:
                    if (dimensionAware) {
                        return forHere(valueProvider);
                    } else {
                        return forAllValueContexts(valueProvider);
                    }
                default:
                    return NULL;
            }
        }

        @Override
        public List<StsValueHint> getValueHints(String query) {
            if (dimensionAware) {
                // pickier, completions only suggested in the domain of map, but not for map itself.
                return ImmutableList.of();
            } else {
                return valueProvider.getValueHints(query);
            }
        }

        @Override
        public List<TypedProperty> getPropertyHints(String query) {
            List<StsValueHint> keyHints = keyProvider.getValueHints(query);
            if (CollectionUtil.hasElements(keyHints)) {
                List<TypedProperty> props = new ArrayList<>(keyHints.size());
                for (StsValueHint keyHint : keyHints) {
                    Object key = keyHint.getValue();
                    if (key instanceof String) {
                        props.add(new TypedProperty((String) key, valueType, null));
                    }
                }
                return props;
            }
            return ImmutableList.of();
        }
    };
}
Also used : YamlPathSegment(org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment) ArrayList(java.util.ArrayList) TypedProperty(org.springframework.ide.vscode.boot.metadata.types.TypedProperty)

Aggregations

TypedProperty (org.springframework.ide.vscode.boot.metadata.types.TypedProperty)6 ArrayList (java.util.ArrayList)2 Type (org.springframework.ide.vscode.boot.metadata.types.Type)2 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)2 CommonLanguageTools.getValueType (org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType)1 HintProvider (org.springframework.ide.vscode.boot.metadata.hints.HintProvider)1 EnumCaseMode (org.springframework.ide.vscode.boot.metadata.types.TypeUtil.EnumCaseMode)1 DocumentEdits (org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits)1 ICompletionProposal (org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal)1 ValueParser (org.springframework.ide.vscode.commons.util.ValueParser)1 YamlPathSegment (org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment)1