Replace call with comparison inspection introduced #KT-11425 Fixed
(cherry picked from commit 042fc0d)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
fc13b25ca4
commit
475dc6541b
@@ -1636,6 +1636,14 @@
|
||||
language="kotlin"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceCallWithComparisonInspection"
|
||||
displayName="Can be replaced with comparison"
|
||||
groupName="Kotlin"
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
language="kotlin"
|
||||
/>
|
||||
|
||||
<referenceImporter implementation="org.jetbrains.kotlin.idea.quickfix.KotlinReferenceImporter"/>
|
||||
|
||||
<fileType.fileViewProviderFactory filetype="KJSM" implementationClass="com.intellij.psi.ClassFileViewProviderFactory"/>
|
||||
|
||||
+12
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.intention.HighPriorityAction
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.idea.intentions.*
|
||||
import org.jetbrains.kotlin.lexer.KtSingleValueToken
|
||||
@@ -33,6 +34,17 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
class ReplaceCallWithComparisonInspection(
|
||||
val intention: ReplaceCallWithBinaryOperatorIntention = ReplaceCallWithBinaryOperatorIntention()
|
||||
) : IntentionBasedInspection<KtDotQualifiedExpression>(
|
||||
intention,
|
||||
{ qualifiedExpression ->
|
||||
val calleeExpression = qualifiedExpression.callExpression?.calleeExpression as? KtSimpleNameExpression
|
||||
val identifier = calleeExpression?.getReferencedNameAsName()
|
||||
identifier == OperatorNameConventions.EQUALS || identifier == OperatorNameConventions.COMPARE_TO
|
||||
}
|
||||
)
|
||||
|
||||
class ReplaceCallWithBinaryOperatorIntention : SelfTargetingRangeIntention<KtDotQualifiedExpression>(
|
||||
KtDotQualifiedExpression::class.java,
|
||||
"Replace call with binary operator"
|
||||
|
||||
Reference in New Issue
Block a user