Intellij Idea wrapping live template

364 Views Asked by At

I want to create a live template to wrap a code before the dot.

Example:

  1. I enter userDao.getUser().asst
  2. Press enter
  3. Code is wrapped and the result is: assertThat(userDao.getUser())

So basically I want to create a live template with functionality similar to sout, try, listOf etc. Can you suggest how to create it?

2

There are 2 best solutions below

0
On BEST ANSWER

You can use Postfix Completion for that.

enter image description here

The result will look like this:

enter image description here

0
On

Not exactly what you need but as an alternative;

  • Settings
  • Live templates
  • Surround
  • Add following line in the template text, write asst(or a for shorter version) in the abbreviation input field.
assertThat($SELECTION$)$END$
  • When you type userDao.getUser() and hit cmd + alt + j , you will have Select Template pop-up. When you then hit a it will automatically surround it with assertThat.