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:
- Open Preferences... -> Editor -> Live Templates
- Click "+" under "Android"
- For the 'Abbreviation', I like to use "ppb" (short for "PaperParcel boilerplate"). This is what you'll type to trigger the auto-completion.
- Under "Description", type a message to help you remember what this command does (e.g. "Generates PaperParcel boilerplate")
- 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); }
- Define the "Applicable contexts" to "Java -> Declaration"
- Click "Edit Variables"
- Under "Expression" for
CLASS_NAME
, typeclassName()
and tick "Skip if defined". - 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: