CORDA-2284 Normalise constructor-paired property name to constructor parameter name (#4339)

This commit is contained in:
Dominic Fox 2018-12-03 13:02:07 +00:00 committed by GitHub
parent 0925008f9e
commit da6059d29d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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