Search in sources :

Example 1 with ComponentFunctionParameterData

use of com.vaadin.generator.metadata.ComponentFunctionParameterData in project flow by vaadin.

the class ComponentGeneratorTest method classContainsMethodWithObjectParameter_generatedClassContainsInnerClass.

@Test
public void classContainsMethodWithObjectParameter_generatedClassContainsInnerClass() {
    // note: the tests for the nested class are covered by the
    // NestedClassGeneratorTest
    ComponentObjectTypeInnerType stringObjectType = new ComponentObjectTypeInnerType();
    stringObjectType.setName("internalString");
    stringObjectType.setType(Collections.singletonList(ComponentBasicType.STRING));
    ComponentObjectType objectType = new ComponentObjectType();
    objectType.setInnerTypes(Collections.singletonList(stringObjectType));
    ComponentFunctionParameterData parameter = new ComponentFunctionParameterData();
    parameter.setName("somethingParam");
    parameter.setObjectType(Collections.singletonList(objectType));
    ComponentFunctionData function = new ComponentFunctionData();
    function.setName("callSomething");
    function.setParameters(Collections.singletonList(parameter));
    componentMetadata.setMethods(Collections.singletonList(function));
    String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
    generatedClass = ComponentGeneratorTestUtils.removeIndentation(generatedClass);
    Assert.assertTrue("Generated class should contain the CallSomethingSomethingParam nested class", generatedClass.contains("public static class CallSomethingSomethingParam implements JsonSerializable"));
    Assert.assertTrue("Generated class should contain the callSomething method", generatedClass.contains("public void callSomething(CallSomethingSomethingParam somethingParam)"));
}
Also used : ComponentFunctionParameterData(com.vaadin.generator.metadata.ComponentFunctionParameterData) ComponentObjectTypeInnerType(com.vaadin.generator.metadata.ComponentObjectType.ComponentObjectTypeInnerType) ComponentObjectType(com.vaadin.generator.metadata.ComponentObjectType) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ComponentFunctionData(com.vaadin.generator.metadata.ComponentFunctionData) Test(org.junit.Test)

Example 2 with ComponentFunctionParameterData

use of com.vaadin.generator.metadata.ComponentFunctionParameterData in project flow by vaadin.

the class ComponentGeneratorTest method classContainsOverloadedMethodsForMethodsThatAcceptMultipleTypes_withObjectTypes.

@Test
public void classContainsOverloadedMethodsForMethodsThatAcceptMultipleTypes_withObjectTypes() {
    ComponentObjectTypeInnerType stringObjectTypeInnerType = new ComponentObjectTypeInnerType();
    stringObjectTypeInnerType.setName("internalString");
    stringObjectTypeInnerType.setType(Collections.singletonList(ComponentBasicType.STRING));
    ComponentObjectType stringObjectType = new ComponentObjectType();
    stringObjectType.setInnerTypes(Collections.singletonList(stringObjectTypeInnerType));
    ComponentFunctionParameterData firstParameter = new ComponentFunctionParameterData();
    firstParameter.setName("firstParam");
    firstParameter.setObjectType(Collections.singletonList(stringObjectType));
    ComponentFunctionParameterData secondParameter = new ComponentFunctionParameterData();
    secondParameter.setName("secondParam");
    secondParameter.setType(new HashSet<>(Arrays.asList(ComponentBasicType.STRING, ComponentBasicType.BOOLEAN)));
    ComponentFunctionData function = new ComponentFunctionData();
    function.setName("callSomething");
    function.setParameters(Arrays.asList(firstParameter, secondParameter));
    componentMetadata.setMethods(Collections.singletonList(function));
    String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
    generatedClass = ComponentGeneratorTestUtils.removeIndentation(generatedClass);
    Assert.assertTrue(generatedClass.contains("public void callSomething(CallSomethingFirstParam firstParam, String secondParam)"));
    Assert.assertTrue(generatedClass.contains("public void callSomething(CallSomethingFirstParam firstParam, boolean secondParam)"));
}
Also used : ComponentFunctionParameterData(com.vaadin.generator.metadata.ComponentFunctionParameterData) ComponentObjectTypeInnerType(com.vaadin.generator.metadata.ComponentObjectType.ComponentObjectTypeInnerType) ComponentObjectType(com.vaadin.generator.metadata.ComponentObjectType) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ComponentFunctionData(com.vaadin.generator.metadata.ComponentFunctionData) Test(org.junit.Test)

