You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在IntelliJ中创建支持type.ilist的Instancio Live Template?

解决IntelliJ Instancio Live Template类型捕获问题
  • 打开IntelliJ设置(快捷键Ctrl+Alt+S),导航到Editor > Live Templates
  • 点击右侧+号,先新建一个模板组(比如命名为Instancio),再在该组下新建Live Template
  • 在模板设置中完成以下配置:
    • Abbreviation填写ilist
    • Template text输入:
      List<$TYPE$> $VAR_NAME$ = Instancio.createList($TYPE$.class)
      
    • 点击Edit variables按钮,配置变量规则:
      • TYPE的Expression填写groovyScript("_1.text", complete()),勾选Skip if defined
      • VAR_NAME的Expression填写suggestVariableName(),勾选Skip if defined
    • 设置模板的Applicable in范围为Java(勾选Java相关上下文,比如Java表达式、声明等)
  • 保存设置后,输入Animal.ilist再按Tab,即可自动生成List<Animal> animalList = Instancio.createList(Animal.class)

核心逻辑是通过groovyScript("_1.text", complete())捕获输入时前缀的类型(如Animal),将其赋值给TYPE变量,实现模板中对应位置的自动替换。

内容的提问来源于stack exchange,提问作者Vml11

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 15:17:32