Parcelize: Don't activate both 'kotlin-parcelize' and 'kotlin-android-extensions' in IDE (KT-42267)
The actual problem is a lack of plugin activation check in ParcelableUltraLightClassModifierExtension (see how it should be done in ParcelizeUltraLightClassModifierExtension). However, ParcelableUltraLightClassModifierExtension lays inside ADT sources, and it's impossible to make an fast&easy fix from our side. However, we control the compiler plugin on which the IDE support is based, so the check is added there. There should be no troubles if the application with 'kotlin-android-extensions' includes an Android library with 'kotlin-parcelize' or vise-versa, as runtime libraries of both plugins are attached to the 'implementation' Gradle configuration since AGP 2.5.
This commit is contained in:
+13
-1
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.android.parcel
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import kotlinx.android.parcel.Parceler
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import org.jetbrains.kotlin.android.parcel.ParcelableSyntheticComponent.ComponentKind.DESCRIBE_CONTENTS
|
||||
@@ -158,8 +159,19 @@ interface ParcelableSyntheticComponent {
|
||||
val PARCELIZE_CLASS_FQNAME: FqName = FqName(Parcelize::class.java.canonicalName)
|
||||
internal val PARCELER_FQNAME: FqName = FqName(Parceler::class.java.canonicalName)
|
||||
|
||||
private val PARCELIZE_PLUGIN_PACKAGE = FqName("kotlinx.parcelize")
|
||||
|
||||
val ClassDescriptor.isParcelize: Boolean
|
||||
get() = this.annotations.hasAnnotation(PARCELIZE_CLASS_FQNAME)
|
||||
get() {
|
||||
val parcelizeAnnotation = this.annotations.findAnnotation(PARCELIZE_CLASS_FQNAME) ?: return false
|
||||
if (ApplicationManager.getApplication().isHeadlessEnvironment) {
|
||||
// Module check shouldn't affect compilation
|
||||
return true
|
||||
}
|
||||
|
||||
val module = parcelizeAnnotation.type.constructor.declarationDescriptor?.module ?: return false
|
||||
return module.getPackage(PARCELIZE_PLUGIN_PACKAGE).isEmpty()
|
||||
}
|
||||
|
||||
val KotlinType.isParceler
|
||||
get() = constructor.declarationDescriptor?.fqNameSafe == PARCELER_FQNAME
|
||||
|
||||
Reference in New Issue
Block a user