Skip to content

Commit fdeb863

Browse files
committed
fix(code-gen/go): add support for typeswitch in typeswitch
#1738
1 parent aaf78d9 commit fdeb863

31 files changed

+7973
-262
lines changed

code-generation/language-base-freemarker/src/main/java/org/apache/plc4x/plugins/codegenerator/protocol/freemarker/BaseFreemarkerLanguageTemplateHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ public boolean isWildcard(Term term) {
361361
}
362362

363363
/**
364-
* can be used to throw a exception from the template
364+
* can be used to throw an exception from the template
365365
*
366366
* @param message the message
367367
* @return the exception

code-generation/language-go/src/main/resources/templates/go/complex-type-template.go.ftlh

+3-5
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,13 @@ type _${type.name} struct {
158158
}
159159

160160
<#if type.isDiscriminatedParentTypeDefinition()>
161-
<#assign complexTypeDefinition = type.asComplexTypeDefinition().orElseThrow()>
162161
type _${type.name}ChildRequirements interface {
163162
utils.Serializable
164163
GetLengthInBits(ctx context.Context) uint16
165-
<#list complexTypeDefinition.getDiscriminatorNames() as discriminatorName>
164+
<#list helper.discriminatorTypes as discriminatorName, discriminatorType>
166165
<#-- If the discriminator name matches that of another field, suppress the methods generation -->
167166
<#if type.isDiscriminatorField(discriminatorName)>
168-
<#assign typeRef=helper.getDiscriminatorTypes()[discriminatorName]>
169-
Get${discriminatorName?cap_first}() <#if typeRef.isNonSimpleTypeReference() && !typeRef.isEnumTypeReference()>I</#if>${helper.getLanguageTypeNameForTypeReference(typeRef)}
167+
Get${discriminatorName?cap_first}() <#if discriminatorType.isNonSimpleTypeReference() && !discriminatorType.isEnumTypeReference()>I</#if>${helper.getLanguageTypeNameForTypeReference(discriminatorType)}
170168
</#if>
171169
</#list>
172170
<#list type.abstractFields as field>
@@ -188,7 +186,7 @@ type _${type.name}ChildRequirements interface {
188186
<#list discriminatedChildType.getDiscriminatorMap() as discriminatorName, discriminatorTerm>
189187
<#-- If the discriminator name matches that of another field, suppress the methods generation -->
190188
<#if !type.isNonDiscriminatorField(discriminatorName)>
191-
<#assign typeRef=helper.getDiscriminatorTypes()[discriminatorName]>
189+
<#assign typeRef=helper.getDiscriminatorTypes(discriminatedChildType.parentType.orElseThrow())[discriminatorName]>
192190
func (m *_${type.name}) Get${discriminatorName?cap_first}() <#if typeRef.isNonSimpleTypeReference() && !typeRef.isEnumTypeReference()>I</#if>${helper.getLanguageTypeNameForTypeReference(typeRef)} {
193191
<@compress single_line=true>
194192
return

plc4go/internal/bacnetip/mock_APCI_test.go

+249-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)