Showing posts with label Software development. Show all posts
Showing posts with label Software development. Show all posts

Wednesday, December 31, 2014

Infix notation and Live templates



IntelliJ lets you complete code statements in several different ways.
  1. Infix notation.
  1. To create a loop that goes over each variable, try typing the variable name, a .fori. It should expand into a for loop that creates an index.
  2. To create a loop that creates a foreach, type the variable name and then a .for. It will expand into a foreach loop.
  1. Live templates. Look at Settings -> Live templates.
  1. With these, you can ifn or ifnn and a tab to get if null or if not null constructs.
  2. You can also construct your own.
  1. I added a logging category and set logdecl to private final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(this.getClass());, as I had done before, in Eclipse.
  2. You can also add variables. I set logstart to be log.info("Entering $METHOD$.");. Then I pressed the Edit Variable button and told it that the expression to use was a predefined methodName().

Tuesday, December 30, 2014

The H2 database

I installed H2 on my work desktop. I tried to use Spring Data JPA, but ended up making a plain Maven project.

One of the problems that we have in software development is reading and writing information from a database. You don't want to use your regular database for reading, because you'll have to put test data into your regular database. You don't want to use it for writing, because you'll leave your test data on a database.

Enter H2.

The advertising says that I can set it up in memory, load it up with test data in Maven test phase, run my unit tests against it, and then have it all go away when I'm done. 

So far, I have set up a basic in which I start up the H2 database in one window and then run a Java test in my IntelliJ IDE. It's reading the single record from the single table like a champ.

Next step will be to have Maven start up H2, run the test data, and then politely go away. Should be fun.

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.