logd快捷方式在Intellij中与Kotlin不兼容 [英] logd shortcut doesn't work in Intellij with Kotlin

查看:120
本文介绍了logd快捷方式在Intellij中与Kotlin不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用'logt','logd','loge'等快捷方式在Intellij中记录Java非常简单。但我搬到了Kotlin,我注意到那些快捷方式不再适用了。我不知道它是否与我的配置有关,但如果没有,我该怎么办呢?

Logging Java in Intellij is easy with shortcuts such as 'logt', 'logd', 'loge'... and so on. But I moved to Kotlin, I noticed that those shortcuts doesn't work anymore. I don't know if it has something to do with my configuration, but if not, how can I fix this?

推荐答案

您应该创建单独的模板以使它们正常工作。

以下是分步指南:

You should create separate templates to make them work correctly.
Here is the step-by-step guide:

首先,复制并粘贴AndroidLog模板到Kotlin(只需选择它们并使用CMD + C,CMD + V(或Ctrl + C,Ctrl + V)
其次,你必须手动调整它们:
1. logd (和其他人)
选择 logd 项并按编辑变量

Firstly, Copy and paste AndroidLog templates to Kotlin (Just select them and use CMD+C, CMD+V (or Ctrl+C, Ctrl+V) Secondly, You have to adjust them manually: 1. logd (and others) Select the logd item and press "Edit variables"

将表达式更改为: kotlinMethodName()

Change expression to: kotlinMethodName()

另外,请删除; 在模板的末尾,因为你在Kotlin中不需要它。

Also, remove ; from the end of the template, as you don't need it in Kotlin.

现在你的方法名称将正确显示

Now your method name will be shown correctly


  1. logt
    这个有点棘手。
    解决方案1 ​​TAG =班级名称。


  • 模板文字:

私人val TAG =$ className $


  • 编辑变量 - >表达式:

groovyScript(_ 1.take(Math.min(23,_1) .length()));,kotlinClassName())

解决方案2 TAG =文件名(可在Companion中使用)

Solution 2 TAG = file name (can be used inside Companion)


  • 模板文字:

  • Template text :

私人常数TAG =$ className $

或者:

companion object {
     private const val TAG = "$className$"
}




  • 编辑变量 - >表达式:

    • Edit variables -> Expression:

      groovyScript(_ 1.take(Math.min(23,_1.length()));,fileNameWithoutExtension())

      这篇关于logd快捷方式在Intellij中与Kotlin不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