From 9dc37438bc40f3b0c36c7cf87f2a8cdef3af9365 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 16 Dec 2011 16:29:07 +0400 Subject: [PATCH] Patch by Pavel Talanov. Refactoring in OperatorConventions.java --- .../jet/lang/resolve/calls/CallResolver.java | 12 +----- .../expressions/OperatorConventions.java | 43 +++++++++++++------ 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java index 18524d28943..466b318ed58 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java @@ -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))); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/OperatorConventions.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/OperatorConventions.java index 570d75fb38b..2aea399ef4e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/OperatorConventions.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/OperatorConventions.java @@ -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 NUMBER_CONVERSIONS = ImmutableSet.of( @@ -23,7 +28,7 @@ public class OperatorConventions { "int" ); - public static final ImmutableMap UNARY_OPERATION_NAMES = ImmutableMap.builder() + public static final ImmutableBiMap UNARY_OPERATION_NAMES = ImmutableBiMap.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 BINARY_OPERATION_NAMES = ImmutableMap.builder() + public static final ImmutableBiMap BINARY_OPERATION_NAMES = ImmutableBiMap.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 COMPARISON_OPERATIONS = ImmutableSet.of(JetTokens.LT, JetTokens.GT, JetTokens.LTEQ, JetTokens.GTEQ); - public static final ImmutableSet EQUALS_OPERATIONS = ImmutableSet.of(JetTokens.EQEQ, JetTokens.EXCLEQ); + public static final ImmutableSet NOT_OVERLOADABLE = + ImmutableSet.of(JetTokens.ANDAND, JetTokens.OROR, JetTokens.ELVIS); + + public static final ImmutableSet INCREMENT_OPERATIONS = + ImmutableSet.of(JetTokens.PLUSPLUS, JetTokens.MINUSMINUS); - public static final ImmutableSet IN_OPERATIONS = ImmutableSet.of(JetTokens.IN_KEYWORD, JetTokens.NOT_IN); - public static final ImmutableMap ASSIGNMENT_OPERATIONS = ImmutableMap.builder() + public static final ImmutableSet COMPARISON_OPERATIONS = + ImmutableSet.of(JetTokens.LT, JetTokens.GT, JetTokens.LTEQ, JetTokens.GTEQ); + + public static final ImmutableSet EQUALS_OPERATIONS = + ImmutableSet.of(JetTokens.EQEQ, JetTokens.EXCLEQ); + + public static final ImmutableSet IN_OPERATIONS = + ImmutableSet.of(JetTokens.IN_KEYWORD, JetTokens.NOT_IN); + + public static final ImmutableBiMap ASSIGNMENT_OPERATIONS = ImmutableBiMap.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 ASSIGNMENT_OPERATION_COUNTERPARTS = ImmutableMap.builder() + public static final ImmutableMap ASSIGNMENT_OPERATION_COUNTERPARTS = ImmutableMap.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; - } - + } }