Uast: yet another check for invalid context before resolve (EA-137191, EA-137193)
This commit is contained in:
@@ -91,6 +91,7 @@ open class KotlinUMethod(
|
|||||||
|
|
||||||
|
|
||||||
override val uastBody by lz {
|
override val uastBody by lz {
|
||||||
|
if (kotlinOrigin?.canAnalyze() != true) return@lz null // EA-137193
|
||||||
val bodyExpression = when (kotlinOrigin) {
|
val bodyExpression = when (kotlinOrigin) {
|
||||||
is KtFunction -> kotlinOrigin.bodyExpression
|
is KtFunction -> kotlinOrigin.bodyExpression
|
||||||
is KtProperty -> when {
|
is KtProperty -> when {
|
||||||
@@ -106,7 +107,7 @@ open class KotlinUMethod(
|
|||||||
KotlinUBlockExpression.KotlinLazyUBlockExpression(this, { block ->
|
KotlinUBlockExpression.KotlinLazyUBlockExpression(this, { block ->
|
||||||
val implicitReturn = KotlinUImplicitReturnExpression(block)
|
val implicitReturn = KotlinUImplicitReturnExpression(block)
|
||||||
val uBody = getLanguagePlugin().convertElement(bodyExpression, implicitReturn) as? UExpression
|
val uBody = getLanguagePlugin().convertElement(bodyExpression, implicitReturn) as? UExpression
|
||||||
?: return@KotlinLazyUBlockExpression emptyList()
|
?: return@KotlinLazyUBlockExpression emptyList()
|
||||||
listOf(implicitReturn.apply { returnExpression = uBody })
|
listOf(implicitReturn.apply { returnExpression = uBody })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ open class KotlinUMethod(
|
|||||||
|
|
||||||
|
|
||||||
override val uastBody by lz {
|
override val uastBody by lz {
|
||||||
|
if (kotlinOrigin?.canAnalyze() != true) return@lz null // EA-137193
|
||||||
val bodyExpression = when (kotlinOrigin) {
|
val bodyExpression = when (kotlinOrigin) {
|
||||||
is KtFunction -> kotlinOrigin.bodyExpression
|
is KtFunction -> kotlinOrigin.bodyExpression
|
||||||
is KtProperty -> when {
|
is KtProperty -> when {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ abstract class AbstractKotlinUVariable(givenParent: UElement?) : KotlinAbstractU
|
|||||||
is UastKotlinPsiVariable -> psi.ktInitializer
|
is UastKotlinPsiVariable -> psi.ktInitializer
|
||||||
is UastKotlinPsiParameter -> psi.ktDefaultValue
|
is UastKotlinPsiParameter -> psi.ktDefaultValue
|
||||||
is KtLightElement<*, *> -> {
|
is KtLightElement<*, *> -> {
|
||||||
val origin = psi.kotlinOrigin
|
val origin = psi.kotlinOrigin?.takeIf { it.canAnalyze() } // EA-137191
|
||||||
when (origin) {
|
when (origin) {
|
||||||
is KtVariableDeclaration -> origin.initializer
|
is KtVariableDeclaration -> origin.initializer
|
||||||
is KtParameter -> origin.defaultValue
|
is KtParameter -> origin.defaultValue
|
||||||
|
|||||||
+8
-3
@@ -282,10 +282,15 @@ internal fun KtExpression.unwrapBlockOrParenthesis(): KtExpression {
|
|||||||
return innerExpression
|
return innerExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun KtElement.canAnalyze(): Boolean {
|
||||||
|
if (!isValid) return false
|
||||||
|
val containingFile = containingFile as? KtFile ?: return false // EA-114080, EA-113475, EA-134193
|
||||||
|
if (containingFile.doNotAnalyze != null) return false // To prevent exceptions during analysis
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
internal fun KtElement.analyze(): BindingContext {
|
internal fun KtElement.analyze(): BindingContext {
|
||||||
val containingFile = containingFile
|
if (!canAnalyze()) return BindingContext.EMPTY
|
||||||
if (!isValid || containingFile !is KtFile) return BindingContext.EMPTY // EA-114080, EA-113475, EA-134193
|
|
||||||
if (containingFile.doNotAnalyze != null) return BindingContext.EMPTY // To prevent exceptions during analysis
|
|
||||||
return ServiceManager.getService(project, KotlinUastResolveProviderService::class.java)
|
return ServiceManager.getService(project, KotlinUastResolveProviderService::class.java)
|
||||||
?.getBindingContext(this) ?: BindingContext.EMPTY
|
?.getBindingContext(this) ?: BindingContext.EMPTY
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user