Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij Idea wrapping live template

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?

like image 462
Aleksei Litvin Avatar asked Mar 03 '23 06:03

Aleksei Litvin


2 Answers

You can use Postfix Completion for that.

enter image description here

The result will look like this:

enter image description here

like image 82
Koyasha Avatar answered Mar 10 '23 11:03

Koyasha


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.
like image 42
Ersoy Avatar answered Mar 10 '23 12:03

Ersoy