Paul Robertson's words, punctuated

Thoughts on development, user-centered design, code, etc. by Paul Robertson

"Wrap selection" - more "Burrito" template goodness

I already mentioned that I really like the new templates feature in Flash Builder “Burrito.” Last night I discovered another nice feature in the templates.

I was looking through the template variables and noticed one called ${line_selection}. This variable allows you to select some lines of code and then choose a template to “wrap” around the selected code. A couple of the pre-defined templates make use of this, and I quickly added it to others where it makes sense.

For example, one pretty common refactor is to have a line of code* and decide that you need to wrap it in an if statement.

To wrap a line of code in an if statement:

  1. Start by selecting the code you want to wrap:

  2. Important: My instinct at this point is to type the name of the template (e.g. if) before hitting Ctrl+space. Don’t do it! You’ll just replace the selection with what you type. Unfortunately you can’t type the name of the template in this process. Instead do this:

    Hit Ctrl+space to open code hints. Tip: Hit Ctrl+space again to filter the code hints so only templates are shown. Flash Builder is smart enough to recognize that you have lines selected and only shows templates that include the ${line_selection} variable:

  3. Use the arrow keys or mouse to choose the template you want.

    I love that Flash Builder shows the tooltip with the template output preview:

    (Yes, the indentation in the preview is a bit wonky – hopefully that will be fixed for the final release.)

  4. Hit <Enter> to accept the template, and you’re ready to go. Just like with any template, you can tab between fields (just one in this case) to change other variable data:

Notes

* The code example I’m using here comes from the ”Bowling Game Kata” by “Uncle” Bob Martin

Comments