Minor, move isInfixCall implementation out of InfixCallChecker

This commit is contained in:
Alexander Udalov
2016-07-05 19:09:38 +03:00
parent 9bf91e95d0
commit d331b6ae8e
3 changed files with 10 additions and 18 deletions
@@ -620,7 +620,7 @@ public interface Errors {
DiagnosticFactory1<PsiElement, String> INAPPLICABLE_INFIX_MODIFIER = DiagnosticFactory1.create(ERROR);
DiagnosticFactory2<PsiElement, FunctionDescriptor, String> OPERATOR_MODIFIER_REQUIRED = DiagnosticFactory2.create(ERROR);
DiagnosticFactory2<KtOperationReferenceExpression, FunctionDescriptor, String> INFIX_MODIFIER_REQUIRED = DiagnosticFactory2.create(ERROR);
DiagnosticFactory2<PsiElement, FunctionDescriptor, String> INFIX_MODIFIER_REQUIRED = DiagnosticFactory2.create(ERROR);
DiagnosticFactory2<PsiElement, KtModifierKeywordToken, String> INAPPLICABLE_MODIFIER = DiagnosticFactory2.create(ERROR);
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.CallTransformer
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getValueArgumentForExpression
import org.jetbrains.kotlin.resolve.calls.checkers.InfixCallChecker
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystem
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.EXPECTED_TYPE_POSITION
import org.jetbrains.kotlin.resolve.calls.inference.getNestedTypeVariables
@@ -135,7 +134,11 @@ fun isConventionCall(call: Call): Boolean {
return calleeExpression.getNameForConventionalOperation() != null
}
fun isInfixCall(call: Call): Boolean = InfixCallChecker.isInfixCall(call.calleeExpression)
fun isInfixCall(call: Call): Boolean {
val operationRefExpression = call.calleeExpression as? KtOperationReferenceExpression ?: return false
val binaryExpression = operationRefExpression.parent as? KtBinaryExpression ?: return false
return binaryExpression.operationReference === operationRefExpression && !operationRefExpression.isPredefinedOperator()
}
fun isInvokeCallOnVariable(call: Call): Boolean {
if (call.callType !== Call.CallType.INVOKE) return false
@@ -19,8 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.checkers
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.psi.KtOperationReferenceExpression
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isInfixCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic
@@ -31,20 +30,10 @@ class InfixCallChecker : CallChecker {
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
val functionDescriptor = resolvedCall.resultingDescriptor as? FunctionDescriptor ?: return
if (functionDescriptor.isInfix || functionDescriptor.isDynamic() || ErrorUtils.isError(functionDescriptor)) return
val element = ((resolvedCall as? VariableAsFunctionResolvedCall)?.variableCall ?: resolvedCall).call.calleeExpression
if (isInfixCall(element)) {
val call = ((resolvedCall as? VariableAsFunctionResolvedCall)?.variableCall ?: resolvedCall).call
if (isInfixCall(call)) {
val containingDeclarationName = functionDescriptor.containingDeclaration.fqNameUnsafe.asString()
context.trace.report(Errors.INFIX_MODIFIER_REQUIRED.on(
reportOn as? KtOperationReferenceExpression ?: return, functionDescriptor, containingDeclarationName
))
}
}
companion object {
fun isInfixCall(element: PsiElement?): Boolean {
val operationRefExpression = element as? KtOperationReferenceExpression ?: return false
val binaryExpression = operationRefExpression.parent as? KtBinaryExpression ?: return false
return binaryExpression.operationReference === operationRefExpression && !operationRefExpression.isPredefinedOperator()
context.trace.report(Errors.INFIX_MODIFIER_REQUIRED.on(reportOn, functionDescriptor, containingDeclarationName))
}
}
}