diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantQualifierNameInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantQualifierNameInspection.kt index 4ed92250ef0..862332d0233 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantQualifierNameInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantQualifierNameInspection.kt @@ -9,6 +9,7 @@ import com.intellij.codeInspection.* import com.intellij.openapi.project.Project import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElementVisitor +import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.idea.analysis.analyzeAsReplacement import org.jetbrains.kotlin.idea.caches.resolve.analyze @@ -16,6 +17,7 @@ import org.jetbrains.kotlin.idea.core.ShortenReferences import org.jetbrains.kotlin.idea.core.compareDescriptors import org.jetbrains.kotlin.idea.imports.importableFqName import org.jetbrains.kotlin.idea.references.mainReference +import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor import org.jetbrains.kotlin.idea.util.getResolutionScope import org.jetbrains.kotlin.idea.util.hasNotReceiver import org.jetbrains.kotlin.incremental.components.NoLookupLocation @@ -128,6 +130,11 @@ private fun KtUserType.applicableExpression(context: BindingContext): KtUserType val referenceExpression = referenceExpression as? KtNameReferenceExpression ?: return null val originalDescriptor = referenceExpression.mainReference.resolveToDescriptors(context).firstOrNull() ?: return null + if (originalDescriptor is ClassDescriptor + && originalDescriptor.isInner + && (originalDescriptor.containingDeclaration as? ClassDescriptor)?.typeConstructor != null + ) return null + val shortName = originalDescriptor.importableFqName?.shortName() ?: return null val scope = referenceExpression.getResolutionScope(context) ?: return null val descriptor = scope.findFirstClassifierWithDeprecationStatus(shortName, NoLookupLocation.FROM_IDE)?.descriptor ?: return null diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass.kt new file mode 100644 index 00000000000..e6852edcf07 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass.kt @@ -0,0 +1,4 @@ +// PROBLEM: none +class Outer(val inner: Outer.Inner? = null) { + inner class Inner +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass2.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass2.kt new file mode 100644 index 00000000000..9dbb9c705e2 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass2.kt @@ -0,0 +1,8 @@ +// PROBLEM: none +interface Inv + +class Outer { + inner class Inner + + class Nested : Inv<Outer.Inner> +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass3.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass3.kt new file mode 100644 index 00000000000..3750079a7ac --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass3.kt @@ -0,0 +1,8 @@ +// PROBLEM: none +class Outer { + inner class Inner + + class Nested { + fun bar(x: Outer.Inner) {} + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass4.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass4.kt new file mode 100644 index 00000000000..80d270a383e --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass4.kt @@ -0,0 +1,7 @@ +// PROBLEM: none +class Outer() { + inner class Inner + + fun test(inner: Outer.Inner?) { + } +} \ 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 6f119e89dfe..36cdbba2860 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -8464,6 +8464,26 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableExpression4.kt"); } + @TestMetadata("notApplicableInnerClassInGenericOuterClass.kt") + public void testNotApplicableInnerClassInGenericOuterClass() throws Exception { + runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass.kt"); + } + + @TestMetadata("notApplicableInnerClassInGenericOuterClass2.kt") + public void testNotApplicableInnerClassInGenericOuterClass2() throws Exception { + runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass2.kt"); + } + + @TestMetadata("notApplicableInnerClassInGenericOuterClass3.kt") + public void testNotApplicableInnerClassInGenericOuterClass3() throws Exception { + runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass3.kt"); + } + + @TestMetadata("notApplicableInnerClassInGenericOuterClass4.kt") + public void testNotApplicableInnerClassInGenericOuterClass4() throws Exception { + runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableInnerClassInGenericOuterClass4.kt"); + } + @TestMetadata("notApplicableLocalFun.kt") public void testNotApplicableLocalFun() throws Exception { runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableLocalFun.kt");