From df4780c31026aaa626746f49f0e6fa3fa0278a05 Mon Sep 17 00:00:00 2001 From: CharlesG-Branch <43424788+CharlesG-Branch@users.noreply.github.com> Date: Fri, 18 Feb 2022 07:39:33 -0500 Subject: Fix java getter / setter name generation (#2356) Kotlin has special rules for conversion around properties that start with "is" For more info see: https://kotlinlang.org/docs/java-interop.html#getters-and-setters https://kotlinlang.org/docs/java-to-kotlin-interop.html#properties --- .../DefaultDescriptorToDocumentableTranslator.kt | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'plugins/base/src/main') diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 96bd2fc0..f636f984 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -616,9 +616,25 @@ private class DokkaDescriptorVisitor( ) val name = run { - val modifier = if (isGetter) "get" else "set" val rawName = propertyDescriptor.name.asString() - "$modifier${rawName.capitalize()}" + /* + * Kotlin has special rules for conversion around properties that + * start with "is" For more info see: + * https://kotlinlang.org/docs/java-interop.html#getters-and-setters + * https://kotlinlang.org/docs/java-to-kotlin-interop.html#properties + * + * Based on our testing, this rule only applies when the letter after + * the "is" is *not* lowercase. This means that words like "issue" won't + * have the rule applied but "is_foobar" and "is1of" will have the rule applied. + */ + val specialCaseIs = rawName.startsWith("is") + && rawName.getOrNull(2)?.isLowerCase() == false + + if (specialCaseIs) { + if (isGetter) rawName else rawName.replaceFirst("is", "set") + } else { + if (isGetter) "get${rawName.capitalize()}" else "set${rawName.capitalize()}" + } } val parameters = -- cgit