[
https://issues.jboss.org/browse/ROASTER-50?page=com.atlassian.jira.plugin...
]
Elis Edlund commented on ROASTER-50:
------------------------------------
Here's some very simple unit test that does not work right now:
{code:java}
@Test
public void testSetReturnTypeWithGenerics() {
JavaClassSource source = Roaster.create(JavaClassSource.class);
MethodSource<JavaClassSource> srcMethod = source.addMethod();
srcMethod.setName("name");
srcMethod.setPublic();
srcMethod.addTypeVariable("T");
srcMethod.setReturnType("List");
assertTrue(srcMethod.toString().contains("public <T>List
name()")); //shouldn't it be a space between <T> and List?
srcMethod.setReturnType("List<T>");
assertTrue(srcMethod.toString().contains("public <T> List<T>
name()"));
}
@Test
public void testTransferableReturnType() {
JavaClassSource source = Roaster.create(JavaClassSource.class);
MethodSource<JavaClassSource> srcMethod = source.addMethod();
srcMethod.setName("name");
srcMethod.addTypeVariable("T");
srcMethod.setReturnType("List");
JavaClassSource dest = Roaster.create(JavaClassSource.class);
MethodSource<JavaClassSource> destMethod = source.addMethod();
destMethod.setReturnType(srcMethod.getReturnType()); //not compiling, cast will
still fail!
assertTrue(destMethod.toString().contains("List<T> name()"));
}
@Test
public void testTransferableReturnTypeString() {
JavaClassSource source = Roaster.create(JavaClassSource.class);
MethodSource<JavaClassSource> srcMethod = source.addMethod();
srcMethod.setName("name");
srcMethod.addTypeVariable("T");
srcMethod.setReturnType("List<T>");
JavaClassSource dest = Roaster.create(JavaClassSource.class);
MethodSource<JavaClassSource> destMethod = source.addMethod();
destMethod.setReturnType(srcMethod.getReturnType().getQualifiedNameWithGenerics());
assertTrue(destMethod.toString().contains("List<T> name()"));
}
{code}
Roaster tries to add Generic Type Variable as a java import
-----------------------------------------------------------
Key: ROASTER-50
URL:
https://issues.jboss.org/browse/ROASTER-50
Project: Roaster
Issue Type: Bug
Reporter: Yusuf Iskenderoglu
Fix For: 2.x Future
When you create a new Method with a Type variable, you cannot use it in a parameter, it
crashes with:
{code}
Exception in thread "main" java.lang.IllegalArgumentException: Cannot import
class without a package [T]
at
org.jboss.forge.roaster.model.impl.AbstractJavaSource.addImport(AbstractJavaSource.java:172)
at org.jboss.forge.roaster.model.impl.MethodImpl.addParameter(MethodImpl.java:682)
at de.check24.finance.baufi.roast.main.Roast.parse(Roast.java:225)
{code}
This is due to AbstractJavaSource.requiresImport() not returning false for type
variables.
Can you consider this for the next release, too?
Thanks!
Related To: ROASTER-48
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)