Example 3 with ComponentFunctionParameterData

use of com.vaadin.generator.metadata.ComponentFunctionParameterData in project flow by vaadin.

the class ComponentGeneratorTest method componentContainsFunctionsWithUnregognizedParameterTypes_methodsAreGeneratedAsProtected.

@Test
public void componentContainsFunctionsWithUnregognizedParameterTypes_methodsAreGeneratedAsProtected() {
    ComponentFunctionParameterData objectParameter = new ComponentFunctionParameterData();
    objectParameter.setName("objectParam");
    objectParameter.setType(Collections.singleton(ComponentBasicType.OBJECT));
    ComponentFunctionData function1 = new ComponentFunctionData();
    function1.setName("callSomethingWithObject");
    function1.setParameters(Collections.singletonList(objectParameter));
    ComponentFunctionParameterData stringParameter = new ComponentFunctionParameterData();
    stringParameter.setName("stringParam");
    stringParameter.setType(Collections.singleton(ComponentBasicType.STRING));
    ComponentFunctionData function2 = new ComponentFunctionData();
    function2.setName("callSomethingWithObjectAndString");
    function2.setParameters(Arrays.asList(objectParameter, stringParameter));
    ComponentFunctionParameterData multiParameter = new ComponentFunctionParameterData();
    multiParameter.setName("multiParam");
    multiParameter.setType(new HashSet<>(Arrays.asList(ComponentBasicType.STRING, ComponentBasicType.OBJECT, ComponentBasicType.ARRAY, ComponentBasicType.UNDEFINED)));
    ComponentFunctionData function3 = new ComponentFunctionData();
    function3.setName("callSomethingWithMultiTypes");
    function3.setParameters(Collections.singletonList(multiParameter));
    componentMetadata.setMethods(Arrays.asList(function1, function2, function3));
    String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
    generatedClass = ComponentGeneratorTestUtils.removeIndentation(generatedClass);
    Assert.assertTrue(generatedClass.contains("protected void callSomethingWithObject(JsonObject objectParam)"));
    Assert.assertTrue(generatedClass.contains("protected void callSomethingWithObjectAndString(JsonObject objectParam, String stringParam)"));
    Assert.assertTrue(generatedClass.contains("public void callSomethingWithMultiTypes(String multiParam)"));
    Assert.assertTrue(generatedClass.contains("protected void callSomethingWithMultiTypes(JsonObject multiParam)"));
    Assert.assertTrue(generatedClass.contains("protected void callSomethingWithMultiTypes(JsonArray multiParam)"));
    Assert.assertTrue(generatedClass.contains("protected void callSomethingWithMultiTypes(JsonValue multiParam)"));
}
Also used : ComponentFunctionParameterData(com.vaadin.generator.metadata.ComponentFunctionParameterData) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ComponentFunctionData(com.vaadin.generator.metadata.ComponentFunctionData) Test(org.junit.Test)

Example 4 with ComponentFunctionParameterData

use of com.vaadin.generator.metadata.ComponentFunctionParameterData in project flow by vaadin.

the class ComponentGeneratorTest method componentContainsUnrecognizedPropertyTypes_methodsAreGeneratedAsProtected.

