[forge-issues] [JBoss JIRA] (ROASTER-135) Types.toResolvedType does not resolve types with wildcard correctly
Viktor Micsko (Jira)
issues at jboss.org
Sat Apr 25 08:34:00 EDT 2020
Viktor Micsko created ROASTER-135:
-------------------------------------
Summary: Types.toResolvedType does not resolve types with wildcard correctly
Key: ROASTER-135
URL: https://issues.redhat.com/browse/ROASTER-135
Project: Roaster
Issue Type: Bug
Components: API
Affects Versions: 2.21.1.Final
Reporter: Viktor Micsko
(2.21.2.Final and 2.21.3-SNAPSHOT are also affected)
https://github.com/forge/roaster/blob/master/api/src/main/java/org/jboss/forge/roaster/model/util/Types.java
Types.toResolvedType joins the generic parts using comma as follows:
{code:java}
if (Types.isGeneric(type))
{
StringJoiner genericJoiner = new StringJoiner(",");
for (String genericPart : Types.splitGenerics(type))
{
genericJoiner.add(toResolvedType(genericPart, importer));
}
builder.append("<").append(genericJoiner.toString()).append(">");
}
{code}
This behaviour is incorrect for types like List<? extends Number>.
It also leads to the following being incorrectly generated as void return type for such types:
{code:java}
Type<JavaInterfaceSource> returnType = ...
MethodSource<JavaClassSource> method = ...
destinationMethod.setReturnType(returnType);
{code}
A simple fix would be:
{code:java}
if (Types.isGeneric(type))
{
StringJoiner genericJoiner = new StringJoiner(",");
for (String genericPart : Types.splitGenerics(type))
{
genericJoiner.add(toResolvedType(genericPart, importer));
}
String genericParts = genericJoiner.toString();
genericParts = genericParts.replace("?extends", "? extends ");
genericParts = genericParts.replace("?super", "? super ");
builder.append("<").append(genericParts).append(">");
}
{code}
--
This message was sent by Atlassian Jira
(v7.13.8#713008)
More information about the forge-issues
mailing list