mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Rename Context enum to ExecutionContextType
GitOrigin-RevId: d6e4240042449ba2f5d75f844f5a2a3e72b561f0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8b82ff7769
commit
1658427c0a
@@ -10,39 +10,39 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypes
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
internal fun getContext(element: PsiElement): Context {
|
||||
internal fun getContext(element: PsiElement): ExecutionContextType {
|
||||
val containingLambda = element.getParentOfType<KtLambdaExpression>(false)
|
||||
|
||||
// if lambda is null, check the containing method
|
||||
if (containingLambda == null) {
|
||||
val containingMethod = element.getParentOfType<KtNamedFunction>(false)
|
||||
return if (containingMethod.hasSuspendModifier()) Context.SUSPENDING_FUNCTION else Context.BLOCKING
|
||||
return if (containingMethod.hasSuspendModifier()) ExecutionContextType.SUSPENDING_FUNCTION else ExecutionContextType.BLOCKING
|
||||
}
|
||||
|
||||
// otherwise, check containing argument (whether the corresponding parameter has `suspend` modifier)
|
||||
val containingArgument = containingLambda.getParentOfType<KtValueArgument>(true, KtCallableDeclaration::class.java)
|
||||
if (containingArgument != null) {
|
||||
val callExpression = containingArgument.getStrictParentOfType<KtCallExpression>() ?: return Context.BLOCKING
|
||||
val callExpression = containingArgument.getStrictParentOfType<KtCallExpression>() ?: return ExecutionContextType.BLOCKING
|
||||
analyze(callExpression) {
|
||||
val functionCall = callExpression.resolveCall()?.singleFunctionCallOrNull() ?: return Context.BLOCKING
|
||||
val lambdaArgumentType = functionCall.argumentMapping[containingLambda]?.returnType ?: return Context.BLOCKING
|
||||
val functionCall = callExpression.resolveCall()?.singleFunctionCallOrNull() ?: return ExecutionContextType.BLOCKING
|
||||
val lambdaArgumentType = functionCall.argumentMapping[containingLambda]?.returnType ?: return ExecutionContextType.BLOCKING
|
||||
|
||||
return if (lambdaArgumentType.isSuspendFunctionType) Context.SUSPENDING_LAMBDA else Context.BLOCKING
|
||||
return if (lambdaArgumentType.isSuspendFunctionType) ExecutionContextType.SUSPENDING_LAMBDA else ExecutionContextType.BLOCKING
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise, check if it's a property or a function
|
||||
val containingPropertyOrFunction: KtCallableDeclaration? = containingLambda.getParentOfTypes(true, KtProperty::class.java,
|
||||
KtNamedFunction::class.java)
|
||||
if (containingPropertyOrFunction?.typeReference.hasSuspendModifier()) return Context.SUSPENDING_LAMBDA
|
||||
return if (containingPropertyOrFunction.hasSuspendModifier()) Context.SUSPENDING_LAMBDA else Context.BLOCKING
|
||||
if (containingPropertyOrFunction?.typeReference.hasSuspendModifier()) return ExecutionContextType.SUSPENDING_LAMBDA
|
||||
return if (containingPropertyOrFunction.hasSuspendModifier()) ExecutionContextType.SUSPENDING_LAMBDA else ExecutionContextType.BLOCKING
|
||||
}
|
||||
|
||||
private fun KtModifierListOwner?.hasSuspendModifier(): Boolean {
|
||||
return this?.hasModifier(KtTokens.SUSPEND_KEYWORD) == true
|
||||
}
|
||||
|
||||
internal enum class Context {
|
||||
internal enum class ExecutionContextType {
|
||||
BLOCKING,
|
||||
SUSPENDING_FUNCTION,
|
||||
SUSPENDING_LAMBDA;
|
||||
|
||||
Reference in New Issue
Block a user