Skip to content

Commit

Permalink
fix(plc4j/codgen): avoid duplicating params
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Oct 27, 2021
1 parent 8a16e46 commit 194cff3
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,15 @@ public String getDataReaderCall(TypeReference typeReference, String resolverMeth
StringBuilder paramsString = new StringBuilder();
ComplexTypeReference complexTypeReference = typeReference.asComplexTypeReference().orElseThrow(IllegalStateException::new);
TypeDefinition typeDefinition = getTypeDefinitionForTypeReference(typeReference);
int parentParamIndex = -1;
if (typeDefinition.isDiscriminatedChildTypeDefinition()) {
List<Term> parentParamTerms = typeDefinition.getParentType().getTypeReference().asComplexTypeReference()
.orElseThrow(() -> new IllegalStateException("Shouldn't happen as the parent must be complex"))
.getParams()
.orElse(Collections.emptyList());
ComplexTypeReference parentTypeReference = typeDefinition.getParentType().getTypeReference().asComplexTypeReference().orElseThrow(IllegalStateException::new);
for (int i = 0; i < parentParamTerms.size(); i++) {
parentParamIndex++;
Term paramTerm = parentParamTerms.get(i);
paramsString
.append(", (")
Expand All @@ -396,6 +398,10 @@ public String getDataReaderCall(TypeReference typeReference, String resolverMeth
}
List<Term> paramTerms = complexTypeReference.getParams().orElse(Collections.emptyList());
for (int i = 0; i < paramTerms.size(); i++) {
if (i <= parentParamIndex) {
// Ignore params that are part of the parent
continue;
}
Term paramTerm = paramTerms.get(i);
paramsString
.append(", (")
Expand Down

0 comments on commit 194cff3

Please sign in to comment.