use of com.vaadin.generator.metadata.ComponentType in project flow by vaadin.
the class ComponentGenerator method generateMethodParameters.
/**
* Adds the parameters and javadocs to the given method and generates nested
* classes for complex object parameters if needed.
*
* @param javaClass
* the main class file
* @param method
* the method to add parameters to
* @param function
* the function data
* @param typeVariant
* the list of types to use for each added parameter
* @param nestedClassesMap
* map for memorizing already generated nested classes
* @return a string of the parameters of the function, or an empty string if
* no parameters
*/
private String generateMethodParameters(JavaClassSource javaClass, MethodSource<JavaClassSource> method, ComponentFunctionData function, List<ComponentType> typeVariant, Map<ComponentObjectType, JavaClassSource> nestedClassesMap) {
int paramIndex = 0;
StringBuilder sb = new StringBuilder();
for (ComponentType paramType : typeVariant) {
String paramName = function.getParameters().get(paramIndex).getName();
String paramDescription = function.getParameters().get(paramIndex).getDescription();
String formattedName = StringUtils.uncapitalize(ComponentGeneratorUtils.formatStringToValidJavaIdentifier(function.getParameters().get(paramIndex).getName()));
paramIndex++;
if (paramType.isBasicType()) {
ComponentBasicType bt = (ComponentBasicType) paramType;
ComponentGeneratorUtils.addMethodParameter(javaClass, method, ComponentGeneratorUtils.toJavaType(bt), formattedName);
sb.append(", ").append(formattedName);
} else {
ComponentObjectType ot = (ComponentObjectType) paramType;
String nameHint = function.getName() + "-" + paramName;
JavaClassSource nestedClass = nestedClassesMap.computeIfAbsent(ot, objectType -> generateNestedPojo(javaClass, objectType, nameHint, String.format("Class that encapsulates the data to be sent to the {@link %s#%s(%s)} method.", javaClass.getName(), method.getName(), ComponentGeneratorUtils.generateValidJavaClassName(nameHint))));
sb.append(", ").append(formattedName).append(".toJson()");
method.getJavaDoc().addTagValue(JAVADOC_SEE, nestedClass.getName());
method.addParameter(nestedClass, formattedName);
}
method.getJavaDoc().addTagValue(JAVADOC_PARAM, String.format("%s %s", formattedName, paramDescription));
}
return sb.toString();
}
use of com.vaadin.generator.metadata.ComponentType 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;
}
Aggregations