File tree Expand file tree Collapse file tree 4 files changed +10
-12
lines changed Expand file tree Collapse file tree 4 files changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -9,11 +9,9 @@ import org.jetbrains.kotlin.com.intellij.mock.MockProject
9
9
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
10
10
import org.jetbrains.kotlin.config.CompilerConfiguration
11
11
12
- class ObjectSerializationComponentRegistrar @JvmOverloads constructor(
13
- private val enabled : Boolean = false
14
- ): ComponentRegistrar {
12
+ class ObjectSerializationComponentRegistrar (): ComponentRegistrar {
15
13
override fun registerProjectComponents (project : MockProject , configuration : CompilerConfiguration ) {
16
- if (configuration[KEY_ENABLED ] == false && ! enabled ) {
14
+ if (configuration[KEY_ENABLED ] == false ) {
17
15
return
18
16
}
19
17
Original file line number Diff line number Diff line change @@ -14,24 +14,22 @@ class ObjectSerializationJvmGeneration : ExpressionCodegenExtension {
14
14
if (codegen.descriptor.needSerializableFix()) {
15
15
val selfType = codegen.typeMapper.mapType(codegen.descriptor)
16
16
17
- codegen.addFunction( SERIALIZABLE_READ .identifier, " ()Ljava/lang/Object; " ) {
17
+ codegen.addReadResolveFunction {
18
18
getstatic(codegen.className, " INSTANCE" , selfType.descriptor)
19
19
areturn(selfType)
20
20
}
21
21
}
22
22
23
23
}
24
24
25
- private fun ImplementationBodyCodegen.addFunction (
26
- name : String ,
27
- asmDescriptor : String ,
25
+ private fun ImplementationBodyCodegen.addReadResolveFunction (
28
26
block : InstructionAdapter .() -> Unit
29
27
) {
30
28
val visitor = v.newMethod(
31
29
NO_ORIGIN ,
32
30
ACC_PUBLIC or ACC_SYNTHETIC ,
33
- name ,
34
- asmDescriptor ,
31
+ SERIALIZABLE_READ .identifier ,
32
+ " ()Ljava/lang/Object; " ,
35
33
null ,
36
34
EMPTY_STRING_ARRAY
37
35
)
Original file line number Diff line number Diff line change 1
1
package me.shika.generation
2
2
3
3
import org.jetbrains.kotlin.descriptors.ClassDescriptor
4
+ import org.jetbrains.kotlin.incremental.components.NoLookupLocation
4
5
import org.jetbrains.kotlin.name.FqName
5
6
import org.jetbrains.kotlin.name.Name
6
7
import org.jetbrains.kotlin.platform.has
@@ -19,7 +20,8 @@ fun ClassDescriptor.needSerializableFix() =
19
20
&& ! hasReadMethod()
20
21
21
22
fun ClassDescriptor.hasReadMethod () =
22
- unsubstitutedMemberScope.getFunctionNames().contains(SERIALIZABLE_READ )
23
+ unsubstitutedMemberScope.getContributedFunctions(SERIALIZABLE_READ , NoLookupLocation .FROM_BACKEND )
24
+ .any { it.name == SERIALIZABLE_READ && it.valueParameters.isEmpty() }
23
25
24
26
fun ClassDescriptor.isSerializable (): Boolean =
25
27
getSuperInterfaces().any { it.fqNameSafe == SERIALIZABLE_FQ_NAME || it.isSerializable() }
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ class ObjectSerializationFixTest(enableIr: Boolean) {
18
18
}
19
19
20
20
private val compiler = KotlinCompilation ().apply {
21
- compilerPlugins = listOf (ObjectSerializationComponentRegistrar (enabled = true ))
21
+ compilerPlugins = listOf (ObjectSerializationComponentRegistrar ())
22
22
useIR = enableIr
23
23
}
24
24
You can’t perform that action at this time.
0 commit comments