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/12/09 14:26:56 UTC

[plc4x] 01/04: Made the java template output Enum constants in expressions correctly

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch feature/knxnet-ip
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit aab7db394c799b8a7e85a48df2ee3a1ee95ba3f2
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Dec 9 15:24:43 2019 +0100

    Made the java template output Enum constants in expressions correctly
---
 .../apache/plc4x/language/java/JavaLanguageTemplateHelper.java    | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java b/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java
index 2dc72ba..23101f6 100644
--- a/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java
+++ b/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java
@@ -401,7 +401,13 @@ public class JavaLanguageTemplateHelper implements FreemarkerLanguageTemplateHel
             } else if(term instanceof StringLiteral) {
                 return "\"" + ((StringLiteral) term).getValue() + "\"";
             } else if(term instanceof VariableLiteral) {
-                return variableExpressionGenerator.apply(term);
+                VariableLiteral variableLiteral = (VariableLiteral) term;
+                // If this literal references an Enum type, then we have to output it differently.
+                if(types.get(variableLiteral.getName()) instanceof EnumTypeDefinition) {
+                    return variableLiteral.getName() + "." + variableLiteral.getChild().getName();
+                } else {
+                    return variableExpressionGenerator.apply(term);
+                }
             } else {
                 throw new RuntimeException("Unsupported Literal type " + term.getClass().getName());
             }