Convert KotlinImporterComponent into a module service
Relates to #KT-38407
This commit is contained in:
committed by
Vladimir Dolzhenko
parent
c2c8d81b49
commit
4908d7a78c
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.util.application
|
|||||||
|
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.command.CommandProcessor
|
import com.intellij.openapi.command.CommandProcessor
|
||||||
|
import com.intellij.openapi.components.ComponentManager
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import org.jetbrains.annotations.Nls
|
import org.jetbrains.annotations.Nls
|
||||||
|
|
||||||
@@ -54,5 +55,5 @@ inline fun invokeLater(crossinline action: () -> Unit) =
|
|||||||
|
|
||||||
inline fun isUnitTestMode(): Boolean = ApplicationManager.getApplication().isUnitTestMode
|
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}")
|
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.application.ApplicationManager
|
||||||
import com.intellij.openapi.command.CommandProcessor
|
import com.intellij.openapi.command.CommandProcessor
|
||||||
|
import com.intellij.openapi.components.ComponentManager
|
||||||
import com.intellij.openapi.progress.impl.CancellationCheck
|
import com.intellij.openapi.progress.impl.CancellationCheck
|
||||||
import com.intellij.openapi.project.Project
|
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 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}")
|
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.application.ApplicationManager
|
||||||
import com.intellij.openapi.command.CommandProcessor
|
import com.intellij.openapi.command.CommandProcessor
|
||||||
import com.intellij.openapi.components.ServiceManager
|
import com.intellij.openapi.components.ServiceManager
|
||||||
|
import com.intellij.openapi.components.ComponentManager
|
||||||
import com.intellij.openapi.progress.ProgressIndicator
|
import com.intellij.openapi.progress.ProgressIndicator
|
||||||
import com.intellij.openapi.progress.ProgressIndicatorProvider
|
import com.intellij.openapi.progress.ProgressIndicatorProvider
|
||||||
import com.intellij.openapi.progress.ProgressManager
|
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 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}")
|
this.getService(T::class.java) ?: error("Unable to locate service ${T::class.java.name}")
|
||||||
|
|
||||||
fun <T> Project.getServiceIfCreated(serviceClass: Class<T>): T? =
|
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()
|
||||||
+12
@@ -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")
|
||||||
@@ -418,6 +418,3 @@ class KotlinImporterComponent : PersistentStateComponent<KotlinImporterComponent
|
|||||||
return State(addedSources.sorted())
|
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() {
|
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
|
private fun facetSettings(moduleName: String) = KotlinFacet.get(getModule(moduleName))!!.configuration.settings
|
||||||
|
|||||||
@@ -4,4 +4,10 @@
|
|||||||
<implementation-class>org.jetbrains.kotlin.idea.maven.MavenImportListener</implementation-class>
|
<implementation-class>org.jetbrains.kotlin.idea.maven.MavenImportListener</implementation-class>
|
||||||
</component>
|
</component>
|
||||||
</project-components>
|
</project-components>
|
||||||
|
|
||||||
|
<module-components>
|
||||||
|
<component>
|
||||||
|
<implementation-class>org.jetbrains.kotlin.idea.maven.KotlinImporterComponent</implementation-class>
|
||||||
|
</component>
|
||||||
|
</module-components>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
|
|||||||
Reference in New Issue
Block a user