您应该创建单独的模板以使它们正常工作。
这是分步指南:
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"
Change expression to: kotlinFunctionName()
另外,删除;
从模板末尾开始,因为在 Kotlin 中不需要它。
现在你的方法名称将正确显示
-
logt这个有点棘手。解决方案1 TAG=类名。
私有 val TAG = "$className$"
groovy Script("_1.take(Math.min(23, _1.length()));", kotlin ClassName())
解决方案2 TAG=文件名(可在 Companion 内部使用)
or:
companion object {
private const val TAG = "$className$"
}
编辑 2019 年 2 月 19 日
另外,它可能对某人有用。
为了避免创建TAG
变量,可以使用类名作为变量,例如:
Log.d("BaseActivity", "onCreate: ")
Where BaseActivity
是类名。
该模板现在将如下所示:
android.util.Log.d("$CLASS_NAME$", "$METHOD_NAME$: $content$")
Where CLASS_NAME
变量是:
groovyScript("_1.take(Math.min(23, _1.length()));", fileNameWithoutExtension())