@@ -18,11 +18,13 @@ package org.jetbrains.kotlin.idea.quickfix
18
18
19
19
import com.intellij.openapi.editor.Editor
20
20
import com.intellij.openapi.fileEditor.OpenFileDescriptor
21
+ import com.intellij.openapi.module.Module
21
22
import com.intellij.openapi.module.ModuleUtilCore
22
23
import com.intellij.openapi.project.Project
23
24
import com.intellij.openapi.roots.ModuleRootManager
24
25
import com.intellij.openapi.roots.ModuleRootModificationUtil
25
26
import com.intellij.openapi.roots.ex.ProjectRootManagerEx
27
+ import com.intellij.openapi.roots.libraries.Library
26
28
import com.intellij.openapi.ui.Messages
27
29
import com.intellij.psi.PsiElement
28
30
import org.jetbrains.kotlin.config.ApiVersion
@@ -89,6 +91,10 @@ sealed class EnableUnsupportedFeatureFix(
89
91
return
90
92
}
91
93
94
+ if (runtimeUpdateRequired && ! askUpdateRuntime(module, feature.sinceApiVersion)) {
95
+ return
96
+ }
97
+
92
98
ModuleRootModificationUtil .updateModel(module) {
93
99
with (facetSettings.versionInfo) {
94
100
if (! apiVersionOnly) {
@@ -155,15 +161,25 @@ fun checkUpdateRuntime(project: Project, requiredVersion: ApiVersion): Boolean {
155
161
parsedModuleRuntimeVersion != null && parsedModuleRuntimeVersion < requiredVersion
156
162
}
157
163
if (modulesWithOutdatedRuntime.isNotEmpty()) {
158
- val rc = Messages .showOkCancelDialog(project,
159
- " This language feature requires version $requiredVersion or later of the Kotlin runtime library. " +
160
- " Would you like to update the runtime library in your project?" ,
161
- " Update runtime library" ,
162
- Messages .getQuestionIcon())
163
- if (rc != Messages .OK ) return false
164
-
165
- val librariesToUpdate = modulesWithOutdatedRuntime.mapNotNull(::findKotlinRuntimeLibrary)
166
- updateLibraries(project, librariesToUpdate)
164
+ if (askUpdateRuntime(project, requiredVersion,
165
+ modulesWithOutdatedRuntime.mapNotNull(::findKotlinRuntimeLibrary))) return false
167
166
}
168
167
return true
169
168
}
169
+
170
+ fun askUpdateRuntime (project : Project , requiredVersion : ApiVersion , librariesToUpdate : List <Library >): Boolean {
171
+ val rc = Messages .showOkCancelDialog(project,
172
+ " This language feature requires version $requiredVersion or later of the Kotlin runtime library. " +
173
+ " Would you like to update the runtime library in your project?" ,
174
+ " Update Runtime Library" ,
175
+ Messages .getQuestionIcon())
176
+ if (rc != Messages .OK ) return false
177
+
178
+ updateLibraries(project, librariesToUpdate)
179
+ return true
180
+ }
181
+
182
+ fun askUpdateRuntime (module : Module , requiredVersion : ApiVersion ): Boolean {
183
+ val library = findKotlinRuntimeLibrary(module) ? : return true
184
+ return askUpdateRuntime(module.project, requiredVersion, listOf (library))
185
+ }
0 commit comments