K2: Simplify JvmMappedScope-related code a bit

JvmMappedScope.Signatures became mostly irrelevant and only
"useful" for checking if we really need to have the scope mapped

Now, the check is rewritten according to K1 semantics

^KT-57694 Fixed
diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/scopes/JvmMappedScopes.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/scopes/JvmMappedScopes.kt
index 2aefa08..5d32fc3 100644
--- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/scopes/JvmMappedScopes.kt
+++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/resolve/scopes/JvmMappedScopes.kt
@@ -14,6 +14,8 @@
 import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
 import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
 import org.jetbrains.kotlin.fir.scopes.jvm.JvmMappedScope
+import org.jetbrains.kotlin.fir.types.isSomeFunctionType
+import org.jetbrains.kotlin.name.StandardClassIds
 
 fun wrapScopeWithJvmMapped(
     klass: FirClass,
@@ -28,16 +30,14 @@
     val symbolProvider = useSiteSession.symbolProvider
     val javaClass = symbolProvider.getClassLikeSymbolByClassId(javaClassId)?.fir as? FirJavaClass
         ?: return declaredMemberScope
-    val preparedSignatures = JvmMappedScope.prepareSignatures(javaClass, JavaToKotlinClassMap.isMutable(kotlinUnsafeFqName))
-    return if (preparedSignatures.isNotEmpty()) {
-        JvmMappedScope(
-            useSiteSession,
-            klass,
-            javaClass,
-            declaredMemberScope,
-            preparedSignatures
-        )
-    } else {
+
+    // We don't add additional built-in members to function types and kotlin.Any (see JvmBuiltInsCustomizer.getJavaAnalogue)
+    if (klass.symbol.toLookupTag().isSomeFunctionType(useSiteSession) || classId == StandardClassIds.Any) return declaredMemberScope
+
+    return JvmMappedScope(
+        useSiteSession,
+        klass,
+        javaClass,
         declaredMemberScope
-    }
+    )
 }
diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/scopes/jvm/JvmMappedScope.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/scopes/jvm/JvmMappedScope.kt
index ee53684..79708b4a 100644
--- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/scopes/jvm/JvmMappedScope.kt
+++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/scopes/jvm/JvmMappedScope.kt
@@ -49,7 +49,6 @@
     private val firKotlinClass: FirRegularClass,
     private val firJavaClass: FirJavaClass,
     private val declaredMemberScope: FirContainingNamesAwareScope,
-    private val signatures: Signatures
 ) : FirTypeScope() {
     private val functionsCache = mutableMapOf<FirNamedFunctionSymbol, FirNamedFunctionSymbol>()
 
@@ -211,7 +210,7 @@
     }
 
     override fun processDeclaredConstructors(processor: (FirConstructorSymbol) -> Unit) {
-        javaMappedClassUseSiteScopeWithCustomSupertype.processDeclaredConstructors { javaCtorSymbol ->
+        javaMappedClassUseSiteScopeWithCustomSupertype.processDeclaredConstructors processor@{ javaCtorSymbol ->
 
             fun FirConstructor.isShadowedBy(ctorFromKotlin: FirConstructorSymbol): Boolean {
                 // assuming already checked for visibility
@@ -233,14 +232,15 @@
             // Here the logic is generally the same, but simplified for performance by reordering checks and avoiding checking
             // for the impossible combinations
             val javaCtor = javaCtorSymbol.fir
-            if (javaCtor.status.visibility.isPublicAPI && !javaCtor.isDeprecated() &&
-                javaCtor.computeJvmDescriptor() !in signatures.hiddenConstructors &&
-                !javaCtor.isTrivialCopyConstructor() &&
-                firKotlinClassConstructors.none { javaCtor.isShadowedBy(it) }
-            ) {
-                val newSymbol = getOrCreateCopy(javaCtorSymbol)
-                processor(newSymbol)
-            }
+
+            if (!javaCtor.status.visibility.isPublicAPI || javaCtor.isDeprecated()) return@processor
+            val signature = SignatureBuildingComponents.signature(firJavaClass.classId, javaCtor.computeJvmDescriptor())
+            if (signature in JvmBuiltInsSignatures.HIDDEN_CONSTRUCTOR_SIGNATURES) return@processor
+            if (javaCtor.isTrivialCopyConstructor()) return@processor
+            if (firKotlinClassConstructors.any { javaCtor.isShadowedBy(it) }) return@processor
+
+            val newSymbol = getOrCreateCopy(javaCtorSymbol)
+            processor(newSymbol)
         }
 
         declaredMemberScope.processDeclaredConstructors(processor)
@@ -339,33 +339,6 @@
             val substitutor: ConeSubstitutor,
         ) : ScopeSessionKey<FirClass, FirClassSubstitutionScope>()
 
-        data class Signatures(val visibleMethodSignaturesByName: Map<Name, Set<String>>, val hiddenConstructors: Set<String>) {
-            fun isEmpty() = visibleMethodSignaturesByName.isEmpty() && hiddenConstructors.isEmpty()
-            fun isNotEmpty() = !isEmpty()
-        }
-
-        fun prepareSignatures(klass: FirRegularClass, isMutable: Boolean): Signatures {
-
-            val signaturePrefix = klass.symbol.classId.toString()
-            val visibleMethodsByName = mutableMapOf<Name, MutableSet<String>>()
-            (JvmBuiltInsSignatures.VISIBLE_METHOD_SIGNATURES).filter { signature ->
-                signature in JvmBuiltInsSignatures.MUTABLE_METHOD_SIGNATURES == isMutable &&
-                        signature.startsWith(signaturePrefix)
-            }.map { signature ->
-                // +1 to delete dot before function name
-                signature.substring(signaturePrefix.length + 1)
-            }.forEach {
-                visibleMethodsByName.getOrPut(Name.identifier(it.substringBefore("("))) { mutableSetOf() }.add(it)
-            }
-
-            val hiddenConstructors =
-                JvmBuiltInsSignatures.HIDDEN_CONSTRUCTOR_SIGNATURES
-                    .filter { it.startsWith(signaturePrefix) }
-                    .mapTo(mutableSetOf()) { it.substring(signaturePrefix.length + 1) }
-
-            return Signatures(visibleMethodsByName, hiddenConstructors)
-        }
-
         /**
          * For fromClass=A<T1, T2>, toClass=B<F1, F1> classes
          * @returns {T1  -> F1, T2 -> F2} substitution