Fix false positive 'Remove redundant qualifier name' for property

#KT-31112 Fixed
This commit is contained in:
Dmitry Gridin
2019-04-19 11:07:39 +07:00
parent 673b54554c
commit 3838976083
5 changed files with 46 additions and 1 deletions
@@ -59,7 +59,7 @@ class RemoveRedundantQualifierNameInspection : AbstractKotlinInspection(), Clean
}
private tailrec fun KtDotQualifiedExpression.firstExpressionWithoutReceiver(): KtDotQualifiedExpression? =
if ((getQualifiedElementSelector()?.mainReference?.resolve() as? KtFunction)?.receiverTypeReference == null) this
if ((getQualifiedElementSelector()?.mainReference?.resolve() as? KtCallableDeclaration)?.receiverTypeReference == null) this
else (receiverExpression as? KtDotQualifiedExpression)?.firstExpressionWithoutReceiver()
private tailrec fun <T : KtElement> T.firstApplicableExpression(validator: T.() -> T?, generator: T.() -> T?): T? =
@@ -0,0 +1,11 @@
package inspector.p30879
import inspector.p30879.C.G
val <T> T.letVar: Int; get() = 0
fun test() {
C<caret>.G.letVar
}
class B { object G }
class C { object G }
@@ -0,0 +1,11 @@
package inspector.p30879
import inspector.p30879.C.G
val <T> T.letVar: Int; get() = 0
fun test() {
G.letVar
}
class B { object G }
class C { object G }
@@ -0,0 +1,13 @@
// PROBLEM: none
package inspector.p30879
import inspector.p30879.B.G
val <T> T.letVar: Int; get() = 0
fun test() {
C<caret>.G.letVar
}
class B { object G }
class C { object G }
@@ -6275,6 +6275,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/asReceiver.kt");
}
@TestMetadata("asReceiverProperty.kt")
public void testAsReceiverProperty() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/asReceiverProperty.kt");
}
@TestMetadata("companionCollision.kt")
public void testCompanionCollision() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/companionCollision.kt");
@@ -6400,6 +6405,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableAsReceiver.kt");
}
@TestMetadata("notApplicableAsReceiverProperty.kt")
public void testNotApplicableAsReceiverProperty() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableAsReceiverProperty.kt");
}
@TestMetadata("notApplicableCollisionTopLevelClass.kt")
public void testNotApplicableCollisionTopLevelClass() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCollisionTopLevelClass.kt");