Do not show "Replace overloaded operator with function call" intention on incomplete expressions
#KT-33115 fixed
This commit is contained in:
+2
@@ -40,6 +40,7 @@ class OperatorToFunctionIntention :
|
|||||||
SelfTargetingIntention<KtExpression>(KtExpression::class.java, "Replace overloaded operator with function call") {
|
SelfTargetingIntention<KtExpression>(KtExpression::class.java, "Replace overloaded operator with function call") {
|
||||||
companion object {
|
companion object {
|
||||||
private fun isApplicableUnary(element: KtUnaryExpression, caretOffset: Int): Boolean {
|
private fun isApplicableUnary(element: KtUnaryExpression, caretOffset: Int): Boolean {
|
||||||
|
if (element.baseExpression == null) return false
|
||||||
val opRef = element.operationReference
|
val opRef = element.operationReference
|
||||||
if (!opRef.textRange.containsOffset(caretOffset)) return false
|
if (!opRef.textRange.containsOffset(caretOffset)) return false
|
||||||
return when (opRef.getReferencedNameElementType()) {
|
return when (opRef.getReferencedNameElementType()) {
|
||||||
@@ -63,6 +64,7 @@ class OperatorToFunctionIntention :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun isApplicableBinary(element: KtBinaryExpression, caretOffset: Int): Boolean {
|
private fun isApplicableBinary(element: KtBinaryExpression, caretOffset: Int): Boolean {
|
||||||
|
if (element.left == null || element.right == null) return false
|
||||||
val opRef = element.operationReference
|
val opRef = element.operationReference
|
||||||
if (!opRef.textRange.containsOffset(caretOffset)) return false
|
if (!opRef.textRange.containsOffset(caretOffset)) return false
|
||||||
return when (opRef.getReferencedNameElementType()) {
|
return when (opRef.getReferencedNameElementType()) {
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// DISABLE-ERRORS
|
||||||
|
// IS_APPLICABLE: false
|
||||||
|
|
||||||
|
val x: Int = 1 <caret>+
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
|
||||||
|
val x = <caret>+
|
||||||
@@ -12492,6 +12492,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
runTest("idea/testData/intentions/operatorToFunction/inRightSideOfAssignment.kt");
|
runTest("idea/testData/intentions/operatorToFunction/inRightSideOfAssignment.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("incompleteBinaryExpression.kt")
|
||||||
|
public void testIncompleteBinaryExpression() throws Exception {
|
||||||
|
runTest("idea/testData/intentions/operatorToFunction/incompleteBinaryExpression.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("incompleteUnaryExpression.kt")
|
||||||
|
public void testIncompleteUnaryExpression() throws Exception {
|
||||||
|
runTest("idea/testData/intentions/operatorToFunction/incompleteUnaryExpression.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("keepComments.kt")
|
@TestMetadata("keepComments.kt")
|
||||||
public void testKeepComments() throws Exception {
|
public void testKeepComments() throws Exception {
|
||||||
runTest("idea/testData/intentions/operatorToFunction/keepComments.kt");
|
runTest("idea/testData/intentions/operatorToFunction/keepComments.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user