[FE] Return Name? instead of List<Name> from getBuiltinFunctionNamesByJvmName
This is much more correct, because we have one to one mapping for special java functions in this case, so using single nullable name instead of list of names makes code more readable
This commit is contained in:
+14
-16
@@ -222,9 +222,9 @@ class JavaClassUseSiteMemberScope(
|
||||
override fun processFunctionsByName(name: Name, processor: (FirNamedFunctionSymbol) -> Unit) {
|
||||
val potentialPropertyNames = getPropertyNamesCandidatesByAccessorName(name)
|
||||
|
||||
val renamedSpecialBuiltInNames = SpecialGenericSignatures.getBuiltinFunctionNamesByJvmName(name)
|
||||
val renamedSpecialBuiltInName = SpecialGenericSignatures.getBuiltinFunctionNamesByJvmName(name)
|
||||
|
||||
if (potentialPropertyNames.isEmpty() && renamedSpecialBuiltInNames.isEmpty() &&
|
||||
if (potentialPropertyNames.isEmpty() && renamedSpecialBuiltInName == null &&
|
||||
!name.sameAsBuiltinMethodWithErasedValueParameters && !name.sameAsRenamedInJvmBuiltin
|
||||
) {
|
||||
return super.processFunctionsByName(name, processor)
|
||||
@@ -233,7 +233,7 @@ class JavaClassUseSiteMemberScope(
|
||||
val overriddenProperties = potentialPropertyNames.flatMap(this::getProperties).filterIsInstance<FirPropertySymbol>()
|
||||
|
||||
specialFunctions.getOrPut(name) {
|
||||
doProcessSpecialFunctions(name, overriddenProperties, renamedSpecialBuiltInNames)
|
||||
doProcessSpecialFunctions(name, overriddenProperties, renamedSpecialBuiltInName)
|
||||
}.forEach {
|
||||
processor(it)
|
||||
}
|
||||
@@ -242,14 +242,14 @@ class JavaClassUseSiteMemberScope(
|
||||
private fun doProcessSpecialFunctions(
|
||||
name: Name,
|
||||
overriddenProperties: List<FirPropertySymbol>,
|
||||
renamedSpecialBuiltInNames: List<Name>
|
||||
renamedSpecialBuiltInName: Name?
|
||||
): List<FirNamedFunctionSymbol> {
|
||||
val result = mutableListOf<FirNamedFunctionSymbol>()
|
||||
|
||||
declaredMemberScope.processFunctionsByName(name) { functionSymbol ->
|
||||
if (functionSymbol.isStatic) return@processFunctionsByName
|
||||
if (overriddenProperties.none { it.isOverriddenInClassBy(functionSymbol) } &&
|
||||
!functionSymbol.doesOverrideRenamedBuiltins(renamedSpecialBuiltInNames) &&
|
||||
!functionSymbol.doesOverrideRenamedBuiltins(renamedSpecialBuiltInName) &&
|
||||
!functionSymbol.shouldBeVisibleAsOverrideOfBuiltInWithErasedValueParameters()
|
||||
) {
|
||||
result += functionSymbol
|
||||
@@ -392,19 +392,17 @@ class JavaClassUseSiteMemberScope(
|
||||
return upperBound.classId == StandardClassIds.Any
|
||||
}
|
||||
|
||||
private fun FirNamedFunctionSymbol.doesOverrideRenamedBuiltins(renamedSpecialBuiltInNames: List<Name>): Boolean {
|
||||
return renamedSpecialBuiltInNames.any {
|
||||
// e.g. 'removeAt' or 'toInt'
|
||||
builtinName ->
|
||||
val builtinSpecialFromSuperTypes =
|
||||
getFunctionsFromSupertypes(builtinName).filter { it.getOverriddenBuiltinWithDifferentJvmName() != null }
|
||||
if (builtinSpecialFromSuperTypes.isEmpty()) return@any false
|
||||
private fun FirNamedFunctionSymbol.doesOverrideRenamedBuiltins(renamedSpecialBuiltInName: Name?): Boolean {
|
||||
if (renamedSpecialBuiltInName == null) return false
|
||||
// e.g. 'removeAt' or 'toInt'
|
||||
val builtinSpecialFromSuperTypes =
|
||||
getFunctionsFromSupertypes(renamedSpecialBuiltInName).filter { it.getOverriddenBuiltinWithDifferentJvmName() != null }
|
||||
if (builtinSpecialFromSuperTypes.isEmpty()) return false
|
||||
|
||||
val currentJvmDescriptor = fir.computeJvmDescriptor(customName = builtinName.asString())
|
||||
val currentJvmDescriptor = fir.computeJvmDescriptor(customName = renamedSpecialBuiltInName.asString())
|
||||
|
||||
builtinSpecialFromSuperTypes.any { builtinSpecial ->
|
||||
builtinSpecial.fir.computeJvmDescriptor() == currentJvmDescriptor
|
||||
}
|
||||
return builtinSpecialFromSuperTypes.any { builtinSpecial ->
|
||||
builtinSpecial.fir.computeJvmDescriptor() == currentJvmDescriptor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -127,13 +127,13 @@ open class SpecialGenericSignatures {
|
||||
|
||||
val ORIGINAL_SHORT_NAMES: List<Name> = NAME_AND_SIGNATURE_TO_JVM_REPRESENTATION_NAME_MAP.keys.map { it.name }
|
||||
|
||||
val JVM_SHORT_NAME_TO_BUILTIN_SHORT_NAMES_MAP: Map<Name, List<Name>> =
|
||||
val JVM_SHORT_NAME_TO_BUILTIN_SHORT_NAMES_MAP: Map<Name, Name> =
|
||||
NAME_AND_SIGNATURE_TO_JVM_REPRESENTATION_NAME_MAP.entries
|
||||
.map { Pair(it.key.name, it.value) }
|
||||
.groupBy({ it.second }, { it.first })
|
||||
.associateBy({ it.second }, { it.first })
|
||||
|
||||
fun getBuiltinFunctionNamesByJvmName(name: Name): List<Name> =
|
||||
JVM_SHORT_NAME_TO_BUILTIN_SHORT_NAMES_MAP[name] ?: emptyList()
|
||||
fun getBuiltinFunctionNamesByJvmName(name: Name): Name? =
|
||||
JVM_SHORT_NAME_TO_BUILTIN_SHORT_NAMES_MAP[name]
|
||||
|
||||
val Name.sameAsBuiltinMethodWithErasedValueParameters: Boolean
|
||||
get() = this in ERASED_VALUE_PARAMETERS_SHORT_NAMES
|
||||
|
||||
+7
-9
@@ -205,17 +205,15 @@ class LazyJavaClassMemberScope(
|
||||
}
|
||||
|
||||
private fun SimpleFunctionDescriptor.doesOverrideRenamedBuiltins(): Boolean {
|
||||
return SpecialGenericSignatures.getBuiltinFunctionNamesByJvmName(name).any {
|
||||
// e.g. 'removeAt' or 'toInt'
|
||||
builtinName ->
|
||||
val builtinSpecialFromSuperTypes =
|
||||
getFunctionsFromSupertypes(builtinName).filter { it.doesOverrideBuiltinWithDifferentJvmName() }
|
||||
if (builtinSpecialFromSuperTypes.isEmpty()) return@any false
|
||||
// e.g. 'removeAt' or 'toInt'
|
||||
val builtinName = SpecialGenericSignatures.getBuiltinFunctionNamesByJvmName(name) ?: return false
|
||||
val builtinSpecialFromSuperTypes =
|
||||
getFunctionsFromSupertypes(builtinName).filter { it.doesOverrideBuiltinWithDifferentJvmName() }
|
||||
if (builtinSpecialFromSuperTypes.isEmpty()) return false
|
||||
|
||||
val methodDescriptor = this.createRenamedCopy(builtinName)
|
||||
val methodDescriptor = this.createRenamedCopy(builtinName)
|
||||
|
||||
builtinSpecialFromSuperTypes.any { doesOverrideRenamedDescriptor(it, methodDescriptor) }
|
||||
}
|
||||
return builtinSpecialFromSuperTypes.any { doesOverrideRenamedDescriptor(it, methodDescriptor) }
|
||||
}
|
||||
|
||||
private fun SimpleFunctionDescriptor.doesOverrideSuspendFunction(): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user