use of org.kie.workbench.common.stunner.core.processors.ProcessingContext in project kie-wb-common by kiegroup.
the class BindableDefinitionAdapterGenerator method generate.
public StringBuffer generate(final String packageName, final String className, final ProcessingContext processingContext, final Messager messager) throws GenerationException {
Map<String, Object> root = new HashMap<String, Object>();
root.put("packageName", packageName);
root.put("className", className);
root.put("generatedByClassName", BindableDefinitionAdapterGenerator.class.getName());
ProcessingDefinitionAnnotations processingDefinitionAnnotations = processingContext.getDefinitionAnnotations();
// Bindings.
Map<String, List<String>> fieldNames = processingDefinitionAnnotations.getPropertyFieldNames();
Map<String, String> defAdapterBindings = new HashMap<>();
fieldNames.forEach((type, fields) -> {
String baseType = processingDefinitionAnnotations.getBaseTypes().get(type);
baseType = null != baseType && baseType.trim().length() > 0 ? baseType : "java.lang.Object";
String graphFactory = processingDefinitionAnnotations.getGraphFactory().get(type);
String idField = processingDefinitionAnnotations.getIdFieldNames().get(type);
idField = null != idField && idField.trim().length() > 0 ? "\"" + idField + "\"" : null;
String titleField = processingDefinitionAnnotations.getTitleFieldNames().get(type);
titleField = null != titleField && titleField.trim().length() > 0 ? "\"" + titleField + "\"" : null;
String labelsField = "\"" + processingDefinitionAnnotations.getLabelsFieldNames().get(type) + "\"";
String categoryField = "\"" + processingDefinitionAnnotations.getCategoryFieldNames().get(type) + "\"";
String descriptionField = processingDefinitionAnnotations.getDescriptionFieldNames().get(type);
descriptionField = null != descriptionField && descriptionField.trim().length() > 0 ? "\"" + descriptionField + "\"" : null;
List<String> propertyFields = processingDefinitionAnnotations.getPropertyFieldNames().get(type);
String propertyFieldsArray = propertyFields.stream().map(f -> "\"" + f + "\"").collect(Collectors.joining(","));
List<Boolean> typedPropertyFields = processingDefinitionAnnotations.getTypedPropertyFields().get(type);
String typedPropertyFieldsArray = typedPropertyFields.stream().map(Object::toString).collect(Collectors.joining(","));
DefinitionAdapterBindings.PropertyMetaTypes metaTypes = processingContext.getMetaPropertyTypesFields().get(type);
defAdapterBindings.put(type, "new DefinitionAdapterBindings()" + ".setBaseType(" + baseType + ".class)" + ".setGraphFactory(" + graphFactory + ".class)" + ".setIdField(" + idField + ")" + ".setTitleField(" + titleField + ")" + ".setLabelsField(" + labelsField + ")" + ".setCategoryField(" + categoryField + ")" + ".setDescriptionField(" + descriptionField + ")" + ".setPropertiesFieldNames(Arrays.asList(" + propertyFieldsArray + "))" + ".setTypedPropertyFields(Arrays.asList(" + typedPropertyFieldsArray + "))" + ".setMetaTypes(DefinitionAdapterBindings.PropertyMetaTypes.parse(\"" + metaTypes.format() + "\"))");
});
addFields("bindings", root, defAdapterBindings);
// Generate code
return writeTemplate(packageName, className, root, messager);
}
Aggregations