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