Book a Demo

Author Topic: Java import statements by code generation  (Read 3431 times)

du-it

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Java import statements by code generation
« on: December 14, 2005, 02:57:36 am »
I encountered some strange behaviour of EA during Java code generation. I have to insert an import statement manually when using classes not contained in my own model like java.util.Map and so on (or is there a flag I can set to do this automatically in EA?).
But I have to do this for classes I have modelled by myself, either, unless I have defined an attribute within a class. In this case EA generates an imoport statement automatically. If some classes for instance are used only as a method's parameter, no appropriate import statements are generated and I have to add them manually in the code generation dialog.

What can I do to automate this generation of import statements?

Thank you,
Dirk

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Java import statements by code generation
« Reply #1 on: December 14, 2005, 01:05:48 pm »
EA doesn't know what package Map (or any other class) is contained in until it is in the model.  So it can't generate an import statement.  The way to resolve this is to include (at least) a portion of the JDK in the model.

Classes used for method parameters should have import statements generated for parameter types, but try clicking on the ... button next to the type to make sure that the classifier is set properly.

Finally, if a class is only used within a method body a dependency connector should do the job.

du-it

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Java import statements by code generation
« Reply #2 on: December 15, 2005, 01:14:03 am »
It's clear to me that I have to generate an import statement manually for classes defined externally like thje JDK classes.

The [...] button doesn't help.

A dependency connectory, however, does the job well. I have separated the views for certain parts of the model to make them more concise. For instance I have some events defined by myself and I put them on a separate diagram so that the focus is on these events and not on the stuff around. Using a dependency connector I have to include all the used classes into this diagram which makes it less concise.
But I partly understand that it's a kind of dilemma for EA to know when to generate import statements automatically.

I would suggest, however, that EA should automatically generate import statements whenever another class is used. Either as instance variables or as method parameters. The quintessence is: the class uses another class which needs to be imported. Thus, I have to generate an import statement automatically independent from placing any kind of connectors to the model.

Thank you very much for your help.  :)

Regards,
Dirk

du-it

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Java import statements by code generation
« Reply #3 on: December 15, 2005, 03:41:42 am »
Oh, I found out that I can setup the dependency as described and then delete the dependent class from the VIEW without removing the dependency from the concerned class as I can see in its 'Link' tab.
::)

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Java import statements by code generation
« Reply #4 on: December 15, 2005, 01:18:26 pm »
Quote
It's clear to me that I have to generate an import statement manually for classes defined externally like thje JDK classes.

No you don't.  You also have the option of importing the JDK into your model, and making sure that your classes have the correct types set using the [...] button.

Quote
I would suggest, however, that EA should automatically generate import statements whenever another class is used. Either as instance variables or as method parameters.

I just ran a test, and EA certainly does do this for me.  With the exception that EA doesn't know what types are being used inside methods, and as such you need to create a dependency to that type.