Book a Demo

Author Topic: Java Code Generation / Import Statements  (Read 4543 times)

John Gentilin

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Java Code Generation / Import Statements
« on: September 21, 2015, 10:19:45 am »
I am evaluating EA 12.0.1215 doing some simple round trip engineering.
My top issue is on #import statements. Using the Jersey REST API HelloWorld App as example, I imported the App.java and HelloWorldResource.java classes They seemed to reverse into the model just fine.  To test round trip code generation, I modified the name of the getHello() method

On code generation, I had the following errors.

1) The import statements were stripped from my code (big issue)

2) The annotations @GET /@Provides were moved to the same line.  (More of a style thing)

I have tried both a ressync before generate and to do a full on import before generating code. In both cases, the resultant file is missing the import statements.

Note: the import statements involved relate to the @GET / @Provides annotations.

Am I missing some kind of  Language option like remember import statements on reverse ?

Thanks
-John Gentilin
« Last Edit: September 21, 2015, 12:48:54 pm by gentijo »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Java Code Generation / Import Statements
« Reply #1 on: September 21, 2015, 01:35:20 pm »
Code import doesn't record import statements, just as synchronization won't edit them at all.

You can manually add import statements into the code generation dialog (for a single class)

The position of annotations can be changed by editing the code generation templates.

John Gentilin

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Java Code Generation / Import Statements
« Reply #2 on: September 24, 2015, 06:15:06 am »
Thank you, I am finding that synchronization is the key.. If you import it again, then generate to do round trip engineering it will not only wipe out the include statements it will strip out any existing code body..

For the Code Gen Templates, I am assuming I need to change the Operation Declaration template. It seems that it is not configured to accept a list of annotation declarations.  Here is the template code
%opTag:"annotations"%

How would you handle that, have the tag support a CSV separated list then loop thru and convert "," to CR/LF or support multiple annotation tags and add them in on their own line. I can add multiple annotation lines to the class model but it only picks up the first one for code generation.

Thank you for your support, so far it's a great product.
-John Gentilin

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Java Code Generation / Import Statements
« Reply #3 on: September 24, 2015, 08:02:27 am »
From memory EA will import multiple annotations separated by a space. You should be able to replace " @" with "\n@" before outputting it.