diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt index 7d57e1b6ae8..b95d1ad4d33 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt @@ -23,7 +23,10 @@ import org.jetbrains.kotlin.fir.scopes.impl.FirSuperTypeScope import org.jetbrains.kotlin.fir.symbols.CallableId import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.jvm.FirJavaTypeRef +import org.jetbrains.kotlin.load.java.propertyNameByGetMethodName import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly +import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeFirstWord class JavaClassUseSiteMemberScope( klass: FirRegularClass, @@ -86,7 +89,7 @@ class JavaClassUseSiteMemberScope( private fun processAccessorFunctionsAndPropertiesByName( propertyName: Name, - getterName: Name, + getterNames: List, setterName: Name, processor: (FirCallableSymbol<*>) -> ProcessorAction ): ProcessorAction { @@ -98,12 +101,8 @@ class JavaClassUseSiteMemberScope( } ) return STOP if (klass is FirJavaClass) { - if (!declaredMemberScope.processFunctionsByName(getterName) { functionSymbol -> - processAccessorFunction(functionSymbol, propertyName, overrideCandidates, processor, isGetter = true) - } - ) return STOP - if (propertyName.asString().startsWith(IS_PREFIX)) { - if (!declaredMemberScope.processFunctionsByName(propertyName) { functionSymbol -> + for (getterName in getterNames) { + if (!declaredMemberScope.processFunctionsByName(getterName) { functionSymbol -> processAccessorFunction(functionSymbol, propertyName, overrideCandidates, processor, isGetter = true) } ) return STOP @@ -151,9 +150,18 @@ class JavaClassUseSiteMemberScope( } override fun processPropertiesByName(name: Name, processor: (FirCallableSymbol<*>) -> ProcessorAction): ProcessorAction { - val getterName = Name.identifier(GETTER_PREFIX + name.asString().capitalize()) + val identifier = name.identifier + val capitalizedAsciiName = identifier.capitalizeAsciiOnly() + val capitalizedFirstWordName = identifier.capitalizeFirstWord(asciiOnly = true) + val getterNames = listOfNotNull( + Name.identifier(GETTER_PREFIX + capitalizedAsciiName), + if (capitalizedFirstWordName == capitalizedAsciiName) null else Name.identifier(GETTER_PREFIX + capitalizedFirstWordName), + name.takeIf { identifier.startsWith(IS_PREFIX) } + ).filter { + propertyNameByGetMethodName(it) == name + } val setterName = Name.identifier(SETTER_PREFIX + name.asString().capitalize()) - return processAccessorFunctionsAndPropertiesByName(name, getterName, setterName, processor) + return processAccessorFunctionsAndPropertiesByName(name, getterNames, setterName, processor) } companion object { diff --git a/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.kt b/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.kt index 685ba55cc50..7a2258723c5 100644 --- a/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.kt +++ b/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.kt @@ -55,8 +55,8 @@ public class D { // FILE: main.kt fun test_1(x: A) { - val str1 = x.vmParameters // OK - val str2 = x.vMParameters // should be error + val str1 = x.vmParameters // OK + val str2 = x.vMParameters // should be error } fun test_2(x: B) { @@ -65,8 +65,8 @@ fun test_2(x: B) { } fun test_3(x: C) { - val error = x.vmParameters // should be error - val int = x.vMParameters // should be error + val error = x.vmParameters // should be error + val int = x.vMParameters // should be error } class Foo { diff --git a/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.txt b/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.txt index bc18c54e86c..79d58c33d0e 100644 --- a/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.txt +++ b/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.txt @@ -1,15 +1,15 @@ FILE: main.kt public final fun test_1(x: R|A|): R|kotlin/Unit| { - lval str1: = R|/x|.# - lval str2: R|ft!| = R|/x|.R|/A.vMParameters| + lval str1: R|ft!| = R|/x|.R|/A.vmParameters| + lval str2: = R|/x|.# } public final fun test_2(x: R|B|): R|kotlin/Unit| { lval int: R|ft!| = R|/x|.R|/B.vmParameters| lval error: = R|/x|.# } public final fun test_3(x: R|C|): R|kotlin/Unit| { - lval error: R|ft!| = R|/x|.R|/C.vmParameters| - lval int: R|ft!| = R|/x|.R|/C.vMParameters| + lval error: = R|/x|.# + lval int: = R|/x|.# } public final class Foo : R|kotlin/Any| { public constructor(): R|Foo| {