Hi all, my name is Hubert A. Klein Ikkink. Not a very common name, right? To make things easier I just picked the first letters of my firstname and surname and came up with haki. So there you have it, now I am also known as Mr. Haki or mrhaki for short. You can read more blog postings at www.mrhaki.com. I am a passionate Groovy and Java developer based in Tilburg, The Netherlands. My goal is to write clean, elegant, user-centered and high quality software. You can find me on Google+ and Twitter. Hubert is a DZone MVB and is not an employee of DZone and has posted 170 posts at DZone. You can read more from them at their website. View Full User Profile

IntelliJ IDEA Knows How to Format Spock where: Blocks

04.22.2013
| 3182 views |
  • submit to reddit

IntelliJ IDEA keeps amazing me. Last week I learned the code formatter of IntelliJ IDEA 12 supports Spock specific where: block formatting. Spock has great a great feature called data tables. We can define a fixed set of data values in a table-like format where cells are separated with pipe (|) symbols. These tables are easiest to read if formatted in fixed size columns. The IntelliJ IDEA formatter will do this for us automatically.

Look at the following source code with a data table just typed with pipe symbols as separators, but not clearly formatted in fixed size columns:


If we run the code reformat command with Cmd+Alt+L (Windows/Linux: Ctrl+Alt+L) or use the menu option Code | Reformat Code... we get a dialog and select Run button to format the code:


The result is that our data table in the where: block is now correctly formatted:


Example with IntelliJ IDEA 12.1

 

Published at DZone with permission of Hubert Klein Ikkink, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Cathal King replied on Sun, 2013/07/14 - 3:45pm

This is a neat feature. Unfortunately it doesn't handle tables that use Spock's neat double-pipe (||) separator anywhere other than in the very last column.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.