[forge-issues] [JBoss JIRA] (ROASTER-4) Having Parameterize interface bit more typed
Kai Müller (Jira)
issues at jboss.org
Thu Jan 24 15:21:00 EST 2019
[ https://issues.jboss.org/browse/ROASTER-4?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13687308#comment-13687308 ]
Kai Müller commented on ROASTER-4:
----------------------------------
Hi, I need some help with jdt:
I currently try to add the generic type to a class with this code, but it fails, because the simple name if the class has already a parent, which I can't delete.
{code:java}
ParameterizedType pt = body.getAST().newParameterizedType(
body.getAST().newSimpleType(getBodyDeclaration().getName()));
org.eclipse.jdt.core.dom.Type t = fromString(Types.toSimpleName(clazz.getName()), body.getAST());
System.out.println(t);
pt.typeArguments().add(t);
{code}
{code:java}
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
javaClass.setName("Teest");
javaClass.addGenericType(String.class);
System.out.println(javaClass);
{code}
Can somebody please assist how to do this? I basically want to have "public class Test<String>{}"
BR,
Kai
> Having Parameterize interface bit more typed
> --------------------------------------------
>
> Key: ROASTER-4
> URL: https://issues.jboss.org/browse/ROASTER-4
> Project: Roaster
> Issue Type: Feature Request
> Components: API
> Affects Versions: 2.1.0.Final
> Reporter: Antonio Goncalves
> Assignee: Kai Müller
> Priority: Major
> Fix For: 2.x Future
>
>
> For a constraint, I need to implement a parametrize interface like this :
> {code}
> public class MaxValidatorForString implements ConstraintValidator<Max, Number> {
> {code}
> The only way I could find is by passing a String :
> {code}
> final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
> javaClass.setName("MaxValidatorForString");
> javaClass.addImport(ConstraintValidator.class);
> javaClass.addInterface("ConstraintValidator<Max, Number>");
> {code}
> It's a shame because with {{addInterface(Class)}}, it does the import automatically and things are more typed. But I cannot add types :
> {code}
> final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
> javaClass.setName("MaxValidatorForString");
> javaClass.addInterface(ConstraintValidator.class);
> {code}
> It would be good to have something like :
> {code}
> javaClass.addInterface(ConstraintValidator.class).addType(Max.class).addType(Number.class);
> {code}
--
This message was sent by Atlassian Jira
(v7.12.1#712002)
More information about the forge-issues
mailing list