@Test
public void componentContainsUnrecognizedPropertyTypes_methodsAreGeneratedAsProtected() {
    ComponentPropertyData objectProperty = new ComponentPropertyData();
    objectProperty.setName("objectProperty");
    objectProperty.setType(Collections.singleton(ComponentBasicType.OBJECT));
    ComponentPropertyData arrayProperty = new ComponentPropertyData();
    arrayProperty.setName("arrayProperty");
    arrayProperty.setType(Collections.singleton(ComponentBasicType.ARRAY));
    ComponentPropertyData undefinedProperty = new ComponentPropertyData();
    undefinedProperty.setName("undefinedProperty");
    undefinedProperty.setType(Collections.singleton(ComponentBasicType.UNDEFINED));
    componentMetadata.setProperties(Arrays.asList(objectProperty, arrayProperty, undefinedProperty));
    ComponentFunctionParameterData objectParameter = new ComponentFunctionParameterData();
    objectParameter.setName("objectParam");
    objectParameter.setType(Collections.singleton(ComponentBasicType.OBJECT));
    ComponentFunctionData function = new ComponentFunctionData();
    function.setName("callSomething");
    function.setParameters(Collections.singletonList(objectParameter));
    componentMetadata.setMethods(Collections.singletonList(function));
    String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
    generatedClass = ComponentGeneratorTestUtils.removeIndentation(generatedClass);
    Assert.assertThat(generatedClass, CoreMatchers.containsString("protected JsonObject getObjectPropertyJsonObject()"));
    Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void setObjectProperty(JsonObject objectProperty)"));
    Assert.assertThat(generatedClass, CoreMatchers.containsString("protected JsonArray getArrayPropertyJsonArray()"));
    Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void setArrayProperty(JsonArray arrayProperty)"));
    Assert.assertThat(generatedClass, CoreMatchers.containsString("protected JsonValue getUndefinedPropertyJsonValue()"));
    Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void setUndefinedProperty(JsonValue undefinedProperty)"));
    Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void callSomething(JsonObject objectParam)"));
}
Also used : ComponentFunctionParameterData(com.vaadin.generator.metadata.ComponentFunctionParameterData) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ComponentPropertyData(com.vaadin.generator.metadata.ComponentPropertyData) ComponentFunctionData(com.vaadin.generator.metadata.ComponentFunctionData) Test(org.junit.Test)

Example 5 with ComponentFunctionParameterData

use of com.vaadin.generator.metadata.ComponentFunctionParameterData in project flow by vaadin.

the class FunctionParameterVariantCombinator method generateCombinations.

private static Set<List<ComponentType>> generateCombinations(ComponentFunctionParameterData paramData, List<ComponentFunctionParameterData> rest) {
    Comparator<List<ComponentType>> listComparator = Comparator.comparing(List::toString);
    if (rest.isEmpty()) {
        return getTypeVariants(paramData).stream().map(Arrays::asList).sorted(listComparator).collect(Collectors.toSet());
    }
    List<ComponentFunctionParameterData> copy = new ArrayList<>(rest);
    Set<List<ComponentType>> ret = new TreeSet<>(listComparator);
    for (List<ComponentType> subCombinations : generateCombinations(copy.remove(0), copy)) {
        for (ComponentType typeVariants : getTypeVariants(paramData)) {
            List<ComponentType> tmp = new ArrayList<>(subCombinations);
            tmp.add(0, typeVariants);
            ret.add(tmp);
        }
    }
    return ret;
}
Also used : ComponentFunctionParameterData(com.vaadin.generator.metadata.ComponentFunctionParameterData) ComponentType(com.vaadin.generator.metadata.ComponentType) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Arrays(java.util.Arrays)

Aggregations

ComponentFunctionParameterData (com.vaadin.generator.metadata.ComponentFunctionParameterData)7 ComponentFunctionData (com.vaadin.generator.metadata.ComponentFunctionData)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 Test (org.junit.Test)6 ComponentObjectType (com.vaadin.generator.metadata.ComponentObjectType)2 ComponentObjectTypeInnerType (com.vaadin.generator.metadata.ComponentObjectType.ComponentObjectTypeInnerType)2 ComponentPropertyData (com.vaadin.generator.metadata.ComponentPropertyData)1 ComponentType (com.vaadin.generator.metadata.ComponentType)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1