Search in sources :

Example 11 with PropertyInfo

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

the class CommonLanguageTools method findLongestValidProperty.

/**
 * Find the longest known property that is a prefix of the given name. Here prefix does not mean
 * 'string prefix' but a prefix in the sense of treating '.' as a kind of separators. So
 * 'prefix' is not allowed to end in the middle of a 'segment'.
 */
public static PropertyInfo findLongestValidProperty(FuzzyMap<PropertyInfo> index, String name) {
    int bracketPos = name.indexOf('[');
    int endPos = bracketPos >= 0 ? bracketPos : name.length();
    PropertyInfo prop = null;
    String prefix = null;
    while (endPos > 0 && prop == null) {
        prefix = name.substring(0, endPos);
        String canonicalPrefix = camelCaseToHyphens(prefix);
        prop = index.get(canonicalPrefix);
        if (prop == null) {
            endPos = name.lastIndexOf('.', endPos - 1);
        }
    }
    if (prop != null) {
        // match the names exactly even if we found them using relaxed name matching.
        return prop.withId(prefix);
    }
    return null;
}
Also used : PropertyInfo(org.springframework.ide.vscode.boot.metadata.PropertyInfo) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint)

Example 12 with PropertyInfo

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

the class CommonLanguageTools method getValueType.

/**
 * Determine the value type for a give propertyName.
 */
public static Type getValueType(FuzzyMap<PropertyInfo> index, TypeUtil typeUtil, String propertyName) {
    try {
        PropertyInfo prop = index.get(propertyName);
        if (prop != null) {
            return TypeParser.parse(prop.getType());
        } else {
            prop = CommonLanguageTools.findLongestValidProperty(index, propertyName);
            if (prop != null) {
                TextDocument doc = new TextDocument(null, LanguageId.PLAINTEXT);
                doc.setText(propertyName);
                PropertyNavigator navigator = new PropertyNavigator(doc, null, typeUtil, new DocumentRegion(doc, 0, doc.getLength()));
                return navigator.navigate(prop.getId().length(), TypeParser.parse(prop.getType()));
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return null;
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) 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)

Aggregations

PropertyInfo (org.springframework.ide.vscode.boot.metadata.PropertyInfo)12 Type (org.springframework.ide.vscode.boot.metadata.types.Type)5 DocumentEdits (org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits)4 Match (org.springframework.ide.vscode.commons.util.FuzzyMap.Match)4 DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)4 ArrayList (java.util.ArrayList)3 StsValueHint (org.springframework.ide.vscode.boot.metadata.hints.StsValueHint)3 ICompletionProposal (org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal)3 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)3 CommonLanguageTools.getValueType (org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType)2 PropertyNavigator (org.springframework.ide.vscode.boot.properties.reconcile.PropertyNavigator)2 Collection (java.util.Collection)1 Annotation (org.eclipse.jdt.core.dom.Annotation)1 MemberValuePair (org.eclipse.jdt.core.dom.MemberValuePair)1 SimpleName (org.eclipse.jdt.core.dom.SimpleName)1 StringLiteral (org.eclipse.jdt.core.dom.StringLiteral)1 Test (org.junit.Test)1 AbstractPropsEditorTest (org.springframework.ide.vscode.boot.editor.harness.AbstractPropsEditorTest)1 IndexNavigator (org.springframework.ide.vscode.boot.metadata.IndexNavigator)1 HintProvider (org.springframework.ide.vscode.boot.metadata.hints.HintProvider)1