Search in sources :

Example 11 with Type

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

the class ApplicationYamlAssistContext method getAllJavaElements.

private static List<IJavaElement> getAllJavaElements(TypeUtil typeUtil, Type parentType, String propName) {
    if (propName != null) {
        Type beanType = parentType;
        if (TypeUtil.isMap(beanType)) {
            Type keyType = typeUtil.getKeyType(beanType);
            if (keyType != null && typeUtil.isEnum(keyType)) {
                IField field = typeUtil.getEnumConstant(keyType, propName);
                if (field != null) {
                    return ImmutableList.of(field);
                }
            }
        } else {
            ArrayList<IJavaElement> elements = new ArrayList<IJavaElement>(3);
            maybeAdd(elements, typeUtil.getField(beanType, propName));
            maybeAdd(elements, typeUtil.getSetter(beanType, propName).get());
            maybeAdd(elements, typeUtil.getGetter(beanType, propName));
            if (!elements.isEmpty()) {
                return elements;
            }
        }
    }
    return ImmutableList.of();
}
Also used : IJavaElement(org.springframework.ide.vscode.commons.java.IJavaElement) Type(org.springframework.ide.vscode.boot.metadata.types.Type) YamlPathSegmentType(org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment.YamlPathSegmentType) ArrayList(java.util.ArrayList) IField(org.springframework.ide.vscode.commons.java.IField)

Example 12 with Type

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

the class TypeParserTest method testMultipleParams.

@Test
public void testMultipleParams() throws Exception {
    Type type = TypeParser.parse("Map<Foo,Bar>");
    assertEquals("Map", type.getErasure());
    assertTrue(type.isGeneric());
    Type[] params = type.getParams();
    assertEquals(2, params.length);
    type = params[0];
    assertEquals("Foo", type.getErasure());
    assertFalse(type.isGeneric());
    type = params[1];
    assertEquals("Bar", type.getErasure());
    assertFalse(type.isGeneric());
}
Also used : Type(org.springframework.ide.vscode.boot.metadata.types.Type) Test(org.junit.Test)

Example 13 with Type

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

the class TypeParserTest method testTypeEquality.

@Test
public void testTypeEquality() throws Exception {
    Type type1 = TypeParser.parse("Map<Foo,List<Bar>>");
    Type type2 = TypeParser.parse("Map<Foo,List<Bar>>");
    Type type3 = TypeParser.parse("Map<Bar,List<Bar>>");
    assertEquals(type1, type2);
    assertNotEquals(type1, type3);
}
Also used : Type(org.springframework.ide.vscode.boot.metadata.types.Type) Test(org.junit.Test)

Example 14 with Type

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

the class TypeParserTest method testSimpleGeneric.

@Test
public void testSimpleGeneric() throws Exception {
    Type type = TypeParser.parse("List<Foo>");
    assertEquals("List", type.getErasure());
    assertTrue(type.isGeneric());
    Type[] params = type.getParams();
    assertEquals(1, params.length);
    type = params[0];
    assertEquals("Foo", type.getErasure());
    assertFalse(type.isGeneric());
}
Also used : Type(org.springframework.ide.vscode.boot.metadata.types.Type) Test(org.junit.Test)

Example 15 with Type

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

the class TypeParserTest method testNestedGenerics.

@Test
public void testNestedGenerics() throws Exception {
    Type type = TypeParser.parse("Map<Foo,List<Bar>>");
    assertEquals("Map", type.getErasure());
    assertTrue(type.isGeneric());
    assertEquals("Map<Foo,List<Bar>>", 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