Improved processing related to parameter parsing on Kotlin#760
Merged
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.
k163377
commented
Jan 20, 2024
Comment on lines
-123
to
-159
| @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 | ||
| } | ||
| } |
Contributor
Author
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
kotlinFunctionhas 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.