简体   繁体   English

Intellij Idea 包装实时模板

[英]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我输入userDao.getUser().asst
  2. Press enter按回车
  3. Code is wrapped and the result is: assertThat(userDao.getUser())代码被包装,结果是: 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?所以基本上我想创建一个功能类似于souttrylistOf等的实时模板。你能建议如何创建它吗?

You can use Postfix Completion for that.您可以为此使用Postfix Completion

在此处输入图像描述

The result will look like this:结果将如下所示:

在此处输入图像描述

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.template text中添加以下行,在缩写输入字段中写入asst (或更短a版本)。
assertThat($SELECTION$)$END$
  • When you type userDao.getUser() and hit cmd + alt + j , you will have Select Template pop-up.当您输入userDao.getUser()并点击cmd + alt + j时,您将弹出Select Template When you then hit a it will automatically surround it with assertThat.然后当你点击a时,它会自动用 assertThat 包围它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM