[
https://issues.jboss.org/browse/ROASTER-10?page=com.atlassian.jira.plugin...
]
Kai Müller edited comment on ROASTER-10 at 1/16/19 2:51 PM:
------------------------------------------------------------
Hi, with 2.20.5 my code compiles but is WRONG:
{code:java}
public static void main(final String[] args) {
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
javaClass.setPackage("testPackage").setName("Main");
// Field one
javaClass.addField().setName("field1").setType("package1.Type");
// Field two
javaClass.addField().setName("field2").setType("package2.Type");
// out
System.out.println(javaClass.toString());
}
{code}
The code which is produced is:
{code:java}
package testPackage;
import package1.Type;
public class Main {
Type field1;
Type field2;
}
{code}
BR,
Kai
was (Author: kaijmueller):
Hi, we 2.20.5 my code compiles but is WRONG:
{code:java}
public static void main(final String[] args) {
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
javaClass.setPackage("testPackage").setName("Main");
// Field one
javaClass.addField().setName("field1").setType("package1.Type");
// Field two
javaClass.addField().setName("field2").setType("package2.Type");
// out
System.out.println(javaClass.toString());
}
{code}
The code which is produced is:
{code:java}
package testPackage;
import package1.Type;
public class Main {
Type field1;
Type field2;
}
{code}
BR,
Kai
Auto generated imports when a field type is set causes .java file to
not compile.
---------------------------------------------------------------------------------
Key: ROASTER-10
URL:
https://issues.jboss.org/browse/ROASTER-10
Project: Roaster
Issue Type: Bug
Components: API
Affects Versions: 2.2.0.Final
Reporter: Walter Medvedeo
Priority: Major
Fix For: 2.x Future
When we set the Type for a given field using the FieldSource.setType( X ) methods an
import is generated automatically.
Under some situations it causes the resulting class to not compile and it's not
posible to fix it using the api.
In order to avoid this, and also to be able to modify a given class in a more "safe
or controlled" way (for example in cases when we don't want to manage complex
refactorings or controlling imports), It's desirable to have setType( X, boolean
addImports) method that just change the field type to the provided type name and don't
add imports.
e.g:
Given the following declaration:
private org.test.Class1 myField;
myField.setType("org.somepackage.Class2", false)
will produce the following result:
private org.somepackage.Class2 myField;
and:
myField.setType("Class2", false)
will produce the following result:
private Class2 myField.
--
This message was sent by Atlassian Jira
(v7.12.1#712002)