Minor, remove DataFlowValueFactory.INSTANCE

DataFlowValueFactory's methods are all static
This commit is contained in:
Alexander Udalov
2013-09-12 10:51:40 +02:00
committed by Alexander Udalov
parent 7e72494ddb
commit 7d64b84c42
6 changed files with 29 additions and 34 deletions
@@ -665,7 +665,7 @@ public class CandidateResolver {
) {
if (argumentExpression == null || type == null) return type;
DataFlowValue dataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(
JetPsiUtil.unwrapFromBlock(argumentExpression), type, trace.getBindingContext());
Set<JetType> possibleTypes = dataFlowInfoForArgument.getPossibleTypes(dataFlowValue);
if (possibleTypes.isEmpty()) return type;
@@ -858,7 +858,7 @@ public class CandidateResolver {
context.tracing.unsafeCall(trace, receiverArgumentType, implicitInvokeCheck);
return UNSAFE_CALL_ERROR;
}
DataFlowValue receiverValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(receiverArgument, bindingContext);
DataFlowValue receiverValue = DataFlowValueFactory.createDataFlowValue(receiverArgument, bindingContext);
if (safeAccess && !context.dataFlowInfo.getNullability(receiverValue).canBeNull()) {
context.tracing.unnecessarySafeCall(trace, receiverArgumentType);
}
@@ -69,8 +69,8 @@ public class AutoCastUtils {
@Override
public List<ReceiverValue> visitExpressionReceiver(ExpressionReceiver receiver, Object data) {
DataFlowValue dataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(receiver.getExpression(), receiver.getType(),
bindingContext);
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiver.getExpression(), receiver.getType(),
bindingContext);
List<ReceiverValue> result = Lists.newArrayList();
for (JetType possibleType : dataFlowInfo.getPossibleTypes(dataFlowValue)) {
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) {
assert receiver.exists();
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));
}
return result;
@@ -30,18 +30,18 @@ import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils;
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.RESOLVED_CALL;
public class DataFlowValueFactory {
public static final DataFlowValueFactory INSTANCE = new DataFlowValueFactory();
private DataFlowValueFactory() {}
@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) {
JetConstantExpression constantExpression = (JetConstantExpression) expression;
if (constantExpression.getNode().getElementType() == JetNodeTypes.NULL) return DataFlowValue.NULL;
@@ -52,19 +52,13 @@ public class DataFlowValueFactory {
}
@NotNull
public DataFlowValue createDataFlowValue(@NotNull ThisReceiver receiver) {
public static DataFlowValue createDataFlowValue(@NotNull ThisReceiver receiver) {
JetType type = receiver.getType();
return new DataFlowValue(receiver, type, true, getImmanentNullability(type));
}
@NotNull
public DataFlowValue createDataFlowValue(@NotNull VariableDescriptor variableDescriptor) {
JetType type = variableDescriptor.getType();
return new DataFlowValue(variableDescriptor, type, isStableVariable(variableDescriptor), getImmanentNullability(type));
}
@NotNull
public DataFlowValue createDataFlowValue(@NotNull ReceiverValue receiverValue, @NotNull BindingContext bindingContext) {
public static DataFlowValue createDataFlowValue(@NotNull ReceiverValue receiverValue, @NotNull BindingContext bindingContext) {
return receiverValue.accept(new ReceiverValueVisitor<DataFlowValue, BindingContext>() {
@Override
public DataFlowValue visitNoReceiver(ReceiverValue noReceiver, BindingContext data) {
@@ -105,7 +99,8 @@ public class DataFlowValueFactory {
}, 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;
}
@@ -200,8 +200,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
checkBinaryWithTypeRHS(expression, contextWithNoExpectedType, targetType, subjectType);
dataFlowInfo = typeInfo.getDataFlowInfo();
if (operationType == AS_KEYWORD) {
DataFlowValue value =
DataFlowValueFactory.INSTANCE.createDataFlowValue(left, subjectType, context.trace.getBindingContext());
DataFlowValue value = DataFlowValueFactory.createDataFlowValue(left, subjectType, context.trace.getBindingContext());
dataFlowInfo = dataFlowInfo.establishSubtyping(value, targetType);
}
}
@@ -709,7 +708,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
context.trace.report(UNNECESSARY_NOT_NULL_ASSERTION.on(operationSign, baseType));
}
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);
}
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) {
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();
}
@@ -1016,7 +1015,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetType type = facade.getTypeInfo(expr, context).getType();
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);
boolean expressionIsAlways;
@@ -24,11 +24,10 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
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.DataFlowValue;
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.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType;
@@ -91,8 +90,8 @@ public class DataFlowUtils {
if (rhsType == null) return;
BindingContext bindingContext = context.trace.getBindingContext();
DataFlowValue leftValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(left, lhsType, bindingContext);
DataFlowValue rightValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(right, rhsType, bindingContext);
DataFlowValue leftValue = DataFlowValueFactory.createDataFlowValue(left, lhsType, bindingContext);
DataFlowValue rightValue = DataFlowValueFactory.createDataFlowValue(right, rhsType, bindingContext);
Boolean equals = null;
if (operationToken == JetTokens.EQEQ || operationToken == JetTokens.EQEQEQ) {
@@ -179,7 +178,7 @@ public class DataFlowUtils {
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)) {
if (JetTypeChecker.INSTANCE.isSubtypeOf(possibleType, expectedType)) {
if (dataFlowValue.isStableIdentifier()) {
@@ -37,8 +37,9 @@ import java.util.Collections;
import java.util.Set;
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.resolve.calls.context.ContextDependency.*;
import static org.jetbrains.jet.lang.types.TypeUtils.*;
import static org.jetbrains.jet.lang.resolve.calls.context.ContextDependency.INDEPENDENT;
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;
public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
@@ -54,7 +55,8 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
JetType knownType = typeInfo.getType();
DataFlowInfo dataFlowInfo = typeInfo.getDataFlowInfo();
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 newDataFlowInfo = conditionInfo.and(dataFlowInfo);
context.trace.record(BindingContext.DATAFLOW_INFO_AFTER_CONDITION, expression, newDataFlowInfo);
@@ -84,7 +86,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
context = context.replaceDataFlowInfo(typeInfo.getDataFlowInfo());
}
DataFlowValue subjectDataFlowValue = subjectExpression != null
? DataFlowValueFactory.INSTANCE.createDataFlowValue(subjectExpression, subjectType, context.trace.getBindingContext())
? DataFlowValueFactory.createDataFlowValue(subjectExpression, subjectType, context.trace.getBindingContext())
: DataFlowValue.NULL;
// TODO : exhaustive patterns
@@ -263,7 +265,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
}
checkTypeCompatibility(context, type, subjectType, expression);
DataFlowValue expressionDataFlowValue =
DataFlowValueFactory.INSTANCE.createDataFlowValue(expression, type, context.trace.getBindingContext());
DataFlowValueFactory.createDataFlowValue(expression, type, context.trace.getBindingContext());
DataFlowInfos result = noChange(context);
result = new DataFlowInfos(
result.thenInfo.equate(subjectDataFlowValue, expressionDataFlowValue),