From affa8814212543c3af7d377a3796a0e15f572f87 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Tue, 25 Sep 2018 11:14:09 +0900 Subject: [PATCH] "Redundant SAM constructor": Fix highlighting range #KT-27034 Fixed --- .../inspections/RedundantSamConstructorInspection.kt | 3 ++- .../redundantSamConstructor/simple.1.java | 7 +++++++ .../inspectionsLocal/redundantSamConstructor/simple.kt | 5 +++++ .../redundantSamConstructor/simple.kt.after | 5 +++++ .../redundantSamConstructor/simple2.1.java | 7 +++++++ .../redundantSamConstructor/simple2.kt | 6 ++++++ .../idea/inspections/LocalInspectionTestGenerated.java | 10 ++++++++++ 7 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 idea/testData/inspectionsLocal/redundantSamConstructor/simple.1.java create mode 100644 idea/testData/inspectionsLocal/redundantSamConstructor/simple.kt create mode 100644 idea/testData/inspectionsLocal/redundantSamConstructor/simple.kt.after create mode 100644 idea/testData/inspectionsLocal/redundantSamConstructor/simple2.1.java create mode 100644 idea/testData/inspectionsLocal/redundantSamConstructor/simple2.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSamConstructorInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSamConstructorInspection.kt index 2d4aa21ae21..b7ac450d4a4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSamConstructorInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSamConstructorInspection.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.anyDescendantOfType import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext +import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelector import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelectorOrThis import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingTraceContext @@ -51,7 +52,7 @@ class RedundantSamConstructorInspection : AbstractKotlinInspection() { if (single != null) { val calleeExpression = single.calleeExpression ?: return val problemDescriptor = holder.manager.createProblemDescriptor( - single.getQualifiedExpressionForSelectorOrThis(), + single.getQualifiedExpressionForSelector()?.receiverExpression ?: calleeExpression, single.typeArgumentList ?: calleeExpression, "Redundant SAM-constructor", ProblemHighlightType.LIKE_UNUSED_SYMBOL, diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/simple.1.java b/idea/testData/inspectionsLocal/redundantSamConstructor/simple.1.java new file mode 100644 index 00000000000..2411bf2927d --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/simple.1.java @@ -0,0 +1,7 @@ +public interface Foo { + boolean foo(); + + class Bar { + void bar(Foo foo) {} + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/simple.kt b/idea/testData/inspectionsLocal/redundantSamConstructor/simple.kt new file mode 100644 index 00000000000..53a38f2a6e8 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/simple.kt @@ -0,0 +1,5 @@ +fun test() { + Foo.Bar().bar(Foo { + true + }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/simple.kt.after b/idea/testData/inspectionsLocal/redundantSamConstructor/simple.kt.after new file mode 100644 index 00000000000..cb36a0a8b58 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/simple.kt.after @@ -0,0 +1,5 @@ +fun test() { + Foo.Bar().bar({ + true + }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/simple2.1.java b/idea/testData/inspectionsLocal/redundantSamConstructor/simple2.1.java new file mode 100644 index 00000000000..2411bf2927d --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/simple2.1.java @@ -0,0 +1,7 @@ +public interface Foo { + boolean foo(); + + class Bar { + void bar(Foo foo) {} + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantSamConstructor/simple2.kt b/idea/testData/inspectionsLocal/redundantSamConstructor/simple2.kt new file mode 100644 index 00000000000..0f36ec713ff --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSamConstructor/simple2.kt @@ -0,0 +1,6 @@ +// PROBLEM: none +fun test() { + Foo.Bar().bar(Foo { + true + }) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 664deee1f1c..da204c23b92 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -4221,6 +4221,16 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { public void testNestedInterface() throws Exception { runTest("idea/testData/inspectionsLocal/redundantSamConstructor/nestedInterface.kt"); } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantSamConstructor/simple.kt"); + } + + @TestMetadata("simple2.kt") + public void testSimple2() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantSamConstructor/simple2.kt"); + } } @TestMetadata("idea/testData/inspectionsLocal/redundantSemicolon")