mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
Python: move getOrCreateAdditionalData to sdk module.
It doesn't belong to `community.impl` GitOrigin-RevId: 51e197ca19e5e64363229ddc5c27aa0332fcb62f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a7ec5dd4a6
commit
11be6ed929
@@ -0,0 +1,41 @@
|
||||
package com.jetbrains.python.sdk
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.jetbrains.python.sdk.flavors.PythonSdkFlavor
|
||||
|
||||
/**
|
||||
* Each [Sdk] has [PythonSdkAdditionalData]. Use this method to get it.
|
||||
* Although each SDK should already have one, some old may lack it.
|
||||
*
|
||||
* This method creates new in this case, but only if an SDK flavor doesn't require special additional data.
|
||||
*/
|
||||
fun Sdk.getOrCreateAdditionalData(): PythonSdkAdditionalData {
|
||||
val existingData = sdkAdditionalData as? PythonSdkAdditionalData
|
||||
if (existingData != null) {
|
||||
return existingData
|
||||
}
|
||||
|
||||
if (homePath == null) {
|
||||
error("homePath is null for $this")
|
||||
}
|
||||
|
||||
val flavor = PythonSdkFlavor.tryDetectFlavorByLocalPath(homePath!!)
|
||||
if (flavor == null) {
|
||||
error("No flavor detected for $homePath sdk")
|
||||
}
|
||||
|
||||
val newData = PythonSdkAdditionalData(if (flavor.supportsEmptyData()) flavor else null)
|
||||
val modificator = sdkModificator
|
||||
modificator.sdkAdditionalData = newData
|
||||
val application = ApplicationManager.getApplication()
|
||||
if (application.isDispatchThread) {
|
||||
application.runWriteAction { modificator.commitChanges() }
|
||||
}
|
||||
else {
|
||||
application.invokeLater {
|
||||
application.runWriteAction { modificator.commitChanges() }
|
||||
}
|
||||
}
|
||||
return newData
|
||||
}
|
||||
Reference in New Issue
Block a user