Search in sources :

Example 1 with Type

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

the class PropertiesCompletionProposalsCalculator method createPropertyProposals.

protected Collection<ICompletionProposal> createPropertyProposals(Type type, int navOffset, String prefix, List<TypedProperty> objectProperties) {
    ArrayList<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
    for (TypedProperty prop : objectProperties) {
        double score = FuzzyMatcher.matchScore(prefix, prop.getName());
        if (score != 0) {
            Type valueType = prop.getType();
            String postFix = propertyCompletionPostfix(typeUtil, valueType);
            DocumentEdits edits = new DocumentEdits(doc);
            edits.delete(navOffset + 1, offset);
            edits.insert(offset, prop.getName() + postFix);
            proposals.add(completionFactory.beanProperty(doc, null, type, prefix, prop, score, edits, typeUtil));
        }
    }
    return proposals;
}
Also used : CommonLanguageTools.getValueType(org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType) Type(org.springframework.ide.vscode.boot.metadata.types.Type) DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits) ICompletionProposal(org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal) ArrayList(java.util.ArrayList) TypedProperty(org.springframework.ide.vscode.boot.metadata.types.TypedProperty)

Example 2 with Type

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

the class PropertiesCompletionProposalsCalculator method getNavigationProposals.

private Collection<ICompletionProposal> getNavigationProposals() {
    String navPrefix = navigationPrefixFinder.getPrefix(doc, offset);
    try {
        if (navPrefix != null) {
            // offset of 'nav' operator char (i.e. '.' or ']').
            int navOffset = offset - navPrefix.length() - 1;
            navPrefix = fuzzySearchPrefix.getPrefix(doc, navOffset);
            if (navPrefix != null && !navPrefix.isEmpty()) {
                PropertyInfo prop = findLongestValidProperty(index, navPrefix);
                if (prop != null) {
                    int regionStart = navOffset - navPrefix.length();
                    Collection<ICompletionProposal> hintProposals = getKeyHintProposals(prop, navOffset);
                    if (CollectionUtil.hasElements(hintProposals)) {
                        return hintProposals;
                    }
                    PropertyNavigator navigator = new PropertyNavigator(doc, null, typeUtil, new DocumentRegion(doc, regionStart, navOffset));
                    Type type = navigator.navigate(regionStart + prop.getId().length(), TypeParser.parse(prop.getType()));
                    if (type != null) {
                        return getNavigationProposals(type, navOffset);
                    }
                }
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return Collections.emptyList();
}
Also used : CommonLanguageTools.getValueType(org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType) Type(org.springframework.ide.vscode.boot.metadata.types.Type) ICompletionProposal(org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) PropertyNavigator(org.springframework.ide.vscode.boot.properties.reconcile.PropertyNavigator) PropertyInfo(org.springframework.ide.vscode.boot.metadata.PropertyInfo) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Example 3 with Type

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

the class PropertyNavigator method dotNavigate.

/**
 * Handle dot navigation into given type, after a '.' was
 * was found at given offset. Assumes the type has already been
 * checked to be 'dotable'.
 */
private Type dotNavigate(int offset, Type type) {
    if (TypeUtil.isMap(type)) {
        int keyStart = offset + 1;
        Type domainType = TypeUtil.getDomainType(type);
        int keyEnd = -1;
        if (typeUtil.isDotable(domainType)) {
            // '.' should be interpreted as navigation.
            keyEnd = nextNavOp(".[", offset + 1);
        } else {
            // '.' should *not* be interpreted as navigation.
            keyEnd = nextNavOp("[", offset + 1);
        }
        String key = textBetween(keyStart, keyEnd);
        Type keyType = typeUtil.getKeyType(type);
        if (keyType != null) {
            ValueParser keyParser = typeUtil.getValueParser(keyType);
            if (keyParser != null) {
                try {
                    keyParser.parse(key);
                } catch (Exception e) {
                    problemCollector.accept(problem(ApplicationPropertiesProblemType.PROP_VALUE_TYPE_MISMATCH, "Expecting " + typeUtil.niceTypeName(keyType), keyStart, keyEnd - keyStart));
                }
            }
        }
        return navigate(keyEnd, domainType);
    } else {
        // dot navigation into object properties
        int keyStart = offset + 1;
        int keyEnd = nextNavOp(".[", offset + 1);
        if (keyEnd < 0) {
            keyEnd = region.getEnd();
        }
        String key = StringUtil.camelCaseToHyphens(textBetween(keyStart, keyEnd));
        List<TypedProperty> properties = typeUtil.getProperties(type, EnumCaseMode.ALIASED, BeanPropertyNameMode.ALIASED);
        if (properties != null) {
            TypedProperty prop = null;
            for (TypedProperty p : properties) {
                if (p.getName().equals(key)) {
                    prop = p;
                    break;
                }
            }
            if (prop == null) {
                problemCollector.accept(problem(ApplicationPropertiesProblemType.PROP_INVALID_BEAN_PROPERTY, "Type '" + typeUtil.niceTypeName(type) + "' has no property '" + key + "'", keyStart, keyEnd - keyStart));
            } else {
                if (prop.isDeprecated()) {
                    problemCollector.accept(problemDeprecated(type, prop, keyStart, keyEnd - keyStart));
                }
                return navigate(keyEnd, prop.getType());
            }
        }
    }
    return null;
}
Also used : Type(org.springframework.ide.vscode.boot.metadata.types.Type) ValueParser(org.springframework.ide.vscode.commons.util.ValueParser) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException) TypedProperty(org.springframework.ide.vscode.boot.metadata.types.TypedProperty)

Example 4 with Type

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

the class CommonLanguageTools method getValueHints.

public static Collection<StsValueHint> getValueHints(FuzzyMap<PropertyInfo> index, TypeUtil typeUtil, String query, String propertyName, EnumCaseMode caseMode) {
    Type type = getValueType(index, typeUtil, propertyName);
    if (TypeUtil.isSequencable(type)) {
        // It is useful to provide content assist for the values in the list when entering a list
        type = TypeUtil.getDomainType(type);
    }
    List<StsValueHint> allHints = new ArrayList<>();
    {
        Collection<StsValueHint> hints = typeUtil.getHintValues(type, query, caseMode);
        if (CollectionUtil.hasElements(hints)) {
            allHints.addAll(hints);
        }
    }
    {
        PropertyInfo prop = index.findLongestCommonPrefixEntry(propertyName);
        if (prop != null) {
            HintProvider hintProvider = prop.getHints(typeUtil, false);
            if (!HintProviders.isNull(hintProvider)) {
                allHints.addAll(hintProvider.getValueHints(query));
            }
        }
    }
    return allHints;
}
Also used : Type(org.springframework.ide.vscode.boot.metadata.types.Type) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) ArrayList(java.util.ArrayList) Collection(java.util.Collection) HintProvider(org.springframework.ide.vscode.boot.metadata.hints.HintProvider) PropertyInfo(org.springframework.ide.vscode.boot.metadata.PropertyInfo)

Example 5 with Type

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

the class TypeParserTest method testNonGeneric.

@Test
public void testNonGeneric() throws Exception {
    Type type = TypeParser.parse("java.lang.String");
    assertEquals("java.lang.String", type.getErasure());
    assertFalse(type.isGeneric());
    assertEquals("java.lang.String", type.toString());
}
Also used : Type(org.springframework.ide.vscode.boot.metadata.types.Type) Test(org.junit.Test)

Aggregations

Type (org.springframework.ide.vscode.boot.metadata.types.Type)17 Test (org.junit.Test)7 PropertyInfo (org.springframework.ide.vscode.boot.metadata.PropertyInfo)6 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)5 ArrayList (java.util.ArrayList)4 CommonLanguageTools.getValueType (org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType)4 StsValueHint (org.springframework.ide.vscode.boot.metadata.hints.StsValueHint)3 ICompletionProposal (org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal)3 DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)3 Collection (java.util.Collection)2 TypedProperty (org.springframework.ide.vscode.boot.metadata.types.TypedProperty)2 DocumentEdits (org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits)2 ParseResults (org.springframework.ide.vscode.java.properties.parser.ParseResults)2 ImmutableList (com.google.common.collect.ImmutableList)1 Builder (com.google.common.collect.ImmutableList.Builder)1 Optional (java.util.Optional)1 SPACES (org.springframework.ide.vscode.boot.common.CommonLanguageTools.SPACES)1 CommonLanguageTools.getValueHints (org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueHints)1 InformationTemplates (org.springframework.ide.vscode.boot.common.InformationTemplates)1 IndexNavigator (org.springframework.ide.vscode.boot.metadata.IndexNavigator)1