diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/shortenRefs/FirShortenRefsTestGenerated.java b/idea/idea-fir/tests/org/jetbrains/kotlin/shortenRefs/FirShortenRefsTestGenerated.java index c6e8e608fb5..dfd16ca314a 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/shortenRefs/FirShortenRefsTestGenerated.java +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/shortenRefs/FirShortenRefsTestGenerated.java @@ -144,6 +144,11 @@ public class FirShortenRefsTestGenerated extends AbstractFirShortenRefsTest { runTest("idea/testData/shortenRefsFir/types/ParameterTypeNestedType.kt"); } + @TestMetadata("ParameterTypeNestedTypeWithoutPackageNotShorten.kt") + public void testParameterTypeNestedTypeWithoutPackageNotShorten() throws Exception { + runTest("idea/testData/shortenRefsFir/types/ParameterTypeNestedTypeWithoutPackageNotShorten.kt"); + } + @TestMetadata("ParameterTypeNonImportedClass.kt") public void testParameterTypeNonImportedClass() throws Exception { runTest("idea/testData/shortenRefsFir/types/ParameterTypeNonImportedClass.kt"); diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirReferenceShortener.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirReferenceShortener.kt index 5a58e7ac80a..c1520243ac8 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirReferenceShortener.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirReferenceShortener.kt @@ -185,6 +185,9 @@ internal class KtFirReferenceShortener( val positionScopes = findScopesAtPosition(wholeTypeElement, namesToImport) ?: return for ((classId, typeElement) in allClassIds.zip(allTypeElements)) { + // if qualifier is null, then this type have no package and thus cannot be shortened + if (typeElement.qualifier == null) return + val firstFoundClass = findFirstClassifierInScopesByName(positionScopes, classId.shortClassName)?.classId if (firstFoundClass == classId) { @@ -234,7 +237,7 @@ internal class KtFirReferenceShortener( val singleAvailableProperty = findSinglePropertyInScopesByName(scopes, propertyId.callableName) if (singleAvailableProperty?.callableId == propertyId) { - callsToShorten.add(qualifiedProperty) + addElementToShorten(qualifiedProperty) } } @@ -251,9 +254,13 @@ internal class KtFirReferenceShortener( val singleAvailableCallable = findSingleFunctionInScopesByName(scopes, callableId.callableName) if (singleAvailableCallable?.callableId == callableId) { - callsToShorten.add(qualifiedCallExpression) + addElementToShorten(qualifiedCallExpression) } } + + private fun addElementToShorten(element: KtDotQualifiedExpression) { + callsToShorten.add(element) + } } } diff --git a/idea/testData/shortenRefsFir/types/ParameterTypeNestedTypeWithoutPackageNotShorten.kt b/idea/testData/shortenRefsFir/types/ParameterTypeNestedTypeWithoutPackageNotShorten.kt new file mode 100644 index 00000000000..001e3180f67 --- /dev/null +++ b/idea/testData/shortenRefsFir/types/ParameterTypeNestedTypeWithoutPackageNotShorten.kt @@ -0,0 +1,8 @@ +// FIR_COMPARISON +package test + +class T { + class TT +} + +fun foo(t: T.TT) {} diff --git a/idea/testData/shortenRefsFir/types/ParameterTypeNestedTypeWithoutPackageNotShorten.kt.after b/idea/testData/shortenRefsFir/types/ParameterTypeNestedTypeWithoutPackageNotShorten.kt.after new file mode 100644 index 00000000000..55547c490bc --- /dev/null +++ b/idea/testData/shortenRefsFir/types/ParameterTypeNestedTypeWithoutPackageNotShorten.kt.after @@ -0,0 +1,8 @@ +// FIR_COMPARISON +package test + +class T { + class TT +} + +fun foo(t: T.TT) {}