correct way to check if intention is applicable; revert: Delete test that is transformed syntax error

This commit is contained in:
Dmitry Jemerov
2016-10-13 15:19:06 +02:00
parent 925c48c2f0
commit b1b171fbc5
2 changed files with 19 additions and 1 deletions
@@ -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
@@ -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)
}