Convert KotlinImporterComponent into a module service

Relates to #KT-38407
This commit is contained in:
Vladimir Dolzhenko
2020-04-21 09:51:02 +02:00
committed by Vladimir Dolzhenko
parent c2c8d81b49
commit 4908d7a78c
8 changed files with 39 additions and 8 deletions
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.util.application
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.command.CommandProcessor
import com.intellij.openapi.components.ComponentManager
import com.intellij.openapi.project.Project
import org.jetbrains.annotations.Nls
@@ -54,5 +55,5 @@ inline fun invokeLater(crossinline action: () -> Unit) =
inline fun isUnitTestMode(): Boolean = ApplicationManager.getApplication().isUnitTestMode
inline fun <reified T : Any> Project.getServiceSafe(): T =
inline fun <reified T : Any> ComponentManager.getServiceSafe(): T =
this.getService(T::class.java) ?: error("Unable to locate service ${T::class.java.name}")
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.util.application
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.command.CommandProcessor
import com.intellij.openapi.components.ComponentManager
import com.intellij.openapi.progress.impl.CancellationCheck
import com.intellij.openapi.project.Project
@@ -54,5 +55,5 @@ inline fun invokeLater(crossinline action: () -> Unit) =
inline fun isUnitTestMode(): Boolean = ApplicationManager.getApplication().isUnitTestMode
inline fun <reified T : Any> Project.getServiceSafe(): T =
inline fun <reified T : Any> ComponentManager.getServiceSafe(): T =
this.getService(T::class.java) ?: error("Unable to locate service ${T::class.java.name}")
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.util.application
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.command.CommandProcessor
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.components.ComponentManager
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressIndicatorProvider
import com.intellij.openapi.progress.ProgressManager
@@ -57,7 +58,7 @@ inline fun invokeLater(crossinline action: () -> Unit) =
inline fun isUnitTestMode(): Boolean = ApplicationManager.getApplication().isUnitTestMode
inline fun <reified T : Any> Project.getServiceSafe(): T =
inline fun <reified T : Any> ComponentManager.getServiceSafe(): T =
this.getService(T::class.java) ?: error("Unable to locate service ${T::class.java.name}")
fun <T> Project.getServiceIfCreated(serviceClass: Class<T>): T? =
@@ -0,0 +1,13 @@
/*
* Copyright 2010-2020 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.
*/
package org.jetbrains.kotlin.idea.maven
import com.intellij.openapi.module.Module
import org.jetbrains.kotlin.idea.util.application.getServiceSafe
// BUNCH: 192
internal val Module.kotlinImporterComponent: KotlinImporterComponent
get() = this.getServiceSafe()
@@ -0,0 +1,12 @@
/*
* Copyright 2010-2020 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.
*/
package org.jetbrains.kotlin.idea.maven
import com.intellij.openapi.module.Module
// BUNCH: 192
internal val Module.kotlinImporterComponent: KotlinImporterComponent
get() = getComponent(KotlinImporterComponent::class.java) ?: throw IllegalStateException("No maven importer state configured")
@@ -417,7 +417,4 @@ class KotlinImporterComponent : PersistentStateComponent<KotlinImporterComponent
override fun getState(): State {
return State(addedSources.sorted())
}
}
private val Module.kotlinImporterComponent: KotlinImporterComponent
get() = getComponent(KotlinImporterComponent::class.java) ?: throw IllegalStateException("No maven importer state configured")
}
@@ -3036,7 +3036,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
}
private fun assertImporterStatePresent() {
assertNotNull("Kotlin importer component is not present", myTestFixture.module.getComponent(KotlinImporterComponent::class.java))
assertNotNull("Kotlin importer component is not present", myTestFixture.module.kotlinImporterComponent)
}
private fun facetSettings(moduleName: String) = KotlinFacet.get(getModule(moduleName))!!.configuration.settings
+6
View File
@@ -4,4 +4,10 @@
<implementation-class>org.jetbrains.kotlin.idea.maven.MavenImportListener</implementation-class>
</component>
</project-components>
<module-components>
<component>
<implementation-class>org.jetbrains.kotlin.idea.maven.KotlinImporterComponent</implementation-class>
</component>
</module-components>
</idea-plugin>