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;
}
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();
}
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;
}
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;
}
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;
}
Aggregations