Lint: resolve via the accessor descriptor in PropertyAsCAllAndroidUastAdditionalChecker
This commit is contained in:
+19
-5
@@ -18,8 +18,11 @@ package org.jetbrains.kotlin.uast
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.uast.*
|
||||
@@ -28,17 +31,28 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
open class KotlinUSimpleReferenceExpression(
|
||||
override val psi: PsiElement,
|
||||
override val identifier: String,
|
||||
override val parent: UElement
|
||||
override val parent: UElement,
|
||||
private val descriptor: DeclarationDescriptor? = null
|
||||
) : KotlinAbstractUElement(), USimpleReferenceExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper {
|
||||
override fun resolve(context: UastContext) = context.convert(
|
||||
psi.references.firstOrNull()?.resolve()) as? UDeclaration
|
||||
override fun resolve(context: UastContext): UDeclaration? {
|
||||
val resultingDescriptor = descriptor ?: run {
|
||||
val ktElement = psi as? KtElement ?: return null
|
||||
val bindingContext = ktElement.analyze(BodyResolveMode.PARTIAL)
|
||||
val resolvedCall = ktElement.getResolvedCall(bindingContext) ?: return null
|
||||
resolvedCall.resultingDescriptor
|
||||
}
|
||||
|
||||
val source = DescriptorToSourceUtilsIde.getAnyDeclaration(psi.project, resultingDescriptor) ?: return null
|
||||
return context.convert(source) as? UDeclaration
|
||||
}
|
||||
}
|
||||
|
||||
class KotlinNameUSimpleReferenceExpression(
|
||||
psi: PsiElement,
|
||||
identifier: String,
|
||||
parent: UElement
|
||||
) : KotlinUSimpleReferenceExpression(psi, identifier, parent)
|
||||
parent: UElement,
|
||||
descriptor: DeclarationDescriptor? = null
|
||||
) : KotlinUSimpleReferenceExpression(psi, identifier, parent, descriptor)
|
||||
|
||||
class KotlinClassViaConstructorUSimpleReferenceExpression(
|
||||
override val psi: KtCallExpression,
|
||||
|
||||
+10
-2
@@ -51,7 +51,9 @@ class PropertyAsCallAndroidUastAdditionalChecker : AndroidUastAdditionalChecker
|
||||
override val parent = element.parent
|
||||
override val psi = ktElement
|
||||
|
||||
override val functionReference = KotlinNameUSimpleReferenceExpression(expr.psi, expr.identifier, expr.parent)
|
||||
override val functionReference = KotlinNameUSimpleReferenceExpression(
|
||||
expr.psi, expr.identifier, expr.parent, accessorDescriptor)
|
||||
|
||||
override val classReference = null
|
||||
override val functionName = accessorDescriptor.name.asString()
|
||||
override val functionNameElement by lz { KotlinDumbUElement(ktElement, this) }
|
||||
@@ -75,7 +77,13 @@ class PropertyAsCallAndroidUastAdditionalChecker : AndroidUastAdditionalChecker
|
||||
|
||||
override val kind = UastCallKind.FUNCTION_CALL
|
||||
|
||||
override fun resolve(context: UastContext) = element.resolveIfCan(context) as? UFunction
|
||||
override fun resolve(context: UastContext): UFunction? {
|
||||
val source = accessorDescriptor.toSource(psi.project)
|
||||
if (source != null) {
|
||||
(context.convert(source) as? UFunction)?.let { return it }
|
||||
}
|
||||
return element.resolveIfCan(context) as? UFunction
|
||||
}
|
||||
}
|
||||
|
||||
handler(callExpression)
|
||||
|
||||
Reference in New Issue
Block a user