Fixed optimize imports for operators
This commit is contained in:
@@ -23,16 +23,12 @@ import org.jetbrains.kotlin.lexer.KtSingleValueToken
|
||||
import org.jetbrains.kotlin.lexer.KtToken
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.parsing.KotlinExpressionParsing
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.binaryOperations
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
|
||||
class KtOperationReferenceExpression(node: ASTNode) : KtSimpleNameExpressionImpl(node) {
|
||||
override fun getReferencedNameElement() = findChildByType<PsiElement?>(KotlinExpressionParsing.ALL_OPERATIONS) ?: this
|
||||
|
||||
fun getNameForConventionalOperation(unaryOperations: Boolean = true, binaryOperations: Boolean = true): Name? {
|
||||
val operator = (firstChild as? TreeElement)?.elementType as? KtToken ?: return null
|
||||
return OperatorConventions.getNameForOperationSymbol(operator, unaryOperations, binaryOperations)
|
||||
}
|
||||
|
||||
fun isPredefinedOperator() = (firstChild as? TreeElement)?.elementType is KtSingleValueToken
|
||||
|
||||
val operationSignTokenType: KtSingleValueToken?
|
||||
get() = (firstChild as? TreeElement)?.elementType as? KtSingleValueToken
|
||||
}
|
||||
|
||||
@@ -131,13 +131,13 @@ fun isConventionCall(call: Call): Boolean {
|
||||
val callElement = call.callElement
|
||||
if (callElement is KtArrayAccessExpression || callElement is KtDestructuringDeclarationEntry) return true
|
||||
val calleeExpression = call.calleeExpression as? KtOperationReferenceExpression ?: return false
|
||||
return calleeExpression.getNameForConventionalOperation() != null
|
||||
return calleeExpression.operationSignTokenType != null
|
||||
}
|
||||
|
||||
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()
|
||||
return binaryExpression.operationReference === operationRefExpression && operationRefExpression.operationSignTokenType == null
|
||||
}
|
||||
|
||||
fun isInvokeCallOnVariable(call: Call): Boolean {
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ class OperatorCallChecker : CallChecker {
|
||||
return
|
||||
}
|
||||
|
||||
val isConventionOperator = element is KtOperationReferenceExpression && element.getNameForConventionalOperation() != null
|
||||
val isConventionOperator = element is KtOperationReferenceExpression && element.operationSignTokenType != null
|
||||
if (isConventionOperator || element is KtArrayAccessExpression) {
|
||||
if (!functionDescriptor.isOperator) {
|
||||
report(reportOn, functionDescriptor, context.trace)
|
||||
|
||||
Reference in New Issue
Block a user