-
Notifications
You must be signed in to change notification settings - Fork 29
Live template for CREATOR
Important: all information in this on this page is only relevant to PaperParcel 1.x. For information on the latest version of PaperParcel, visit http://grandstaish.github.io/paperparcel/
While it's nice that you don't have to write the implementation of the CREATOR field, it is still a little bit of boilerplate that you need to add it yourself. This is the perfect case for a Live Template.
Steps:
-
Open Preferences... -> Editor -> Live Templates
-
Click '+' under 'Android'
-
Under 'Abbreviation', type the keyword you want to use to create the CREATOR (e.g. 'creator')
-
Under 'Description', type a message to help you remember what this command does (e.g. 'Create a PaperParcelable Creator instance')
-
Type the following code into the template text:
companion object { @JvmField val CREATOR = PaperParcelable.Creator($CLASS_NAME$::class.java) }
-
Define the 'Applicable contexts' to 'Kotlin -> Class'
-
Click 'Edit Variables'
-
Under 'Expression' for
CLASS_NAME
, typekotlinClassName()
-
Apply changes
Now you can simply type your keyword in your data class, press the Tab key, and you'll get an auto-complete box for class names so you can quickly type in the class name.