如何在Android Studio中创建一个代码模板来复制Kotlin中的`val`模板?

huangapple go评论58阅读模式
英文:

How can I create a code template in Android Studio to replicate the val template in Kotlin

问题

Kotlin 和 Java 代码模板在 Android Studio 中。

我尝试创建一个用于 Truth 库的代码模板,它可以像 val 模板一样工作,即:

  • 当您想要从调用函数的结果创建变量时,只需键入 functionName().val
  • 当您按下回车键时,变量将被创建,即 val f = functionName()

我如何复制这种行为到 Truth 库,以便当我键入 f.assert 时,我得到 Truth.assertThat(f)

英文:

Kotlin and Java code templates in Android Studio.

I tried to create a code template for the truth library that would work like the val template works i.e,

  • When you want to create a variable from the result of calling a function? you just type,
    functionName().val.
  • When you press enter a variable is created ie, val f = functionName().

How would I replicate this behaviour on the truth library such that when I type f.assert for instance, I get Truth.assertThat(f)?

答案1

得分: 0

这个功能被命名为“后缀补全”。

你可以在这里找到详细信息:https://www.jetbrains.com/help/idea/settings-postfix-completion.html

我现在已经尝试过了,它允许我添加和编辑Java和Groovy模板,但不支持Kotlin。

Idea的另一个完美功能是Live模板,你可以使用它们来实现所需的模板。

你可以在这里找到详细信息:https://www.jetbrains.com/help/idea/using-live-templates.html

更新:我已经检查了Idea的当前版本,Kotlin目前还不支持。

英文:

This feature is named "Postfix completion"

You can find details here https://www.jetbrains.com/help/idea/settings-postfix-completion.html

I have tried now and it's allowed me to add and edit java and groovy templates but kotlin is not supported.

The other perfect feature of Idea is Live templates you can use them to implement required templates.

You can find details here https://www.jetbrains.com/help/idea/using-live-templates.html

Update: I have checked the current version of Idea, kotlin is not supported yet.

huangapple
  • 本文由 发表于 2023年6月2日 04:09:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76385372.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定