FIR IDE: forbid resolve in HLApplicator/HLApplicabilityRange/HLPresentation
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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 kotlin.reflect.KProperty1
|
||||
|
||||
@RequiresOptIn
|
||||
annotation class ForbidKtResolveInternals
|
||||
|
||||
object ForbidKtResolve {
|
||||
@OptIn(ForbidKtResolveInternals::class)
|
||||
inline fun <R> forbidResolveIn(actionName: String, action: () -> R): R {
|
||||
if (resovleIsForbidenInActionWithName.get() != null) return action()
|
||||
resovleIsForbidenInActionWithName.set(actionName)
|
||||
return try {
|
||||
action()
|
||||
} finally {
|
||||
resovleIsForbidenInActionWithName.set(null)
|
||||
}
|
||||
}
|
||||
|
||||
@ForbidKtResolveInternals
|
||||
val resovleIsForbidenInActionWithName: ThreadLocal<String?> = ThreadLocal.withInitial { null }
|
||||
}
|
||||
+7
-2
@@ -23,22 +23,27 @@ class ReadActionConfinementValidityToken(project: Project) : ValidityToken() {
|
||||
error("Getting invalidation reason for valid validity token")
|
||||
}
|
||||
|
||||
@OptIn(HackToForceAllowRunningAnalyzeOnEDT::class)
|
||||
@OptIn(HackToForceAllowRunningAnalyzeOnEDT::class, ForbidKtResolveInternals::class)
|
||||
override fun isAccessible(): Boolean {
|
||||
val application = ApplicationManager.getApplication()
|
||||
if (application.isDispatchThread && !allowOnEdt.get()) return false
|
||||
if (ForbidKtResolve.resovleIsForbidenInActionWithName.get() != null) return false
|
||||
if (!application.isReadAccessAllowed) return false
|
||||
return true
|
||||
}
|
||||
|
||||
@OptIn(HackToForceAllowRunningAnalyzeOnEDT::class)
|
||||
@OptIn(HackToForceAllowRunningAnalyzeOnEDT::class, ForbidKtResolveInternals::class)
|
||||
override fun getInaccessibilityReason(): String {
|
||||
val application = ApplicationManager.getApplication()
|
||||
if (application.isDispatchThread && !allowOnEdt.get()) return "Called in EDT thread"
|
||||
if (!application.isReadAccessAllowed) return "Called outside read action"
|
||||
ForbidKtResolve.resovleIsForbidenInActionWithName.get()?.let { actionName ->
|
||||
return "Resolve is forbidden in $actionName"
|
||||
}
|
||||
error("Getting inaccessibility reason for validity token when it is accessible")
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
@HackToForceAllowRunningAnalyzeOnEDT
|
||||
val allowOnEdt: ThreadLocal<Boolean> = ThreadLocal.withInitial { false }
|
||||
|
||||
Reference in New Issue
Block a user