ApplicationUtils syntax improvements
This commit is contained in:
+1
-1
@@ -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 {
|
||||
|
||||
+1
-2
@@ -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)
|
||||
+1
-2
@@ -46,8 +46,7 @@ class CompletionBindingContextProvider(project: Project) {
|
||||
internal var TEST_LOG: StringBuilder? = null
|
||||
|
||||
companion object {
|
||||
fun getInstance(project: Project): CompletionBindingContextProvider =
|
||||
project.getServiceSafe(CompletionBindingContextProvider::class.java)
|
||||
fun getInstance(project: Project): CompletionBindingContextProvider = project.getServiceSafe()
|
||||
|
||||
var ENABLED = true
|
||||
}
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ class LookupCancelService {
|
||||
private var lastReminiscence: Reminiscence? = null
|
||||
|
||||
companion object {
|
||||
fun getInstance(project: Project): LookupCancelService = project.getServiceSafe(LookupCancelService::class.java)
|
||||
fun getInstance(project: Project): LookupCancelService = project.getServiceSafe()
|
||||
|
||||
fun getServiceIfCreated(project: Project): LookupCancelService? = project.getServiceIfCreated(LookupCancelService::class.java)
|
||||
|
||||
|
||||
+2
-3
@@ -12,7 +12,6 @@ import com.intellij.ide.scratch.ScratchFileService
|
||||
import com.intellij.ide.scratch.ScratchRootType
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.runWriteAction
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.diagnostic.ControlFlowException
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import com.intellij.openapi.extensions.Extensions
|
||||
@@ -29,6 +28,7 @@ import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.idea.caches.project.SdkInfo
|
||||
import org.jetbrains.kotlin.idea.caches.project.getScriptRelatedModuleInfo
|
||||
import org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings
|
||||
import org.jetbrains.kotlin.idea.util.application.getServiceSafe
|
||||
import org.jetbrains.kotlin.idea.util.getProjectJdkTableSafe
|
||||
import org.jetbrains.kotlin.script.ScriptTemplatesProvider
|
||||
import org.jetbrains.kotlin.scripting.definitions.*
|
||||
@@ -206,8 +206,7 @@ class ScriptDefinitionsManager(private val project: Project) : LazyScriptDefinit
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getInstance(project: Project): ScriptDefinitionsManager =
|
||||
ServiceManager.getService(project, ScriptDefinitionProvider::class.java) as ScriptDefinitionsManager
|
||||
fun getInstance(project: Project): ScriptDefinitionsManager = project.getServiceSafe<ScriptDefinitionProvider>() as ScriptDefinitionsManager
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.idea.core.script.settings
|
||||
|
||||
import com.intellij.openapi.components.PersistentStateComponent
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.components.State
|
||||
import com.intellij.openapi.components.Storage
|
||||
import com.intellij.openapi.project.Project
|
||||
@@ -14,6 +13,7 @@ import com.intellij.util.addOptionTag
|
||||
import com.intellij.util.attribute
|
||||
import com.intellij.util.getAttributeBooleanValue
|
||||
import org.jdom.Element
|
||||
import org.jetbrains.kotlin.idea.util.application.getServiceSafe
|
||||
import org.jetbrains.kotlin.scripting.definitions.ScriptDefinition
|
||||
|
||||
@State(
|
||||
@@ -136,8 +136,7 @@ class KotlinScriptingSettings : PersistentStateComponent<Element> {
|
||||
getChildren("option").firstOrNull { it.getAttribute("name").value == name }?.getAttributeBooleanValue("value")
|
||||
|
||||
companion object {
|
||||
fun getInstance(project: Project): KotlinScriptingSettings =
|
||||
ServiceManager.getService(project, KotlinScriptingSettings::class.java)
|
||||
fun getInstance(project: Project): KotlinScriptingSettings = project.getServiceSafe()
|
||||
|
||||
private const val SCRIPT_DEFINITION_TAG = "scriptDefinition"
|
||||
|
||||
|
||||
@@ -113,11 +113,7 @@ class KotlinMigrationProjectService(val project: Project) {
|
||||
companion object {
|
||||
fun getInstanceIfNotDisposed(project: Project): KotlinMigrationProjectService? {
|
||||
return runReadAction {
|
||||
if (!project.isDisposed) {
|
||||
project.getServiceSafe(KotlinMigrationProjectService::class.java)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
if (!project.isDisposed) project.getServiceSafe() else null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class KotlinCodeHintsModel(val project: Project) : EditorFactoryListener {
|
||||
companion object {
|
||||
fun getInstance(project: Project): KotlinCodeHintsModel = project.getServiceSafe(KotlinCodeHintsModel::class.java)
|
||||
fun getInstance(project: Project): KotlinCodeHintsModel = project.getServiceSafe()
|
||||
}
|
||||
|
||||
private class DocumentExtensionInfoModel(val document: Document) {
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.script
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.progress.ProgressIndicator
|
||||
import com.intellij.openapi.progress.Task
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptDefinitionSourceAsContributor
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptDefinitionsManager
|
||||
import org.jetbrains.kotlin.idea.util.application.executeOnPooledThread
|
||||
import org.jetbrains.kotlin.scripting.definitions.ScriptDefinition
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
import kotlin.concurrent.read
|
||||
@@ -100,7 +100,7 @@ abstract class AsyncScriptDefinitionsContributor(protected val project: Project)
|
||||
if (isHeadless) {
|
||||
// If new script definitions found, then ScriptDefinitionsManager.reloadDefinitionsBy should be called
|
||||
// This may cause deadlock because Task.Backgroundable.queue executes task synchronously in headless mode
|
||||
ApplicationManager.getApplication().executeOnPooledThread {
|
||||
executeOnPooledThread {
|
||||
ScriptDefinitionsManager.getInstance(project).reloadDefinitionsBy(this@AsyncScriptDefinitionsContributor)
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user