1 // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.openapi.components
4 import com.intellij.openapi.application.ApplicationManager
5 import com.intellij.openapi.components.impl.stores.IComponentStore
6 import com.intellij.openapi.project.Project
7 import com.intellij.project.ProjectStoreOwner
9 inline fun <reified T : Any> service(): T = ApplicationManager.getApplication().getService(T::class.java, true)
11 inline fun <reified T : Any> serviceOrNull(): T? = ApplicationManager.getApplication().getService(T::class.java, true)
13 inline fun <reified T : Any> serviceIfCreated(): T? = ApplicationManager.getApplication().getServiceIfCreated(T::class.java)
15 inline fun <reified T : Any> Project.service(): T = getService(T::class.java, true)
17 val ComponentManager.stateStore: IComponentStore
20 is ProjectStoreOwner -> this.getComponentStore()
22 // module or application service
23 getService(IComponentStore::class.java)
28 @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
29 @Deprecated(message = "do not use", replaceWith = ReplaceWith("getComponentInstancesOfType(baseClass)"))
30 fun <T> ComponentManager.getComponents(baseClass: Class<T>): List<T> {
31 @Suppress("DEPRECATION")
32 return getComponentInstancesOfType(baseClass, false)