KT-59093 [Analysis API] Make all resolveCall overloads nullable

Instead of returning an error which does not mean anything specific,
it's easier just to return `null`
This commit is contained in:
Roman Golyshev
2023-06-20 17:06:16 +02:00
committed by teamcity
parent c81b22e7de
commit 50c93b0228
3 changed files with 5 additions and 19 deletions
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.psi.KtExpression
class KtFirInvokeFunctionReference(expression: KtCallExpression) : KtInvokeFunctionReference(expression), KtFirReference {
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
return expression.resolveCall().calls.mapNotNull { call ->
return expression.resolveCall()?.calls.orEmpty().mapNotNull { call ->
(call as? KtSimpleFunctionCall)
?.takeIf { it.isImplicitInvoke }
?.partiallyAppliedSymbol
@@ -8,8 +8,6 @@ package org.jetbrains.kotlin.analysis.api.components
import org.jetbrains.kotlin.analysis.api.KtAnalysisApiInternals
import org.jetbrains.kotlin.analysis.api.calls.KtCallCandidateInfo
import org.jetbrains.kotlin.analysis.api.calls.KtCallInfo
import org.jetbrains.kotlin.analysis.api.calls.KtErrorCallInfo
import org.jetbrains.kotlin.analysis.api.diagnostics.KtNonBoundToPsiErrorDiagnostic
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
import org.jetbrains.kotlin.psi.KtArrayAccessExpression
import org.jetbrains.kotlin.psi.KtCallElement
@@ -20,15 +18,6 @@ public abstract class KtCallResolver : KtAnalysisSessionComponent() {
public abstract fun resolveCall(psi: KtElement): KtCallInfo?
public abstract fun collectCallCandidates(psi: KtElement): List<KtCallCandidateInfo>
@KtAnalysisApiInternals
public fun unresolvedKtCallError(psi: KtElement): KtErrorCallInfo {
return KtErrorCallInfo(
_candidateCalls = emptyList(),
KtNonBoundToPsiErrorDiagnostic(factoryName = null, "Unresolved call", token),
token
)
}
}
@OptIn(KtAnalysisApiInternals::class)
@@ -37,20 +26,17 @@ public interface KtCallResolverMixIn : KtAnalysisSessionMixIn {
public fun KtElement.resolveCall(): KtCallInfo? =
withValidityAssertion { analysisSession.callResolver.resolveCall(this) }
public fun KtCallElement.resolveCall(): KtCallInfo = withValidityAssertion {
public fun KtCallElement.resolveCall(): KtCallInfo? = withValidityAssertion {
analysisSession.callResolver.resolveCall(this)
?: analysisSession.callResolver.unresolvedKtCallError(this)
}
public fun KtUnaryExpression.resolveCall(): KtCallInfo = withValidityAssertion {
public fun KtUnaryExpression.resolveCall(): KtCallInfo? = withValidityAssertion {
analysisSession.callResolver.resolveCall(this)
?: analysisSession.callResolver.unresolvedKtCallError(this)
}
public fun KtArrayAccessExpression.resolveCall(): KtCallInfo = withValidityAssertion {
public fun KtArrayAccessExpression.resolveCall(): KtCallInfo? = withValidityAssertion {
analysisSession.callResolver.resolveCall(this)
?: analysisSession.callResolver.unresolvedKtCallError(this)
}
/**
@@ -62,7 +62,7 @@ internal abstract class SymbolLightAbstractAnnotation(parent: PsiElement) :
val callElement = kotlinOrigin ?: return null
return analyzeForLightClasses(callElement) {
val valueParameter = callElement.resolveCall()
.singleConstructorCallOrNull()
?.singleConstructorCallOrNull()
?.symbol
?.valueParameters
?.find { it.name.identifierOrNullIfSpecial == attributeName }