FIR IDE: introduce KtAnalysisSessionProvider & helping functions for working with analysis session

This commit is contained in:
Ilya Kirillov
2020-07-04 01:07:19 +03:00
parent acb8546583
commit 8c0197e081
12 changed files with 96 additions and 36 deletions
@@ -0,0 +1,27 @@
/*
* 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.frontend.api
import com.intellij.openapi.components.service
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.psi.KtElement
abstract class KtAnalysisSessionProvider {
abstract fun getAnalysisSessionFor(contextElement: KtElement): KtAnalysisSession
}
fun getAnalysisSessionFor(contextElement: KtElement): KtAnalysisSession =
service<KtAnalysisSessionProvider>().getAnalysisSessionFor(contextElement)
inline fun <R> analyze(contextElement: KtElement, action: KtAnalysisSession.() -> R): R =
getAnalysisSessionFor(contextElement).action()
inline fun <R> analyzeWithReadAction(
contextElement: KtElement,
crossinline action: KtAnalysisSession.() -> R
): R = runReadAction {
analyze(contextElement, action)
}