Receiver refactoring in DataFlowValueFactory
This commit is contained in:
+6
-7
@@ -104,7 +104,7 @@ public class DataFlowValueFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static DataFlowValue createDataFlowValue(@NotNull ThisReceiver receiver) {
|
public static DataFlowValue createDataFlowValueForStableReceiver(@NotNull ReceiverValue receiver) {
|
||||||
KotlinType type = receiver.getType();
|
KotlinType type = receiver.getType();
|
||||||
return new DataFlowValue(receiver, type, STABLE_VALUE, getImmanentNullability(type));
|
return new DataFlowValue(receiver, type, STABLE_VALUE, getImmanentNullability(type));
|
||||||
}
|
}
|
||||||
@@ -124,12 +124,11 @@ public class DataFlowValueFactory {
|
|||||||
@NotNull BindingContext bindingContext,
|
@NotNull BindingContext bindingContext,
|
||||||
@NotNull DeclarationDescriptor containingDeclarationOrModule
|
@NotNull DeclarationDescriptor containingDeclarationOrModule
|
||||||
) {
|
) {
|
||||||
if (receiverValue instanceof TransientReceiver || receiverValue instanceof ScriptReceiver) {
|
if (receiverValue instanceof TransientReceiver ||
|
||||||
KotlinType type = receiverValue.getType();
|
receiverValue instanceof ScriptReceiver ||
|
||||||
return new DataFlowValue(receiverValue, type, STABLE_VALUE, getImmanentNullability(type));
|
receiverValue instanceof ClassReceiver ||
|
||||||
}
|
receiverValue instanceof ExtensionReceiver) {
|
||||||
else if (receiverValue instanceof ClassReceiver || receiverValue instanceof ExtensionReceiver) {
|
return createDataFlowValueForStableReceiver(receiverValue);
|
||||||
return createDataFlowValue((ThisReceiver) receiverValue);
|
|
||||||
}
|
}
|
||||||
else if (receiverValue instanceof ExpressionReceiver) {
|
else if (receiverValue instanceof ExpressionReceiver) {
|
||||||
return createDataFlowValue(((ExpressionReceiver) receiverValue).getExpression(),
|
return createDataFlowValue(((ExpressionReceiver) receiverValue).getExpression(),
|
||||||
|
|||||||
+1
-1
@@ -178,7 +178,7 @@ data class ExtractionData(
|
|||||||
val typeInfo = context[BindingContext.EXPRESSION_TYPE_INFO, expression] ?: return emptySet()
|
val typeInfo = context[BindingContext.EXPRESSION_TYPE_INFO, expression] ?: return emptySet()
|
||||||
|
|
||||||
(resolvedCall?.getImplicitReceiverValue() as? ThisReceiver)?.let {
|
(resolvedCall?.getImplicitReceiverValue() as? ThisReceiver)?.let {
|
||||||
return typeInfo.dataFlowInfo.getPossibleTypes(DataFlowValueFactory.createDataFlowValue(it))
|
return typeInfo.dataFlowInfo.getPossibleTypes(DataFlowValueFactory.createDataFlowValueForStableReceiver(it))
|
||||||
}
|
}
|
||||||
|
|
||||||
val type = resolvedCall?.resultingDescriptor?.returnType ?: return emptySet()
|
val type = resolvedCall?.resultingDescriptor?.returnType ?: return emptySet()
|
||||||
|
|||||||
+1
-1
@@ -281,7 +281,7 @@ private fun suggestParameterType(
|
|||||||
val calleeExpression = resolvedCall!!.call.calleeExpression
|
val calleeExpression = resolvedCall!!.call.calleeExpression
|
||||||
val typeByDataFlowInfo = if (useSmartCastsIfPossible) {
|
val typeByDataFlowInfo = if (useSmartCastsIfPossible) {
|
||||||
bindingContext[BindingContext.EXPRESSION_TYPE_INFO, calleeExpression]?.dataFlowInfo?.let { dataFlowInfo ->
|
bindingContext[BindingContext.EXPRESSION_TYPE_INFO, calleeExpression]?.dataFlowInfo?.let { dataFlowInfo ->
|
||||||
val possibleTypes = dataFlowInfo.getPossibleTypes(DataFlowValueFactory.createDataFlowValue(receiverToExtract))
|
val possibleTypes = dataFlowInfo.getPossibleTypes(DataFlowValueFactory.createDataFlowValueForStableReceiver(receiverToExtract))
|
||||||
if (possibleTypes.isNotEmpty()) CommonSupertypes.commonSupertype(possibleTypes) else null
|
if (possibleTypes.isNotEmpty()) CommonSupertypes.commonSupertype(possibleTypes) else null
|
||||||
}
|
}
|
||||||
} else null
|
} else null
|
||||||
|
|||||||
Reference in New Issue
Block a user