allowAnalysisFromWriteAction¶
inline fun <T> allowAnalysisFromWriteAction(action: () -> T): T
Allows analyze to be called from a write action in the given action, which is normally not allowed.
Analysis is not supposed to be called from a write action. Such actions can lead to IDE freezes and incorrect behavior in some cases.
There is no guarantee that PSI changes will be reflected in an Analysis API world inside one analyze session. Example:
// code to be analyzed
fun foo(): Int = 0
// use case code
fun useCase() {
analyse(function) {
// 'getConstantFromExpressionBody' is an imaginary function
val valueBefore = function.getConstantFromExpressionBody() // valueBefore is 0
changeExpressionBodyTo(1) // now function will looks like `fun foo(): Int = 1`
val valueAfter = function.getConstantFromExpressionBody() // Wrong way: valueAfter is not guaranteed to be '1'
}
analyse(function) {
val valueAfter = function.getConstantFromExpressionBody() // OK: valueAfter is guaranteed to be '1'
}
}