diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/UnsupportedAbiVersionNotificationPanelProvider.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/UnsupportedAbiVersionNotificationPanelProvider.kt index 1c777898aff..736eee2480c 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/UnsupportedAbiVersionNotificationPanelProvider.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/UnsupportedAbiVersionNotificationPanelProvider.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -81,73 +81,83 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec val isPluginOldForAllRoots = badVersionedRoots.all { it.supportedVersion < it.version } val isPluginNewForAllRoots = badVersionedRoots.all { it.supportedVersion > it.version } - if (!badRuntimeLibraries.isEmpty()) { - val badRootsInRuntimeLibraries = findBadRootsInRuntimeLibraries(badRuntimeLibraries, badVersionedRoots) - val otherBadRootsCount = badVersionedRoots.size - badRootsInRuntimeLibraries.size + when { + badRuntimeLibraries.isNotEmpty() -> { + val badRootsInRuntimeLibraries = findBadRootsInRuntimeLibraries(badRuntimeLibraries, badVersionedRoots) + val otherBadRootsCount = badVersionedRoots.size - badRootsInRuntimeLibraries.size - val text = MessageFormat.format("{0,choice,0#|1#|1" + - "{1,choice,0#|1# and one other jar|1< and {1} other jars} " + - "{1,choice,0#has|0", - badRuntimeLibraries.size, - otherBadRootsCount) + val text = MessageFormat.format( + "{0,choice,0#|1#|1" + + "{1,choice,0#|1# and one other jar|1< and {1} other jars} " + + "{1,choice,0#has|0", + badRuntimeLibraries.size, + otherBadRootsCount + ) - answer.setText(text) + answer.setText(text) - if (isPluginOldForAllRoots) { + if (isPluginOldForAllRoots) { + createUpdatePluginLink(answer) + } + + val isPluginOldForAllRuntimeLibraries = badRootsInRuntimeLibraries.all { it.supportedVersion < it.version } + val isPluginNewForAllRuntimeLibraries = badRootsInRuntimeLibraries.all { it.supportedVersion > it.version } + + val updateAction = when { + isPluginNewForAllRuntimeLibraries -> "Update" + isPluginOldForAllRuntimeLibraries -> "Downgrade" + else -> "Replace" + } + + val actionLabelText = MessageFormat.format( + "$updateAction {0,choice,0#|1#|1 { + val badVersionedRoot = badVersionedRoots.first() + val presentableName = badVersionedRoot.file.presentableName + + when { + isPluginOldForAllRoots -> { + answer.setText("Kotlin library '$presentableName' was compiled with a newer Kotlin compiler and can't be read. Please update Kotlin plugin.") + createUpdatePluginLink(answer) + } + + isPluginNewForAllRoots -> + answer.setText("Kotlin library '$presentableName' has outdated binary format and can't be read by current plugin. Please update the library.") + + else -> { + throw IllegalStateException("Bad root with compatible version found: $badVersionedRoot") + } + } + + answer.createActionLabel("Go to $presentableName") { navigateToLibraryRoot(project, badVersionedRoot.file) } + } + + isPluginOldForAllRoots -> { + answer.setText( + "Some Kotlin libraries attached to this project were compiled with a newer Kotlin compiler and can't be read. " + + "Please update Kotlin plugin." + ) createUpdatePluginLink(answer) } - val isPluginOldForAllRuntimeLibraries = badRootsInRuntimeLibraries.all { it.supportedVersion < it.version } - val isPluginNewForAllRuntimeLibraries = badRootsInRuntimeLibraries.all { it.supportedVersion > it.version } + isPluginNewForAllRoots -> + answer.setText( + "Some Kotlin libraries attached to this project have outdated binary format and can't be read by current plugin. " + + "Please update found libraries." + ) - val updateAction = when { - isPluginNewForAllRuntimeLibraries -> "Update" - isPluginOldForAllRuntimeLibraries -> "Downgrade" - else -> "Replace" - } + else -> + answer.setText("Some Kotlin libraries attached to this project have unsupported binary format. Please update the libraries or the plugin.") - val actionLabelText = MessageFormat.format("$updateAction {0,choice,0#|1#|1 { - answer.setText("Kotlin library '$presentableName' was compiled with a newer Kotlin compiler and can't be read. Please update Kotlin plugin.") - createUpdatePluginLink(answer) - } - - isPluginNewForAllRoots -> - answer.setText("Kotlin library '$presentableName' has outdated binary format and can't be read by current plugin. Please update the library.") - - else -> { - throw IllegalStateException("Bad root with compatible version found: $badVersionedRoot") - } - } - - answer.createActionLabel("Go to " + presentableName) { navigateToLibraryRoot(project, badVersionedRoot.file) } - } - else { - when { - isPluginOldForAllRoots -> { - answer.setText("Some Kotlin libraries attached to this project were compiled with a newer Kotlin compiler and can't be read. " + - "Please update Kotlin plugin.") - createUpdatePluginLink(answer) - } - - isPluginNewForAllRoots -> - answer.setText("Some Kotlin libraries attached to this project have outdated binary format and can't be read by current plugin. " + - "Please update found libraries.") - - else -> - answer.setText("Some Kotlin libraries attached to this project have unsupported binary format. Please update the libraries or the plugin.") - } } createShowPathsActionLabel(module, answer, "Details") @@ -157,16 +167,21 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec private fun createShowPathsActionLabel(module: Module, answer: EditorNotificationPanel, labelText: String) { answer.createComponentActionLabel(labelText) { label -> - DumbService.getInstance(project).tryRunReadActionInSmartMode({ + val task = { val badRoots = collectBadRoots(module) assert(!badRoots.isEmpty()) { "This action should only be called when bad roots are present" } - val listPopupModel = LibraryRootsPopupModel("Unsupported format, plugin version: " + KotlinPluginUtil.getPluginVersion(), project, badRoots) + val listPopupModel = LibraryRootsPopupModel( + "Unsupported format, plugin version: " + KotlinPluginUtil.getPluginVersion(), + project, + badRoots + ) val popup = JBPopupFactory.getInstance().createListPopup(listPopupModel) popup.showUnderneathOf(label) null - }, "Can't show all paths during index update") + } + DumbService.getInstance(project).tryRunReadActionInSmartMode(task, "Can't show all paths during index update") } } @@ -207,11 +222,9 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec val module = ModuleUtilCore.findModuleForFile(file, project) ?: return null return checkAndCreate(module) - } - catch (e: ProcessCanceledException) { + } catch (e: ProcessCanceledException) { // Ignore - } - catch (e: IndexNotReadyException) { + } catch (e: IndexNotReadyException) { DumbService.getInstance(project).runWhenSmart(updateNotifications) } @@ -233,8 +246,9 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec } private fun findBadRootsInRuntimeLibraries( - badRuntimeLibraries: List, - badVersionedRoots: Collection>): ArrayList> { + badRuntimeLibraries: List, + badVersionedRoots: Collection> + ): ArrayList> { val badRootsInLibraries = ArrayList>() fun addToBadRoots(file: VirtualFile?) { @@ -256,9 +270,9 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec } private class LibraryRootsPopupModel( - title: String, - private val project: Project, - roots: Collection> + title: String, + private val project: Project, + roots: Collection> ) : BaseListPopupStep>(title, *roots.toTypedArray()) { override fun getTextFor(root: BinaryVersionedFile): String { @@ -290,7 +304,7 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec val label = JLabel(text) myLinksPanel.add(label) - val successLink = createActionLabel(successLinkText, { }) + val successLink = createActionLabel(successLinkText) { } successLink.isVisible = false // Several notification panels can be created almost instantly but we want to postpone deferred checks until