Search in sources :

Example 1 with DefinitionAdapterBindings

use of org.kie.workbench.common.stunner.core.definition.adapter.binding.DefinitionAdapterBindings 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);
}
Also used : GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException) List(java.util.List) AbstractBindableAdapterGenerator(org.kie.workbench.common.stunner.core.processors.AbstractBindableAdapterGenerator) DefinitionAdapterBindings(org.kie.workbench.common.stunner.core.definition.adapter.binding.DefinitionAdapterBindings) Map(java.util.Map) ProcessingDefinitionAnnotations(org.kie.workbench.common.stunner.core.processors.ProcessingDefinitionAnnotations) HashMap(java.util.HashMap) ProcessingContext(org.kie.workbench.common.stunner.core.processors.ProcessingContext) Collectors(java.util.stream.Collectors) Messager(javax.annotation.processing.Messager) HashMap(java.util.HashMap) ProcessingDefinitionAnnotations(org.kie.workbench.common.stunner.core.processors.ProcessingDefinitionAnnotations) List(java.util.List) DefinitionAdapterBindings(org.kie.workbench.common.stunner.core.definition.adapter.binding.DefinitionAdapterBindings)

Aggregations

HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Messager (javax.annotation.processing.Messager)1 DefinitionAdapterBindings (org.kie.workbench.common.stunner.core.definition.adapter.binding.DefinitionAdapterBindings)1 AbstractBindableAdapterGenerator (org.kie.workbench.common.stunner.core.processors.AbstractBindableAdapterGenerator)1 ProcessingContext (org.kie.workbench.common.stunner.core.processors.ProcessingContext)1 ProcessingDefinitionAnnotations (org.kie.workbench.common.stunner.core.processors.ProcessingDefinitionAnnotations)1 GenerationException (org.uberfire.annotations.processors.exceptions.GenerationException)1