public void generate ( ) { PsiElementFactory elementFactory = JavaPsiFacade . getElementFactory ( psiClass . getProject ( ) ) ; JavaCodeStyleManager styleManager = JavaCodeStyleManager . getInstance ( psiClass . getProject ( ) ) ; // Clear any previous clearPrevious ( ) ; // Implements parcelable makeClassImplementParcelable ( elementFactory , styleManager ) ; // @ParcelablePlease Annotation addAnnotation ( elementFactory , styleManager ) ; // Creator PsiField creatorField = elementFactory . createFieldFromText ( generateCreator ( ) , psiClass ) ; // Describe contents method PsiMethod describeContentsMethod = elementFactory . createMethodFromText ( generateDescribeContents ( ) , psiClass ) ; // Method for writing to the parcel PsiMethod writeToParcelMethod = elementFactory . createMethodFromText ( generateWriteToParcel ( ) , psiClass ) ; styleManager . shortenClassReferences ( psiClass . addBefore ( describeContentsMethod , psiClass . getLastChild ( ) ) ) ; styleManager . shortenClassReferences ( psiClass . addBefore ( writeToParcelMethod , psiClass . getLastChild ( ) ) ) ; styleManager . shortenClassReferences ( psiClass . addBefore ( creatorField , psiClass . getLastChild ( ) ) ) ; }
Generate and insert the Parcel and ParcelablePlease code