[Parcelize] Fix subclass check of deprecated Parceler interface
^KT-59949 Fixed ^KT-60090 Fixed
This commit is contained in:
+8
-9
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirClassChecker
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.*
|
||||
import org.jetbrains.kotlin.fir.resolve.isSubclassOf
|
||||
import org.jetbrains.kotlin.fir.resolve.lookupSuperTypes
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
@@ -95,16 +96,14 @@ object FirParcelizeClassChecker : FirClassChecker() {
|
||||
}
|
||||
|
||||
private fun checkParcelerClass(klass: FirClass, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
if (klass !is FirRegularClass || klass.isCompanion) return
|
||||
for (superTypeRef in klass.superTypeRefs) {
|
||||
if (superTypeRef.coneType.classId == OLD_PARCELER_ID) {
|
||||
val strategy = if (klass.name == SpecialNames.NO_NAME_PROVIDED) {
|
||||
SourceElementPositioningStrategies.OBJECT_KEYWORD
|
||||
} else {
|
||||
SourceElementPositioningStrategies.NAME_IDENTIFIER
|
||||
}
|
||||
reporter.reportOn(klass.source, KtErrorsParcelize.DEPRECATED_PARCELER, context, positioningStrategy = strategy)
|
||||
if (klass !is FirRegularClass || !klass.isCompanion) return
|
||||
if (klass.isSubclassOf(OLD_PARCELER_ID.toLookupTag(), context.session, isStrict = true)) {
|
||||
val strategy = if (klass.name == SpecialNames.NO_NAME_PROVIDED) {
|
||||
SourceElementPositioningStrategies.OBJECT_KEYWORD
|
||||
} else {
|
||||
SourceElementPositioningStrategies.NAME_IDENTIFIER
|
||||
}
|
||||
reporter.reportOn(klass.source, KtErrorsParcelize.DEPRECATED_PARCELER, context, positioningStrategy = strategy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -5,7 +5,7 @@ import kotlinx.android.parcel.*
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
object <!DEPRECATED_PARCELER!>Parceler1<!> : Parceler<String> {
|
||||
object Parceler1 : Parceler<String> {
|
||||
override fun create(parcel: Parcel) = parcel.readInt().toString()
|
||||
|
||||
override fun String.write(parcel: Parcel, flags: Int) {
|
||||
@@ -13,7 +13,7 @@ object <!DEPRECATED_PARCELER!>Parceler1<!> : Parceler<String> {
|
||||
}
|
||||
}
|
||||
|
||||
object <!DEPRECATED_PARCELER!>Parceler2<!> : Parceler<List<String>> {
|
||||
object Parceler2 : Parceler<List<String>> {
|
||||
override fun create(parcel: Parcel) = listOf(parcel.readString()!!)
|
||||
|
||||
override fun List<String>.write(parcel: Parcel, flags: Int) {
|
||||
@@ -32,11 +32,11 @@ data class Test(
|
||||
val x by lazy { "foo" }
|
||||
}
|
||||
|
||||
interface <!DEPRECATED_PARCELER!>ParcelerForUser<!>: Parceler<User>
|
||||
interface ParcelerForUser: Parceler<User>
|
||||
|
||||
<!DEPRECATED_ANNOTATION!>@Parcelize<!>
|
||||
class User(val name: String) : Parcelable {
|
||||
private companion object : ParcelerForUser {
|
||||
private companion <!DEPRECATED_PARCELER!>object<!> : ParcelerForUser {
|
||||
override fun User.write(parcel: Parcel, flags: Int) {
|
||||
parcel.writeString(name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user