Search in sources :

Example 16 with Type

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

the class TypeUtilTest method testGetProperties.

@Test
public void testGetProperties() throws Exception {
    useProject("enums-boot-1.3.2-app");
    assertNotNull(project.getClasspath().findType("demo.Color"));
    assertNotNull(project.getClasspath().findType("demo.ColorData"));
    Type data = TypeParser.parse("demo.ColorData");
    assertType("java.lang.Double", getPropertyType(data, "wavelen"));
    assertType("java.lang.String", getPropertyType(data, "name"));
    assertType("demo.Color", getPropertyType(data, "next"));
    assertType("demo.ColorData", getPropertyType(data, "nested"));
    assertType("java.util.List<java.lang.String>", getPropertyType(data, "tags"));
    assertType("java.util.Map<java.lang.String,demo.ColorData>", getPropertyType(data, "mapped-children"));
    assertType("java.util.Map<demo.Color,demo.ColorData>", getPropertyType(data, "color-children"));
    // Also gets aliased as camelCased names?
    assertType("java.util.Map<demo.Color,demo.ColorData>", getPropertyType(data, "colorChildren"));
    assertType("java.util.Map<java.lang.String,demo.ColorData>", getPropertyType(data, "mappedChildren"));
    // Gets aliased names only if asked for it?
    assertType("java.util.Map<java.lang.String,demo.ColorData>", getPropertyType(data, "mappedChildren", EnumCaseMode.ORIGNAL, BeanPropertyNameMode.CAMEL_CASE));
    assertType(null, getPropertyType(data, "mappedChildren", EnumCaseMode.ORIGNAL, BeanPropertyNameMode.HYPHENATED));
    assertType(null, getPropertyType(data, "mapped-children", EnumCaseMode.ORIGNAL, BeanPropertyNameMode.CAMEL_CASE));
    assertType("java.util.Map<java.lang.String,demo.ColorData>", getPropertyType(data, "mapped-children", EnumCaseMode.ORIGNAL, BeanPropertyNameMode.HYPHENATED));
}
Also used : Type(org.springframework.ide.vscode.boot.metadata.types.Type) Test(org.junit.Test)

Example 17 with Type

use of org.springframework.ide.vscode.boot.metadata.types.Type 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

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