Search in sources :

Example 6 with GenerationException

use of org.uberfire.annotations.processors.exceptions.GenerationException in project kie-wb-common by kiegroup.

the class AbstractGenerator method writeTemplate.

protected StringBuffer writeTemplate(final Map<String, Object> ctxt, final String path) throws GenerationException {
    // Generate code
    final StringWriter sw = new StringWriter();
    final BufferedWriter bw = new BufferedWriter(sw);
    try {
        final Template template = config.getTemplate(path + ".ftl");
        template.process(ctxt, bw);
    } catch (IOException ioe) {
        throw new GenerationException(ioe);
    } catch (TemplateException te) {
        throw new GenerationException(te);
    } finally {
        try {
            bw.close();
            sw.close();
        } catch (IOException ioe) {
            throw new GenerationException(ioe);
        }
    }
    return sw.getBuffer();
}
Also used : StringWriter(java.io.StringWriter) TemplateException(freemarker.template.TemplateException) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) Template(freemarker.template.Template)

Example 7 with GenerationException

use of org.uberfire.annotations.processors.exceptions.GenerationException in project kie-wb-common by kiegroup.

the class CircleDefinitionGenerator method doGenerate.

@Override
public StringBuffer doGenerate(final CircleDefinition input) throws GeneratorException {
    final double radius = input.getRadius();
    final Map<String, Object> root = new HashMap<String, Object>();
    root.put("className", Circle.class.getName());
    root.put("radius", formatDouble(radius));
    // Generate the code using the given template.
    try {
        return writeTemplate(root);
    } catch (final GenerationException e) {
        throw new GeneratorException(e);
    }
}
Also used : Circle(com.ait.lienzo.client.core.shape.Circle) HashMap(java.util.HashMap) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException) GeneratorException(org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException)

Example 8 with GenerationException

use of org.uberfire.annotations.processors.exceptions.GenerationException in project kie-wb-common by kiegroup.

the class GroupDefinitionGenerator method generate.

@Override
public StringBuffer generate(final GroupDefinition input) throws GeneratorException {
    final StringBuffer wrapped = super.generate(input);
    final StringBuffer wrapper;
    try {
        wrapper = writeTemplate(new HashMap<>());
        super.appendDraggable(wrapper, input);
        super.appendListening(wrapped, input);
        wrapper.append(formatString(ADD_WRAPPED, wrapped.toString()));
    } catch (final GenerationException e) {
        throw new GeneratorException(e);
    }
    return wrapper;
}
Also used : HashMap(java.util.HashMap) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException) GeneratorException(org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException)

Example 9 with GenerationException

use of org.uberfire.annotations.processors.exceptions.GenerationException in project kie-wb-common by kiegroup.

the class RectDefinitionGenerator method doGenerate.

@Override
public StringBuffer doGenerate(final RectDefinition input) throws GeneratorException {
    final double width = input.getWidth();
    final double height = input.getHeight();
    final double radius = input.getCornerRadius();
    final Map<String, Object> root = new HashMap<String, Object>();
    root.put("className", Rectangle.class.getName());
    root.put("width", formatDouble(width));
    root.put("height", formatDouble(height));
    root.put("radius", formatDouble(radius));
    // Generate the code using the given template.
    try {
        return writeTemplate(root);
    } catch (final GenerationException e) {
        throw new GeneratorException(e);
    }
}
Also used : HashMap(java.util.HashMap) Rectangle(com.ait.lienzo.client.core.shape.Rectangle) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException) GeneratorException(org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException)

Example 10 with GenerationException

use of org.uberfire.annotations.processors.exceptions.GenerationException in project kie-wb-common by kiegroup.

the class SVGViewFactoryGenerator method generate.

@Override
public StringBuffer generate(final ViewFactory viewFactory) throws GeneratorException {
    final List<StringBuffer> viewBuffers = new LinkedList<>();
    final String name = viewFactory.getSimpleName();
    final String pkg = viewFactory.getPackage();
    final List<ViewDefinition<?>> viewDefinitions = viewFactory.getViewDefinitions();
    final Map<String, String> staticFields = new LinkedHashMap<>();
    viewDefinitions.stream().forEach((viewDefinition) -> {
        try {
            if (viewDefinition instanceof ViewDefinitionImpl) {
                staticFields.putAll(((ViewDefinitionImpl) viewDefinition).getStaticFields());
            }
            final StringBuffer viewBuffer = generateView(viewFactory, viewDefinition);
            viewBuffers.add(viewBuffer);
        } catch (GeneratorException e) {
            throw new RuntimeException(e);
        }
    });
    // Generate template context.
    final List<String> viewsContent = new LinkedList<>();
    viewBuffers.forEach(b -> viewsContent.add(b.toString()));
    Map<String, Object> root = new HashMap<>();
    root.put("genClassName", this.getClass().getName());
    root.put("name", name);
    root.put("pkg", pkg);
    root.put("implementedTypeName", viewFactory.getImplementedType());
    root.put("fmethods", viewsContent);
    root.put("fields", generateStaticFields(staticFields));
    // Generate the code using the given template.
    StringBuffer result;
    try {
        result = writeTemplate(root);
    } catch (final GenerationException e) {
        throw new GeneratorException(e);
    }
    return result;
}
Also used : ViewDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ViewDefinition(org.kie.workbench.common.stunner.svg.gen.model.ViewDefinition) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException) GeneratorException(org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException)

Aggregations

GenerationException (org.uberfire.annotations.processors.exceptions.GenerationException)24 HashMap (java.util.HashMap)13 Messager (javax.annotation.processing.Messager)11 Template (freemarker.template.Template)9 TemplateException (freemarker.template.TemplateException)9 BufferedWriter (java.io.BufferedWriter)9 IOException (java.io.IOException)9 StringWriter (java.io.StringWriter)9 GeneratorException (org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException)7 LinkedHashMap (java.util.LinkedHashMap)3 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 TypeElement (javax.lang.model.element.TypeElement)3 AnnotationMirror (javax.lang.model.element.AnnotationMirror)2 AnnotationValue (javax.lang.model.element.AnnotationValue)2 ViewDefinitionImpl (org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl)2 Circle (com.ait.lienzo.client.core.shape.Circle)1 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)1 Picture (com.ait.lienzo.client.core.shape.Picture)1 Rectangle (com.ait.lienzo.client.core.shape.Rectangle)1