mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
CORDA-2284 Normalise constructor-paired property name to constructor parameter name (#4339)
This commit is contained in:
parent
0925008f9e
commit
da6059d29d
@ -299,19 +299,23 @@ internal data class LocalTypeInformationBuilder(val lookup: LocalTypeLookup,
|
||||
}.toMap()
|
||||
|
||||
return rawType.propertyDescriptors().asSequence().mapNotNull { (name, descriptor) ->
|
||||
val property = makeConstructorPairedProperty(constructorParameterIndices, name, descriptor, constructorInformation)
|
||||
if (property == null) null else name to property
|
||||
val normalisedName = when {
|
||||
name in constructorParameterIndices -> name
|
||||
name.decapitalize() in constructorParameterIndices -> name.decapitalize()
|
||||
else -> return@mapNotNull null
|
||||
}
|
||||
|
||||
val property = makeConstructorPairedProperty(
|
||||
constructorParameterIndices[normalisedName]!!,
|
||||
descriptor,
|
||||
constructorInformation)
|
||||
if (property == null) null else normalisedName to property
|
||||
}
|
||||
}
|
||||
|
||||
private fun makeConstructorPairedProperty(constructorParameterIndices: Map<String, Int>,
|
||||
name: String,
|
||||
private fun makeConstructorPairedProperty(constructorIndex: Int,
|
||||
descriptor: PropertyDescriptor,
|
||||
constructorInformation: LocalConstructorInformation): LocalPropertyInformation? {
|
||||
// In some very rare cases we have a constructor parameter matched by a getter with no backing field,
|
||||
// and cannot infer whether the property name should be capitalised or not.
|
||||
val constructorIndex = constructorParameterIndices[name] ?: constructorParameterIndices[name.decapitalize()]
|
||||
if (constructorIndex == null) return null
|
||||
|
||||
if (descriptor.getter == null) {
|
||||
if (descriptor.field == null) return null
|
||||
|
Loading…
Reference in New Issue
Block a user