FIR IDE: Unwrap nullable types
This commit is contained in:
+5
@@ -96,6 +96,11 @@ public class FirShortenRefsTestGenerated extends AbstractFirShortenRefsTest {
|
||||
runTest("idea/testData/shortenRefsFir/types/ParameterTypeNotImportedNestedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ParameterTypeNullableType.kt")
|
||||
public void testParameterTypeNullableType() throws Exception {
|
||||
runTest("idea/testData/shortenRefsFir/types/ParameterTypeNullableType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ParameterTypeStarImportedTypeLoses.kt")
|
||||
public void testParameterTypeStarImportedTypeLoses() throws Exception {
|
||||
runTest("idea/testData/shortenRefsFir/types/ParameterTypeStarImportedTypeLoses.kt");
|
||||
|
||||
+9
-2
@@ -53,7 +53,11 @@ internal class KtFirReferenceShortener(
|
||||
|
||||
firFile.acceptChildren(TypesCollectingVisitor(typesToImport, typesToShorten))
|
||||
|
||||
return ShortenCommandImpl(file, typesToImport, typesToShorten.map { it.createSmartPointer() })
|
||||
return ShortenCommandImpl(
|
||||
file,
|
||||
typesToImport.distinct(),
|
||||
typesToShorten.distinct().map { it.createSmartPointer() }
|
||||
)
|
||||
}
|
||||
|
||||
private fun findFirstClassifierInScopesByName(positionScopes: List<FirScope>, targetClassName: Name): ClassId? {
|
||||
@@ -134,7 +138,7 @@ internal class KtFirReferenceShortener(
|
||||
val wholeTypeReference = resolvedTypeRef.psi as? KtTypeReference ?: return
|
||||
|
||||
val wholeClassifierId = resolvedTypeRef.type.classId ?: return
|
||||
val wholeTypeElement = wholeTypeReference.typeElement as? KtUserType ?: return
|
||||
val wholeTypeElement = wholeTypeReference.typeElement.unwrapNullable() as? KtUserType ?: return
|
||||
|
||||
if (wholeTypeElement.qualifier == null) return
|
||||
|
||||
@@ -197,3 +201,6 @@ private class ShortenCommandImpl(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private tailrec fun KtTypeElement?.unwrapNullable(): KtTypeElement? =
|
||||
if (this is KtNullableType) this.innerType.unwrapNullable() else this
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// FIR_COMPARISON
|
||||
package test
|
||||
|
||||
class T
|
||||
|
||||
<selection>fun foo(t: test.T???) {}</selection>
|
||||
@@ -0,0 +1,6 @@
|
||||
// FIR_COMPARISON
|
||||
package test
|
||||
|
||||
class T
|
||||
|
||||
fun foo(t: T???) {}
|
||||
Reference in New Issue
Block a user