Code cleanup in BasicExpressionTypingVisitor: added 'statics', removed unused method.
This commit is contained in:
+29
-24
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.types.expressions;
|
package org.jetbrains.jet.lang.types.expressions;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
@@ -174,7 +173,12 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
return DataFlowUtils.checkType(result, expression, context, dataFlowInfo);
|
return DataFlowUtils.checkType(result, expression, context, dataFlowInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkBinaryWithTypeRHS(JetBinaryExpressionWithTypeRHS expression, ExpressionTypingContext context, @NotNull JetType targetType, JetType actualType) {
|
private static boolean checkBinaryWithTypeRHS(
|
||||||
|
JetBinaryExpressionWithTypeRHS expression,
|
||||||
|
ExpressionTypingContext context,
|
||||||
|
@NotNull JetType targetType,
|
||||||
|
JetType actualType
|
||||||
|
) {
|
||||||
JetSimpleNameExpression operationSign = expression.getOperationSign();
|
JetSimpleNameExpression operationSign = expression.getOperationSign();
|
||||||
IElementType operationType = operationSign.getReferencedNameElementType();
|
IElementType operationType = operationSign.getReferencedNameElementType();
|
||||||
if (operationType == JetTokens.COLON) {
|
if (operationType == JetTokens.COLON) {
|
||||||
@@ -194,7 +198,12 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkForCastImpossibility(JetBinaryExpressionWithTypeRHS expression, JetType actualType, JetType targetType, ExpressionTypingContext context) {
|
private static void checkForCastImpossibility(
|
||||||
|
JetBinaryExpressionWithTypeRHS expression,
|
||||||
|
JetType actualType,
|
||||||
|
JetType targetType,
|
||||||
|
ExpressionTypingContext context
|
||||||
|
) {
|
||||||
if (actualType == null || targetType == NO_EXPECTED_TYPE) return;
|
if (actualType == null || targetType == NO_EXPECTED_TYPE) return;
|
||||||
|
|
||||||
JetTypeChecker typeChecker = JetTypeChecker.INSTANCE;
|
JetTypeChecker typeChecker = JetTypeChecker.INSTANCE;
|
||||||
@@ -362,18 +371,6 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private List<JetType> checkArgumentTypes(@NotNull List<JetType> argumentTypes, @NotNull List<JetExpression> arguments, @NotNull List<TypeProjection> expectedArgumentTypes, @NotNull ExpressionTypingContext context) {
|
|
||||||
if (arguments.size() == 0 || argumentTypes.size() != arguments.size() || expectedArgumentTypes.size() != arguments.size()) {
|
|
||||||
return argumentTypes;
|
|
||||||
}
|
|
||||||
List<JetType> result = Lists.newArrayListWithCapacity(arguments.size());
|
|
||||||
for (int i = 0, argumentTypesSize = argumentTypes.size(); i < argumentTypesSize; i++) {
|
|
||||||
result.add(DataFlowUtils.checkType(argumentTypes.get(i), arguments.get(i), context.replaceExpectedType(expectedArgumentTypes.get(i).getType())));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetTypeInfo visitThisExpression(JetThisExpression expression, ExpressionTypingContext context) {
|
public JetTypeInfo visitThisExpression(JetThisExpression expression, ExpressionTypingContext context) {
|
||||||
JetType result = null;
|
JetType result = null;
|
||||||
@@ -419,7 +416,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
throw new IllegalStateException("Unknown code: " + resolutionResult.getCode());
|
throw new IllegalStateException("Unknown code: " + resolutionResult.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
private JetTypeInfo errorInSuper(JetSuperExpression expression, ExpressionTypingContext context) {
|
private static JetTypeInfo errorInSuper(JetSuperExpression expression, ExpressionTypingContext context) {
|
||||||
JetTypeReference superTypeQualifier = expression.getSuperTypeQualifier();
|
JetTypeReference superTypeQualifier = expression.getSuperTypeQualifier();
|
||||||
if (superTypeQualifier != null) {
|
if (superTypeQualifier != null) {
|
||||||
context.expressionTypingServices.getTypeResolver().resolveType(context.scope, superTypeQualifier, context.trace, true);
|
context.expressionTypingServices.getTypeResolver().resolveType(context.scope, superTypeQualifier, context.trace, true);
|
||||||
@@ -427,7 +424,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
return JetTypeInfo.create(null, context.dataFlowInfo);
|
return JetTypeInfo.create(null, context.dataFlowInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private JetType checkPossiblyQualifiedSuper(
|
private static JetType checkPossiblyQualifiedSuper(
|
||||||
JetSuperExpression expression,
|
JetSuperExpression expression,
|
||||||
ExpressionTypingContext context,
|
ExpressionTypingContext context,
|
||||||
ReceiverParameterDescriptor thisReceiver
|
ReceiverParameterDescriptor thisReceiver
|
||||||
@@ -507,7 +504,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull // No class receivers
|
@NotNull // No class receivers
|
||||||
private LabelResolver.LabeledReceiverResolutionResult resolveToReceiver(
|
private static LabelResolver.LabeledReceiverResolutionResult resolveToReceiver(
|
||||||
JetLabelQualifiedInstanceExpression expression,
|
JetLabelQualifiedInstanceExpression expression,
|
||||||
ExpressionTypingContext context,
|
ExpressionTypingContext context,
|
||||||
boolean onlyClassReceivers
|
boolean onlyClassReceivers
|
||||||
@@ -544,7 +541,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDeclaredInClass(ReceiverParameterDescriptor receiver) {
|
private static boolean isDeclaredInClass(ReceiverParameterDescriptor receiver) {
|
||||||
return receiver.getContainingDeclaration() instanceof ClassDescriptor;
|
return receiver.getContainingDeclaration() instanceof ClassDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,7 +550,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
return visitBlockExpression(expression, context, false);
|
return visitBlockExpression(expression, context, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JetTypeInfo visitBlockExpression(JetBlockExpression expression, ExpressionTypingContext context, boolean isStatement) {
|
public static JetTypeInfo visitBlockExpression(JetBlockExpression expression, ExpressionTypingContext context, boolean isStatement) {
|
||||||
return context.expressionTypingServices.getBlockReturnedType(context.scope, expression, isStatement
|
return context.expressionTypingServices.getBlockReturnedType(context.scope, expression, isStatement
|
||||||
? CoercionStrategy.COERCION_TO_UNIT
|
? CoercionStrategy.COERCION_TO_UNIT
|
||||||
: CoercionStrategy.NO_COERCION, context, context.trace);
|
: CoercionStrategy.NO_COERCION, context, context.trace);
|
||||||
@@ -642,6 +639,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetType returnType = resolutionResults.getResultingDescriptor().getReturnType();
|
JetType returnType = resolutionResults.getResultingDescriptor().getReturnType();
|
||||||
JetType result;
|
JetType result;
|
||||||
if (operationType == JetTokens.PLUSPLUS || operationType == JetTokens.MINUSMINUS) {
|
if (operationType == JetTokens.PLUSPLUS || operationType == JetTokens.MINUSMINUS) {
|
||||||
|
assert returnType != null : "returnType is null for " + resolutionResults.getResultingDescriptor();
|
||||||
if (JetTypeChecker.INSTANCE.isSubtypeOf(returnType, KotlinBuiltIns.getInstance().getUnitType())) {
|
if (JetTypeChecker.INSTANCE.isSubtypeOf(returnType, KotlinBuiltIns.getInstance().getUnitType())) {
|
||||||
result = ErrorUtils.createErrorType(KotlinBuiltIns.UNIT_ALIAS.getName());
|
result = ErrorUtils.createErrorType(KotlinBuiltIns.UNIT_ALIAS.getName());
|
||||||
context.trace.report(INC_DEC_SHOULD_NOT_RETURN_UNIT.on(operationSign));
|
context.trace.report(INC_DEC_SHOULD_NOT_RETURN_UNIT.on(operationSign));
|
||||||
@@ -710,18 +708,18 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
return DataFlowUtils.checkType(typeInfo.getType(), expression, context, typeInfo.getDataFlowInfo());
|
return DataFlowUtils.checkType(typeInfo.getType(), expression, context, typeInfo.getDataFlowInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isKnownToBeNotNull(JetExpression expression, ExpressionTypingContext context) {
|
private static boolean isKnownToBeNotNull(JetExpression expression, ExpressionTypingContext context) {
|
||||||
JetType type = context.trace.get(EXPRESSION_TYPE, expression);
|
JetType type = context.trace.get(EXPRESSION_TYPE, expression);
|
||||||
assert type != null : "This method is only supposed to be called when the type is not null";
|
assert type != null : "This method is only supposed to be called when the type is not null";
|
||||||
DataFlowValue dataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(expression, type, context.trace.getBindingContext());
|
DataFlowValue dataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(expression, type, context.trace.getBindingContext());
|
||||||
return !context.dataFlowInfo.getNullability(dataFlowValue).canBeNull();
|
return !context.dataFlowInfo.getNullability(dataFlowValue).canBeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkLValue(BindingTrace trace, JetExpression expression) {
|
public static void checkLValue(BindingTrace trace, JetExpression expression) {
|
||||||
checkLValue(trace, expression, false);
|
checkLValue(trace, expression, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkLValue(BindingTrace trace, JetExpression expressionWithParenthesis, boolean canBeThis) {
|
private static void checkLValue(BindingTrace trace, JetExpression expressionWithParenthesis, boolean canBeThis) {
|
||||||
JetExpression expression = JetPsiUtil.deparenthesizeWithNoTypeResolution(expressionWithParenthesis);
|
JetExpression expression = JetPsiUtil.deparenthesizeWithNoTypeResolution(expressionWithParenthesis);
|
||||||
if (expression instanceof JetArrayAccessExpression) {
|
if (expression instanceof JetArrayAccessExpression) {
|
||||||
checkLValue(trace, ((JetArrayAccessExpression) expression).getArrayExpression(), true);
|
checkLValue(trace, ((JetArrayAccessExpression) expression).getArrayExpression(), true);
|
||||||
@@ -998,7 +996,14 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
/*package*/ OverloadResolutionResults<FunctionDescriptor> getResolutionResultsForBinaryCall(JetScope scope, Name name, ExpressionTypingContext context, JetBinaryExpression binaryExpression, ExpressionReceiver receiver) {
|
static
|
||||||
|
/*package*/ OverloadResolutionResults<FunctionDescriptor> getResolutionResultsForBinaryCall(
|
||||||
|
JetScope scope,
|
||||||
|
Name name,
|
||||||
|
ExpressionTypingContext context,
|
||||||
|
JetBinaryExpression binaryExpression,
|
||||||
|
ExpressionReceiver receiver
|
||||||
|
) {
|
||||||
// ExpressionReceiver receiver = safeGetExpressionReceiver(facade, binaryExpression.getLeft(), context.replaceScope(scope));
|
// ExpressionReceiver receiver = safeGetExpressionReceiver(facade, binaryExpression.getLeft(), context.replaceScope(scope));
|
||||||
return context.replaceScope(scope).resolveCallWithGivenName(
|
return context.replaceScope(scope).resolveCallWithGivenName(
|
||||||
CallMaker.makeCall(receiver, binaryExpression),
|
CallMaker.makeCall(receiver, binaryExpression),
|
||||||
|
|||||||
+13
-7
@@ -69,7 +69,11 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private JetType checkAssignmentType(@Nullable JetType assignmentType, @NotNull JetBinaryExpression expression, @NotNull ExpressionTypingContext context) {
|
private static JetType checkAssignmentType(
|
||||||
|
@Nullable JetType assignmentType,
|
||||||
|
@NotNull JetBinaryExpression expression,
|
||||||
|
@NotNull ExpressionTypingContext context
|
||||||
|
) {
|
||||||
if (assignmentType != null && !KotlinBuiltIns.getInstance().isUnit(assignmentType) && context.expectedType != TypeUtils.NO_EXPECTED_TYPE &&
|
if (assignmentType != null && !KotlinBuiltIns.getInstance().isUnit(assignmentType) && context.expectedType != TypeUtils.NO_EXPECTED_TYPE &&
|
||||||
TypeUtils.equalTypes(context.expectedType, assignmentType)) {
|
TypeUtils.equalTypes(context.expectedType, assignmentType)) {
|
||||||
context.trace.report(Errors.ASSIGNMENT_TYPE_MISMATCH.on(expression, context.expectedType));
|
context.trace.report(Errors.ASSIGNMENT_TYPE_MISMATCH.on(expression, context.expectedType));
|
||||||
@@ -227,13 +231,15 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
// Check for '+='
|
// Check for '+='
|
||||||
Name name = OperatorConventions.ASSIGNMENT_OPERATIONS.get(operationType);
|
Name name = OperatorConventions.ASSIGNMENT_OPERATIONS.get(operationType);
|
||||||
TemporaryBindingTrace assignmentOperationTrace = TemporaryBindingTrace.create(context.trace, "trace to check assignment operation like '+=' for", expression);
|
TemporaryBindingTrace assignmentOperationTrace = TemporaryBindingTrace.create(context.trace, "trace to check assignment operation like '+=' for", expression);
|
||||||
OverloadResolutionResults<FunctionDescriptor> assignmentOperationDescriptors = basic.getResolutionResultsForBinaryCall(scope, name, context.replaceBindingTrace(assignmentOperationTrace), expression, receiver);
|
OverloadResolutionResults<FunctionDescriptor> assignmentOperationDescriptors = BasicExpressionTypingVisitor.getResolutionResultsForBinaryCall(
|
||||||
|
scope, name, context.replaceBindingTrace(assignmentOperationTrace), expression, receiver);
|
||||||
JetType assignmentOperationType = OverloadResolutionResultsUtil.getResultType(assignmentOperationDescriptors);
|
JetType assignmentOperationType = OverloadResolutionResultsUtil.getResultType(assignmentOperationDescriptors);
|
||||||
|
|
||||||
// Check for '+'
|
// Check for '+'
|
||||||
Name counterpartName = OperatorConventions.BINARY_OPERATION_NAMES.get(OperatorConventions.ASSIGNMENT_OPERATION_COUNTERPARTS.get(operationType));
|
Name counterpartName = OperatorConventions.BINARY_OPERATION_NAMES.get(OperatorConventions.ASSIGNMENT_OPERATION_COUNTERPARTS.get(operationType));
|
||||||
TemporaryBindingTrace binaryOperationTrace = TemporaryBindingTrace.create(context.trace, "trace to check binary operation like '+' for", expression);
|
TemporaryBindingTrace binaryOperationTrace = TemporaryBindingTrace.create(context.trace, "trace to check binary operation like '+' for", expression);
|
||||||
OverloadResolutionResults<FunctionDescriptor> binaryOperationDescriptors = basic.getResolutionResultsForBinaryCall(scope, counterpartName, context.replaceBindingTrace(binaryOperationTrace), expression, receiver);
|
OverloadResolutionResults<FunctionDescriptor> binaryOperationDescriptors = BasicExpressionTypingVisitor.getResolutionResultsForBinaryCall(
|
||||||
|
scope, counterpartName, context.replaceBindingTrace(binaryOperationTrace), expression, receiver);
|
||||||
JetType binaryOperationType = OverloadResolutionResultsUtil.getResultType(binaryOperationDescriptors);
|
JetType binaryOperationType = OverloadResolutionResultsUtil.getResultType(binaryOperationDescriptors);
|
||||||
|
|
||||||
JetType type = assignmentOperationType != null ? assignmentOperationType : binaryOperationType;
|
JetType type = assignmentOperationType != null ? assignmentOperationType : binaryOperationType;
|
||||||
@@ -265,7 +271,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
basic.resolveArrayAccessSetMethod((JetArrayAccessExpression) left, right, contextForResolve, context.trace);
|
basic.resolveArrayAccessSetMethod((JetArrayAccessExpression) left, right, contextForResolve, context.trace);
|
||||||
}
|
}
|
||||||
dataFlowInfo = facade.getTypeInfo(right, context.replaceDataFlowInfo(dataFlowInfo)).getDataFlowInfo();
|
dataFlowInfo = facade.getTypeInfo(right, context.replaceDataFlowInfo(dataFlowInfo)).getDataFlowInfo();
|
||||||
basic.checkLValue(context.trace, expression.getLeft());
|
BasicExpressionTypingVisitor.checkLValue(context.trace, expression.getLeft());
|
||||||
}
|
}
|
||||||
temporaryBindingTrace.commit();
|
temporaryBindingTrace.commit();
|
||||||
return JetTypeInfo.create(checkAssignmentType(type, expression, contextWithExpectedType), dataFlowInfo);
|
return JetTypeInfo.create(checkAssignmentType(type, expression, contextWithExpectedType), dataFlowInfo);
|
||||||
@@ -280,7 +286,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
JetArrayAccessExpression arrayAccessExpression = (JetArrayAccessExpression) left;
|
JetArrayAccessExpression arrayAccessExpression = (JetArrayAccessExpression) left;
|
||||||
if (right == null) return JetTypeInfo.create(null, context.dataFlowInfo);
|
if (right == null) return JetTypeInfo.create(null, context.dataFlowInfo);
|
||||||
JetTypeInfo typeInfo = basic.resolveArrayAccessSetMethod(arrayAccessExpression, right, context, context.trace);
|
JetTypeInfo typeInfo = basic.resolveArrayAccessSetMethod(arrayAccessExpression, right, context, context.trace);
|
||||||
basic.checkLValue(context.trace, arrayAccessExpression);
|
BasicExpressionTypingVisitor.checkLValue(context.trace, arrayAccessExpression);
|
||||||
return JetTypeInfo.create(checkAssignmentType(typeInfo.getType(), expression, contextWithExpectedType),
|
return JetTypeInfo.create(checkAssignmentType(typeInfo.getType(), expression, contextWithExpectedType),
|
||||||
typeInfo.getDataFlowInfo());
|
typeInfo.getDataFlowInfo());
|
||||||
}
|
}
|
||||||
@@ -292,7 +298,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
dataFlowInfo = rightInfo.getDataFlowInfo();
|
dataFlowInfo = rightInfo.getDataFlowInfo();
|
||||||
}
|
}
|
||||||
if (leftType != null) { //if leftType == null, some another error has been generated
|
if (leftType != null) { //if leftType == null, some another error has been generated
|
||||||
basic.checkLValue(context.trace, expression.getLeft());
|
BasicExpressionTypingVisitor.checkLValue(context.trace, expression.getLeft());
|
||||||
}
|
}
|
||||||
return DataFlowUtils.checkStatementType(expression, contextWithExpectedType, dataFlowInfo);
|
return DataFlowUtils.checkStatementType(expression, contextWithExpectedType, dataFlowInfo);
|
||||||
}
|
}
|
||||||
@@ -336,7 +342,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetTypeInfo visitBlockExpression(JetBlockExpression expression, ExpressionTypingContext context) {
|
public JetTypeInfo visitBlockExpression(JetBlockExpression expression, ExpressionTypingContext context) {
|
||||||
return basic.visitBlockExpression(expression, context, true);
|
return BasicExpressionTypingVisitor.visitBlockExpression(expression, context, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user