While PaperParcel elimitates the majority of the work involved in creating Parcelable types, it still requires you to manually call the generated code in your model objects. This is fairly repetitive code and is a perfect candidate for Intellij Live Templates. The following steps will help you set up a Live Template for PaperParcel:

  1. Open Preferences... -> Editor -> Live Templates
  2. Click "+" under "Android"
  3. For the 'Abbreviation', I like to use "ppb" (short for "PaperParcel boilerplate"). This is what you'll type to trigger the auto-completion.
  4. Under "Description", type a message to help you remember what this command does (e.g. "Generates PaperParcel boilerplate")
  5. Type the following code into the template text:
    companion object {
      @JvmField val CREATOR = PaperParcel$CLASS$.CREATOR
    }
  6. Define the "Applicable contexts" to "Kotlin -> Class"
  7. Click "Edit Variables"
  8. Under "Expression" for CLASS_NAME, type kotlinClassName() and tick "Skip if defined".
  9. Apply changes

Now in any kotlin class you should be able to type your abbreviation (e.g. ppb), press tab, and Intellij will fill in the remaining boilerplate like so:

PaperParcel Boilerplate Demo

Back to main site.