fun init()

in remote-robot/src/main/kotlin/com/intellij/remoterobot/fixtures/dataExtractor/server/TextToKeyCache.kt [11:50]


    fun init(ideClassLoader: ClassLoader) {
        val bundleClass = Class.forName("com.intellij.BundleBase", true, ideClassLoader)

        // 213
        val setTranslationConsumerFunction = try {
            bundleClass.getMethod("setTranslationConsumer", BiConsumer::class.java)
        } catch (e: Throwable) {
            null
        }
        if (setTranslationConsumerFunction != null) {
            val consumer = BiConsumer<String, String> { key, t ->
                val text = removeMnemonic(ideClassLoader, t)
                if (textToKeyMap.containsKey(text).not()) {
                    textToKeyMap[text] = mutableSetOf()
                }
                textToKeyMap[text]?.add(key)
            }
            setTranslationConsumerFunction.invoke(null, consumer)
        } else {
            // 212
            val messageCallConsumerListField = try {
                bundleClass.getField("translationConsumerList")
            } catch (e: Throwable) {
                null
            }
            if (messageCallConsumerListField != null) {
                val list =
                    messageCallConsumerListField.get(null) as MutableList<Consumer<*>>
                list.add {
                    val key = it.javaClass.getDeclaredField("first").get(it) as String
                    val value = it.javaClass.getDeclaredField("second").get(it) as String
                    val text = removeMnemonic(ideClassLoader, value)
                    if (textToKeyMap.containsKey(text).not()) {
                        textToKeyMap[text] = mutableSetOf()
                    }
                    textToKeyMap[text]?.add(key)
                }
            }
        }
    }