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:
    public static final android.os.Parcelable.Creator<$CLASS_NAME$> CREATOR = PaperParcel$CLASS_NAME$.CREATOR;
    
    @Override public int describeContents() {
        return 0;
    }
    
    @Override public void writeToParcel(android.os.Parcel dest, int flags) {
        PaperParcel$CLASS_NAME$.writeToParcel(this, dest, flags);
    }
  6. Define the "Applicable contexts" to "Java -> Declaration"
  7. Click "Edit Variables"
  8. Under "Expression" for CLASS_NAME, type className() and tick "Skip if defined".
  9. Apply changes

Now in any java 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.