Files
Andrey Cherkasov 4b6a11a1bb [devkit] "Simplifiable service retrieving" must not warn on safe calls
The inspection must not issue warnings on Kotlin safe calls, such as:

- `ApplicationManager.getApplication()?.getService(...)`
- `project?.getService(...)`

GitOrigin-RevId: d7942dfaf9287347d9c09dd705fc8ab969b37986
2023-11-29 13:31:39 +00:00

29 lines
916 B
Kotlin

@file:Suppress("NO_REFLECTION_IN_CLASS_PATH")
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
@Service(Service.Level.APP)
class MyAppService {
companion object {
@JvmStatic
fun getInstance(): MyAppService = ApplicationManager.getApplication().getService(MyAppService::class.java)
}
}
@Service(Service.Level.PROJECT)
class MyProjectService {
companion object {
@JvmStatic
fun getInstance(project: Project): MyProjectService = project.getService(MyProjectService::class.java)
}
}
fun test(project: Project?) {
ApplicationManager.getApplication()?.getService(MyAppService::class.java)
ApplicationManager.getApplication()?.service<MyAppService>()
project?.getService(MyProjectService::class.java)
project?.service<MyProjectService>()
}