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

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


The following commit(s) were added to refs/heads/feature/external-types by this 
push:
     new 952c05a736 chore: Finished implementing the
952c05a736 is described below

commit 952c05a7364e39413939735c7fd9758f66d10d4b
Author: Christofer Dutz <[email protected]>
AuthorDate: Wed Oct 16 21:20:34 2024 +0200

    chore: Finished implementing the
---
 .../protocol/freemarker/FreemarkerLanguageOutput.java  |  4 ++--
 .../main/resources/templates/go/enum-template.go.ftlh  |  7 +++----
 .../templates/go/parser-factory-template.go.ftlh       | 18 +++++++++++++++++-
 .../templates/go/xml-parser-factory-template.go.ftlh   | 18 +++++++++++++++++-
 plc4go/protocols/ads/readwrite/ParserHelper.go         |  3 ++-
 plc4go/protocols/ads/readwrite/XmlParserHelper.go      |  3 ++-
 6 files changed, 43 insertions(+), 10 deletions(-)

diff --git 
a/code-generation/language-base-freemarker/src/main/java/org/apache/plc4x/plugins/codegenerator/protocol/freemarker/FreemarkerLanguageOutput.java
 
b/code-generation/language-base-freemarker/src/main/java/org/apache/plc4x/plugins/codegenerator/protocol/freemarker/FreemarkerLanguageOutput.java
index 68cc3e29fc..6de1d9593e 100644
--- 
a/code-generation/language-base-freemarker/src/main/java/org/apache/plc4x/plugins/codegenerator/protocol/freemarker/FreemarkerLanguageOutput.java
+++ 
b/code-generation/language-base-freemarker/src/main/java/org/apache/plc4x/plugins/codegenerator/protocol/freemarker/FreemarkerLanguageOutput.java
@@ -75,7 +75,7 @@ public abstract class FreemarkerLanguageOutput implements 
LanguageOutput {
             typeContext.put("languageName", languageName);
             typeContext.put("protocolName", protocolName);
             typeContext.put("outputFlavor", outputFlavor);
-            typeContext.put("helper", getHelper(null, protocolName, 
outputFlavor, types, options, externalTypes));
+            typeContext.put("helper", getHelper(null, protocolName, 
outputFlavor, types, externalTypes, options));
             typeContext.put("tracer", Tracer.start("global"));
             typeContext.putAll(options);
 
@@ -129,7 +129,7 @@ public abstract class FreemarkerLanguageOutput implements 
LanguageOutput {
             typeContext.put("languageName", languageName);
             typeContext.put("protocolName", protocolName);
             typeContext.put("outputFlavor", outputFlavor);
-            typeContext.put("helper", getHelper(null, protocolName, 
outputFlavor, types, options, externalTypes));
+            typeContext.put("helper", getHelper(null, protocolName, 
outputFlavor, types, externalTypes, options));
             typeContext.putAll(options);
 
             for (Template template : miscTemplateList) {
diff --git 
a/code-generation/language-go/src/main/resources/templates/go/enum-template.go.ftlh
 
b/code-generation/language-go/src/main/resources/templates/go/enum-template.go.ftlh
index cc2ee762b4..38595a0ac6 100644
--- 
a/code-generation/language-go/src/main/resources/templates/go/enum-template.go.ftlh
+++ 
b/code-generation/language-go/src/main/resources/templates/go/enum-template.go.ftlh
@@ -54,7 +54,6 @@ import (
        "context"
        "fmt"
 
-       "github.com/apache/plc4x/plc4go/spi/utils"
        <#if helper.getRequiredImports()?has_content>
                <#list helper.getRequiredImports() as import>
                        ${import}
@@ -68,10 +67,10 @@ import (
        ${sectionContent}
 </#macro>
 
-<#macro emitImport import>${helper.emitDataIoRequiredImport(import)}</#macro>
-<#macro emitImportWithAlias alias 
import>${helper.emitDataIoRequiredImport(alias, import)}</#macro>
+<#macro emitImport import>${helper.emitRequiredImport(import)}</#macro>
+<#macro emitImportWithAlias alias import>${helper.emitRequiredImport(alias, 
import)}</#macro>
 
-<@importSectionWithContentBelow><@emitImport 
import="github.com/apache/plc4x/plc4go/spi/utils" /><@emitImport 
import="github.com/apache/plc4x/plc4go/spi/values" /><@emitImportWithAlias 
alias="api" import="github.com/apache/plc4x/plc4go/pkg/api/values" />
+<@importSectionWithContentBelow><@emitImport 
import="github.com/apache/plc4x/plc4go/spi/utils" />
 // Code generated by code-generation. DO NOT EDIT.
 
 <#assign baseType><#if 
type.type.isPresent()>${helper.getLanguageTypeNameForTypeReference(type.type.orElseThrow())}<#else>string</#if></#assign>
diff --git 
a/code-generation/language-go/src/main/resources/templates/go/parser-factory-template.go.ftlh
 
b/code-generation/language-go/src/main/resources/templates/go/parser-factory-template.go.ftlh
index 92d9207444..f41746fd9b 100644
--- 
a/code-generation/language-go/src/main/resources/templates/go/parser-factory-template.go.ftlh
+++ 
b/code-generation/language-go/src/main/resources/templates/go/parser-factory-template.go.ftlh
@@ -47,14 +47,28 @@ ${helper.fileName(protocolName, languageName, 
outputFlavor)?replace(".", "/")}/P
 
 package ${outputFlavor?replace("-","")}
 
+<#macro importSectionWithContentBelow>
+       <#local sectionContent><#nested></#local>
 import (
        "context"
 
        . 
"github.com/apache/plc4x/plc4go/protocols/${helper.getSanitizedPackageName()}/${outputFlavor?replace("-","")}/model"
-       "github.com/apache/plc4x/plc4go/spi/utils"
+       <#if helper.getRequiredImports()?has_content>
+               <#list helper.getRequiredImports() as import>
+                       ${import}
+               </#list>
+       </#if>
+
        "github.com/pkg/errors"
 )
 
+       ${sectionContent}
+</#macro>
+
+<#macro emitImport import>${helper.emitRequiredImport(import)}</#macro>
+<#macro emitImportWithAlias alias import>${helper.emitRequiredImport(alias, 
import)}</#macro>
+
+<@importSectionWithContentBelow><@emitImport 
import="github.com/apache/plc4x/plc4go/spi/utils" />
 // Code generated by code-generation. DO NOT EDIT.
 
 type ${helper.getSanitizedProtocolName()?cap_first}ParserHelper struct {
@@ -83,4 +97,6 @@ func (m 
${helper.getSanitizedProtocolName()?cap_first}ParserHelper) Parse(typeNa
        }
        return nil, errors.Errorf("Unsupported type %s", typeName)
 }
+</@importSectionWithContentBelow>
+
 </#outputformat>
\ No newline at end of file
diff --git 
a/code-generation/language-go/src/main/resources/templates/go/xml-parser-factory-template.go.ftlh
 
b/code-generation/language-go/src/main/resources/templates/go/xml-parser-factory-template.go.ftlh
index c3a115de6c..94b7720612 100644
--- 
a/code-generation/language-go/src/main/resources/templates/go/xml-parser-factory-template.go.ftlh
+++ 
b/code-generation/language-go/src/main/resources/templates/go/xml-parser-factory-template.go.ftlh
@@ -47,16 +47,30 @@ ${helper.fileName(protocolName, languageName, 
outputFlavor)?replace(".", "/")}/X
 
 package ${outputFlavor?replace("-","")}
 
+<#macro importSectionWithContentBelow>
+       <#local sectionContent><#nested></#local>
 import (
        "context"
        "strings"
        "strconv"
 
        . 
"github.com/apache/plc4x/plc4go/protocols/${helper.getSanitizedPackageName()}/${outputFlavor?replace("-","")}/model"
-       "github.com/apache/plc4x/plc4go/spi/utils"
+       <#if helper.getRequiredImports()?has_content>
+               <#list helper.getRequiredImports() as import>
+                       ${import}
+               </#list>
+       </#if>
+
        "github.com/pkg/errors"
 )
 
+       ${sectionContent}
+</#macro>
+
+<#macro emitImport import>${helper.emitRequiredImport(import)}</#macro>
+<#macro emitImportWithAlias alias import>${helper.emitRequiredImport(alias, 
import)}</#macro>
+
+<@importSectionWithContentBelow><@emitImport 
import="github.com/apache/plc4x/plc4go/spi/utils" />
 // Code generated by code-generation. DO NOT EDIT.
 
 type ${helper.getSanitizedProtocolName()?cap_first}XmlParserHelper struct {
@@ -127,4 +141,6 @@ func (m 
${helper.getSanitizedProtocolName()?cap_first}XmlParserHelper) Parse(typ
     }
     return nil, errors.Errorf("Unsupported type %s", typeName)
 }
