-
-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved processing related to parameter parsing on Kotlin #760
Conversation
…existing In addition, kotlinFunction calls were replaced with calls from the cache. The hasRequiredMarker process had no problem without the check, so the findKotlinParameterName check process was removed.
@Suppress("UNCHECKED_CAST") | ||
private fun findKotlinParameterName(param: AnnotatedParameter): String? { | ||
return if (param.declaringClass.isKotlinClass()) { | ||
val member = param.owner.member | ||
if (member is Constructor<*>) { | ||
val ctor = (member as Constructor<Any>) | ||
val ctorParmCount = ctor.parameterTypes.size | ||
val ktorParmCount = try { ctor.kotlinFunction?.parameters?.size ?: 0 } | ||
catch (ex: KotlinReflectionInternalError) { 0 } | ||
catch (ex: UnsupportedOperationException) { 0 } | ||
if (ktorParmCount > 0 && ktorParmCount == ctorParmCount) { | ||
ctor.kotlinFunction?.parameters?.get(param.index)?.name | ||
} else { | ||
null | ||
} | ||
} else if (member is Method) { | ||
try { | ||
val temp = member.kotlinFunction | ||
|
||
val firstParamKind = temp?.parameters?.firstOrNull()?.kind | ||
val idx = if (firstParamKind != KParameter.Kind.VALUE) param.index + 1 else param.index | ||
val parmCount = temp?.parameters?.size ?: 0 | ||
if (parmCount > idx) { | ||
temp?.parameters?.get(idx)?.name | ||
} else { | ||
null | ||
} | ||
} catch (ex: KotlinReflectionInternalError) { | ||
null | ||
} | ||
} else { | ||
null | ||
} | ||
} else { | ||
null | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the previous implementation of AnnotatedParameter.hasRequiredMarker
in KotlinAnnotationIntrospector
, parameter acquisition was called without a check.
In other words, these check processes are now considered meaningless and have been removed.
https://github.com/FasterXML/jackson-module-kotlin/pull/760/files#diff-938d5c566367fbca40b3ef96c99967dba4cd563f3854370272e0ae6b5d0f7f0d
The
kotlinFunction
has been changed so that it is not called directly, but is referred to in the cache.This should improve the parsing speed at initialization.
Also, a common process for obtaining parameters on Kotlin was implemented, replacing the existing parameter obtaining process.