Over a million developers have joined DZone.

IntelliJ IDEA Knows How to Format Spock where: Blocks

· Java Zone

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

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

 

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.

Topics:

Published at DZone with permission of Hubert Klein Ikkink, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}