DataFlowInfo Refactoring: getNullability() --> getCollectedNullability(); getPossibleTypes() --> getCollectedTypes()

This commit is contained in:
Mikhail Glukhikh
2015-12-08 11:21:10 +03:00
parent 57b3bc0496
commit d08f6f8238
9 changed files with 24 additions and 24 deletions
@@ -94,7 +94,7 @@ public object RuntimeAssertionsTypeChecker : AdditionalTypeChecker {
override val canBeNull: Boolean
get() = c.dataFlowInfo.getPredictableNullability(dataFlowValue).canBeNull()
override val possibleTypes: Set<KotlinType>
get() = c.dataFlowInfo.getPossibleTypes(dataFlowValue)
get() = c.dataFlowInfo.getCollectedTypes(dataFlowValue)
override val presentableText: String
get() = StringUtil.trimMiddle(expression.getText(), 50)
@@ -194,7 +194,7 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes
val dataFlowValue = DataFlowValueFactory.createDataFlowValue(deparenthesizedArgument, type, context)
if (!dataFlowValue.isPredictable) return type
val possibleTypes = context.dataFlowInfo.getPossibleTypes(dataFlowValue)
val possibleTypes = context.dataFlowInfo.getCollectedTypes(dataFlowValue)
if (possibleTypes.isEmpty()) return type
return TypeIntersector.intersectTypes(KotlinTypeChecker.DEFAULT, possibleTypes + type)
@@ -41,7 +41,7 @@ public interface DataFlowInfo {
* Returns collected nullability for the given value, NOT taking its predictability into account.
*/
@NotNull
Nullability getNullability(@NotNull DataFlowValue key);
Nullability getCollectedNullability(@NotNull DataFlowValue key);
/**
* Returns collected nullability for the given value if it's predictable.
@@ -57,7 +57,7 @@ public interface DataFlowInfo {
* are NOT included. So it's quite possible to get an empty set here.
*/
@NotNull
Set<KotlinType> getPossibleTypes(@NotNull DataFlowValue key);
Set<KotlinType> getCollectedTypes(@NotNull DataFlowValue key);
/**
* Returns possible types for the given value if it's predictable.
@@ -109,7 +109,7 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL
@Override
@NotNull
public Nullability getNullability(@NotNull DataFlowValue key) {
public Nullability getCollectedNullability(@NotNull DataFlowValue key) {
return getNullability(key, false);
}
@@ -124,7 +124,7 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL
if (predictableOnly && !key.isPredictable()) return key.getImmanentNullability();
Nullability nullability = nullabilityInfo.get(key);
return nullability != null ? nullability :
parent != null ? parent.getNullability(key) :
parent != null ? parent.getCollectedNullability(key) :
key.getImmanentNullability();
}
@@ -134,19 +134,19 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL
@NotNull Nullability nullability
) {
map.put(value, nullability);
return nullability != getNullability(value);
return nullability != getCollectedNullability(value);
}
@Override
@NotNull
public Set<KotlinType> getPossibleTypes(@NotNull DataFlowValue key) {
return getPossibleTypes(key, true);
public Set<KotlinType> getCollectedTypes(@NotNull DataFlowValue key) {
return getCollectedTypes(key, true);
}
@NotNull
private Set<KotlinType> getPossibleTypes(@NotNull DataFlowValue key, boolean enrichWithNotNull) {
private Set<KotlinType> getCollectedTypes(@NotNull DataFlowValue key, boolean enrichWithNotNull) {
Set<KotlinType> types = collectTypesFromMeAndParents(key);
if (!enrichWithNotNull || getNullability(key).canBeNull()) {
if (!enrichWithNotNull || getCollectedNullability(key).canBeNull()) {
return types;
}
@@ -173,7 +173,7 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL
if (!key.isPredictable()) {
return new LinkedHashSet<KotlinType>();
}
return getPossibleTypes(key, enrichWithNotNull);
return getCollectedTypes(key, enrichWithNotNull);
}
/**
@@ -271,7 +271,7 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL
}
}
else {
types.addAll(current.getPossibleTypes(value));
types.addAll(current.getCollectedTypes(value));
break;
}
}
@@ -296,7 +296,7 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL
@NotNull
public DataFlowInfo establishSubtyping(@NotNull DataFlowValue value, @NotNull KotlinType type) {
if (value.getType().equals(type)) return this;
if (getPossibleTypes(value).contains(type)) return this;
if (getCollectedTypes(value).contains(type)) return this;
if (!FlexibleTypesKt.isFlexible(value.getType()) && TypeUtilsKt.isSubtypeOf(value.getType(), type)) return this;
ImmutableMap<DataFlowValue, Nullability> newNullabilityInfo =
type.isMarkedNullable() ? EMPTY_NULLABILITY_INFO : ImmutableMap.of(value, NOT_NULL);
@@ -318,7 +318,7 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL
for (Map.Entry<DataFlowValue, Nullability> entry : other.getCompleteNullabilityInfo().entrySet()) {
DataFlowValue key = entry.getKey();
Nullability otherFlags = entry.getValue();
Nullability thisFlags = getNullability(key);
Nullability thisFlags = getCollectedNullability(key);
Nullability flags = thisFlags.and(otherFlags);
if (flags != thisFlags) {
nullabilityMapBuilder.put(key, flags);
@@ -352,7 +352,7 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL
for (Map.Entry<DataFlowValue, Nullability> entry : other.getCompleteNullabilityInfo().entrySet()) {
DataFlowValue key = entry.getKey();
Nullability otherFlags = entry.getValue();
Nullability thisFlags = getNullability(key);
Nullability thisFlags = getCollectedNullability(key);
nullabilityMapBuilder.put(key, thisFlags.or(otherFlags));
}
@@ -116,7 +116,7 @@ public class SmartCastManager {
receiverToCast, bindingContext, containingDeclarationOrModule
);
return dataFlowInfo.getPossibleTypes(dataFlowValue);
return dataFlowInfo.getCollectedTypes(dataFlowValue);
}
public boolean isSubTypeBySmartCastIgnoringNullability(
@@ -178,7 +178,7 @@ public class SmartCastManager {
@Nullable KtExpression calleeExpression,
boolean recordExpressionType
) {
for (KotlinType possibleType : c.dataFlowInfo.getPossibleTypes(dataFlowValue)) {
for (KotlinType possibleType : c.dataFlowInfo.getCollectedTypes(dataFlowValue)) {
if (ArgumentTypeResolver.isSubtypeOfForArgumentType(possibleType, expectedType)) {
if (expression != null) {
recordCastOrError(expression, possibleType, c.trace, dataFlowValue, recordExpressionType);
@@ -190,7 +190,7 @@ public class SmartCastManager {
}
}
if (!c.dataFlowInfo.getNullability(dataFlowValue).canBeNull() && !expectedType.isMarkedNullable()) {
if (!c.dataFlowInfo.getCollectedNullability(dataFlowValue).canBeNull() && !expectedType.isMarkedNullable()) {
// Handling cases like:
// fun bar(x: Any) {}
// fun <T : Any?> foo(x: T) {
@@ -125,7 +125,7 @@ private class DataFlowDecoratorImpl(private val resolutionContext: ResolutionCon
private fun getSmartCastInfo(receiver: ReceiverValue): SmartCastInfo
= cache.getOrPut(receiver) {
val dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiver, resolutionContext)
SmartCastInfo(dataFlowValue, dataFlowInfo.getPossibleTypes(dataFlowValue))
SmartCastInfo(dataFlowValue, dataFlowInfo.getCollectedTypes(dataFlowValue))
}
override fun getDataFlowValue(receiver: ReceiverValue): DataFlowValue = getSmartCastInfo(receiver).dataFlowValue
@@ -128,7 +128,7 @@ fun KtExpression.guessTypes(
val theType1 = context.getType(this)
if (theType1 != null) {
val dataFlowInfo = context.getDataFlowInfo(this)
val possibleTypes = dataFlowInfo.getPossibleTypes(DataFlowValueFactory.createDataFlowValue(this, theType1, context, module))
val possibleTypes = dataFlowInfo.getCollectedTypes(DataFlowValueFactory.createDataFlowValue(this, theType1, context, module))
return if (possibleTypes.isNotEmpty()) possibleTypes.toTypedArray() else arrayOf(theType1)
}
@@ -182,13 +182,13 @@ data class ExtractionData(
val dataFlowInfo = context.getDataFlowInfo(expression)
(resolvedCall?.getImplicitReceiverValue() as? ImplicitReceiver)?.let {
return dataFlowInfo.getPossibleTypes(DataFlowValueFactory.createDataFlowValueForStableReceiver(it))
return dataFlowInfo.getCollectedTypes(DataFlowValueFactory.createDataFlowValueForStableReceiver(it))
}
val type = resolvedCall?.resultingDescriptor?.returnType ?: return emptySet()
val containingDescriptor = expression.getResolutionScope(context, expression.getResolutionFacade()).ownerDescriptor
val dataFlowValue = DataFlowValueFactory.createDataFlowValue(expression, type, context, containingDescriptor)
return dataFlowInfo.getPossibleTypes(dataFlowValue)
return dataFlowInfo.getCollectedTypes(dataFlowValue)
}
fun getBrokenReferencesInfo(body: KtBlockExpression): List<ResolvedReferenceInfo> {
@@ -313,7 +313,7 @@ private fun suggestParameterType(
receiverToExtract is ImplicitReceiver -> {
val typeByDataFlowInfo = if (useSmartCastsIfPossible) {
val dataFlowInfo = bindingContext.getDataFlowInfo(resolvedCall!!.call.callElement)
val possibleTypes = dataFlowInfo.getPossibleTypes(DataFlowValueFactory.createDataFlowValueForStableReceiver(receiverToExtract))
val possibleTypes = dataFlowInfo.getCollectedTypes(DataFlowValueFactory.createDataFlowValueForStableReceiver(receiverToExtract))
if (possibleTypes.isNotEmpty()) CommonSupertypes.commonSupertype(possibleTypes) else null
} else null
typeByDataFlowInfo ?: receiverToExtract.type