Minor, remove DataFlowValueFactory.INSTANCE
DataFlowValueFactory's methods are all static
This commit is contained in:
committed by
Alexander Udalov
parent
7e72494ddb
commit
7d64b84c42
@@ -665,7 +665,7 @@ public class CandidateResolver {
|
|||||||
) {
|
) {
|
||||||
if (argumentExpression == null || type == null) return type;
|
if (argumentExpression == null || type == null) return type;
|
||||||
|
|
||||||
DataFlowValue dataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(
|
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(
|
||||||
JetPsiUtil.unwrapFromBlock(argumentExpression), type, trace.getBindingContext());
|
JetPsiUtil.unwrapFromBlock(argumentExpression), type, trace.getBindingContext());
|
||||||
Set<JetType> possibleTypes = dataFlowInfoForArgument.getPossibleTypes(dataFlowValue);
|
Set<JetType> possibleTypes = dataFlowInfoForArgument.getPossibleTypes(dataFlowValue);
|
||||||
if (possibleTypes.isEmpty()) return type;
|
if (possibleTypes.isEmpty()) return type;
|
||||||
@@ -858,7 +858,7 @@ public class CandidateResolver {
|
|||||||
context.tracing.unsafeCall(trace, receiverArgumentType, implicitInvokeCheck);
|
context.tracing.unsafeCall(trace, receiverArgumentType, implicitInvokeCheck);
|
||||||
return UNSAFE_CALL_ERROR;
|
return UNSAFE_CALL_ERROR;
|
||||||
}
|
}
|
||||||
DataFlowValue receiverValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(receiverArgument, bindingContext);
|
DataFlowValue receiverValue = DataFlowValueFactory.createDataFlowValue(receiverArgument, bindingContext);
|
||||||
if (safeAccess && !context.dataFlowInfo.getNullability(receiverValue).canBeNull()) {
|
if (safeAccess && !context.dataFlowInfo.getNullability(receiverValue).canBeNull()) {
|
||||||
context.tracing.unnecessarySafeCall(trace, receiverArgumentType);
|
context.tracing.unnecessarySafeCall(trace, receiverArgumentType);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -69,8 +69,8 @@ public class AutoCastUtils {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ReceiverValue> visitExpressionReceiver(ExpressionReceiver receiver, Object data) {
|
public List<ReceiverValue> visitExpressionReceiver(ExpressionReceiver receiver, Object data) {
|
||||||
DataFlowValue dataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(receiver.getExpression(), receiver.getType(),
|
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiver.getExpression(), receiver.getType(),
|
||||||
bindingContext);
|
bindingContext);
|
||||||
List<ReceiverValue> result = Lists.newArrayList();
|
List<ReceiverValue> result = Lists.newArrayList();
|
||||||
for (JetType possibleType : dataFlowInfo.getPossibleTypes(dataFlowValue)) {
|
for (JetType possibleType : dataFlowInfo.getPossibleTypes(dataFlowValue)) {
|
||||||
result.add(new AutoCastReceiver(receiver, possibleType, dataFlowValue.isStableIdentifier()));
|
result.add(new AutoCastReceiver(receiver, possibleType, dataFlowValue.isStableIdentifier()));
|
||||||
@@ -83,7 +83,7 @@ public class AutoCastUtils {
|
|||||||
private static List<ReceiverValue> castThis(@NotNull DataFlowInfo dataFlowInfo, @NotNull ThisReceiver receiver) {
|
private static List<ReceiverValue> castThis(@NotNull DataFlowInfo dataFlowInfo, @NotNull ThisReceiver receiver) {
|
||||||
assert receiver.exists();
|
assert receiver.exists();
|
||||||
List<ReceiverValue> result = Lists.newArrayList();
|
List<ReceiverValue> result = Lists.newArrayList();
|
||||||
for (JetType possibleType : dataFlowInfo.getPossibleTypes(DataFlowValueFactory.INSTANCE.createDataFlowValue(receiver))) {
|
for (JetType possibleType : dataFlowInfo.getPossibleTypes(DataFlowValueFactory.createDataFlowValue(receiver))) {
|
||||||
result.add(new AutoCastReceiver(receiver, possibleType, true));
|
result.add(new AutoCastReceiver(receiver, possibleType, true));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+9
-14
@@ -30,18 +30,18 @@ import org.jetbrains.jet.lang.types.JetType;
|
|||||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
|
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
|
||||||
|
|
||||||
public class DataFlowValueFactory {
|
public class DataFlowValueFactory {
|
||||||
public static final DataFlowValueFactory INSTANCE = new DataFlowValueFactory();
|
|
||||||
|
|
||||||
private DataFlowValueFactory() {}
|
private DataFlowValueFactory() {}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public DataFlowValue createDataFlowValue(@NotNull JetExpression expression, @NotNull JetType type, @NotNull BindingContext bindingContext) {
|
public static DataFlowValue createDataFlowValue(
|
||||||
|
@NotNull JetExpression expression,
|
||||||
|
@NotNull JetType type,
|
||||||
|
@NotNull BindingContext bindingContext
|
||||||
|
) {
|
||||||
if (expression instanceof JetConstantExpression) {
|
if (expression instanceof JetConstantExpression) {
|
||||||
JetConstantExpression constantExpression = (JetConstantExpression) expression;
|
JetConstantExpression constantExpression = (JetConstantExpression) expression;
|
||||||
if (constantExpression.getNode().getElementType() == JetNodeTypes.NULL) return DataFlowValue.NULL;
|
if (constantExpression.getNode().getElementType() == JetNodeTypes.NULL) return DataFlowValue.NULL;
|
||||||
@@ -52,19 +52,13 @@ public class DataFlowValueFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public DataFlowValue createDataFlowValue(@NotNull ThisReceiver receiver) {
|
public static DataFlowValue createDataFlowValue(@NotNull ThisReceiver receiver) {
|
||||||
JetType type = receiver.getType();
|
JetType type = receiver.getType();
|
||||||
return new DataFlowValue(receiver, type, true, getImmanentNullability(type));
|
return new DataFlowValue(receiver, type, true, getImmanentNullability(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public DataFlowValue createDataFlowValue(@NotNull VariableDescriptor variableDescriptor) {
|
public static DataFlowValue createDataFlowValue(@NotNull ReceiverValue receiverValue, @NotNull BindingContext bindingContext) {
|
||||||
JetType type = variableDescriptor.getType();
|
|
||||||
return new DataFlowValue(variableDescriptor, type, isStableVariable(variableDescriptor), getImmanentNullability(type));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public DataFlowValue createDataFlowValue(@NotNull ReceiverValue receiverValue, @NotNull BindingContext bindingContext) {
|
|
||||||
return receiverValue.accept(new ReceiverValueVisitor<DataFlowValue, BindingContext>() {
|
return receiverValue.accept(new ReceiverValueVisitor<DataFlowValue, BindingContext>() {
|
||||||
@Override
|
@Override
|
||||||
public DataFlowValue visitNoReceiver(ReceiverValue noReceiver, BindingContext data) {
|
public DataFlowValue visitNoReceiver(ReceiverValue noReceiver, BindingContext data) {
|
||||||
@@ -105,7 +99,8 @@ public class DataFlowValueFactory {
|
|||||||
}, bindingContext);
|
}, bindingContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Nullability getImmanentNullability(JetType type) {
|
@NotNull
|
||||||
|
private static Nullability getImmanentNullability(@NotNull JetType type) {
|
||||||
return type.isNullable() || TypeUtils.hasNullableSuperType(type) ? Nullability.UNKNOWN : Nullability.NOT_NULL;
|
return type.isNullable() || TypeUtils.hasNullableSuperType(type) ? Nullability.UNKNOWN : Nullability.NOT_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-5
@@ -200,8 +200,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
checkBinaryWithTypeRHS(expression, contextWithNoExpectedType, targetType, subjectType);
|
checkBinaryWithTypeRHS(expression, contextWithNoExpectedType, targetType, subjectType);
|
||||||
dataFlowInfo = typeInfo.getDataFlowInfo();
|
dataFlowInfo = typeInfo.getDataFlowInfo();
|
||||||
if (operationType == AS_KEYWORD) {
|
if (operationType == AS_KEYWORD) {
|
||||||
DataFlowValue value =
|
DataFlowValue value = DataFlowValueFactory.createDataFlowValue(left, subjectType, context.trace.getBindingContext());
|
||||||
DataFlowValueFactory.INSTANCE.createDataFlowValue(left, subjectType, context.trace.getBindingContext());
|
|
||||||
dataFlowInfo = dataFlowInfo.establishSubtyping(value, targetType);
|
dataFlowInfo = dataFlowInfo.establishSubtyping(value, targetType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -709,7 +708,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
context.trace.report(UNNECESSARY_NOT_NULL_ASSERTION.on(operationSign, baseType));
|
context.trace.report(UNNECESSARY_NOT_NULL_ASSERTION.on(operationSign, baseType));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataFlowValue value = DataFlowValueFactory.INSTANCE.createDataFlowValue(baseExpression, baseType, context.trace.getBindingContext());
|
DataFlowValue value = DataFlowValueFactory.createDataFlowValue(baseExpression, baseType, context.trace.getBindingContext());
|
||||||
dataFlowInfo = dataFlowInfo.disequate(value, DataFlowValue.NULL);
|
dataFlowInfo = dataFlowInfo.disequate(value, DataFlowValue.NULL);
|
||||||
}
|
}
|
||||||
return JetTypeInfo.create(TypeUtils.makeNotNullable(baseType), dataFlowInfo);
|
return JetTypeInfo.create(TypeUtils.makeNotNullable(baseType), dataFlowInfo);
|
||||||
@@ -737,7 +736,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isKnownToBeNotNull(JetExpression expression, JetType jetType, ExpressionTypingContext context) {
|
private static boolean isKnownToBeNotNull(JetExpression expression, JetType jetType, ExpressionTypingContext context) {
|
||||||
DataFlowValue dataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(expression, jetType, context.trace.getBindingContext());
|
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(expression, jetType, context.trace.getBindingContext());
|
||||||
return !context.dataFlowInfo.getNullability(dataFlowValue).canBeNull();
|
return !context.dataFlowInfo.getNullability(dataFlowValue).canBeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1016,7 +1015,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetType type = facade.getTypeInfo(expr, context).getType();
|
JetType type = facade.getTypeInfo(expr, context).getType();
|
||||||
if (type == null || ErrorUtils.isErrorType(type)) return;
|
if (type == null || ErrorUtils.isErrorType(type)) return;
|
||||||
|
|
||||||
DataFlowValue value = DataFlowValueFactory.INSTANCE.createDataFlowValue(expr, type, context.trace.getBindingContext());
|
DataFlowValue value = DataFlowValueFactory.createDataFlowValue(expr, type, context.trace.getBindingContext());
|
||||||
Nullability nullability = context.dataFlowInfo.getNullability(value);
|
Nullability nullability = context.dataFlowInfo.getNullability(value);
|
||||||
|
|
||||||
boolean expressionIsAlways;
|
boolean expressionIsAlways;
|
||||||
|
|||||||
@@ -24,11 +24,10 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
|||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.context.ContextDependency;
|
|
||||||
import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext;
|
|
||||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue;
|
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory;
|
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstantResolver;
|
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstantResolver;
|
||||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
@@ -91,8 +90,8 @@ public class DataFlowUtils {
|
|||||||
if (rhsType == null) return;
|
if (rhsType == null) return;
|
||||||
|
|
||||||
BindingContext bindingContext = context.trace.getBindingContext();
|
BindingContext bindingContext = context.trace.getBindingContext();
|
||||||
DataFlowValue leftValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(left, lhsType, bindingContext);
|
DataFlowValue leftValue = DataFlowValueFactory.createDataFlowValue(left, lhsType, bindingContext);
|
||||||
DataFlowValue rightValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(right, rhsType, bindingContext);
|
DataFlowValue rightValue = DataFlowValueFactory.createDataFlowValue(right, rhsType, bindingContext);
|
||||||
|
|
||||||
Boolean equals = null;
|
Boolean equals = null;
|
||||||
if (operationToken == JetTokens.EQEQ || operationToken == JetTokens.EQEQEQ) {
|
if (operationToken == JetTokens.EQEQ || operationToken == JetTokens.EQEQEQ) {
|
||||||
@@ -179,7 +178,7 @@ public class DataFlowUtils {
|
|||||||
return expressionType;
|
return expressionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataFlowValue dataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(expression, expressionType, trace.getBindingContext());
|
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(expression, expressionType, trace.getBindingContext());
|
||||||
for (JetType possibleType : dataFlowInfo.getPossibleTypes(dataFlowValue)) {
|
for (JetType possibleType : dataFlowInfo.getPossibleTypes(dataFlowValue)) {
|
||||||
if (JetTypeChecker.INSTANCE.isSubtypeOf(possibleType, expectedType)) {
|
if (JetTypeChecker.INSTANCE.isSubtypeOf(possibleType, expectedType)) {
|
||||||
if (dataFlowValue.isStableIdentifier()) {
|
if (dataFlowValue.isStableIdentifier()) {
|
||||||
|
|||||||
+7
-5
@@ -37,8 +37,9 @@ import java.util.Collections;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||||
import static org.jetbrains.jet.lang.resolve.calls.context.ContextDependency.*;
|
import static org.jetbrains.jet.lang.resolve.calls.context.ContextDependency.INDEPENDENT;
|
||||||
import static org.jetbrains.jet.lang.types.TypeUtils.*;
|
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||||
|
import static org.jetbrains.jet.lang.types.TypeUtils.isIntersectionEmpty;
|
||||||
import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.newWritableScopeImpl;
|
import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.newWritableScopeImpl;
|
||||||
|
|
||||||
public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
||||||
@@ -54,7 +55,8 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetType knownType = typeInfo.getType();
|
JetType knownType = typeInfo.getType();
|
||||||
DataFlowInfo dataFlowInfo = typeInfo.getDataFlowInfo();
|
DataFlowInfo dataFlowInfo = typeInfo.getDataFlowInfo();
|
||||||
if (expression.getTypeRef() != null) {
|
if (expression.getTypeRef() != null) {
|
||||||
DataFlowValue dataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(leftHandSide, knownType, context.trace.getBindingContext());
|
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(leftHandSide, knownType,
|
||||||
|
context.trace.getBindingContext());
|
||||||
DataFlowInfo conditionInfo = checkTypeForIs(context, knownType, expression.getTypeRef(), dataFlowValue).thenInfo;
|
DataFlowInfo conditionInfo = checkTypeForIs(context, knownType, expression.getTypeRef(), dataFlowValue).thenInfo;
|
||||||
DataFlowInfo newDataFlowInfo = conditionInfo.and(dataFlowInfo);
|
DataFlowInfo newDataFlowInfo = conditionInfo.and(dataFlowInfo);
|
||||||
context.trace.record(BindingContext.DATAFLOW_INFO_AFTER_CONDITION, expression, newDataFlowInfo);
|
context.trace.record(BindingContext.DATAFLOW_INFO_AFTER_CONDITION, expression, newDataFlowInfo);
|
||||||
@@ -84,7 +86,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
context = context.replaceDataFlowInfo(typeInfo.getDataFlowInfo());
|
context = context.replaceDataFlowInfo(typeInfo.getDataFlowInfo());
|
||||||
}
|
}
|
||||||
DataFlowValue subjectDataFlowValue = subjectExpression != null
|
DataFlowValue subjectDataFlowValue = subjectExpression != null
|
||||||
? DataFlowValueFactory.INSTANCE.createDataFlowValue(subjectExpression, subjectType, context.trace.getBindingContext())
|
? DataFlowValueFactory.createDataFlowValue(subjectExpression, subjectType, context.trace.getBindingContext())
|
||||||
: DataFlowValue.NULL;
|
: DataFlowValue.NULL;
|
||||||
|
|
||||||
// TODO : exhaustive patterns
|
// TODO : exhaustive patterns
|
||||||
@@ -263,7 +265,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
checkTypeCompatibility(context, type, subjectType, expression);
|
checkTypeCompatibility(context, type, subjectType, expression);
|
||||||
DataFlowValue expressionDataFlowValue =
|
DataFlowValue expressionDataFlowValue =
|
||||||
DataFlowValueFactory.INSTANCE.createDataFlowValue(expression, type, context.trace.getBindingContext());
|
DataFlowValueFactory.createDataFlowValue(expression, type, context.trace.getBindingContext());
|
||||||
DataFlowInfos result = noChange(context);
|
DataFlowInfos result = noChange(context);
|
||||||
result = new DataFlowInfos(
|
result = new DataFlowInfos(
|
||||||
result.thenInfo.equate(subjectDataFlowValue, expressionDataFlowValue),
|
result.thenInfo.equate(subjectDataFlowValue, expressionDataFlowValue),
|
||||||
|
|||||||
Reference in New Issue
Block a user