Skip to content

Commit

Permalink
fix(plc4j/codgen): fixed issue with missing type reference params
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl authored and chrisdutz committed Nov 17, 2021
1 parent 72cb49f commit 1329013
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ public Map<String, Map<String, String>> getDiscriminatorValues() {
}
return thisType.getDiscriminatorCaseToKeyValueMap();
}

public TypeReference getArgumentType(TypeReference typeReference, int index) {
Objects.requireNonNull(typeReference, "type reference must not be null");
ComplexTypeReference complexTypeReference = typeReference.asComplexTypeReference().orElseThrow(() -> new FreemarkerException("Only complex type references supported here."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
import org.apache.plc4x.plugins.codegenerator.types.definitions.TypeDefinition;
import org.apache.plc4x.plugins.codegenerator.types.references.DefaultComplexTypeReference;
import org.apache.plc4x.plugins.codegenerator.types.references.TypeReference;
import org.apache.plc4x.plugins.codegenerator.types.terms.DefaultVariableLiteral;
import org.apache.plc4x.plugins.codegenerator.types.terms.Term;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;

public abstract class DefaultTypeDefinition {

Expand All @@ -49,7 +48,7 @@ public String getName() {
}

public Optional<Term> getAttribute(String attributeName) {
if(attributes.containsKey(attributeName)) {
if (attributes.containsKey(attributeName)) {
return Optional.of(attributes.get(attributeName));
}
return Optional.empty();
Expand All @@ -68,7 +67,13 @@ public void setParentType(TypeDefinition parentType) {
}

public TypeReference getTypeReference() {
return new DefaultComplexTypeReference(getName(), null);
List<Term> params = getParserArguments()
.map(arguments -> arguments.stream()
.map(argument -> new DefaultVariableLiteral(argument.getName(), null, -1, null))
.map(Term.class::cast)
.collect(Collectors.toList()))
.orElse(null);
return new DefaultComplexTypeReference(getName(), params);
}

}

0 comments on commit 1329013

Please sign in to comment.