"Convert to run / with": don't suggest on java static method call
#KT-25739 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
0a5aa2b60c
commit
28aa0763a9
+6
-2
@@ -17,14 +17,18 @@
|
||||
package org.jetbrains.kotlin.idea.intentions
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiClass
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||
|
||||
abstract class ConvertDotQualifiedToScopeIntention(
|
||||
text: String
|
||||
text: String
|
||||
) : ConvertToScopeIntention<KtDotQualifiedExpression>(KtDotQualifiedExpression::class.java, text) {
|
||||
|
||||
override fun isApplicableTo(element: KtDotQualifiedExpression, caretOffset: Int): Boolean {
|
||||
val receiverExpressionText = element.getReceiverExpressionText() ?: return false
|
||||
val receiverExpression = element.getLeftMostReceiverExpression()
|
||||
if (receiverExpression.mainReference?.resolve() is PsiClass) return false
|
||||
val receiverExpressionText = receiverExpression.text
|
||||
if (receiverExpressionText in BLACKLIST_RECEIVER_NAME) return false
|
||||
if (!isApplicableWithGivenReceiverText(element, receiverExpressionText)) return false
|
||||
val nextSibling = element.getDotQualifiedSiblingIfAny(forward = true)
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
public class JavaClass {
|
||||
void bar1() {}
|
||||
void bar2() {}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
public class JavaClass {
|
||||
void bar1() {}
|
||||
void bar2() {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
fun test(c: JavaClass) {
|
||||
<caret>c.bar1()
|
||||
c.bar2()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
fun test(c: JavaClass) {
|
||||
c.run {
|
||||
bar1()
|
||||
bar2()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
public class JavaClass {
|
||||
public static void foo1() {}
|
||||
public static void foo2() {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun test() {
|
||||
<caret>JavaClass.foo1()
|
||||
JavaClass.foo2()
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
public class JavaClass {
|
||||
void bar1() {}
|
||||
void bar2() {}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
public class JavaClass {
|
||||
void bar1() {}
|
||||
void bar2() {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
fun test(c: JavaClass) {
|
||||
<caret>c.bar1()
|
||||
c.bar2()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
fun test(c: JavaClass) {
|
||||
with(c) {
|
||||
bar1()
|
||||
bar2()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
public class JavaClass {
|
||||
public static void foo1() {}
|
||||
public static void foo2() {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun test() {
|
||||
<caret>JavaClass.foo1()
|
||||
JavaClass.foo2()
|
||||
}
|
||||
@@ -7032,6 +7032,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/convertToRun/itReceiver.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaMethod.kt")
|
||||
public void testJavaMethod() throws Exception {
|
||||
runTest("idea/testData/intentions/convertToRun/javaMethod.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaStaticMethod.kt")
|
||||
public void testJavaStaticMethod() throws Exception {
|
||||
runTest("idea/testData/intentions/convertToRun/javaStaticMethod.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("methodChain.kt")
|
||||
public void testMethodChain() throws Exception {
|
||||
runTest("idea/testData/intentions/convertToRun/methodChain.kt");
|
||||
@@ -7341,6 +7351,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/convertToWith/itReceiver.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaMethod.kt")
|
||||
public void testJavaMethod() throws Exception {
|
||||
runTest("idea/testData/intentions/convertToWith/javaMethod.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaStaticMethod.kt")
|
||||
public void testJavaStaticMethod() throws Exception {
|
||||
runTest("idea/testData/intentions/convertToWith/javaStaticMethod.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("methodChain.kt")
|
||||
public void testMethodChain() throws Exception {
|
||||
runTest("idea/testData/intentions/convertToWith/methodChain.kt");
|
||||
|
||||
Reference in New Issue
Block a user