Skip to content

Commit

Permalink
"Replace 'invoke' with direct call" intention: fix false positive whe…
Browse files Browse the repository at this point in the history
…n function is not operator

#KT-37977 Fixed
  • Loading branch information
t-kameyama authored and vladimirdolzhenko committed Apr 15, 2020
1 parent e0da30f commit 2f29b38
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@ package org.jetbrains.kotlin.idea.intentions.conventionNameCalls
import com.intellij.codeInsight.intention.HighPriorityAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.intentions.SelfTargetingRangeIntention
import org.jetbrains.kotlin.idea.intentions.callExpression
import org.jetbrains.kotlin.idea.intentions.calleeName
import org.jetbrains.kotlin.idea.intentions.toResolvedCall
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.util.OperatorNameConventions

class ReplaceInvokeIntention : SelfTargetingRangeIntention<KtDotQualifiedExpression>(
KtDotQualifiedExpression::class.java,
KotlinBundle.lazyMessage("replace.invoke.with.direct.call")
), HighPriorityAction {
override fun applicabilityRange(element: KtDotQualifiedExpression): TextRange? {
if (element.calleeName != OperatorNameConventions.INVOKE.asString() || element.callExpression?.typeArgumentList != null) return null
if (element.calleeName != OperatorNameConventions.INVOKE.asString() ||
element.callExpression?.typeArgumentList != null ||
(element.toResolvedCall(BodyResolveMode.PARTIAL)?.resultingDescriptor as? FunctionDescriptor)?.isOperator != true
) return null
return element.callExpression?.calleeExpression?.textRange
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class JavaClass {
void invoke() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class JavaClass {
void invoke() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fun main() {
JavaClass().<caret>invoke()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fun main() {
JavaClass()()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// IS_APPLICABLE: false
class C {
fun invoke() {}
}

fun main() {
C().<caret>invoke()
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2f29b38

Please sign in to comment.