UnsupportedAbiVersionNotificationPanelProvider: cleanup code

This commit is contained in:
Dmitry Gridin
2019-08-01 13:23:18 +03:00
parent 7c24ad39ea
commit 49aa4aba71
@@ -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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -81,15 +81,18 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec
val isPluginOldForAllRoots = badVersionedRoots.all { it.supportedVersion < it.version } val isPluginOldForAllRoots = badVersionedRoots.all { it.supportedVersion < it.version }
val isPluginNewForAllRoots = badVersionedRoots.all { it.supportedVersion > it.version } val isPluginNewForAllRoots = badVersionedRoots.all { it.supportedVersion > it.version }
if (!badRuntimeLibraries.isEmpty()) { when {
badRuntimeLibraries.isNotEmpty() -> {
val badRootsInRuntimeLibraries = findBadRootsInRuntimeLibraries(badRuntimeLibraries, badVersionedRoots) val badRootsInRuntimeLibraries = findBadRootsInRuntimeLibraries(badRuntimeLibraries, badVersionedRoots)
val otherBadRootsCount = badVersionedRoots.size - badRootsInRuntimeLibraries.size val otherBadRootsCount = badVersionedRoots.size - badRootsInRuntimeLibraries.size
val text = MessageFormat.format("<html><b>{0,choice,0#|1#|1<Some }Kotlin runtime librar{0,choice,0#|1#y|1<ies}</b>" + val text = MessageFormat.format(
"<html><b>{0,choice,0#|1#|1<Some }Kotlin runtime librar{0,choice,0#|1#y|1<ies}</b>" +
"{1,choice,0#|1# and one other jar|1< and {1} other jars} " + "{1,choice,0#|1# and one other jar|1< and {1} other jars} " +
"{1,choice,0#has|0<have} an unsupported binary format.</html>", "{1,choice,0#has|0<have} an unsupported binary format.</html>",
badRuntimeLibraries.size, badRuntimeLibraries.size,
otherBadRootsCount) otherBadRootsCount
)
answer.setText(text) answer.setText(text)
@@ -106,14 +109,18 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec
else -> "Replace" else -> "Replace"
} }
val actionLabelText = MessageFormat.format("$updateAction {0,choice,0#|1#|1<all }Kotlin runtime librar{0,choice,0#|1#y|1<ies} ", badRuntimeLibraries.size) val actionLabelText = MessageFormat.format(
"$updateAction {0,choice,0#|1#|1<all }Kotlin runtime librar{0,choice,0#|1#y|1<ies} ",
badRuntimeLibraries.size
)
answer.createActionLabel(actionLabelText) { answer.createActionLabel(actionLabelText) {
ApplicationManager.getApplication().invokeLater { ApplicationManager.getApplication().invokeLater {
updateLibraries(project, badRuntimeLibraries) updateLibraries(project, badRuntimeLibraries)
} }
} }
} }
else if (badVersionedRoots.size == 1) {
badVersionedRoots.size == 1 -> {
val badVersionedRoot = badVersionedRoots.first() val badVersionedRoot = badVersionedRoots.first()
val presentableName = badVersionedRoot.file.presentableName val presentableName = badVersionedRoot.file.presentableName
@@ -131,23 +138,26 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec
} }
} }
answer.createActionLabel("Go to " + presentableName) { navigateToLibraryRoot(project, badVersionedRoot.file) } answer.createActionLabel("Go to $presentableName") { navigateToLibraryRoot(project, badVersionedRoot.file) }
} }
else {
when {
isPluginOldForAllRoots -> { isPluginOldForAllRoots -> {
answer.setText("Some Kotlin libraries attached to this project were compiled with a newer Kotlin compiler and can't be read. " + answer.setText(
"Please update Kotlin plugin.") "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) createUpdatePluginLink(answer)
} }
isPluginNewForAllRoots -> isPluginNewForAllRoots ->
answer.setText("Some Kotlin libraries attached to this project have outdated binary format and can't be read by current plugin. " + answer.setText(
"Please update found libraries.") "Some Kotlin libraries attached to this project have outdated binary format and can't be read by current plugin. " +
"Please update found libraries."
)
else -> else ->
answer.setText("Some Kotlin libraries attached to this project have unsupported binary format. Please update the libraries or the plugin.") answer.setText("Some Kotlin libraries attached to this project have unsupported binary format. Please update the libraries or the plugin.")
}
} }
createShowPathsActionLabel(module, answer, "Details") createShowPathsActionLabel(module, answer, "Details")
@@ -157,16 +167,21 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec
private fun createShowPathsActionLabel(module: Module, answer: EditorNotificationPanel, labelText: String) { private fun createShowPathsActionLabel(module: Module, answer: EditorNotificationPanel, labelText: String) {
answer.createComponentActionLabel(labelText) { label -> answer.createComponentActionLabel(labelText) { label ->
DumbService.getInstance(project).tryRunReadActionInSmartMode({ val task = {
val badRoots = collectBadRoots(module) val badRoots = collectBadRoots(module)
assert(!badRoots.isEmpty()) { "This action should only be called when bad roots are present" } 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) val popup = JBPopupFactory.getInstance().createListPopup(listPopupModel)
popup.showUnderneathOf(label) popup.showUnderneathOf(label)
null 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 val module = ModuleUtilCore.findModuleForFile(file, project) ?: return null
return checkAndCreate(module) return checkAndCreate(module)
} } catch (e: ProcessCanceledException) {
catch (e: ProcessCanceledException) {
// Ignore // Ignore
} } catch (e: IndexNotReadyException) {
catch (e: IndexNotReadyException) {
DumbService.getInstance(project).runWhenSmart(updateNotifications) DumbService.getInstance(project).runWhenSmart(updateNotifications)
} }
@@ -234,7 +247,8 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec
private fun findBadRootsInRuntimeLibraries( private fun findBadRootsInRuntimeLibraries(
badRuntimeLibraries: List<Library>, badRuntimeLibraries: List<Library>,
badVersionedRoots: Collection<BinaryVersionedFile<BinaryVersion>>): ArrayList<BinaryVersionedFile<BinaryVersion>> { badVersionedRoots: Collection<BinaryVersionedFile<BinaryVersion>>
): ArrayList<BinaryVersionedFile<BinaryVersion>> {
val badRootsInLibraries = ArrayList<BinaryVersionedFile<BinaryVersion>>() val badRootsInLibraries = ArrayList<BinaryVersionedFile<BinaryVersion>>()
fun addToBadRoots(file: VirtualFile?) { fun addToBadRoots(file: VirtualFile?) {
@@ -290,7 +304,7 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec
val label = JLabel(text) val label = JLabel(text)
myLinksPanel.add(label) myLinksPanel.add(label)
val successLink = createActionLabel(successLinkText, { }) val successLink = createActionLabel(successLinkText) { }
successLink.isVisible = false successLink.isVisible = false
// Several notification panels can be created almost instantly but we want to postpone deferred checks until // Several notification panels can be created almost instantly but we want to postpone deferred checks until