KTIJ-26713 [AA] Handle FirFunctionTypeParameter in KtFirReferenceShortener

^KTIJ-26713 Fixed
This commit is contained in:
Roman Golyshev
2023-08-21 11:52:35 +02:00
committed by teamcity
parent 830084a678
commit 24a13348c4
5 changed files with 31 additions and 2 deletions
@@ -85,7 +85,7 @@ internal class KtFirReferenceShortener(
val declarationToVisit = file.findSmallestElementOfTypeContainingSelection<KtDeclaration>(selection) val declarationToVisit = file.findSmallestElementOfTypeContainingSelection<KtDeclaration>(selection)
?: file ?: file
val firDeclaration = declarationToVisit.getCorrespondingFirDeclaration() ?: return ShortenCommandImpl( val firDeclaration = declarationToVisit.getCorrespondingFirElement() ?: return ShortenCommandImpl(
file.createSmartPointer(), file.createSmartPointer(),
importsToAdd = emptySet(), importsToAdd = emptySet(),
starImportsToAdd = emptySet(), starImportsToAdd = emptySet(),
@@ -140,7 +140,7 @@ internal class KtFirReferenceShortener(
) )
} }
private fun KtElement.getCorrespondingFirDeclaration(): FirDeclaration? { private fun KtElement.getCorrespondingFirElement(): FirElement? {
require(this is KtFile || this is KtDeclaration) require(this is KtFile || this is KtDeclaration)
val firElement = getOrBuildFir(firResolveSession) val firElement = getOrBuildFir(firResolveSession)
@@ -148,6 +148,7 @@ internal class KtFirReferenceShortener(
return when (firElement) { return when (firElement) {
is FirDeclaration -> firElement is FirDeclaration -> firElement
is FirAnonymousFunctionExpression -> firElement.anonymousFunction is FirAnonymousFunctionExpression -> firElement.anonymousFunction
is FirFunctionTypeParameter -> firElement
else -> null else -> null
} }
} }
@@ -274,6 +274,12 @@ public class FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated ext
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/extensionProperty_objectReceiverWithOtherThisInScope.kt"); runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/extensionProperty_objectReceiverWithOtherThisInScope.kt");
} }
@Test
@TestMetadata("functionalType_parameterPosition.kt")
public void testFunctionalType_parameterPosition() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/functionalType_parameterPosition.kt");
}
@Test @Test
@TestMetadata("kdoc.kt") @TestMetadata("kdoc.kt")
public void testKdoc() throws Exception { public void testKdoc() throws Exception {
@@ -274,6 +274,12 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenera
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/extensionProperty_objectReceiverWithOtherThisInScope.kt"); runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/extensionProperty_objectReceiverWithOtherThisInScope.kt");
} }
@Test
@TestMetadata("functionalType_parameterPosition.kt")
public void testFunctionalType_parameterPosition() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/functionalType_parameterPosition.kt");
}
@Test @Test
@TestMetadata("kdoc.kt") @TestMetadata("kdoc.kt")
public void testKdoc() throws Exception { public void testKdoc() throws Exception {
@@ -0,0 +1,9 @@
// FILE: main.kt
package test
fun take(action: (<expr>dependency.Foo</expr>) -> Unit) {}
// FILE: dependency.kt
package dependency
class Foo
@@ -0,0 +1,7 @@
Before shortening: dependency.Foo
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT:
[type] dependency.Foo
with SHORTEN_AND_STAR_IMPORT:
[type] dependency.Foo