ApplicationUtils syntax improvements

This commit is contained in:
Vladimir Dolzhenko
2020-03-30 23:08:58 +02:00
parent 23ea2446e0
commit 9f09e50a28
13 changed files with 36 additions and 36 deletions
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.idea.util.application.getServiceSafe
class LibraryModificationTracker(project: Project) : SimpleModificationTracker() {
companion object {
@JvmStatic
fun getInstance(project: Project) = project.getServiceSafe(LibraryModificationTracker::class.java)
fun getInstance(project: Project): LibraryModificationTracker = project.getServiceSafe()
}
init {
@@ -308,8 +308,7 @@ class KotlinCodeBlockModificationListener(project: Project) : PsiTreeChangePrepr
KtScriptInitializer::class.java
)
fun getInstance(project: Project): KotlinCodeBlockModificationListener =
project.getServiceSafe(KotlinCodeBlockModificationListener::class.java)
fun getInstance(project: Project): KotlinCodeBlockModificationListener = project.getServiceSafe()
}
}
@@ -46,11 +46,13 @@ fun <T> Project.executeCommand(@Nls name: String, groupId: Any? = null, command:
fun <T> runWithCancellationCheck(block: () -> T): T = block()
inline fun invokeLater(crossinline action: () -> Unit) {
inline fun executeOnPooledThread(crossinline action: () -> Unit) =
ApplicationManager.getApplication().executeOnPooledThread { action() }
inline fun invokeLater(crossinline action: () -> Unit) =
ApplicationManager.getApplication().invokeLater { action() }
}
inline fun isUnitTestMode(): Boolean = ApplicationManager.getApplication().isUnitTestMode
fun <T> Project.getServiceSafe(serviceClass: Class<T>): T =
this.getService(serviceClass) ?: error("Unable to locate service ${serviceClass.name}")
inline fun <reified T : Any> Project.getServiceSafe(): T =
this.getService(T::class.java) ?: error("Unable to locate service ${T::class.java.name}")
@@ -49,11 +49,13 @@ fun <T> Project.executeCommand(name: String, groupId: Any? = null, command: () -
fun <T> runWithCancellationCheck(block: () -> T): T = block()
inline fun invokeLater(crossinline action: () -> Unit) {
inline fun executeOnPooledThread(crossinline action: () -> Unit) =
ApplicationManager.getApplication().executeOnPooledThread { action() }
inline fun invokeLater(crossinline action: () -> Unit) =
ApplicationManager.getApplication().invokeLater { action() }
}
inline fun isUnitTestMode(): Boolean = ApplicationManager.getApplication().isUnitTestMode
fun <T> Project.getServiceSafe(serviceClass: Class<T>): T =
ServiceManager.getService(this, serviceClass) ?: error("Unable to locate service ${serviceClass.name}")
inline fun <reified T : Any> Project.getServiceSafe(): T =
ServiceManager.getService(this, T::class.java) ?: error("Unable to locate service ${T::class.java.name}")
@@ -46,11 +46,13 @@ fun <T> Project.executeCommand(name: String, groupId: Any? = null, command: () -
fun <T> runWithCancellationCheck(block: () -> T): T = CancellationCheck.runWithCancellationCheck(block)
inline fun invokeLater(crossinline action: () -> Unit) {
inline fun executeOnPooledThread(crossinline action: () -> Unit) =
ApplicationManager.getApplication().executeOnPooledThread { action() }
inline fun invokeLater(crossinline action: () -> Unit) =
ApplicationManager.getApplication().invokeLater { action() }
}
inline fun isUnitTestMode(): Boolean = ApplicationManager.getApplication().isUnitTestMode
fun <T> Project.getServiceSafe(serviceClass: Class<T>) =
this.getService(serviceClass) ?: error("Unable to locate service ${serviceClass.name}")
inline fun <reified T : Any> Project.getServiceSafe(): T =
this.getService(T::class.java) ?: error("Unable to locate service ${T::class.java.name}")
@@ -49,14 +49,16 @@ fun <T> Project.executeCommand(name: String, groupId: Any? = null, command: () -
fun <T> runWithCancellationCheck(block: () -> T): T = block()
inline fun invokeLater(crossinline action: () -> Unit) {
inline fun executeOnPooledThread(crossinline action: () -> Unit) =
ApplicationManager.getApplication().executeOnPooledThread { action() }
inline fun invokeLater(crossinline action: () -> Unit) =
ApplicationManager.getApplication().invokeLater { action() }
}
inline fun isUnitTestMode(): Boolean = ApplicationManager.getApplication().isUnitTestMode
fun <T> Project.getServiceSafe(serviceClass: Class<T>): T =
ServiceManager.getService(this, serviceClass) ?: error("Unable to locate service ${serviceClass.name}")
inline fun <reified T : Any> Project.getServiceSafe(): T =
this.getService(T::class.java) ?: error("Unable to locate service ${T::class.java.name}")
fun <T> Project.getServiceIfCreated(serviceClass: Class<T>): T? =
ServiceManager.getServiceIfCreated(this, serviceClass)