correct way to check if intention is applicable; revert: Delete test that is transformed syntax error
This commit is contained in:
+10
-1
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.intentions.*
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
|
||||
@@ -49,11 +50,19 @@ class ReplaceContainsIntention : SelfTargetingRangeIntention<KtDotQualifiedExpre
|
||||
|
||||
val functionDescriptor = getFunctionDescriptor(element) ?: return null
|
||||
|
||||
if (!functionDescriptor.isOperator && !OperatorChecks.check(functionDescriptor).isSuccess) return null
|
||||
if (!functionDescriptor.isOperatorOrCompatible) return null
|
||||
|
||||
return element.callExpression!!.calleeExpression!!.textRange
|
||||
}
|
||||
|
||||
private val FunctionDescriptor.isOperatorOrCompatible: Boolean
|
||||
get() {
|
||||
if (this is JavaMethodDescriptor) {
|
||||
return OperatorChecks.check(this).isSuccess
|
||||
}
|
||||
return isOperator
|
||||
}
|
||||
|
||||
override fun applyTo(element: KtDotQualifiedExpression, editor: Editor?) {
|
||||
val argument = element.callExpression!!.valueArguments.single().getArgumentExpression()!!
|
||||
val receiver = element.receiverExpression
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
fun test() {
|
||||
class Test{
|
||||
fun contains(a: Int) : Boolean = true
|
||||
}
|
||||
val test = Test()
|
||||
test.c<caret>ontains(0)
|
||||
}
|
||||
Reference in New Issue
Block a user