Add Kotlin Parcelize snippets - #1049
Open
erikrodriguez-se wants to merge 1 commit into
Open
Conversation
Snippets for the Parcelize guide (developer.android.com/kotlin/parcelize), extracted into kotlin/src/main/kotlin/com/example/android/basics with region tags, plus the parcelize plugin in kotlin/build.gradle.kts. One deviation from the page as published: the data class serializer example uses a declaration-level @OptIn rather than the page's file-level @file:OptIn. A file annotation must precede the package declaration, so it cannot sit inside a region tag, and the published snippet would otherwise lose the opt-in entirely. The page's block needs the matching change. Kotlin only. Co-authored-by: Katherine Kuan <843428+kkuan2011@users.noreply.github.com>
|
|
||
| getByName("release") { | ||
| isMinifyEnabled = true | ||
| isShrinkResources = true |
Author
There was a problem hiding this comment.
Not in the original fork PR but this is a linter nit worth addressing since we're touching the file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Snippets migration - Kotlin parcelize
Snippets for the Parcelize guide at developer.android.com/kotlin/parcelize, extracted into
kotlin/src/main/kotlin/com/example/android/basics/(Parcelize.ktandParcelizeDataClass.kt) with region tags, plus the parcelize plugin inkotlin/build.gradle.kts.Thirteen of the page's 24 code blocks are extracted. Most are verbatim; the differences that exist fall into three kinds, described below.
android_kotlin_parcelize_*)_basic_companion_parceler_external_class_parceler_type_parceler_class_type_parceler_property_type_parceler_type_parcelable_creator_ignored_on_parcel_raw_valueParcel.writeValue_sealed_class_data_class@file:OptInshown as a comment_data_class_wrapper_inheritance_basevalorvarparamsThe three kinds of deviation
Colon spacing. The page writes
): Parcelable; this repo's ktlint config rewrites it to) : Parcelable. This is unavoidable —spotlessApplymakes the change when run — and it accounts for most of the non-verbatim rows above.File-top declarations shown as a comment. The
_basicand_parcelable_creatorblocks open with animport, and_data_classopens with@file:OptIn(kotlinx.parcelize.Experimental::class). Kotlin requires those at the top of the file, above thepackagedeclaration and outside any snippet region. To keep them visible in the published snippet, the real line lives at the top of the file (uncommented, so it compiles) and a commented copy is placed inside the region. The published snippet therefore shows, for example,// import kotlinx.parcelize.Parcelizewhere the page currently shows a liveimportstatement. The page's blocks would be updated to match.One experimental block omitted. The page's "Non
valorvarparameters" section has two code blocks:_inheritance_base(the non-experimental approach, extracted) and an experimental variant that requiresexperimentalCodeGeneration=true. That flag is a parcelize compiler-plugin argument with module-level granularity — it cannot be scoped to a single snippet, and enabling it module-wide would compile thekotlinmodule's unrelated snippets (coroutines, flow testing) under experimental codegen. The experimental block is therefore not extracted, and the flag is not set._inheritance_basealone still demonstrates the section's point.Code not extracted
pluginsblock (this repo is Kotlin DSL only), the Kotlin DSLpluginsblock, theadditionalAnnotationblock and theexperimentalCodeGenerationblock. Build-config blocks are published in their portableid("…")form on the page rather than this repo's version-catalog form, so they are left hand-maintained.UserCreatorblock under Create data from Parcel. Kotlin only.expect/actualblocks under Setup Parcelize for Kotlin multiplatform. Will not compile in a plain Android module.// ERROR: not allowedexample, both under Non val or var parameters in primary constructor. See "One experimental block omitted" above; the ERROR example cannot compile by design.Deprecations
None. Ten imports, all current —
android.os.Parcel,android.os.Parcelableand eightkotlinx.parcelizesymbols. A forced full recompile produced zero warnings.