FIR IDE: Do not try to shorten type without qualifier

This commit is contained in:
Roman Golyshev
2020-12-25 13:50:18 +03:00
committed by Space
parent 534f4a66ad
commit 0e271b72c7
4 changed files with 30 additions and 2 deletions
@@ -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");
@@ -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)
}
}
}
@@ -0,0 +1,8 @@
// FIR_COMPARISON
package test
class T {
class TT
}
<selection>fun foo(t: T.TT) {}</selection>
@@ -0,0 +1,8 @@
// FIR_COMPARISON
package test
class T {
class TT
}
fun foo(t: T.TT) {}