You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2019/06/03 11:34:34 UTC
[plc4x] 02/03: - Fine-tuned the code generation of optionals
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch feature/code-gen
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 9e13c3ebf3b42408a796f1656038d9bd39cb72d3
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Jun 3 13:33:46 2019 +0200
- Fine-tuned the code generation of optionals
---
.../src/main/resources/templates/java/io-template.ftlh | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/sandbox/code-generation/language-template-java/src/main/resources/templates/java/io-template.ftlh b/sandbox/code-generation/language-template-java/src/main/resources/templates/java/io-template.ftlh
index 019eb20..08f0364 100644
--- a/sandbox/code-generation/language-template-java/src/main/resources/templates/java/io-template.ftlh
+++ b/sandbox/code-generation/language-template-java/src/main/resources/templates/java/io-template.ftlh
@@ -115,7 +115,8 @@ public class ${typeName}IO {
// Optional Field (Can be skipped, if a given expression evaluates to false)
${helper.getLanguageTypeNameForSpecType(field.type)} ${field.name} = ${helper.getNullValueForType(field.type)};
- if(${field.conditionExpression}) {
+ JexlExpression ex${field.name?cap_first} = jexl.createExpression("${field.conditionExpression}");
+ if(ex${field.name?cap_first}.evaluate(jc) == Boolean.TRUE) {
${field.name} = <#if helper.isSimpleType(field.type)>io.${helper.getReadBufferReadMethodCall(field.type)}<#else>${field.type.name}IO.parse(io);</#if>;
}
jc.set("${field.name}", ${field.name});
@@ -205,7 +206,8 @@ public class ${typeName}IO {
<#case "optional">
// Optional Field (Can be skipped, if a given expression evaluates to false)
- if(value.get${field.name?cap_first}() != null) {
+ JexlExpression ex${field.name?cap_first} = jexl.createExpression("${field.conditionExpression}");
+ if(ex${field.name?cap_first}.evaluate(jc) == Boolean.TRUE) {
<#if helper.isSimpleType(field.type)>
io.${helper.getWriteBufferReadMethodCall(field.type, "value.get" + field.name?cap_first + "()")};
<#else>