Patch by Pavel Talanov. Refactoring in OperatorConventions.java
This commit is contained in:
@@ -19,6 +19,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.jet.lexer.JetToken;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import java.util.*;
|
||||
@@ -344,7 +345,7 @@ public class CallResolver {
|
||||
if (callElement instanceof JetBinaryExpression) {
|
||||
JetBinaryExpression binaryExpression = (JetBinaryExpression) callElement;
|
||||
JetSimpleNameExpression operationReference = binaryExpression.getOperationReference();
|
||||
String operationString = operationReference.getReferencedNameElementType() == JetTokens.IDENTIFIER ? operationReference.getText() : OperatorConventions.getNameForOperationSymbol(operationReference.getReferencedNameElementType());
|
||||
String operationString = operationReference.getReferencedNameElementType() == JetTokens.IDENTIFIER ? operationReference.getText() : OperatorConventions.getNameForOperationSymbol((JetToken) operationReference.getReferencedNameElementType());
|
||||
JetExpression right = binaryExpression.getRight();
|
||||
if (right != null) {
|
||||
trace.report(UNSAFE_INFIX_CALL.on(reference, binaryExpression.getLeft().getText(), operationString, right.getText()));
|
||||
@@ -506,15 +507,6 @@ public class CallResolver {
|
||||
}
|
||||
else {
|
||||
tracing.typeInferenceFailed(temporaryTrace, solution.getStatus());
|
||||
// // Substitute DONT_CARE types to make further type checking as tolerant as possible
|
||||
// D candidateWithDontCares = (D) candidate.substitute(TypeSubstitutor.makeConstantSubstitutor(candidate.getTypeParameters(), DONT_CARE));
|
||||
// if (candidateWithDontCares == null) {
|
||||
// candidateWithDontCares = (D) candidate.substitute(TypeSubstitutor.makeConstantSubstitutor(candidate.getTypeParameters(), Variance.INVARIANT, DONT_CARE));
|
||||
// }
|
||||
// if (!ErrorUtils.isErrorType(candidateWithDontCares.getReturnType())) {
|
||||
// // Returning an error type provokes overload resolution ambiguities that mask errors
|
||||
// candidateCall.setResultingDescriptor(candidateWithDontCares);
|
||||
// }
|
||||
candidateCall.setStatus(OTHER_ERROR.combine(checkAllValueArguments(scope, tracing, task, candidateCall)));
|
||||
}
|
||||
}
|
||||
|
||||
+29
-14
@@ -1,10 +1,11 @@
|
||||
package org.jetbrains.jet.lang.types.expressions;
|
||||
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lexer.JetToken;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
/**
|
||||
@@ -12,6 +13,10 @@ import org.jetbrains.jet.lexer.JetTokens;
|
||||
*/
|
||||
public class OperatorConventions {
|
||||
|
||||
public static final String EQUALS = "equals";
|
||||
public static final String COMPARE_TO = "compareTo";
|
||||
public static final String CONTAINS = "contains";
|
||||
|
||||
private OperatorConventions() {}
|
||||
|
||||
public static final ImmutableSet<String> NUMBER_CONVERSIONS = ImmutableSet.of(
|
||||
@@ -23,7 +28,7 @@ public class OperatorConventions {
|
||||
"int"
|
||||
);
|
||||
|
||||
public static final ImmutableMap<IElementType, String> UNARY_OPERATION_NAMES = ImmutableMap.<IElementType, String>builder()
|
||||
public static final ImmutableBiMap<JetToken, String> UNARY_OPERATION_NAMES = ImmutableBiMap.<JetToken, String>builder()
|
||||
.put(JetTokens.PLUSPLUS, "inc")
|
||||
.put(JetTokens.MINUSMINUS, "dec")
|
||||
.put(JetTokens.PLUS, "plus")
|
||||
@@ -31,7 +36,7 @@ public class OperatorConventions {
|
||||
.put(JetTokens.EXCL, "not")
|
||||
.build();
|
||||
|
||||
public static final ImmutableMap<IElementType, String> BINARY_OPERATION_NAMES = ImmutableMap.<IElementType, String>builder()
|
||||
public static final ImmutableBiMap<JetToken, String> BINARY_OPERATION_NAMES = ImmutableBiMap.<JetToken, String>builder()
|
||||
.put(JetTokens.MUL, "times")
|
||||
.put(JetTokens.PLUS, "plus")
|
||||
.put(JetTokens.MINUS, "minus")
|
||||
@@ -41,11 +46,22 @@ public class OperatorConventions {
|
||||
.put(JetTokens.RANGE, "rangeTo")
|
||||
.build();
|
||||
|
||||
public static final ImmutableSet<IElementType> COMPARISON_OPERATIONS = ImmutableSet.<IElementType>of(JetTokens.LT, JetTokens.GT, JetTokens.LTEQ, JetTokens.GTEQ);
|
||||
public static final ImmutableSet<IElementType> EQUALS_OPERATIONS = ImmutableSet.<IElementType>of(JetTokens.EQEQ, JetTokens.EXCLEQ);
|
||||
public static final ImmutableSet<JetToken> NOT_OVERLOADABLE =
|
||||
ImmutableSet.<JetToken>of(JetTokens.ANDAND, JetTokens.OROR, JetTokens.ELVIS);
|
||||
|
||||
public static final ImmutableSet<JetToken> INCREMENT_OPERATIONS =
|
||||
ImmutableSet.<JetToken>of(JetTokens.PLUSPLUS, JetTokens.MINUSMINUS);
|
||||
|
||||
public static final ImmutableSet<IElementType> IN_OPERATIONS = ImmutableSet.<IElementType>of(JetTokens.IN_KEYWORD, JetTokens.NOT_IN);
|
||||
public static final ImmutableMap<IElementType, String> ASSIGNMENT_OPERATIONS = ImmutableMap.<IElementType, String>builder()
|
||||
public static final ImmutableSet<JetToken> COMPARISON_OPERATIONS =
|
||||
ImmutableSet.<JetToken>of(JetTokens.LT, JetTokens.GT, JetTokens.LTEQ, JetTokens.GTEQ);
|
||||
|
||||
public static final ImmutableSet<JetToken> EQUALS_OPERATIONS =
|
||||
ImmutableSet.<JetToken>of(JetTokens.EQEQ, JetTokens.EXCLEQ);
|
||||
|
||||
public static final ImmutableSet<JetToken> IN_OPERATIONS =
|
||||
ImmutableSet.<JetToken>of(JetTokens.IN_KEYWORD, JetTokens.NOT_IN);
|
||||
|
||||
public static final ImmutableBiMap<JetToken, String> ASSIGNMENT_OPERATIONS = ImmutableBiMap.<JetToken, String>builder()
|
||||
.put(JetTokens.MULTEQ, "timesAssign")
|
||||
.put(JetTokens.DIVEQ, "divAssign")
|
||||
.put(JetTokens.PERCEQ, "modAssign")
|
||||
@@ -53,7 +69,7 @@ public class OperatorConventions {
|
||||
.put(JetTokens.MINUSEQ, "minusAssign")
|
||||
.build();
|
||||
|
||||
public static final ImmutableMap<IElementType, IElementType> ASSIGNMENT_OPERATION_COUNTERPARTS = ImmutableMap.<IElementType, IElementType>builder()
|
||||
public static final ImmutableMap<JetToken, JetToken> ASSIGNMENT_OPERATION_COUNTERPARTS = ImmutableMap.<JetToken, JetToken>builder()
|
||||
.put(JetTokens.MULTEQ, JetTokens.MUL)
|
||||
.put(JetTokens.DIVEQ, JetTokens.DIV)
|
||||
.put(JetTokens.PERCEQ, JetTokens.PERC)
|
||||
@@ -62,17 +78,16 @@ public class OperatorConventions {
|
||||
.build();
|
||||
|
||||
@Nullable
|
||||
public static String getNameForOperationSymbol(@NotNull IElementType token) {
|
||||
public static String getNameForOperationSymbol(@NotNull JetToken token) {
|
||||
String name = UNARY_OPERATION_NAMES.get(token);
|
||||
if (name != null) return name;
|
||||
name = BINARY_OPERATION_NAMES.get(token);
|
||||
if (name != null) return name;
|
||||
name = ASSIGNMENT_OPERATIONS.get(token);
|
||||
if (name != null) return name;
|
||||
if (COMPARISON_OPERATIONS.contains(token)) return "compareTo";
|
||||
if (EQUALS_OPERATIONS.contains(token)) return "equals";
|
||||
if (IN_OPERATIONS.contains(token)) return "contains";
|
||||
if (COMPARISON_OPERATIONS.contains(token)) return COMPARE_TO;
|
||||
if (EQUALS_OPERATIONS.contains(token)) return EQUALS;
|
||||
if (IN_OPERATIONS.contains(token)) return CONTAINS;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user