Skip to content
Browse files

Code cleanup in BasicExpressionTypingVisitor: added 'statics', remove…

…d unused method.
  • Loading branch information...
1 parent 0b34378 commit ce86f27b4380855eb69b5bf7e098bfc4be64309c Evgeny Gerashchenko committed Mar 19, 2013
View
53 ...r/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.types.expressions;
-import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
@@ -174,7 +173,12 @@ public JetTypeInfo visitBinaryWithTypeRHSExpression(JetBinaryExpressionWithTypeR
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();
IElementType operationType = operationSign.getReferencedNameElementType();
if (operationType == JetTokens.COLON) {
@@ -194,7 +198,12 @@ else if (operationType == JetTokens.AS_KEYWORD || operationType == JetTokens.AS_
}
}
- 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;
JetTypeChecker typeChecker = JetTypeChecker.INSTANCE;
@@ -362,18 +371,6 @@ private static boolean hasErasedTypeArguments(
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
public JetTypeInfo visitThisExpression(JetThisExpression expression, ExpressionTypingContext context) {
JetType result = null;
@@ -419,15 +416,15 @@ public JetTypeInfo visitSuperExpression(JetSuperExpression expression, Expressio
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();
if (superTypeQualifier != null) {
context.expressionTypingServices.getTypeResolver().resolveType(context.scope, superTypeQualifier, context.trace, true);
}
return JetTypeInfo.create(null, context.dataFlowInfo);
}
- private JetType checkPossiblyQualifiedSuper(
+ private static JetType checkPossiblyQualifiedSuper(
JetSuperExpression expression,
ExpressionTypingContext context,
ReceiverParameterDescriptor thisReceiver
@@ -507,7 +504,7 @@ else if (redundantTypeArguments != null) {
}
@NotNull // No class receivers
- private LabelResolver.LabeledReceiverResolutionResult resolveToReceiver(
+ private static LabelResolver.LabeledReceiverResolutionResult resolveToReceiver(
JetLabelQualifiedInstanceExpression expression,
ExpressionTypingContext context,
boolean onlyClassReceivers
@@ -544,7 +541,7 @@ else if (!receivers.isEmpty()) {
}
}
- private boolean isDeclaredInClass(ReceiverParameterDescriptor receiver) {
+ private static boolean isDeclaredInClass(ReceiverParameterDescriptor receiver) {
return receiver.getContainingDeclaration() instanceof ClassDescriptor;
}
@@ -553,7 +550,7 @@ public JetTypeInfo visitBlockExpression(JetBlockExpression expression, Expressio
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
? CoercionStrategy.COERCION_TO_UNIT
: CoercionStrategy.NO_COERCION, context, context.trace);
@@ -642,6 +639,7 @@ public JetTypeInfo visitUnaryExpression(JetUnaryExpression expression, Expressio
JetType returnType = resolutionResults.getResultingDescriptor().getReturnType();
JetType result;
if (operationType == JetTokens.PLUSPLUS || operationType == JetTokens.MINUSMINUS) {
+ assert returnType != null : "returnType is null for " + resolutionResults.getResultingDescriptor();
if (JetTypeChecker.INSTANCE.isSubtypeOf(returnType, KotlinBuiltIns.getInstance().getUnitType())) {
result = ErrorUtils.createErrorType(KotlinBuiltIns.UNIT_ALIAS.getName());
context.trace.report(INC_DEC_SHOULD_NOT_RETURN_UNIT.on(operationSign));
@@ -710,18 +708,18 @@ private JetTypeInfo visitLabeledExpression(@NotNull JetUnaryExpression expressio
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);
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());
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);
}
- private void checkLValue(BindingTrace trace, JetExpression expressionWithParenthesis, boolean canBeThis) {
+ private static void checkLValue(BindingTrace trace, JetExpression expressionWithParenthesis, boolean canBeThis) {
JetExpression expression = JetPsiUtil.deparenthesizeWithNoTypeResolution(expressionWithParenthesis);
if (expression instanceof JetArrayAccessExpression) {
checkLValue(trace, ((JetArrayAccessExpression) expression).getArrayExpression(), true);
@@ -998,7 +996,14 @@ public JetTypeInfo getTypeInfoForBinaryCall(
}
@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));
return context.replaceScope(scope).resolveCallWithGivenName(
CallMaker.makeCall(receiver, binaryExpression),
View
20 ...nd/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingVisitorForStatements.java
@@ -69,7 +69,11 @@ public ExpressionTypingVisitorForStatements(
}
@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 &&
TypeUtils.equalTypes(context.expectedType, assignmentType)) {
context.trace.report(Errors.ASSIGNMENT_TYPE_MISMATCH.on(expression, context.expectedType));
@@ -227,13 +231,15 @@ protected JetTypeInfo visitAssignmentOperation(JetBinaryExpression expression, E
// Check for '+='
Name name = OperatorConventions.ASSIGNMENT_OPERATIONS.get(operationType);
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);
// Check for '+'
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);
- 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 type = assignmentOperationType != null ? assignmentOperationType : binaryOperationType;
@@ -265,7 +271,7 @@ else if (assignmentOperationType != null) {
basic.resolveArrayAccessSetMethod((JetArrayAccessExpression) left, right, contextForResolve, context.trace);
}
dataFlowInfo = facade.getTypeInfo(right, context.replaceDataFlowInfo(dataFlowInfo)).getDataFlowInfo();
- basic.checkLValue(context.trace, expression.getLeft());
+ BasicExpressionTypingVisitor.checkLValue(context.trace, expression.getLeft());
}
temporaryBindingTrace.commit();
return JetTypeInfo.create(checkAssignmentType(type, expression, contextWithExpectedType), dataFlowInfo);
@@ -280,7 +286,7 @@ protected JetTypeInfo visitAssignment(JetBinaryExpression expression, Expression
JetArrayAccessExpression arrayAccessExpression = (JetArrayAccessExpression) left;
if (right == null) return JetTypeInfo.create(null, context.dataFlowInfo);
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),
typeInfo.getDataFlowInfo());
}
@@ -292,7 +298,7 @@ protected JetTypeInfo visitAssignment(JetBinaryExpression expression, Expression
dataFlowInfo = rightInfo.getDataFlowInfo();
}
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);
}
@@ -336,7 +342,7 @@ public JetTypeInfo visitWhenExpression(JetWhenExpression expression, ExpressionT
@Override
public JetTypeInfo visitBlockExpression(JetBlockExpression expression, ExpressionTypingContext context) {
- return basic.visitBlockExpression(expression, context, true);
+ return BasicExpressionTypingVisitor.visitBlockExpression(expression, context, true);
}
@Override

0 comments on commit ce86f27

Please sign in to comment.
Something went wrong with that request. Please try again.