Search in sources :

Example 16 with GenerationException

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

the class MainProcessor method processLastRoundDefinitionSetProxyAdapter.

private boolean processLastRoundDefinitionSetProxyAdapter(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() + DEFINITIONSET_PROXY_CLASSNAME;
        final String classFQName = packageName + "." + className;
        messager.printMessage(Diagnostic.Kind.NOTE, "Starting DefinitionSetProxyAdapter adf for class named " + classFQName);
        final StringBuffer ruleClassCode = definitionSetProxyGenerator.generate(packageName, className, processingContext.getDefinitionSet(), processingContext.getDefSetAnnotations().getBuilderFieldNames(), 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 17 with GenerationException

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

the class CardinalityRuleGenerator method generateRule.

private StringBuffer generateRule(final Messager messager, final String ruleName, final String role, final long min, final long max) throws GenerationException {
    Map<String, Object> root = new HashMap<String, Object>();
    root.put("ruleName", ruleName);
    root.put("role", role);
    root.put("min", min);
    root.put("max", max);
    // Generate code
    final StringWriter sw = new StringWriter();
    final BufferedWriter bw = new BufferedWriter(sw);
    try {
        final Template template = config.getTemplate("CardinalityRule.ftl");
        template.process(root, 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 [" + ruleName + "]");
    return sw.getBuffer();
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) Template(freemarker.template.Template)

Example 18 with GenerationException

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

the class ConnectionRuleGenerator method generate.

@Override
public StringBuffer generate(final String packageName, final PackageElement packageElement, final String className, final Element element, final ProcessingEnvironment processingEnvironment) throws GenerationException {
    final Messager messager = processingEnvironment.getMessager();
    messager.printMessage(Diagnostic.Kind.NOTE, "Starting code adf for [" + className + "]");
    final Elements elementUtils = processingEnvironment.getElementUtils();
    // Extract required information
    final TypeElement classElement = (TypeElement) element;
    final boolean isInterface = classElement.getKind().isInterface();
    final String ruleId = MainProcessor.toValidId(className);
    final String ruleDefinitionId = classElement.getQualifiedName().toString();
    CanConnect[] pcs = classElement.getAnnotationsByType(CanConnect.class);
    List<ConnectionRuleEntry> ruleEntries = new ArrayList<>();
    if (null != pcs) {
        for (final CanConnect pc : pcs) {
            String startRole = pc.startRole();
            String endRole = pc.endRole();
            ruleEntries.add(new ConnectionRuleEntry(startRole, endRole));
        }
    }
    Map<String, Object> root = new HashMap<String, Object>();
    root.put("ruleId", ruleId);
    root.put("ruleDefinitionId", ruleDefinitionId);
    root.put("connectionsSize", ruleEntries.size());
    root.put("connections", ruleEntries);
    // Generate code
    final StringWriter sw = new StringWriter();
    final BufferedWriter bw = new BufferedWriter(sw);
    try {
        final Template template = config.getTemplate("ConnectionRule.ftl");
        template.process(root, 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 [" + className + "]");
    processingContext.addRule(ruleId, ProcessingRule.TYPE.CONNECTION, sw.getBuffer());
    return null;
}
Also used : Messager(javax.annotation.processing.Messager) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) TypeElement(javax.lang.model.element.TypeElement) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Elements(javax.lang.model.util.Elements) CanConnect(org.kie.workbench.common.stunner.core.rule.annotation.CanConnect) BufferedWriter(java.io.BufferedWriter) Template(freemarker.template.Template) StringWriter(java.io.StringWriter) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException)

Example 19 with GenerationException

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

the class ContainmentRuleGenerator method generate.

@Override
public StringBuffer generate(final String packageName, final PackageElement packageElement, final String className, final Element element, final ProcessingEnvironment processingEnvironment) throws GenerationException {
    final Messager messager = processingEnvironment.getMessager();
    messager.printMessage(Diagnostic.Kind.NOTE, "Starting code adf for [" + className + "]");
    // Extract required information
    final TypeElement classElement = (TypeElement) element;
    final String annotationName = MainProcessor.ANNOTATION_RULE_CAN_CONTAIN;
    final String ruleId = MainProcessor.toValidId(className);
    final String ruleDefinitionId = ((TypeElement) element).getQualifiedName().toString();
    List<String> roles = null;
    for (final AnnotationMirror am : classElement.getAnnotationMirrors()) {
        if (annotationName.equals(am.getAnnotationType().toString())) {
            for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet()) {
                AnnotationValue aval = entry.getValue();
                if ("roles".equals(entry.getKey().getSimpleName().toString())) {
                    roles = (List<String>) aval.getValue();
                }
            }
            break;
        }
    }
    processingContext.getContainmentRuleElementsProcessed().add(element);
    if (roles == null) {
        return null;
    }
    Map<String, Object> root = new HashMap<String, Object>();
    root.put("ruleId", ruleId);
    root.put("ruleDefinitionId", ruleDefinitionId);
    root.put("roles", roles);
    root.put("rolesCount", roles.size());
    // Generate code
    final StringWriter sw = new StringWriter();
    final BufferedWriter bw = new BufferedWriter(sw);
    try {
        final Template template = config.getTemplate("ContainmentRule.ftl");
        template.process(root, 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 [" + className + "]");
    processingContext.addRule(ruleId, ProcessingRule.TYPE.CONTAINMENT, sw.getBuffer());
    return null;
}
Also used : Messager(javax.annotation.processing.Messager) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) TypeElement(javax.lang.model.element.TypeElement) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) Template(freemarker.template.Template) AnnotationMirror(javax.lang.model.element.AnnotationMirror) StringWriter(java.io.StringWriter) AnnotationValue(javax.lang.model.element.AnnotationValue) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with GenerationException

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

the class DockingRuleGenerator method generate.

@Override
public StringBuffer generate(final String packageName, final PackageElement packageElement, final String className, final Element element, final ProcessingEnvironment processingEnvironment) throws GenerationException {
    final Messager messager = processingEnvironment.getMessager();
    messager.printMessage(Diagnostic.Kind.NOTE, "Starting code generation for [" + className + "]");
    // Extract required information
    final TypeElement classElement = (TypeElement) element;
    final String annotationName = MainProcessor.ANNOTATION_RULE_CAN_DOCK;
    final String ruleId = MainProcessor.toValidId(className);
    final String ruleDefinitionId = ((TypeElement) element).getQualifiedName().toString();
    List<String> roles = null;
    for (final AnnotationMirror am : classElement.getAnnotationMirrors()) {
        if (annotationName.equals(am.getAnnotationType().toString())) {
            for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet()) {
                AnnotationValue aval = entry.getValue();
                if ("roles".equals(entry.getKey().getSimpleName().toString())) {
                    roles = (List<String>) aval.getValue();
                }
            }
            break;
        }
    }
    processingContext.getDockingRuleElementsProcessed().add(element);
    if (roles == null) {
        return null;
    }
    Map<String, Object> root = new HashMap<String, Object>();
    root.put("ruleId", ruleId);
    root.put("ruleDefinitionId", ruleDefinitionId);
    root.put("roles", roles);
    root.put("rolesCount", roles.size());
    // Generate code
    final StringWriter sw = new StringWriter();
    final BufferedWriter bw = new BufferedWriter(sw);
    try {
        final Template template = config.getTemplate("DockingRule.ftl");
        template.process(root, 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 [" + className + "]");
    processingContext.addRule(ruleId, ProcessingRule.TYPE.DOCKING, sw.getBuffer());
    return null;
}
Also used : Messager(javax.annotation.processing.Messager) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) TypeElement(javax.lang.model.element.TypeElement) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) Template(freemarker.template.Template) AnnotationMirror(javax.lang.model.element.AnnotationMirror) StringWriter(java.io.StringWriter) AnnotationValue(javax.lang.model.element.AnnotationValue) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException) HashMap(java.util.HashMap) Map(java.util.Map)

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