Fixed check for convention operator
This commit is contained in:
@@ -20,10 +20,7 @@ import com.intellij.lang.ASTNode
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.impl.source.tree.TreeElement
|
import com.intellij.psi.impl.source.tree.TreeElement
|
||||||
import org.jetbrains.kotlin.lexer.KtSingleValueToken
|
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.parsing.KotlinExpressionParsing
|
||||||
import org.jetbrains.kotlin.resolve.constants.evaluate.binaryOperations
|
|
||||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||||
|
|
||||||
class KtOperationReferenceExpression(node: ASTNode) : KtSimpleNameExpressionImpl(node) {
|
class KtOperationReferenceExpression(node: ASTNode) : KtSimpleNameExpressionImpl(node) {
|
||||||
@@ -31,4 +28,9 @@ class KtOperationReferenceExpression(node: ASTNode) : KtSimpleNameExpressionImpl
|
|||||||
|
|
||||||
val operationSignTokenType: KtSingleValueToken?
|
val operationSignTokenType: KtSingleValueToken?
|
||||||
get() = (firstChild as? TreeElement)?.elementType as? KtSingleValueToken
|
get() = (firstChild as? TreeElement)?.elementType as? KtSingleValueToken
|
||||||
|
|
||||||
|
fun isConventionOperator(): Boolean {
|
||||||
|
val tokenType = operationSignTokenType ?: return false
|
||||||
|
return OperatorConventions.getNameForOperationSymbol(tokenType) != null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ fun isConventionCall(call: Call): Boolean {
|
|||||||
val callElement = call.callElement
|
val callElement = call.callElement
|
||||||
if (callElement is KtArrayAccessExpression || callElement is KtDestructuringDeclarationEntry) return true
|
if (callElement is KtArrayAccessExpression || callElement is KtDestructuringDeclarationEntry) return true
|
||||||
val calleeExpression = call.calleeExpression as? KtOperationReferenceExpression ?: return false
|
val calleeExpression = call.calleeExpression as? KtOperationReferenceExpression ?: return false
|
||||||
return calleeExpression.operationSignTokenType != null
|
return calleeExpression.isConventionOperator()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isInfixCall(call: Call): Boolean {
|
fun isInfixCall(call: Call): Boolean {
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ class OperatorCallChecker : CallChecker {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val isConventionOperator = element is KtOperationReferenceExpression && element.operationSignTokenType != null
|
val isConventionOperator = element is KtOperationReferenceExpression && element.isConventionOperator()
|
||||||
if (isConventionOperator || element is KtArrayAccessExpression) {
|
if (isConventionOperator || element is KtArrayAccessExpression) {
|
||||||
if (!functionDescriptor.isOperator) {
|
if (!functionDescriptor.isOperator) {
|
||||||
report(reportOn, functionDescriptor, context.trace)
|
report(reportOn, functionDescriptor, context.trace)
|
||||||
|
|||||||
+9
-10
@@ -213,16 +213,15 @@ class KtSimpleNameReference(expression: KtSimpleNameExpression) : KtSimpleRefere
|
|||||||
val tokenType = element.operationSignTokenType
|
val tokenType = element.operationSignTokenType
|
||||||
if (tokenType != null) {
|
if (tokenType != null) {
|
||||||
val name = OperatorConventions.getNameForOperationSymbol(
|
val name = OperatorConventions.getNameForOperationSymbol(
|
||||||
tokenType, element.parent is KtUnaryExpression, element.parent is KtBinaryExpression)
|
tokenType, element.parent is KtUnaryExpression, element.parent is KtBinaryExpression
|
||||||
if (name != null) { // can it be null ever?
|
) ?: return emptyList()
|
||||||
val counterpart = OperatorConventions.ASSIGNMENT_OPERATION_COUNTERPARTS[tokenType]
|
val counterpart = OperatorConventions.ASSIGNMENT_OPERATION_COUNTERPARTS[tokenType]
|
||||||
if (counterpart != null) {
|
if (counterpart != null) {
|
||||||
val counterpartName = OperatorConventions.getNameForOperationSymbol(counterpart, false, true)!!
|
val counterpartName = OperatorConventions.getNameForOperationSymbol(counterpart, false, true)!!
|
||||||
return listOf(name, counterpartName)
|
return listOf(name, counterpartName)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return listOf(name)
|
return listOf(name)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user