Skip to content

Commit 9a54173

Browse files
committed
Reduction of information held in property-related
1 parent cce73b8 commit 9a54173

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

src/main/kotlin/io/github/projectmapk/jackson/module/kogera/annotationIntrospector/KotlinPrimaryAnnotationIntrospector.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@ import io.github.projectmapk.jackson.module.kogera.JSON_PROPERTY_CLASS
1616
import io.github.projectmapk.jackson.module.kogera.ReflectionCache
1717
import io.github.projectmapk.jackson.module.kogera.hasCreatorAnnotation
1818
import io.github.projectmapk.jackson.module.kogera.jmClass.JmClass
19+
import io.github.projectmapk.jackson.module.kogera.jmClass.JmProperty
1920
import io.github.projectmapk.jackson.module.kogera.reconstructClass
2021
import io.github.projectmapk.jackson.module.kogera.toSignature
2122
import kotlinx.metadata.KmClassifier
22-
import kotlinx.metadata.KmProperty
2323
import kotlinx.metadata.KmValueParameter
2424
import kotlinx.metadata.declaresDefaultValue
2525
import kotlinx.metadata.isNullable
26-
import kotlinx.metadata.isSecondary
27-
import kotlinx.metadata.jvm.getterSignature
28-
import kotlinx.metadata.jvm.setterSignature
29-
import kotlinx.metadata.jvm.signature
3026
import java.lang.reflect.Constructor
3127
import java.lang.reflect.Executable
3228
import java.lang.reflect.Method
@@ -71,11 +67,11 @@ internal class KotlinPrimaryAnnotationIntrospector(
7167
// only a check for the existence of a getter is performed.
7268
// https://youtrack.jetbrains.com/issue/KT-6519
7369
?.let {
74-
if (it.getterSignature == null) !(it.returnType.isNullable || type.hasDefaultEmptyValue()) else null
70+
if (it.getterName == null) !(it.returnType.isNullable || type.hasDefaultEmptyValue()) else null
7571
}
7672
}
7773

78-
private fun KmProperty.isRequiredByNullability(): Boolean = !this.returnType.isNullable
74+
private fun JmProperty.isRequiredByNullability(): Boolean = !this.returnType.isNullable
7975

8076
private fun AnnotatedMethod.getRequiredMarkerFromCorrespondingAccessor(jmClass: JmClass): Boolean? =
8177
when (parameterCount) {

src/main/kotlin/io/github/projectmapk/jackson/module/kogera/jmClass/JmClass.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import kotlinx.metadata.ClassKind
77
import kotlinx.metadata.ClassName
88
import kotlinx.metadata.KmClass
99
import kotlinx.metadata.KmFunction
10-
import kotlinx.metadata.KmProperty
1110
import kotlinx.metadata.isNullable
12-
import kotlinx.metadata.jvm.getterSignature
1311
import kotlinx.metadata.jvm.signature
1412
import kotlinx.metadata.kind
1513
import java.lang.reflect.Constructor
@@ -40,7 +38,7 @@ internal sealed interface JmClass {
4038
val constructors: List<JmConstructor>
4139
val sealedSubclasses: List<ClassName>
4240
val propertyNameSet: Set<String>
43-
val properties: List<KmProperty>
41+
val properties: List<JmProperty>
4442
val companion: CompanionObject?
4543
// endregion
4644

@@ -49,8 +47,8 @@ internal sealed interface JmClass {
4947
// endregion
5048

5149
fun findKmConstructor(constructor: Constructor<*>): JmConstructor?
52-
fun findPropertyByField(field: Field): KmProperty?
53-
fun findPropertyByGetter(getter: Method): KmProperty?
50+
fun findPropertyByField(field: Field): JmProperty?
51+
fun findPropertyByGetter(getter: Method): JmProperty?
5452
}
5553

5654
private class JmClassImpl(
@@ -59,10 +57,10 @@ private class JmClassImpl(
5957
superJmClass: JmClass?,
6058
interfaceJmClasses: List<JmClass>
6159
) : JmClass {
62-
private val allPropsMap: Map<String, KmProperty>
60+
private val allPropsMap: Map<String, JmProperty>
6361

6462
// Defined as non-lazy because it is always read in both serialization and deserialization
65-
override val properties: List<KmProperty>
63+
override val properties: List<JmProperty>
6664

6765
private val companionPropName: String? = kmClass.companionObject
6866
override val kind: ClassKind = kmClass.kind
@@ -77,7 +75,7 @@ private class JmClassImpl(
7775
// it is necessary to obtain a more specific type, so always add it from the abstract class first.
7876
val tempPropsMap = ((superJmClass as JmClassImpl?)?.allPropsMap?.toMutableMap() ?: mutableMapOf()).apply {
7977
kmClass.properties.forEach {
80-
this[it.name] = it
78+
this[it.name] = JmProperty(it)
8179
}
8280
}
8381

@@ -119,11 +117,11 @@ private class JmClassImpl(
119117
}
120118

121119
// Field name always matches property name
122-
override fun findPropertyByField(field: Field): KmProperty? = allPropsMap[field.name]
120+
override fun findPropertyByField(field: Field): JmProperty? = allPropsMap[field.name]
123121

124-
override fun findPropertyByGetter(getter: Method): KmProperty? {
122+
override fun findPropertyByGetter(getter: Method): JmProperty? {
125123
val getterName = getter.name
126-
return properties.find { it.getterSignature?.name == getterName }
124+
return properties.find { it.getterName == getterName }
127125
}
128126
}
129127

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.github.projectmapk.jackson.module.kogera.jmClass
2+
3+
import kotlinx.metadata.KmProperty
4+
import kotlinx.metadata.KmType
5+
import kotlinx.metadata.jvm.JvmMemberSignature
6+
import kotlinx.metadata.jvm.getterSignature
7+
import kotlinx.metadata.jvm.setterSignature
8+
9+
internal data class JmProperty(
10+
val name: String?,
11+
val getterName: String?,
12+
val setterSignature: JvmMemberSignature?,
13+
val returnType: KmType
14+
) {
15+
constructor(kmProperty: KmProperty) : this(
16+
name = kmProperty.name,
17+
getterName = kmProperty.getterSignature?.name,
18+
setterSignature = kmProperty.setterSignature,
19+
returnType = kmProperty.returnType
20+
)
21+
}

0 commit comments

Comments
 (0)