CodeModel help needed for right-hand singleton.getinstance() assignment.
Posted
by
antarti
on Stack Overflow
See other posts from Stack Overflow
or by antarti
Published on 2011-01-31T14:21:29Z
Indexed on
2011/03/02
23:25 UTC
Read the original article
Hit count: 204
java
|code-generation
I've been able to generate 99% of what I need with the CodeModel API, but I am stumped here...
Using the various "directXX" methods does not add import statements to the generated code, and I can work without the "directXXX" type of methods except for one place in a generated class.
Suppose I desire a generated method like:
/**
* Copies data from this Value-Obj instance, to the returned PERSON instance.
*
* @return PERSON
*
*/
public PERSON mapVOToPERSON() throws MappingException
{
Mapper mapper = (com.blah.util.MapperSingleton.getMapperInstance());
return mapper.map(this, PERSON.class);
}
You can see the right hand of the Mapper assignment in parens. Emitting the entire package+class was the only way I could find to just declare "SomeSingleton.someMethod()" on the right hand side and have the generated code compile. Without the MapperSingleton being added to the object model, there is no import generated...
Questions:
1) Is there a way to force an import to be generated?
2) How to declare an expression that gives me the right side of the Mapper assignment within the object model (so that an import of MapperSingleton gets generated.
Any help appreciated...
© Stack Overflow or respective owner