Redundant qualifier name: fix false positive with same name variable

#KT-39200 Fixed
This commit is contained in:
Toshiaki Kameyama
2020-06-18 12:52:40 +09:00
committed by Dmitry Gridin
parent bf26d87ee9
commit ba5e643cb2
4 changed files with 28 additions and 0 deletions
@@ -61,6 +61,7 @@ class RemoveRedundantQualifierNameInspection : AbstractKotlinInspection(), Clean
val expressionParent = expression.parent val expressionParent = expression.parent
if (expressionParent is KtDotQualifiedExpression || expressionParent is KtPackageDirective || expressionParent is KtImportDirective) return if (expressionParent is KtDotQualifiedExpression || expressionParent is KtPackageDirective || expressionParent is KtImportDirective) return
val expressionForAnalyze = expression.firstExpressionWithoutReceiver() ?: return val expressionForAnalyze = expression.firstExpressionWithoutReceiver() ?: return
if (expressionForAnalyze.selectorExpression?.text == expressionParent.getNonStrictParentOfType<KtProperty>()?.name) return
val originalExpression: KtExpression = expressionForAnalyze.parent as? KtClassLiteralExpression ?: expressionForAnalyze val originalExpression: KtExpression = expressionForAnalyze.parent as? KtClassLiteralExpression ?: expressionForAnalyze
@@ -0,0 +1,8 @@
// PROBLEM: none
sealed class Foo {
object BAR : Foo()
companion object {
val BAR: Foo = <caret>Foo.BAR
}
}
@@ -0,0 +1,9 @@
// PROBLEM: none
// WITH_RUNTIME
sealed class Foo {
object BAR : Foo()
companion object {
val BAR: Foo by lazy { <caret>Foo.BAR }
}
}
@@ -9521,6 +9521,16 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableOuterClass.kt"); runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableOuterClass.kt");
} }
@TestMetadata("notApplicableSameNameVariable.kt")
public void testNotApplicableSameNameVariable() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableSameNameVariable.kt");
}
@TestMetadata("notApplicableSameNameVariable2.kt")
public void testNotApplicableSameNameVariable2() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableSameNameVariable2.kt");
}
@TestMetadata("notApplicableThis.kt") @TestMetadata("notApplicableThis.kt")
public void testNotApplicableThis() throws Exception { public void testNotApplicableThis() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableThis.kt"); runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableThis.kt");