diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 93fb540049f..6da8678761b 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -1099,8 +1099,8 @@ (ReplaceGetIntention()) +public class ExplicitGetInspection : IntentionBasedInspection( + ReplaceGetIntention(), + additionalChecker = { expression -> (expression.toResolvedCall()!!.resultingDescriptor as FunctionDescriptor).isExplicitOperator() } +) + +private fun FunctionDescriptor.isExplicitOperator(): Boolean { + return if (overriddenDescriptors.isEmpty()) + containingDeclaration !is JavaClassDescriptor && isOperator + else + overriddenDescriptors.any { it.isExplicitOperator() } +} public class ReplaceGetIntention : JetSelfTargetingRangeIntention(javaClass(), "Replace 'get' call with index operator"), HighPriorityAction { override fun applicabilityRange(element: JetDotQualifiedExpression): TextRange? { diff --git a/idea/testData/intentions/conventionNameCalls/replaceGet/JavaMethods.java b/idea/testData/intentions/conventionNameCalls/replaceGet/JavaMethods.java new file mode 100644 index 00000000000..3d3851c18b5 --- /dev/null +++ b/idea/testData/intentions/conventionNameCalls/replaceGet/JavaMethods.java @@ -0,0 +1,12 @@ +import java.util.List; + +public abstract class JavaMethods implements List { + @Override + public String get(int i) { + return null; + } + + public int get(String s, int p) { + return 1; + } +} \ No newline at end of file diff --git a/idea/testData/intentions/conventionNameCalls/replaceGet/inspectionData/expected.xml b/idea/testData/intentions/conventionNameCalls/replaceGet/inspectionData/expected.xml index 59d765eeadc..82129038e30 100644 --- a/idea/testData/intentions/conventionNameCalls/replaceGet/inspectionData/expected.xml +++ b/idea/testData/intentions/conventionNameCalls/replaceGet/inspectionData/expected.xml @@ -61,4 +61,13 @@ Explicit 'get' Replace 'get' call with index operator + + + javaMethods.kt + 6 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + diff --git a/idea/testData/intentions/conventionNameCalls/replaceGet/javaMethods.kt b/idea/testData/intentions/conventionNameCalls/replaceGet/javaMethods.kt new file mode 100644 index 00000000000..9ebd7965324 --- /dev/null +++ b/idea/testData/intentions/conventionNameCalls/replaceGet/javaMethods.kt @@ -0,0 +1,8 @@ +// DISABLE-ERRORS +// IS_APPLICABLE: false +import JavaMethods + +fun foo(javaClass: JavaMethods) { + val v1 = javaClass.get(1) + val v2 = javaClass.get("a", 1) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index d3dddac23a4..ee23778fad9 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -2765,6 +2765,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest { doTest(fileName); } + @TestMetadata("javaMethods.kt") + public void testJavaMethods() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/javaMethods.kt"); + doTest(fileName); + } + @TestMetadata("missingDefaultArgument.kt") public void testMissingDefaultArgument() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/missingDefaultArgument.kt");