Hi,
I'm currently trying to generate Builder classes. I was able to reconstruct the type hierarchy of my beans in the corresponding Builder hierarchy too. E.g. Foo<Concrete> extends Bar<T>, then FooBuilder<Concrete> extends BarBuilder<T> too.
Now I was trying to generate the Builder fields and methods too. But I couldn't achieve to generate fields and methods with the generic type T ;-(. I wanted to have one Builder method that accepts a list of T and one convenience method that simply adds T to the existing list of values. So my active annotation looks like this:
val builder = (qualifiedName + "Builder").findClass
builder => [
builtFields.forEach [ builtField |
addField(builtField.simpleName, [
type = builtField.type
])
]
addMethod(builtField.simpleName) [
addParameter(builtField.simpleName, builtField.type)
...
]
if (builtField.type.isAssignableFrom(typeof(List).newTypeReference)) {
addMethod(builtField.simpleName, [
val paramName = builtField.getListParameterSimpleName
val paramType = builtField.type.actualTypeArguments.get(0)
docComment = paramType.toString
addParameter(paramName, paramType)
...
])
}
...
]
In my example class :
class AppendableList<T> {
List<T> values
}
I only get something like this (which doesn't compile):
private List<?> values;
public AppendableListBuilder values(final List<?> value) {
...
}
/**
* T
*/
public AppendableListBuilder values(final ? value) {
...
}
It seems that the generic information T is somehow lost? But the javadoc still has this information?!? Btw: this also happens in the Builable annotation from xtend-contrib. Is there any chance to enhance xtend to remain the generic info in the TypeDeclaration? Or is there any trick I missed?
Thx and Regards
Kai