Build fix. The second version of DataFlowInfo.getPossibleTypes returning also the original type added and used.

This commit is contained in:
Mikhail Glukhikh
2015-04-17 11:49:44 +03:00
parent 6421f48c07
commit 86bb0d5bc5
5 changed files with 31 additions and 10 deletions
@@ -40,12 +40,23 @@ public interface DataFlowInfo {
@NotNull @NotNull
Nullability getNullability(@NotNull DataFlowValue key); Nullability getNullability(@NotNull DataFlowValue key);
/**
* Gets a set of all possible types for this value, INCLUDING the original (native) type
*/
@NotNull
Set<JetType> getPossibleTypes(@NotNull DataFlowValue key, boolean withOriginalType);
/**
* IMPORTANT: by default, the original (native) type for this value
* are NOT included. So it's quite possible to get an empty set here.
* If you need also the original type, use getPossibleTypes(key, true)
*/
@NotNull @NotNull
Set<JetType> getPossibleTypes(@NotNull DataFlowValue key); Set<JetType> getPossibleTypes(@NotNull DataFlowValue key);
/** /**
* Call this function to clear all data flow information about * Call this function to clear all data flow information about
* the given data flow value. * the given data flow value. Useful when we are not sure how this value can be changed, e.g. in a loop.
*/ */
@NotNull @NotNull
DataFlowInfo clearValueInfo(@NotNull DataFlowValue value); DataFlowInfo clearValueInfo(@NotNull DataFlowValue value);
@@ -33,17 +33,17 @@ public class DataFlowValue {
public static final DataFlowValue ERROR = new DataFlowValue(new Object(), ErrorUtils.createErrorType("Error type for data flow"), false, false, Nullability.IMPOSSIBLE); public static final DataFlowValue ERROR = new DataFlowValue(new Object(), ErrorUtils.createErrorType("Error type for data flow"), false, false, Nullability.IMPOSSIBLE);
private final boolean stableIdentifier; private final boolean stableIdentifier;
private final boolean uncapturedlocalVariable; private final boolean uncapturedLocalVariable;
private final JetType type; private final JetType type;
private final Object id; private final Object id;
private final Nullability immanentNullability; private final Nullability immanentNullability;
// Use DataFlowValueFactory // Use DataFlowValueFactory
/*package*/ DataFlowValue(Object id, JetType type, boolean stableIdentifier, boolean uncapturedlocalVariable, Nullability immanentNullability) { /*package*/ DataFlowValue(Object id, JetType type, boolean stableIdentifier, boolean uncapturedLocalVariable, Nullability immanentNullability) {
assert !stableIdentifier || !uncapturedlocalVariable : assert !stableIdentifier || !uncapturedLocalVariable :
"data flow value cannot be together a stable identifier and an uncaptured local variable"; "data flow value for object " + id + " cannot be together a stable identifier and an uncaptured local variable";
this.stableIdentifier = stableIdentifier; this.stableIdentifier = stableIdentifier;
this.uncapturedlocalVariable = uncapturedlocalVariable; this.uncapturedLocalVariable = uncapturedLocalVariable;
this.type = type; this.type = type;
this.id = id; this.id = id;
this.immanentNullability = immanentNullability; this.immanentNullability = immanentNullability;
@@ -73,7 +73,7 @@ public class DataFlowValue {
* Identifier is considered a local variable here if it's mutable (var), local and not captured in a closure * Identifier is considered a local variable here if it's mutable (var), local and not captured in a closure
*/ */
public boolean isUncapturedLocalVariable() { public boolean isUncapturedLocalVariable() {
return uncapturedlocalVariable; return uncapturedLocalVariable;
} }
/** /**
@@ -82,7 +82,7 @@ public class DataFlowValue {
* like accessing mutable properties in another thread or mutable variables from closures. * like accessing mutable properties in another thread or mutable variables from closures.
*/ */
public boolean isPredictable() { public boolean isPredictable() {
return stableIdentifier || uncapturedlocalVariable; return stableIdentifier || uncapturedLocalVariable;
} }
@NotNull @NotNull
@@ -146,6 +146,7 @@ public class DataFlowValueFactory {
public final boolean isPackage; public final boolean isPackage;
private IdentifierInfo(Object id, boolean isStable, boolean isLocal, boolean isPackage) { private IdentifierInfo(Object id, boolean isStable, boolean isLocal, boolean isPackage) {
assert !isStable || !isLocal : "Identifier info for object " + id + " cannot be stable and local at one time";
this.id = id; this.id = id;
this.isStable = isStable; this.isStable = isStable;
this.isLocal = isLocal; this.isLocal = isLocal;
@@ -131,13 +131,22 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL
@Override @Override
@NotNull @NotNull
public Set<JetType> getPossibleTypes(@NotNull DataFlowValue key) { public Set<JetType> getPossibleTypes(@NotNull DataFlowValue key) {
return getPossibleTypes(key, false);
}
@Override
@NotNull
public Set<JetType> getPossibleTypes(@NotNull DataFlowValue key, boolean withOriginalType) {
JetType originalType = key.getType();
Set<JetType> types = collectTypesFromMeAndParents(key); Set<JetType> types = collectTypesFromMeAndParents(key);
if (withOriginalType) {
types.add(originalType);
}
if (getNullability(key).canBeNull()) { if (getNullability(key).canBeNull()) {
return types; return types;
} }
Set<JetType> enrichedTypes = Sets.newHashSetWithExpectedSize(types.size() + 1); Set<JetType> enrichedTypes = Sets.newHashSetWithExpectedSize(types.size() + 1);
JetType originalType = key.getType();
if (originalType.isMarkedNullable()) { if (originalType.isMarkedNullable()) {
enrichedTypes.add(TypeUtils.makeNotNullable(originalType)); enrichedTypes.add(TypeUtils.makeNotNullable(originalType));
} }
@@ -657,7 +657,7 @@ private fun ExtractionData.inferParametersInfo(
receiverToExtract is ThisReceiver -> { receiverToExtract is ThisReceiver -> {
val calleeExpression = resolvedCall!!.getCall().getCalleeExpression() val calleeExpression = resolvedCall!!.getCall().getCalleeExpression()
bindingContext[BindingContext.EXPRESSION_DATA_FLOW_INFO, calleeExpression]?.let { dataFlowInfo -> bindingContext[BindingContext.EXPRESSION_DATA_FLOW_INFO, calleeExpression]?.let { dataFlowInfo ->
val possibleTypes = dataFlowInfo.getPossibleTypes(DataFlowValueFactory.createDataFlowValue(receiverToExtract)) val possibleTypes = dataFlowInfo.getPossibleTypes(DataFlowValueFactory.createDataFlowValue(receiverToExtract), true)
CommonSupertypes.commonSupertype(possibleTypes) CommonSupertypes.commonSupertype(possibleTypes)
} ?: receiverToExtract.getType() } ?: receiverToExtract.getType()
} }