KTIJ-28385 [AA] Support SAM constructors in computeImportableName

This allows to properly report them as used in `KtFirImportOptimizer`

This change will also be important for properly fixing KTIJ-28167,
since `computeImportableName` is also used in reference shortener

^KTIJ-28385 Fixed
This commit is contained in:
Roman Golyshev
2024-01-04 00:56:58 +01:00
committed by Space Team
parent 9ec469e3c3
commit 31291fc8fa
7 changed files with 69 additions and 0 deletions
@@ -57,6 +57,9 @@ internal fun KtTypeNullability.toConeNullability() = when (this) {
internal fun FirCallableSymbol<*>.computeImportableName(useSiteSession: FirSession): FqName? {
if (callableId.isLocal) return null
// SAM constructors are synthetic, but can be imported
if (origin is FirDeclarationOrigin.SamConstructor) return callableId.asSingleFqName()
// if classId == null, callable is topLevel
val containingClassId = callableId.classId
?: return callableId.asSingleFqName()
@@ -232,6 +232,18 @@ public class FirIdeNormalAnalysisSourceModuleAnalysisApiImportOptimizerTestGener
runTest("analysis/analysis-api/testData/components/importOptimizer/analyseImports/usedInvokeOperatorImport.kt");
}
@Test
@TestMetadata("usedNestedSamInterface_constructorCall.kt")
public void testUsedNestedSamInterface_constructorCall() throws Exception {
runTest("analysis/analysis-api/testData/components/importOptimizer/analyseImports/usedNestedSamInterface_constructorCall.kt");
}
@Test
@TestMetadata("usedNestedSamInterface_constructorReference.kt")
public void testUsedNestedSamInterface_constructorReference() throws Exception {
runTest("analysis/analysis-api/testData/components/importOptimizer/analyseImports/usedNestedSamInterface_constructorReference.kt");
}
@Test
@TestMetadata("usedObject_invokeOperator.kt")
public void testUsedObject_invokeOperator() throws Exception {
@@ -232,6 +232,18 @@ public class FirStandaloneNormalAnalysisSourceModuleAnalysisApiImportOptimizerTe
runTest("analysis/analysis-api/testData/components/importOptimizer/analyseImports/usedInvokeOperatorImport.kt");
}
@Test
@TestMetadata("usedNestedSamInterface_constructorCall.kt")
public void testUsedNestedSamInterface_constructorCall() throws Exception {
runTest("analysis/analysis-api/testData/components/importOptimizer/analyseImports/usedNestedSamInterface_constructorCall.kt");
}
@Test
@TestMetadata("usedNestedSamInterface_constructorReference.kt")
public void testUsedNestedSamInterface_constructorReference() throws Exception {
runTest("analysis/analysis-api/testData/components/importOptimizer/analyseImports/usedNestedSamInterface_constructorReference.kt");
}
@Test
@TestMetadata("usedObject_invokeOperator.kt")
public void testUsedObject_invokeOperator() throws Exception {
@@ -0,0 +1,6 @@
USED DECLARATIONS:
Declaration: dependency.Outer.NestedSAM
By names: [NestedSAM]
UNRESOLVED NAMES:
@@ -0,0 +1,15 @@
// FILE: main.kt
package test
import dependency.Outer.NestedSAM
val handler = NestedSAM {}
// FILE: dependency.kt
package dependency
class Outer {
fun interface NestedSAM {
fun method()
}
}
@@ -0,0 +1,6 @@
USED DECLARATIONS:
Declaration: dependency.Outer.NestedSAM
By names: [NestedSAM]
UNRESOLVED NAMES:
@@ -0,0 +1,15 @@
// FILE: main.kt
package test
import dependency.Outer.NestedSAM
val handler = ::NestedSAM
// FILE: dependency.kt
package dependency
class Outer {
fun interface NestedSAM {
fun method()
}
}