Monday, December 29, 2014

UML Class Diagrams, IntelliJ, and automatic code generation

I built a small class diagram with a class and a subclass in IntelliJ. (This capability is found in the Ultimate Edition, but apparently not the (free) Community Edition.)

I added some class fields, constants, methods. Then I created a subclass. I also had the opportunity to refactor the code and pull up some things from the subclass to the parent class.

Then, without fanfare, I press F4 to jump from the diagram to the code. I expected that it would whirr and crank for a bit before it jumped to the code that was yet to be generated, but it generated the skeleton and displayed the code before you could say "Bob's your uncle."

I didn't save the UML diagram, but it was easy to regenerate it.

I also found that I could generate a JUnit or TestNG code by selecting the method and pressing Ctrl-Shift-T (or Navigate => Test).

If you're curious about the details, you may view details on my IntelliJ wiki on GitHub.

Very cool stuff.

No comments: