Logd shortcut not working in Intellij with Kotlin

Writing in Java in Intellij is easy with shortcuts like "logt", "logd", "loge" ... and so on. But I moved to Kotlin, I noticed that these shortcuts no longer work. I do not know if this is due to my configuration, but if not, how can I fix it?

+4
source share
2 answers

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

First, copy and paste the AndroidLog templates into Kotlin (just select them and use CMD + C, CMD + V (or Ctrl + C, Ctrl + V) Secondly, you must configure them manually: 1. logd (and others ) Select the logd element and click "Edit Variables", enter image description here

Change the expression to: kotlinMethodName() enter image description here

Also, remove ;from the end of the template as it is not needed in Kotlin.

Now your method name will be displayed correctly

  1. logt This is a little trickier. Solution 1 TAG = class name.

    • Template text:

    private val TAG = "$ className $"

    • Change Variables → Expression:

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

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

  • Template text:

    private const val TAG = "$ className $

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

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

+2

Source: https://habr.com/ru/post/1679304/


All Articles