[
https://issues.jboss.org/browse/ROASTER-41?page=com.atlassian.jira.plugin...
]
Antonio Goncalves commented on ROASTER-41:
------------------------------------------
There is no {{addConstructor}} method in Roaster as it treats it as a method. Instead you
should use {{setConstructor(true)}} :
{code}
javaClassSource.addMethod().setPublic().setConstructor(true).setBody("super();");
javaClassSource.addMethod().setPublic().setConstructor(true).setParameters("String
message").setBody("super(message);");
{code}
Being able to add constructors
------------------------------
Key: ROASTER-41
URL:
https://issues.jboss.org/browse/ROASTER-41
Project: Roaster
Issue Type: Feature Request
Components: API
Affects Versions: 2.8.2.Final
Reporter: Antonio Goncalves
Fix For: 2.x Future
At the moment there is no easy way to add a constructor. {{JavaClassSource}} has an API
to add methods, fields, annotation... but no constructor. The closest to create a
constructor would be :
{code}
javaClassSource.setName("MyException").setSuperType(Exception.class);
javaClassSource.addMethod().setPublic().setName("MyException").setBody("super();");
{code}
The method returns void and setting the name of the method is useless. It would be better
to have something like :
{code}
javaClassSource.setName("MyException").setSuperType(Exception.class);
javaClassSource.addConstructor().setPublic().setBody("super();");
javaClassSource.addConstructor().setPublic().setParameters("String
message").setBody("super(message);");
{code}
--
This message was sent by Atlassian JIRA
(v6.3.1#6329)