Thanks @CrazyCoder answer , I will show my code how I added the custom expression to live templates.
- Creating a Plugin Gradle Project
https://plugins.jetbrains.com/docs/intellij/creating-plugin-project.html
If you have error like Could not resolve all files for configuration ':classpath'.
you should open Preferences -> Build,Execution,Deployment -> Build Tools -> Gradle
select Gradle JVM to you have installed version
- Create your own class like this:
package com.xxxx.yourPackage;
import com.intellij.codeInsight.template.*;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class MyLiveTemplateExpression extends Macro {
@Override
public @NonNls String getName() {
return "MyLiveTemplateExpression";
}
@Override
public @Nullable Result calculateResult(Expression @NotNull [] params, ExpressionContext context) {
return new TextResult("测试自己的宏");
}
}
In this code the method getName
will return a string name which will be shown in live-templates

- edit
plugin.xml
add liveTemplateMacro tag into extensions tag, like this:
<liveTemplateMacro implementation="com.xxxx.yourPackage.yourClass"/>
In my case implementation value is com.xxxx.cusomLiveTemplate.MyLiveTemplateExpression
Select right sidebar Gradle
to build jar

open Perference -> plugins
click setting icon and choose install from disk
to install plugin
you can use this expression now
Because I am a frontend developer, I do not how to write java code... so the code is not strong, I really hope some javaer can edit this answer or tell me how to write more better!
Sorry for my poor English, Hope someone can edit it and make it more easy to understand