+</@importSectionWithContentBelow>
+
 </#outputformat>
\ No newline at end of file
diff --git a/plc4go/protocols/ads/readwrite/ParserHelper.go 
b/plc4go/protocols/ads/readwrite/ParserHelper.go
index 50fdbe34b6..820fc70a6b 100644
--- a/plc4go/protocols/ads/readwrite/ParserHelper.go
+++ b/plc4go/protocols/ads/readwrite/ParserHelper.go
@@ -24,6 +24,7 @@ import (
 
        "github.com/pkg/errors"
 
+       api "github.com/apache/plc4x/plc4go/pkg/api/values"
        . "github.com/apache/plc4x/plc4go/protocols/ads/readwrite/model"
        "github.com/apache/plc4x/plc4go/spi/utils"
 )
@@ -38,7 +39,7 @@ func (m AdsParserHelper) Parse(typeName string, arguments 
[]string, io utils.Rea
        case "AmsSerialFrame":
                return AmsSerialFrameParseWithBuffer(context.Background(), io)
        case "DataItem":
-               plcValueType, _ := PlcValueTypeByName(arguments[0])
+               plcValueType, _ := api.PlcValueTypeByName(arguments[0])
                stringLength, err := utils.StrToInt32(arguments[1])
                if err != nil {
                        return nil, errors.Wrap(err, "Error parsing")
diff --git a/plc4go/protocols/ads/readwrite/XmlParserHelper.go 
b/plc4go/protocols/ads/readwrite/XmlParserHelper.go
index 124aaf7ae1..3a9228d9cb 100644
--- a/plc4go/protocols/ads/readwrite/XmlParserHelper.go
+++ b/plc4go/protocols/ads/readwrite/XmlParserHelper.go
@@ -26,6 +26,7 @@ import (
 
        "github.com/pkg/errors"
 
+       api "github.com/apache/plc4x/plc4go/pkg/api/values"
        . "github.com/apache/plc4x/plc4go/protocols/ads/readwrite/model"
        "github.com/apache/plc4x/plc4go/spi/utils"
 )
@@ -48,7 +49,7 @@ func (m AdsXmlParserHelper) Parse(typeName string, xmlString 
string, parserArgum
        case "AmsSerialFrame":
                return AmsSerialFrameParseWithBuffer(context.Background(), 
utils.NewXmlReadBuffer(strings.NewReader(xmlString)))
        case "DataItem":
-               plcValueType, _ := PlcValueTypeByName(parserArguments[0])
+               plcValueType, _ := api.PlcValueTypeByName(parserArguments[0])
                parsedInt1, err := strconv.ParseInt(parserArguments[1], 10, 32)
                if err != nil {
                        return nil, err

Reply via email to