diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java index f1dd2f4ceae..ade3fbfb5ab 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java @@ -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 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); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastUtils.java index 36cb89f5e46..2760c59c58f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastUtils.java @@ -69,8 +69,8 @@ public class AutoCastUtils { @Override public List 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 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 castThis(@NotNull DataFlowInfo dataFlowInfo, @NotNull ThisReceiver receiver) { assert receiver.exists(); List 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; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DataFlowValueFactory.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DataFlowValueFactory.java index 4b095e3a7d8..d11aa507e46 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DataFlowValueFactory.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DataFlowValueFactory.java @@ -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() { @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; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index 91069ce893d..370dd4a0828 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -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; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/DataFlowUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/DataFlowUtils.java index e3790780899..e2fb2c3fcf5 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/DataFlowUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/DataFlowUtils.java @@ -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()) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java index f5ce19361d2..efb9959dc70 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java @@ -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),