Replace with binary operator: don't highlight when receiver is platform type
#KT-35097 Fixed
This commit is contained in:
committed by
Yan Zhulanow
parent
93db78e7ac
commit
ad3ea9a36a
+3
-5
@@ -36,12 +36,10 @@ import org.jetbrains.kotlin.idea.intentions.conventionNameCalls.isAnyEquals
|
|||||||
import org.jetbrains.kotlin.idea.intentions.isOperatorOrCompatible
|
import org.jetbrains.kotlin.idea.intentions.isOperatorOrCompatible
|
||||||
import org.jetbrains.kotlin.idea.intentions.isReceiverExpressionWithValue
|
import org.jetbrains.kotlin.idea.intentions.isReceiverExpressionWithValue
|
||||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||||
import org.jetbrains.kotlin.idea.project.platform
|
|
||||||
import org.jetbrains.kotlin.idea.resolve.getDataFlowValueFactory
|
import org.jetbrains.kotlin.idea.resolve.getDataFlowValueFactory
|
||||||
import org.jetbrains.kotlin.idea.util.calleeTextRangeInThis
|
import org.jetbrains.kotlin.idea.util.calleeTextRangeInThis
|
||||||
import org.jetbrains.kotlin.lexer.KtSingleValueToken
|
import org.jetbrains.kotlin.lexer.KtSingleValueToken
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.platform.js.isJs
|
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getLastParentOfTypeInRow
|
import org.jetbrains.kotlin.psi.psiUtil.getLastParentOfTypeInRow
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getFirstArgumentExpression
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getFirstArgumentExpression
|
||||||
@@ -54,7 +52,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.getKotlinTypeWithPossibleSm
|
|||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||||
import org.jetbrains.kotlin.types.isDynamic
|
import org.jetbrains.kotlin.types.isNullabilityFlexible
|
||||||
import org.jetbrains.kotlin.types.typeUtil.*
|
import org.jetbrains.kotlin.types.typeUtil.*
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||||
|
|
||||||
@@ -95,9 +93,9 @@ class ReplaceCallWithBinaryOperatorInspection : AbstractApplicabilityBasedInspec
|
|||||||
override fun inspectionHighlightType(element: KtDotQualifiedExpression): ProblemHighlightType {
|
override fun inspectionHighlightType(element: KtDotQualifiedExpression): ProblemHighlightType {
|
||||||
val calleeExpression = element.callExpression?.calleeExpression as? KtSimpleNameExpression
|
val calleeExpression = element.callExpression?.calleeExpression as? KtSimpleNameExpression
|
||||||
val identifier = calleeExpression?.getReferencedNameAsName()
|
val identifier = calleeExpression?.getReferencedNameAsName()
|
||||||
if (element.platform.isJs() && identifier == OperatorNameConventions.EQUALS) {
|
if (identifier == OperatorNameConventions.EQUALS) {
|
||||||
val context = element.analyze(BodyResolveMode.PARTIAL)
|
val context = element.analyze(BodyResolveMode.PARTIAL)
|
||||||
if (element.receiverExpression.getType(context)?.isDynamic() == true) {
|
if (element.receiverExpression.getType(context)?.isNullabilityFlexible() == true) {
|
||||||
return ProblemHighlightType.INFORMATION
|
return ProblemHighlightType.INFORMATION
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
public class Foo {
|
||||||
|
public static class Bar {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bar getBar1() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bar getBar2() {
|
||||||
|
return new Bar();
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
public class Foo {
|
||||||
|
public static class Bar {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bar getBar1() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bar getBar2() {
|
||||||
|
return new Bar();
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// HIGHLIGHT: INFORMATION
|
||||||
|
fun main() {
|
||||||
|
val bar1 = Foo().bar1
|
||||||
|
val bar2 = Foo().bar2
|
||||||
|
val b = bar1.<caret>equals(bar2)
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// HIGHLIGHT: INFORMATION
|
||||||
|
fun main() {
|
||||||
|
val bar1 = Foo().bar1
|
||||||
|
val bar2 = Foo().bar2
|
||||||
|
val b = bar1 == bar2
|
||||||
|
}
|
||||||
+5
@@ -3287,6 +3287,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
|||||||
runTest("idea/testData/inspectionsLocal/conventionNameCalls/replaceCallWithBinaryOperator/operatorCannotBeApplied.kt");
|
runTest("idea/testData/inspectionsLocal/conventionNameCalls/replaceCallWithBinaryOperator/operatorCannotBeApplied.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("platformTypeEquals.kt")
|
||||||
|
public void testPlatformTypeEquals() throws Exception {
|
||||||
|
runTest("idea/testData/inspectionsLocal/conventionNameCalls/replaceCallWithBinaryOperator/platformTypeEquals.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("plusFromJava.kt")
|
@TestMetadata("plusFromJava.kt")
|
||||||
public void testPlusFromJava() throws Exception {
|
public void testPlusFromJava() throws Exception {
|
||||||
runTest("idea/testData/inspectionsLocal/conventionNameCalls/replaceCallWithBinaryOperator/plusFromJava.kt");
|
runTest("idea/testData/inspectionsLocal/conventionNameCalls/replaceCallWithBinaryOperator/plusFromJava.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user