[AA LC] Map unresolved types according to aliased imports
This commit is contained in:
committed by
Space Team
parent
d5a76a1b3b
commit
36ae901b19
+1
-1
@@ -19,6 +19,6 @@ internal class KtFirJvmTypeMapper(
|
||||
) : KtJvmTypeMapper(), KtFirAnalysisSessionComponent {
|
||||
|
||||
override fun mapTypeToJvmType(type: KtType, mode: TypeMappingMode): Type {
|
||||
return analysisSession.useSiteSession.jvmTypeMapper.mapType(type.coneType, mode, sw = null)
|
||||
return analysisSession.useSiteSession.jvmTypeMapper.mapType(type.coneType, mode, sw = null, unresolvedQualifierRemapper = null)
|
||||
}
|
||||
}
|
||||
|
||||
+13
-2
@@ -20,8 +20,8 @@ import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeMappingMode
|
||||
import org.jetbrains.kotlin.asJava.classes.KtLightClassForFacade
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightElement
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightParameter
|
||||
import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.descriptors.java.JavaVisibilities
|
||||
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.load.kotlin.getOptimalModeForReturnType
|
||||
import org.jetbrains.kotlin.load.kotlin.getOptimalModeForValueParameter
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.psi
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
|
||||
import java.text.StringCharacterIterator
|
||||
@@ -196,7 +197,14 @@ private fun ConeKotlinType.asPsiType(
|
||||
val signatureWriter = BothSignatureWriter(BothSignatureWriter.Mode.SKIP_CHECKS)
|
||||
|
||||
//TODO Check thread safety
|
||||
session.jvmTypeMapper.mapType(this, mode, signatureWriter)
|
||||
session.jvmTypeMapper.mapType(this, mode, signatureWriter) {
|
||||
val containingFile = useSitePosition.containingKtFile
|
||||
// parameters for default setters does not have kotlin origin, but setter has
|
||||
?: (useSitePosition as? KtLightParameter)?.parent?.parent?.containingKtFile
|
||||
?: return@mapType null
|
||||
val correspondingImport = containingFile.findImportByAlias(it) ?: return@mapType null
|
||||
correspondingImport.importPath?.pathStr
|
||||
}
|
||||
|
||||
val canonicalSignature = signatureWriter.toString()
|
||||
require(!canonicalSignature.contains(SpecialNames.ANONYMOUS_STRING))
|
||||
@@ -213,6 +221,9 @@ private fun ConeKotlinType.asPsiType(
|
||||
return typeElement.type
|
||||
}
|
||||
|
||||
private val PsiElement.containingKtFile: KtFile?
|
||||
get() = (this as? KtLightElement<*, *>)?.kotlinOrigin?.containingKtFile
|
||||
|
||||
private class AnonymousTypesSubstitutor(
|
||||
private val session: FirSession,
|
||||
) : AbstractConeSubstitutor(session.typeContext) {
|
||||
|
||||
+6
@@ -258,6 +258,12 @@ public class SymbolLightClassesByPsiForLibraryTestGenerated extends AbstractSymb
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/typeAnnotations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unresolvedWithAliasedImport.kt")
|
||||
public void testUnresolvedWithAliasedImport() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/unresolvedWithAliasedImport.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("wildcardOptimization.kt")
|
||||
public void testWildcardOptimization() throws Exception {
|
||||
|
||||
+6
@@ -258,6 +258,12 @@ public class SymbolLightClassesByPsiForSourceTestGenerated extends AbstractSymbo
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/typeAnnotations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unresolvedWithAliasedImport.kt")
|
||||
public void testUnresolvedWithAliasedImport() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/unresolvedWithAliasedImport.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("wildcardOptimization.kt")
|
||||
public void testWildcardOptimization() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user