"Redundant SAM constructor": Fix highlighting range #KT-27034 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-09-25 11:14:09 +09:00
committed by Mikhail Glukhikh
parent 487f500f85
commit affa881421
7 changed files with 42 additions and 1 deletions
@@ -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,
@@ -0,0 +1,7 @@
public interface Foo {
boolean foo();
class Bar {
void bar(Foo foo) {}
}
}
@@ -0,0 +1,5 @@
fun test() {
Foo.Bar().bar(Foo<caret> {
true
})
}
@@ -0,0 +1,5 @@
fun test() {
Foo.Bar().bar({
true
})
}
@@ -0,0 +1,7 @@
public interface Foo {
boolean foo();
class Bar {
void bar(Foo foo) {}
}
}
@@ -0,0 +1,6 @@
// PROBLEM: none
fun test() {
Foo.Bar().bar(Foo <caret>{
true
})
}
@@ -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")