Search in sources :

Example 11 with GenerationException

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

the class FormDefinitionsProcessor method writeTemplate.

protected StringBuffer writeTemplate(String templateName, Map<String, Object> context) throws GenerationException {
    // Generate code
    final StringWriter sw = new StringWriter();
    final BufferedWriter bw = new BufferedWriter(sw);
    // 'getResource(templateName).openStream()' seems to be a sensible workaround
    try (InputStream templateIs = this.getClass().getResource(templateName).openStream()) {
        Configuration config = new Configuration();
        Template template = new Template("", new InputStreamReader(templateIs), config);
        template.process(context, 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) Configuration(freemarker.template.Configuration) InputStreamReader(java.io.InputStreamReader) TemplateException(freemarker.template.TemplateException) InputStream(java.io.InputStream) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) Template(freemarker.template.Template)

Example 12 with GenerationException

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

the class AbstractAdapterGenerator method writeTemplate.

protected StringBuffer writeTemplate(final String packageName, final String className, final Map<String, Object> ctxt, final Messager messager) throws GenerationException {
    // Generate code
    final StringWriter sw = new StringWriter();
    final BufferedWriter bw = new BufferedWriter(sw);
    try {
        final Template template = config.getTemplate(getTemplatePath());
        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);
        }
    }
    messager.printMessage(Diagnostic.Kind.NOTE, "Successfully generated code for [" + packageName + "." + className + "]");
    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 13 with GenerationException

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

the class MainProcessor method processLastRoundDefinitionAdapter.

private boolean processLastRoundDefinitionAdapter(final Set<? extends TypeElement> set, final RoundEnvironment roundEnv) throws Exception {
    final Messager messager = processingEnv.getMessager();
    try {
        // Ensure visible on both backend and client sides.
        final String packageName = getGeneratedPackageName() + ".definition.adapter.binding";
        final String className = getSetClassPrefix() + DEFINITION_ADAPTER_CLASSNAME;
        final String classFQName = packageName + "." + className;
        messager.printMessage(Diagnostic.Kind.NOTE, "Starting ErraiBinderAdapter adf named " + classFQName);
        final StringBuffer ruleClassCode = definitionAdapterGenerator.generate(packageName, className, processingContext, messager);
        writeCode(packageName, className, ruleClassCode);
    } catch (GenerationException ge) {
        final String msg = ge.getMessage();
        processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, msg);
    }
    return true;
}
Also used : Messager(javax.annotation.processing.Messager) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException)

Example 14 with GenerationException

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

the class MainProcessor method processLastRoundRuleAdapter.

private boolean processLastRoundRuleAdapter(final Set<? extends TypeElement> set, final RoundEnvironment roundEnv) throws Exception {
    final Messager messager = processingEnv.getMessager();
    try {
        // Ensure visible on both backend and client sides.
        final String packageName = getGeneratedPackageName() + ".definition.adapter.binding";
        final String className = getSetClassPrefix() + RULE_ADAPTER_CLASSNAME;
        final String classFQName = packageName + "." + className;
        messager.printMessage(Diagnostic.Kind.NOTE, "Starting RuleAdapter adf for class named " + classFQName);
        final StringBuffer ruleClassCode = ruleAdapterGenerator.generate(packageName, className, processingContext.getDefinitionSet().getClassName(), processingContext.getRules(), messager);
        writeCode(packageName, className, ruleClassCode);
    } catch (GenerationException ge) {
        final String msg = ge.getMessage();
        processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, msg);
    }
    return true;
}
Also used : Messager(javax.annotation.processing.Messager) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException)

Example 15 with GenerationException

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

the class MainProcessor method processLastRoundMorphing.

private boolean processLastRoundMorphing(final Set<? extends TypeElement> set, final RoundEnvironment roundEnv) throws Exception {
    final Messager messager = processingEnv.getMessager();
    try {
        // Ensure visible on both backend and client sides.
        final String packageName = getGeneratedPackageName() + ".definition.morph";
        final Set<String> generatedDefinitionClasses = new LinkedHashSet<>();
        // MORPH DEFINITIONS GENERATION.
        Map<String, Set<String>> baseTargets = processingContext.getMorphingAnnotations().getBaseTargets();
        if (null != baseTargets && !baseTargets.isEmpty()) {
            for (Map.Entry<String, Set<String>> entry : baseTargets.entrySet()) {
                String baseType = entry.getKey();
                Set<String> targets = entry.getValue();
                final String className = getMorphDefinitionClassName(packageName, baseType, MORPH_DEFINITION_CLASSNAME)[0];
                final String classFQName = getMorphDefinitionClassName(packageName, baseType, MORPH_DEFINITION_CLASSNAME)[1];
                String defaultType = processingContext.getMorphingAnnotations().getBaseDefaultTypes().get(baseType);
                messager.printMessage(Diagnostic.Kind.NOTE, "Starting MorphDefinition adf for class named " + classFQName);
                final StringBuffer ruleClassCode = morphDefinitionGenerator.generate(packageName, className, baseType, targets, defaultType, messager);
                writeCode(packageName, className, ruleClassCode);
                generatedDefinitionClasses.add(classFQName);
            }
        }
        // MORPH PROPERTY DEFINITIONS GENERATION.
        Map<String, List<ProcessingMorphProperty>> morphProperties = processingContext.getMorphingAnnotations().getBaseMorphProperties();
        if (null != morphProperties && !morphProperties.isEmpty()) {
            for (Map.Entry<String, List<ProcessingMorphProperty>> entry : morphProperties.entrySet()) {
                String baseType = entry.getKey();
                List<ProcessingMorphProperty> properties = entry.getValue();
                final String className = getMorphDefinitionClassName(packageName, baseType, MORPH_PROPERTY_DEFINITION_CLASSNAME)[0];
                final String classFQName = getMorphDefinitionClassName(packageName, baseType, MORPH_PROPERTY_DEFINITION_CLASSNAME)[1];
                String defaultType = processingContext.getMorphingAnnotations().getBaseDefaultTypes().get(baseType);
                messager.printMessage(Diagnostic.Kind.NOTE, "Starting MorphPropertyDefinition adf for class named " + classFQName);
                final StringBuffer ruleClassCode = morphPropertyDefinitionGenerator.generate(packageName, className, baseType, properties, defaultType, messager);
                writeCode(packageName, className, ruleClassCode);
                generatedDefinitionClasses.add(classFQName);
            }
        }
        // MORPH DEFINITIONS PROVIDER GENERATION.
        if (!generatedDefinitionClasses.isEmpty()) {
            final String className = getSetClassPrefix() + MORPH_PROVIDER_CLASSNAME;
            final String classFQName = packageName + "." + className;
            messager.printMessage(Diagnostic.Kind.NOTE, "Starting MorphDefinitionProvider adf for class named " + classFQName);
            final StringBuffer ruleClassCode = morphDefinitionProviderGenerator.generate(packageName, className, generatedDefinitionClasses, messager);
            writeCode(packageName, className, ruleClassCode);
        }
    } catch (GenerationException ge) {
        final String msg = ge.getMessage();
        processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, msg);
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) DefinitionSet(org.kie.workbench.common.stunner.core.definition.annotation.DefinitionSet) Messager(javax.annotation.processing.Messager) List(java.util.List) LinkedList(java.util.LinkedList) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

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