Get rid of getInstanceIfNotDisposed
Relates to #EA-216005
This commit is contained in:
+4
-2
@@ -8,11 +8,13 @@ package org.jetbrains.kotlin.idea.actions.internal
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import org.jetbrains.kotlin.idea.configuration.ui.KotlinConfigurationCheckerService
|
||||
import org.jetbrains.kotlin.idea.util.ProgressIndicatorUtils.runUnderDisposeAwareIndicator
|
||||
|
||||
class ReactivePostOpenProjectActionsAction : AnAction() {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val project = e.project ?: return
|
||||
val configurationChecker = KotlinConfigurationCheckerService.getInstanceIfNotDisposed(project) ?: return
|
||||
configurationChecker.performProjectPostOpenActions()
|
||||
runUnderDisposeAwareIndicator(project) {
|
||||
KotlinConfigurationCheckerService.getInstance(project).performProjectPostOpenActions()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-3
@@ -21,18 +21,23 @@ import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotifica
|
||||
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.idea.configuration.ui.KotlinConfigurationCheckerService
|
||||
import org.jetbrains.kotlin.idea.util.ProgressIndicatorUtils.runUnderDisposeAwareIndicator
|
||||
|
||||
class KotlinExternalSystemSyncListener : ExternalSystemTaskNotificationListenerAdapter() {
|
||||
override fun onStart(id: ExternalSystemTaskId, workingDir: String) {
|
||||
val project = id.findResolvedProject() ?: return
|
||||
KotlinMigrationProjectService.getInstanceIfNotDisposed(project)?.onImportAboutToStart()
|
||||
KotlinConfigurationCheckerService.getInstanceIfNotDisposed(project)?.syncStarted()
|
||||
runUnderDisposeAwareIndicator(project) {
|
||||
KotlinMigrationProjectService.getInstance(project).onImportAboutToStart()
|
||||
KotlinConfigurationCheckerService.getInstance(project).syncStarted()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onEnd(id: ExternalSystemTaskId) {
|
||||
// At this point changes might be still not applied to project structure yet.
|
||||
val project = id.findResolvedProject() ?: return
|
||||
KotlinConfigurationCheckerService.getInstanceIfNotDisposed(project)?.syncDone()
|
||||
runUnderDisposeAwareIndicator(project) {
|
||||
KotlinConfigurationCheckerService.getInstance(project).syncDone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ class KotlinSetupEnvironmentNotificationProvider(private val myProject: Project)
|
||||
return createSetupSdkPanel(myProject, psiFile)
|
||||
}
|
||||
|
||||
val configurationChecker = KotlinConfigurationCheckerService.getInstanceIfNotDisposed(module.project) ?: return null
|
||||
val configurationChecker = KotlinConfigurationCheckerService.getInstance(module.project)
|
||||
|
||||
if (!configurationChecker.isSyncing &&
|
||||
isNotConfiguredNotificationRequired(module.toModuleGroup()) &&
|
||||
|
||||
+5
-6
@@ -81,14 +81,13 @@ class KotlinConfigurationCheckerComponent(val project: Project) : ProjectCompone
|
||||
companion object {
|
||||
const val CONFIGURE_NOTIFICATION_GROUP_ID = "Configure Kotlin in Project"
|
||||
|
||||
fun getInstance(project: Project): KotlinConfigurationCheckerComponent =
|
||||
project.getComponent(KotlinConfigurationCheckerComponent::class.java)
|
||||
?: error("Can't find ${KotlinConfigurationCheckerComponent::class} component")
|
||||
|
||||
fun getInstanceIfNotDisposed(project: Project): KotlinConfigurationCheckerComponent? {
|
||||
return runReadAction {
|
||||
if (!project.isDisposed) {
|
||||
project.getComponent(KotlinConfigurationCheckerComponent::class.java)
|
||||
?: error("Can't find ${KotlinConfigurationCheckerComponent::class} component")
|
||||
} else {
|
||||
null
|
||||
}
|
||||
if (!project.isDisposed) getInstance(project) else null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-11
@@ -32,6 +32,8 @@ import org.jetbrains.kotlin.idea.configuration.getModulesWithKotlinFiles
|
||||
import org.jetbrains.kotlin.idea.configuration.notifyOutdatedBundledCompilerIfNecessary
|
||||
import org.jetbrains.kotlin.idea.configuration.ui.notifications.notifyKotlinStyleUpdateIfNeeded
|
||||
import org.jetbrains.kotlin.idea.project.getAndCacheLanguageLevelByDependencies
|
||||
import org.jetbrains.kotlin.idea.util.ProgressIndicatorUtils
|
||||
import org.jetbrains.kotlin.idea.util.application.getServiceSafe
|
||||
import org.jetbrains.kotlin.idea.util.application.isUnitTestMode
|
||||
import java.util.concurrent.Callable
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
@@ -51,7 +53,7 @@ class KotlinConfigurationCheckerStartupActivity : StartupActivity {
|
||||
|
||||
notifyKotlinStyleUpdateIfNeeded(project)
|
||||
|
||||
KotlinConfigurationCheckerService.getInstanceIfNotDisposed(project)?.performProjectPostOpenActions()
|
||||
KotlinConfigurationCheckerService.getInstance(project).performProjectPostOpenActions()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,15 +103,7 @@ class KotlinConfigurationCheckerService(val project: Project) {
|
||||
companion object {
|
||||
const val CONFIGURE_NOTIFICATION_GROUP_ID = "Configure Kotlin in Project"
|
||||
|
||||
fun getInstanceIfNotDisposed(project: Project): KotlinConfigurationCheckerService? {
|
||||
return runReadAction {
|
||||
if (!project.isDisposed) {
|
||||
project.getService(KotlinConfigurationCheckerService::class.java)
|
||||
?: error("Can't find ${KotlinConfigurationCheckerService::class} service")
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
fun getInstance(project: Project): KotlinConfigurationCheckerService = project.getServiceSafe()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user