]
George Gastaldi commented on ROASTER-107:
-----------------------------------------
Yeah, that's why I am removing all the whitespaces while parsing generics. Let me know
if that is working for you and then I can release it
Problems with generic types in MethodSource.setReturnType
---------------------------------------------------------
Key: ROASTER-107
URL:
https://issues.jboss.org/browse/ROASTER-107
Project: Roaster
Issue Type: Bug
Components: API, Formatter
Affects Versions: 2.18.7.Final
Reporter: Kevin Mian Kraiker
Assignee: George Gastaldi
Fix For: 2.19.0.Final
When trying to set a method's return type, if there's a space between two generic
types (for example as in TreeMap<String, Object>), an IllegalArgumentExeption gets
thrown saying the identifier for the second type is invalid (because it includes the space
character as part of it). If there's none, then the final formatted code has one,
although the non-formatted one hasn't, which is inconsistent...
{code:java}
@Test
public void throwsException() {
JavaClassSource classSource = Roaster.create(JavaClassSource.class);
MethodSource<JavaClassSource> newMethod = classSource.addMethod()
.setName("tstMethod")
.setPublic();
newMethod.setReturnType("java.util.TreeMap<java.util.String,
java.util.Object>"); // Counts space as part of the second type's name
newMethod.setBody("return new TreeMap<String, Object>();");
assertTrue(newMethod.getReturnType().toString().equals("TreeMap<String,
Object>")); // If the exception wasn't thrown, this should pass.
// Also, if there's no space - as in
'java.util.TreeMap<java.util.String,java.util.Object>', the class'
formatted code has one but the above test would fail.
}
{code}