In Intellij Idea when i typing psfs
and then press Ctrl+J IDE was getting me a dialog :
And when i press Enter i get an
I know where i can customize my own output
But i can't any doc's how i can write my own live template.
In the end i want to get next result :
psfst
-> press Ctrl+J -> press Enter public static final String TAG = <currentClassName>.class.getSimpleName();
It will be so helpfull, because i have a habit to log my classes.
I find a solution
1) Create a new live template in plain group
2) In template text :
private static final String TAG = $CLASS_NAME$.class.getSimpleName();
3) Define a usage scope :
4) Choose a shortcut :
finally click on Edit variables and change expression value to className()
Click Ok , Apply, Ok and use.
There already exists such shortcut in Android Studio - write logt and enter while cursor is at the class scope.
more here :
It's super simple in Android studio, just type logt
and press Tab.
It generates: private static final String TAG = "xyzActivity";
For those using Android Studio 3 and Kotlin it is necessary to change how Live Templates set:
Editor >> Live Templates >> AndroidLog
By default it is just for Java
Add Kotlin pressing "change" button and check Kotlin
and after that it will work again!
Updated: 2020
Android Studio: 3.6.2
Steps:
private val TAG = this::class.java.simpleName
Update June 2020
There's no need to set anything up anymore. Android Studio 4.0 comes with this functionality by default. The same with Toast
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With