FE1.0 Analysis API: Fix kind in implicit smart-casts info
This commit is contained in:
committed by
teamcity
parent
513af2dfbc
commit
6dd9115ee9
+12
-4
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.psi.KtExpression
|
|||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.ExplicitSmartCasts
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.ExplicitSmartCasts
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.MultipleSmartCasts
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.MultipleSmartCasts
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.checker.intersectWrappedTypes
|
import org.jetbrains.kotlin.types.checker.intersectWrappedTypes
|
||||||
|
|
||||||
internal class KtFe10SmartCastProvider(
|
internal class KtFe10SmartCastProvider(
|
||||||
@@ -51,12 +52,19 @@ internal class KtFe10SmartCastProvider(
|
|||||||
return defaultType?.toKtType(analysisContext)
|
return defaultType?.toKtType(analysisContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun smartCastedImplicitReceiver(type: KotlinType?, kind: KtImplicitReceiverSmartCastKind): KtImplicitReceiverSmartCast? {
|
||||||
|
if (type == null) return null
|
||||||
|
return KtImplicitReceiverSmartCast(type.toKtType(analysisContext), kind, token)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getImplicitReceiverSmartCast(expression: KtExpression): Collection<KtImplicitReceiverSmartCast> {
|
override fun getImplicitReceiverSmartCast(expression: KtExpression): Collection<KtImplicitReceiverSmartCast> {
|
||||||
val bindingContext = analysisContext.analyze(expression)
|
val bindingContext = analysisContext.analyze(expression)
|
||||||
val smartCasts = bindingContext[BindingContext.IMPLICIT_RECEIVER_SMARTCAST, expression] ?: return emptyList()
|
val smartCasts = bindingContext[BindingContext.IMPLICIT_RECEIVER_SMARTCAST, expression] ?: return emptyList()
|
||||||
return smartCasts.receiverTypes.map { (_, type) ->
|
val call = bindingContext[BindingContext.CALL, expression] ?: return emptyList()
|
||||||
val kind = KtImplicitReceiverSmartCastKind.DISPATCH // TODO provide precise kind
|
val resolvedCall = bindingContext[BindingContext.RESOLVED_CALL, call] ?: return emptyList()
|
||||||
KtImplicitReceiverSmartCast(type.toKtType(analysisContext), kind, token)
|
return listOfNotNull(
|
||||||
}
|
smartCastedImplicitReceiver(smartCasts.receiverTypes[resolvedCall.dispatchReceiver], KtImplicitReceiverSmartCastKind.DISPATCH),
|
||||||
|
smartCastedImplicitReceiver(smartCasts.receiverTypes[resolvedCall.extensionReceiver], KtImplicitReceiverSmartCastKind.EXTENSION)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user