Parcelable: Use innerClassNameFactory to figure out the internal name of the Creator class (KT-19680)

KAPT3 class builder mode in 1.1.4 replaces '$' (inner class name separators) with '/' by providing special innerClassNameFactory.
We should use it to be compatible with kapt.
This commit is contained in:
Yan Zhulanow
2017-08-16 02:32:00 +03:00
committed by Yan Zhulanow
parent 84e59601c1
commit c330285fd0
3 changed files with 23 additions and 2 deletions
@@ -50,4 +50,8 @@ dependencies {
kapt { kapt {
generateStubs = true generateStubs = true
}
androidExtensions {
experimental = true
} }
@@ -15,11 +15,15 @@
*/ */
package com.example.dagger.kotlin.ui package com.example.dagger.kotlin.ui
import android.content.Context
import android.content.Intent
import android.location.LocationManager import android.location.LocationManager
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable
import com.example.dagger.kotlin.DemoActivity import com.example.dagger.kotlin.DemoActivity
import com.example.dagger.kotlin.DemoApplication import com.example.dagger.kotlin.DemoApplication
import com.example.dagger.kotlin.R import com.example.dagger.kotlin.R
import kotlinx.android.parcel.Parcelize
import kotlinx.android.synthetic.main.activity_main.locationInfo import kotlinx.android.synthetic.main.activity_main.locationInfo
import javax.inject.Inject import javax.inject.Inject
@@ -36,3 +40,13 @@ class HomeActivity : DemoActivity() {
locationInfo.text = "Injected LocationManager:\n$locationManager" locationInfo.text = "Injected LocationManager:\n$locationManager"
} }
} }
class Foo {
@Inject
lateinit var c: Context
private lateinit var bars: List<Bar>
@Parcelize
data class Bar(val intent: Intent): Parcelable
}
@@ -210,7 +210,9 @@ open class ParcelableCodegenExtension : ExpressionCodegenExtension {
private fun writeCreatorAccessField(codegen: ImplementationBodyCodegen, parcelableClass: ClassDescriptor) { private fun writeCreatorAccessField(codegen: ImplementationBodyCodegen, parcelableClass: ClassDescriptor) {
val parcelableAsmType = codegen.typeMapper.mapType(parcelableClass.defaultType) val parcelableAsmType = codegen.typeMapper.mapType(parcelableClass.defaultType)
val creatorAsmType = Type.getObjectType(parcelableAsmType.internalName + "\$Creator") val creatorAsmType = Type.getObjectType(
codegen.typeMapper.typeMappingConfiguration.innerClassNameFactory(parcelableAsmType.internalName, "Creator"))
codegen.v.newField(JvmDeclarationOrigin.NO_ORIGIN, ACC_STATIC or ACC_PUBLIC or ACC_FINAL, "CREATOR", codegen.v.newField(JvmDeclarationOrigin.NO_ORIGIN, ACC_STATIC or ACC_PUBLIC or ACC_FINAL, "CREATOR",
creatorAsmType.descriptor, null, null) creatorAsmType.descriptor, null, null)
} }
@@ -224,7 +226,8 @@ open class ParcelableCodegenExtension : ExpressionCodegenExtension {
properties: List<Pair<String, KotlinType>> properties: List<Pair<String, KotlinType>>
) { ) {
val containerAsmType = codegen.typeMapper.mapType(parcelableClass.defaultType) val containerAsmType = codegen.typeMapper.mapType(parcelableClass.defaultType)
val creatorAsmType = Type.getObjectType(containerAsmType.internalName + "\$Creator") val creatorAsmType = Type.getObjectType(
codegen.typeMapper.typeMappingConfiguration.innerClassNameFactory(containerAsmType.internalName, "Creator"))
val creatorClass = ClassDescriptorImpl( val creatorClass = ClassDescriptorImpl(
parcelableClass.containingDeclaration, Name.identifier("Creator"), Modality.FINAL, ClassKind.CLASS, emptyList(), parcelableClass.containingDeclaration, Name.identifier("Creator"), Modality.FINAL, ClassKind.CLASS, emptyList(),