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 2020/10/12 21:32:44 UTC

[plc4x] branch feature/plc4go updated: - Finished the last little quirks in the code-generation

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

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


The following commit(s) were added to refs/heads/feature/plc4go by this push:
     new c2246c8  - Finished the last little quirks in the code-generation
c2246c8 is described below

commit c2246c8a5ccaa99de7743f167ccae99176c8f6db
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Oct 12 23:32:33 2020 +0200

    - Finished the last little quirks in the code-generation
---
 .../plc4x/language/go/GoLanguageTemplateHelper.java | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/build-utils/language-go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java b/build-utils/language-go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java
index 6bd1ef1..769e0c6 100644
--- a/build-utils/language-go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java
+++ b/build-utils/language-go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java
@@ -683,17 +683,24 @@ public class GoLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHelp
 
     public List<String> getRequiredImports() {
         List<String> imports = new ArrayList<>();
+
+        // For "Fields with complex type", constant, typeSwitch,  fields: "errors"
+        if(((ComplexTypeDefinition) getThisTypeDefinition()).getFields().stream().anyMatch(field ->
+            (field instanceof ConstField) || (field instanceof SwitchField) ||
+                ((field instanceof TypedField) && ((TypedField) field).getType() instanceof ComplexTypeReference))) {
+            imports.add("\"errors\"");
+        }
+
         // At least one reserved field or simple field with complex type
         if(((ComplexTypeDefinition) getThisTypeDefinition()).getFields().stream().anyMatch(field ->
             (field instanceof ReservedField))) {
             imports.add("log \"github.com/sirupsen/logrus\"");
         }
 
-        // For "Fields with complex type", constant, typeSwitch,  fields: "errors"
+        // For CEIL functions: "math"
         if(((ComplexTypeDefinition) getThisTypeDefinition()).getFields().stream().anyMatch(field ->
-            (field instanceof ConstField) || (field instanceof SwitchField) ||
-                ((field instanceof TypedField) && ((TypedField) field).getType() instanceof ComplexTypeReference))) {
-            imports.add("\"errors\"");
+            FieldUtils.contains(field, "CEIL"))) {
+            imports.add("\"math\"");
         }
 
         // "Fields with complex type": "reflect"
@@ -709,12 +716,6 @@ public class GoLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHelp
             imports.add("\"strconv\"");
         }
 
-        // For CEIL functions: "math"
-        if(((ComplexTypeDefinition) getThisTypeDefinition()).getFields().stream().anyMatch(field ->
-            FieldUtils.contains(field, "CEIL"))) {
-            imports.add("\"math\"");
-        }
-
         return imports;
     }