views:

78

answers:

3

Hi,

I generate (from a progam java) some Java classes but actually, I don't add the import in each class. I'd like to have a kind of parser that is able to see which import needs to be added in a class. Maybe, it's possible to reuse the fonctionnality of Eclipse because it's able to do that. However, I don't know where I can find that.

Do you have any idea?

Many thanks,

Bat

A: 

What are you going to do about name collisions? You use a "Date" - is it java.util.Date or java.sql.Date? You use a "XMLFoo", is it com.foomatics.XMLFoo or is it org.openfoo.XMLFoo? It's better to add the imports as you add the code.

Maybe you can create a HashSet of all the imports you're going to need as you generate the code, and then add them in at the top when you're done?

Paul Tomblin
I'm aware about this problem. I only ask if it's possible to reuse the code of eclipse to add automatically the imports?
@user376112 eclipse will pop up a dialog and prompt you to select an import from a list, if there are collisions. How will your code handle that?
dogbane
A: 
nanda
My code is generated automatically by a server, so I can't use eclipse.
`Ctrl+Shift+O` if it doesn't....Auto-Imports ftw!
st0le
+2  A: 

What about using only Full Qualified Names for classes when creating the code for the generated Java classes?

GHad
yes...why not, It's a good idea