From 5c675f13571baafcebd0c26c2f170121b9a5f528 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 30 May 2021 12:23:04 +0900 Subject: [PATCH] optimize findImplicitPropertyName --- .../KotlinNamesAnnotationIntrospector.kt | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt index e71d5e09..00f4cd3b 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt @@ -28,26 +28,16 @@ import kotlin.reflect.jvm.kotlinFunction internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val cache: ReflectionCache, val ignoredClassesForImplyingJsonCreator: Set>) : NopAnnotationIntrospector() { // since 2.4 - override fun findImplicitPropertyName(member: AnnotatedMember): String? { - if (member is AnnotatedMethod && member.isInlineClass()) { - if (member.name.startsWith("get") && - member.name.contains('-') && - member.parameterCount == 0) { - return member.name.substringAfter("get") - .replaceFirstChar { it.lowercase(Locale.getDefault()) } - .substringBefore('-') - } else if (member.name.startsWith("is") && - member.name.contains('-') && - member.parameterCount == 0) { - return member.name.substringAfter("is") - .replaceFirstChar { it.lowercase(Locale.getDefault()) } - .substringBefore('-') - } - } else if (member is AnnotatedParameter) { - return findKotlinParameterName(member) - } - - return null + override fun findImplicitPropertyName(member: AnnotatedMember): String? = when (member) { + is AnnotatedMethod -> if (member.name.contains('-') && member.parameterCount == 0) { + when { + member.name.startsWith("get") -> member.name.substringAfter("get") + member.name.startsWith("is") -> member.name.substringAfter("is") + else -> null + }?.replaceFirstChar { it.lowercase(Locale.getDefault()) }?.substringBefore('-') + } else null + is AnnotatedParameter -> findKotlinParameterName(member) + else -> null } // since 2.11: support Kotlin's way of handling "isXxx" backed properties where @@ -169,5 +159,3 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c } } } - -private fun AnnotatedMethod.isInlineClass() = declaringClass.declaredMethods.any { it.name.contains('-') }