Parcelize: Use @Parcelize annotations from Android Extensions instead of the copied&deprecated ones (KT-42342, KT-43150)

Dex can't merge class files from both android-extensions-runtime and parcelize-runtime, so we have to keep only one copy of each class.
Instead of @Deprecated annotations, there are new diagnostics (without quick-fixes yet).
The goal is to allow simple usages (@Parcelize alone) but forbid kotlinx.android.synthetic.Parceler usage.
This commit is contained in:
Yan Zhulanow
2020-11-07 02:01:10 +09:00
parent fa42a6ba58
commit e83a3c3f27
36 changed files with 182 additions and 629 deletions
@@ -0,0 +1,46 @@
// WITH_RUNTIME
package test
import kotlinx.android.parcel.*
import android.os.Parcel
import android.os.Parcelable
object Parceler1 : Parceler<String> {
override fun create(parcel: Parcel) = parcel.readInt().toString()
override fun String.write(parcel: Parcel, flags: Int) {
parcel.writeInt(length)
}
}
object Parceler2 : Parceler<List<String>> {
override fun create(parcel: Parcel) = listOf(parcel.readString()!!)
override fun List<String>.write(parcel: Parcel, flags: Int) {
parcel.writeString(this.joinToString(","))
}
}
<warning descr="[DEPRECATED_ANNOTATION] Parcelize annotations from package 'kotlinx.android.parcel' are deprecated. Change package to 'kotlin.parcelize'">@Parcelize</warning>
<error descr="[FORBIDDEN_DEPRECATED_ANNOTATION] Parceler-related annotations from package 'kotlinx.android.parcel' are forbidden. Change package to 'kotlinx.parcelize'">@TypeParceler<String, <error descr="[UPPER_BOUND_VIOLATED] Type argument is not within its bounds: should be subtype of 'Parceler<in String>'">Parceler2</error>></error>
data class Test(
val a: String,
val b: <error descr="[FORBIDDEN_DEPRECATED_ANNOTATION] Parceler-related annotations from package 'kotlinx.android.parcel' are forbidden. Change package to 'kotlinx.parcelize'">@WriteWith<Parceler1></error> String,
val c: <error descr="[FORBIDDEN_DEPRECATED_ANNOTATION] Parceler-related annotations from package 'kotlinx.android.parcel' are forbidden. Change package to 'kotlinx.parcelize'">@WriteWith<Parceler2></error> List<<error descr="[FORBIDDEN_DEPRECATED_ANNOTATION] Parceler-related annotations from package 'kotlinx.android.parcel' are forbidden. Change package to 'kotlinx.parcelize'">@WriteWith<Parceler1></error> String>
) : Parcelable {
<warning descr="[DEPRECATED_ANNOTATION] Parcelize annotations from package 'kotlinx.android.parcel' are deprecated. Change package to 'kotlin.parcelize'">@IgnoredOnParcel</warning>
val x by lazy { "foo" }
}
interface ParcelerForUser: Parceler<User>
<warning descr="[DEPRECATED_ANNOTATION] Parcelize annotations from package 'kotlinx.android.parcel' are deprecated. Change package to 'kotlin.parcelize'">@Parcelize</warning>
class User(val name: String) : Parcelable {
private companion <error descr="[DEPRECATED_PARCELER] 'kotlinx.android.parcel.Parceler' is deprecated. Use 'kotlinx.parcelize.Parceler' instead">object</error> : ParcelerForUser {
override fun User.write(parcel: Parcel, flags: Int) {
parcel.writeString(name)
}
override fun create(parcel: Parcel) = User(parcel.readString()!!)
}
}
@@ -12,16 +12,11 @@ import org.jetbrains.kotlin.test.KotlinTestUtils
abstract class AbstractParcelizeCheckerTest : AbstractPsiCheckerTest() {
override fun setUp() {
super.setUp()
val androidJar = KotlinTestUtils.findAndroidApiJar()
ConfigLibraryUtil.addLibrary(module, "androidJar", androidJar.parentFile.absolutePath, arrayOf(androidJar.name))
ConfigLibraryUtil.addLibrary(module, "androidExtensionsRuntime", "dist/kotlinc/lib", arrayOf("parcelize-runtime.jar"))
addParcelizeLibraries(module)
}
override fun tearDown() {
ConfigLibraryUtil.removeLibrary(module, "androidJar")
ConfigLibraryUtil.removeLibrary(module, "androidExtensionsRuntime")
removeParcelizeLibraries(module)
super.tearDown()
}
}
@@ -23,16 +23,11 @@ import org.jetbrains.kotlin.test.KotlinTestUtils
abstract class AbstractParcelizeQuickFixTest : AbstractQuickFixTest() {
override fun setUp() {
super.setUp()
val androidJar = KotlinTestUtils.findAndroidApiJar()
ConfigLibraryUtil.addLibrary(module, "androidJar", androidJar.parentFile.absolutePath, arrayOf(androidJar.name))
ConfigLibraryUtil.addLibrary(module, "androidExtensionsRuntime", "dist/kotlinc/lib", arrayOf("parcelize-runtime.jar"))
addParcelizeLibraries(module)
}
override fun tearDown() {
ConfigLibraryUtil.removeLibrary(module, "androidJar")
ConfigLibraryUtil.removeLibrary(module, "androidExtensionsRuntime")
removeParcelizeLibraries(module)
super.tearDown()
}
}
@@ -53,6 +53,11 @@ public class ParcelizeCheckerTestGenerated extends AbstractParcelizeCheckerTest
runTest("plugins/parcelize/parcelize-ide/testData/checker/delegate.kt");
}
@TestMetadata("deprecatedAnnotations.kt")
public void testDeprecatedAnnotations() throws Exception {
runTest("plugins/parcelize/parcelize-ide/testData/checker/deprecatedAnnotations.kt");
}
@TestMetadata("emptyPrimaryConstructor.kt")
public void testEmptyPrimaryConstructor() throws Exception {
runTest("plugins/parcelize/parcelize-ide/testData/checker/emptyPrimaryConstructor.kt");
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.pacelize.ide.test
import com.intellij.openapi.module.Module
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
import org.jetbrains.kotlin.test.KotlinTestUtils
fun addParcelizeLibraries(module: Module) {
val androidJar = KotlinTestUtils.findAndroidApiJar()
ConfigLibraryUtil.addLibrary(module, "androidJar", androidJar.parentFile.absolutePath, arrayOf(androidJar.name))
ConfigLibraryUtil.addLibrary(module, "parcelizeRuntime", "dist/kotlinc/lib", arrayOf("parcelize-runtime.jar"))
ConfigLibraryUtil.addLibrary(module, "androidExtensionsRuntime", "dist/kotlinc/lib", arrayOf("android-extensions-runtime.jar"))
}
fun removeParcelizeLibraries(module: Module) {
ConfigLibraryUtil.removeLibrary(module, "androidJar")
ConfigLibraryUtil.removeLibrary(module, "parcelizeRuntime")
ConfigLibraryUtil.removeLibrary(module, "androidExtensionsRuntime")
}