Get rid of MutableDataFlorInfoForArguments.setInitialDataFlowInfo
This commit is contained in:
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.resolve.calls.ValueArgumentsToParametersMapper
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.getExplicitReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
|
||||
@@ -112,7 +113,7 @@ fun getExpectedTypePredicate(
|
||||
resolutionCandidate,
|
||||
DelegatingBindingTrace(bindingContext, "Compute type predicates for unresolved call arguments"),
|
||||
TracingStrategy.EMPTY,
|
||||
DataFlowInfoForArgumentsImpl(call)
|
||||
DataFlowInfoForArgumentsImpl(DataFlowInfo.EMPTY, call)
|
||||
)
|
||||
val status = ValueArgumentsToParametersMapper.mapValueArgumentsToParameters(call,
|
||||
TracingStrategy.EMPTY,
|
||||
|
||||
@@ -313,7 +313,6 @@ public class ArgumentTypeResolver {
|
||||
) {
|
||||
MutableDataFlowInfoForArguments infoForArguments = context.dataFlowInfoForArguments;
|
||||
Call call = context.call;
|
||||
infoForArguments.setInitialDataFlowInfo(context.dataFlowInfo);
|
||||
|
||||
for (ValueArgument argument : call.getValueArguments()) {
|
||||
KtExpression expression = argument.getArgumentExpression();
|
||||
|
||||
+2
-2
@@ -60,10 +60,10 @@ public abstract class CallResolutionContext<Context extends CallResolutionContex
|
||||
this.dataFlowInfoForArguments = dataFlowInfoForArguments;
|
||||
}
|
||||
else if (checkArguments == CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS) {
|
||||
this.dataFlowInfoForArguments = new DataFlowInfoForArgumentsImpl(call);
|
||||
this.dataFlowInfoForArguments = new DataFlowInfoForArgumentsImpl(dataFlowInfo, call);
|
||||
}
|
||||
else {
|
||||
this.dataFlowInfoForArguments = new MutableDataFlowInfoForArguments.WithoutArgumentsCheck();
|
||||
this.dataFlowInfoForArguments = new MutableDataFlowInfoForArguments.WithoutArgumentsCheck(dataFlowInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-17
@@ -27,15 +27,13 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DataFlowInfoForArgumentsImpl implements MutableDataFlowInfoForArguments {
|
||||
@NotNull private final Call call; //for better debug messages only
|
||||
public class DataFlowInfoForArgumentsImpl extends MutableDataFlowInfoForArguments {
|
||||
@Nullable private Map<ValueArgument, DataFlowInfo> infoMap = null;
|
||||
@Nullable private Map<ValueArgument, ValueArgument> nextArgument = null;
|
||||
@Nullable private DataFlowInfo initialInfo;
|
||||
@Nullable private DataFlowInfo resultInfo;
|
||||
|
||||
public DataFlowInfoForArgumentsImpl(@NotNull Call call) {
|
||||
this.call = call;
|
||||
public DataFlowInfoForArgumentsImpl(@NotNull DataFlowInfo initialInfo, @NotNull Call call) {
|
||||
super(initialInfo);
|
||||
initNextArgMap(call.getValueArguments());
|
||||
}
|
||||
|
||||
@@ -54,21 +52,14 @@ public class DataFlowInfoForArgumentsImpl implements MutableDataFlowInfoForArgum
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInitialDataFlowInfo(@NotNull DataFlowInfo dataFlowInfo) {
|
||||
//TODO assert initialInfo == null
|
||||
initialInfo = dataFlowInfo;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DataFlowInfo getInfo(@NotNull ValueArgument valueArgument) {
|
||||
assert initialInfo != null : "Initial data flow info was not set for call: " + call;
|
||||
DataFlowInfo infoForArgument = infoMap == null ? null : infoMap.get(valueArgument);
|
||||
if (infoForArgument == null) {
|
||||
return initialInfo;
|
||||
return initialDataFlowInfo;
|
||||
}
|
||||
return initialInfo.and(infoForArgument);
|
||||
return initialDataFlowInfo.and(infoForArgument);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,8 +79,7 @@ public class DataFlowInfoForArgumentsImpl implements MutableDataFlowInfoForArgum
|
||||
@NotNull
|
||||
@Override
|
||||
public DataFlowInfo getResultInfo() {
|
||||
assert initialInfo != null : "Initial data flow info was not set for call: " + call;
|
||||
if (resultInfo == null) return initialInfo;
|
||||
return initialInfo.and(resultInfo);
|
||||
if (resultInfo == null) return initialDataFlowInfo;
|
||||
return initialDataFlowInfo.and(resultInfo);
|
||||
}
|
||||
}
|
||||
|
||||
+16
-14
@@ -20,18 +20,26 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.psi.ValueArgument;
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||
|
||||
public interface MutableDataFlowInfoForArguments extends DataFlowInfoForArguments {
|
||||
public abstract class MutableDataFlowInfoForArguments implements DataFlowInfoForArguments {
|
||||
|
||||
void setInitialDataFlowInfo(@NotNull DataFlowInfo dataFlowInfo);
|
||||
@NotNull protected final DataFlowInfo initialDataFlowInfo;
|
||||
|
||||
void updateInfo(@NotNull ValueArgument valueArgument, @NotNull DataFlowInfo dataFlowInfo);
|
||||
public MutableDataFlowInfoForArguments(@NotNull DataFlowInfo initialDataFlowInfo) {
|
||||
this.initialDataFlowInfo = initialDataFlowInfo;
|
||||
}
|
||||
|
||||
class WithoutArgumentsCheck implements MutableDataFlowInfoForArguments {
|
||||
private DataFlowInfo dataFlowInfo;
|
||||
public abstract void updateInfo(@NotNull ValueArgument valueArgument, @NotNull DataFlowInfo dataFlowInfo);
|
||||
|
||||
@Override
|
||||
public void setInitialDataFlowInfo(@NotNull DataFlowInfo dataFlowInfo) {
|
||||
this.dataFlowInfo = dataFlowInfo;
|
||||
@NotNull
|
||||
@Override
|
||||
public DataFlowInfo getResultInfo() {
|
||||
return initialDataFlowInfo;
|
||||
}
|
||||
|
||||
public static class WithoutArgumentsCheck extends MutableDataFlowInfoForArguments {
|
||||
|
||||
public WithoutArgumentsCheck(@NotNull DataFlowInfo dataFlowInfo) {
|
||||
super(dataFlowInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,11 +52,5 @@ public interface MutableDataFlowInfoForArguments extends DataFlowInfoForArgument
|
||||
public DataFlowInfo getInfo(@NotNull ValueArgument valueArgument) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DataFlowInfo getResultInfo() {
|
||||
return dataFlowInfo;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+1
-1
@@ -564,7 +564,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
ResolvedCallImpl.create(resolutionCandidate,
|
||||
TemporaryBindingTrace.create(trace, "Fake trace for fake 'this' or 'super' resolved call"),
|
||||
TracingStrategy.EMPTY,
|
||||
new DataFlowInfoForArgumentsImpl(call));
|
||||
new DataFlowInfoForArgumentsImpl(context.dataFlowInfo, call));
|
||||
resolvedCall.markCallAsCompleted();
|
||||
|
||||
trace.record(RESOLVED_CALL, call, resolvedCall);
|
||||
|
||||
+4
-15
@@ -157,15 +157,10 @@ public class ControlStructureTypingUtils {
|
||||
}
|
||||
|
||||
/*package*/ static MutableDataFlowInfoForArguments createIndependentDataFlowInfoForArgumentsForCall(
|
||||
@NotNull DataFlowInfo initialDataFlowInfo,
|
||||
final Map<ValueArgument, DataFlowInfo> dataFlowInfoForArgumentsMap
|
||||
) {
|
||||
return new MutableDataFlowInfoForArguments() {
|
||||
private DataFlowInfo initialDataFlowInfo;
|
||||
|
||||
@Override
|
||||
public void setInitialDataFlowInfo(@NotNull DataFlowInfo dataFlowInfo) {
|
||||
this.initialDataFlowInfo = dataFlowInfo;
|
||||
}
|
||||
return new MutableDataFlowInfoForArguments(initialDataFlowInfo) {
|
||||
|
||||
@Override
|
||||
public void updateInfo(@NotNull ValueArgument valueArgument, @NotNull DataFlowInfo dataFlowInfo) {
|
||||
@@ -177,25 +172,19 @@ public class ControlStructureTypingUtils {
|
||||
public DataFlowInfo getInfo(@NotNull ValueArgument valueArgument) {
|
||||
return dataFlowInfoForArgumentsMap.get(valueArgument);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DataFlowInfo getResultInfo() {
|
||||
//todo merge and use
|
||||
return initialDataFlowInfo;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static MutableDataFlowInfoForArguments createDataFlowInfoForArgumentsForIfCall(
|
||||
@NotNull Call callForIf,
|
||||
@NotNull DataFlowInfo conditionInfo,
|
||||
@NotNull DataFlowInfo thenInfo,
|
||||
@NotNull DataFlowInfo elseInfo
|
||||
) {
|
||||
Map<ValueArgument, DataFlowInfo> dataFlowInfoForArgumentsMap = Maps.newHashMap();
|
||||
dataFlowInfoForArgumentsMap.put(callForIf.getValueArguments().get(0), thenInfo);
|
||||
dataFlowInfoForArgumentsMap.put(callForIf.getValueArguments().get(1), elseInfo);
|
||||
return createIndependentDataFlowInfoForArgumentsForCall(dataFlowInfoForArgumentsMap);
|
||||
return createIndependentDataFlowInfoForArgumentsForCall(conditionInfo, dataFlowInfoForArgumentsMap);
|
||||
}
|
||||
|
||||
/*package*/ static Call createCallForSpecialConstruction(
|
||||
|
||||
+1
-1
@@ -125,7 +125,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
KtBlockExpression elseBlock = psiFactory.wrapInABlockWrapper(elseBranch);
|
||||
Call callForIf = createCallForSpecialConstruction(ifExpression, ifExpression, Lists.newArrayList(thenBlock, elseBlock));
|
||||
MutableDataFlowInfoForArguments dataFlowInfoForArguments =
|
||||
createDataFlowInfoForArgumentsForIfCall(callForIf, thenInfo, elseInfo);
|
||||
createDataFlowInfoForArgumentsForIfCall(callForIf, conditionDataFlowInfo, thenInfo, elseInfo);
|
||||
ResolvedCall<FunctionDescriptor> resolvedCall = components.controlStructureTypingUtils.resolveSpecialConstructionAsCall(
|
||||
callForIf, ResolveConstruct.IF, Lists.newArrayList("thenBranch", "elseBranch"),
|
||||
Lists.newArrayList(false, false),
|
||||
|
||||
Reference in New Issue
Block a user