Minor. Extract getDataFlowValueExcludingReceiver

This commit is contained in:
Denis Zharkov
2015-08-07 12:07:14 +03:00
parent 6ecfa6e985
commit 70d4a7997e
@@ -117,19 +117,33 @@ public class SmartCastManager {
@NotNull DeclarationDescriptor containingDeclarationOrModule, @NotNull DeclarationDescriptor containingDeclarationOrModule,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull ReceiverValue receiverToCast @NotNull ReceiverValue receiverToCast
) {
DataFlowValue dataFlowValue = getDataFlowValueExcludingReceiver(bindingContext, containingDeclarationOrModule, receiverToCast);
if (dataFlowValue != null) {
return dataFlowInfo.getPossibleTypes(dataFlowValue);
}
return Collections.emptyList();
}
@Nullable
public static DataFlowValue getDataFlowValueExcludingReceiver(
@NotNull BindingContext bindingContext,
@NotNull DeclarationDescriptor containingDeclarationOrModule,
@NotNull ReceiverValue receiverToCast
) { ) {
if (receiverToCast instanceof ThisReceiver) { if (receiverToCast instanceof ThisReceiver) {
ThisReceiver receiver = (ThisReceiver) receiverToCast; ThisReceiver receiver = (ThisReceiver) receiverToCast;
assert receiver.exists(); assert receiver.exists();
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiver); return DataFlowValueFactory.createDataFlowValue(receiver);
return dataFlowInfo.getPossibleTypes(dataFlowValue);
} }
else if (receiverToCast instanceof ExpressionReceiver) { else if (receiverToCast instanceof ExpressionReceiver) {
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue( return DataFlowValueFactory.createDataFlowValue(
receiverToCast, bindingContext, containingDeclarationOrModule); receiverToCast, bindingContext, containingDeclarationOrModule
return dataFlowInfo.getPossibleTypes(dataFlowValue); );
} }
return Collections.emptyList(); return null;
} }
public boolean isSubTypeBySmartCastIgnoringNullability( public boolean isSubTypeBySmartCastIgnoringNullability(